// Mount mounts a fuse fs.FS at a given location, and returns a Mount instance. // parent is a ContextGroup to bind the mount's ContextGroup to. func NewMount(p goprocess.Process, fsys fs.FS, mountpoint string, allow_other bool) (Mount, error) { var conn *fuse.Conn var err error if allow_other { conn, err = fuse.Mount(mountpoint, fuse.AllowOther()) } else { conn, err = fuse.Mount(mountpoint) } if err != nil { return nil, err } m := &mount{ mpoint: mountpoint, fuseConn: conn, filesys: fsys, proc: goprocess.WithParent(p), // link it to parent. } m.proc.SetTeardown(m.unmount) // launch the mounting process. if err := m.mount(); err != nil { m.Unmount() // just in case. return nil, err } return m, nil }
func newNAT(realNAT nat.NAT) *NAT { return &NAT{ nat: realNAT, proc: goprocess.WithParent(goprocess.Background()), mappings: make(map[*mapping]struct{}), } }
func newQueryRunner(q *dhtQuery) *dhtQueryRunner { proc := process.WithParent(process.Background()) ctx := ctxproc.OnClosingContext(proc) return &dhtQueryRunner{ query: q, peersToQuery: queue.NewChanQueue(ctx, queue.NewXORDistancePQ(q.key)), peersRemaining: todoctr.NewSyncCounter(), peersSeen: pset.New(), rateLimit: make(chan struct{}, q.concurrency), proc: proc, } }
func newNatManager(host *BasicHost) *natManager { nmgr := &natManager{ host: host, ready: make(chan struct{}), proc: goprocess.WithParent(host.proc), } // teardown nmgr.proc = goprocess.WithTeardown(func() error { // on closing, unregister from network notifications. host.Network().StopNotify((*nmgrNetNotifiee)(nmgr)) return nil }) // host is our parent. close when host closes. host.proc.AddChild(nmgr.proc) // discover the nat. nmgr.discoverNAT() return nmgr }
func NewRateLimiter(parent process.Process, limit int) *RateLimiter { proc := process.WithParent(parent) return &RateLimiter{Process: proc, limiter: LimitChan(limit)} }
// WithContext constructs and returns a Process that respects // given context. It is the equivalent of: // // func ProcessWithContext(ctx context.Context) goprocess.Process { // p := goprocess.WithParent(goprocess.Background()) // CloseAfterContext(p, ctx) // return p // } // func WithContext(ctx context.Context) goprocess.Process { p := goprocess.WithParent(goprocess.Background()) CloseAfterContext(p, ctx) return p }