Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

muxer: expose func to create MuxedConn from backing Conn #1609

Merged
merged 1 commit into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions p2p/muxer/mplex/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ type conn mp.Multiplex

var _ network.MuxedConn = &conn{}

// NewMuxedConn constructs a new Conn from a *mp.Multiplex.
func NewMuxedConn(m *mp.Multiplex) network.MuxedConn {
return (*conn)(m)
}

func (c *conn) Close() error {
return c.mplex().Close()
}
Expand Down
2 changes: 1 addition & 1 deletion p2p/muxer/mplex/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ func (t *Transport) NewConn(nc net.Conn, isServer bool, scope network.PeerScope)
if err != nil {
return nil, err
}
return (*conn)(m), nil
return NewMuxedConn(m), nil
}
5 changes: 5 additions & 0 deletions p2p/muxer/yamux/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ type conn yamux.Session

var _ network.MuxedConn = &conn{}

// NewMuxedConn constructs a new MuxedConn from a yamux.Session.
func NewMuxedConn(m *yamux.Session) network.MuxedConn {
return (*conn)(m)
}

// Close closes underlying yamux
func (c *conn) Close() error {
return c.yamux().Close()
Expand Down
5 changes: 4 additions & 1 deletion p2p/muxer/yamux/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ func (t *Transport) NewConn(nc net.Conn, isServer bool, scope network.PeerScope)
} else {
s, err = yamux.Client(nc, t.Config(), scope)
}
return (*conn)(s), err
if err != nil {
return nil, err
}
return NewMuxedConn(s), nil
}

func (t *Transport) Config() *yamux.Config {
Expand Down