func newCtlFile(name string, permissions qp.FileMode, user, group string, conn *conn) *ctlFile { return &ctlFile{ SyntheticFile: trees.NewSyntheticFile(name, permissions, user, group), mconn: conn, } }
func (h *TCPUDPHandler) new(c net.Conn) (trees.File, error) { curcnt := h.cnt h.cnt++ conn := &conn{state: "Closed", network: h.network, conn: c} if c != nil { conn.state = "Established" } dir := trees.NewSyntheticDir(fmt.Sprintf("%d", curcnt), 0777, h.user, h.group) h.root.Add(fmt.Sprintf("%d", curcnt), dir) ctlfile := newCtlFile("ctl", 0777, h.user, h.group, conn) ctlfile.response([]byte(fmt.Sprintf("%d", curcnt))) dir.Add("ctl", newOpenCounterFile(ctlfile, conn.own, conn.disown)) datafile := newDataFile("data", 0777, h.user, h.group, conn) dir.Add("data", newOpenCounterFile(datafile, conn.own, conn.disown)) localfile := NewMagicWalkFile("local", 0555, h.user, h.group, func(string) (trees.File, error) { // BUG(kl): Refresh requires walking to the file! var cnt []byte if conn.conn != nil { y := conn.conn.LocalAddr().String() cnt = []byte(strings.Replace(y, ":", "!", 1)) } x := trees.NewSyntheticFile("local", 0555, h.user, h.group) x.SetContent(cnt) return newOpenCounterFile(x, conn.own, conn.disown), nil }) dir.Add("local", localfile) remotefile := NewMagicWalkFile("remote", 0555, h.user, h.group, func(string) (trees.File, error) { // BUG(kl): Refresh requires walking to the file! var cnt []byte if conn.conn != nil { y := conn.conn.RemoteAddr().String() cnt = []byte(strings.Replace(y, ":", "!", 1)) } x := trees.NewSyntheticFile("remote", 0555, h.user, h.group) x.SetContent(cnt) return newOpenCounterFile(x, conn.own, conn.disown), nil }) dir.Add("remote", remotefile) statusfile := NewMagicWalkFile("status", 0555, h.user, h.group, func(string) (trees.File, error) { // BUG(kl): Refresh requires walking to the file! x := trees.NewSyntheticFile("status", 0555, h.user, h.group) x.SetContent([]byte(fmt.Sprintf("%s\n", conn.getState()))) return newOpenCounterFile(x, conn.own, conn.disown), nil }) dir.Add("status", statusfile) listenfile := NewMagicWalkFile("listen", 0777, h.user, h.group, func(string) (trees.File, error) { c, err := conn.listen() if err != nil { return nil, err } return h.new(c) }) dir.Add("listen", listenfile) return ctlfile, nil }
func NewMagicWalkFile(name string, permissions qp.FileMode, user, group string, hook func(user string) (trees.File, error)) *MagicWalkFile { return &MagicWalkFile{ SyntheticFile: trees.NewSyntheticFile(name, permissions, user, group), MagicWalkHook: hook, } }
func NewCSFile(user, group string) trees.File { return &csFile{ SyntheticFile: trees.NewSyntheticFile("cs", 0777, user, group), } }