func NewTransport() smux.Transport { mux := mss.NewMultistreamMuxer() mux.AddHandler("/multiplex", nil) mux.AddHandler("/spdystream", nil) mux.AddHandler("/yamux", nil) tpts := map[string]smux.Transport{ "/multiplex": multiplex.DefaultTransport, "/spdystream": spdy.Transport, "/yamux": yamux.DefaultTransport, } return &transport{ mux: mux, tpts: tpts, } }
// New constructs and sets up a new *BasicHost with given Network func New(net inet.Network, opts ...interface{}) *BasicHost { h := &BasicHost{ network: net, mux: msmux.NewMultistreamMuxer(), bwc: metrics.NewBandwidthCounter(), } h.proc = goprocess.WithTeardown(func() error { if h.natmgr != nil { h.natmgr.Close() } return h.Network().Close() }) // setup host services h.ids = identify.NewIDService(h) muxh := h.Mux().Handle handle := func(s inet.Stream) { muxh(s) } h.relay = relay.NewRelayService(h, handle) for _, o := range opts { switch o := o.(type) { case Option: switch o { case NATPortMap: h.natmgr = newNatManager(h) } case metrics.Reporter: h.bwc = o } } net.SetConnHandler(h.newConnHandler) net.SetStreamHandler(h.newStreamHandler) return h }