2024-01-03 21:57:33 +00:00
|
|
|
// DEPRECATED: mplex has been deprecated. Users should prefer Yamux over mplex. see https://github.com/libp2p/specs/issues/553
|
|
|
|
// for details
|
2022-08-19 16:34:07 +00:00
|
|
|
package mplex
|
2021-06-16 20:19:45 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
|
2022-11-04 13:57:20 +00:00
|
|
|
"github.com/libp2p/go-libp2p/core/network"
|
2021-06-16 20:19:45 +00:00
|
|
|
|
|
|
|
mp "github.com/libp2p/go-mplex"
|
|
|
|
)
|
|
|
|
|
|
|
|
// DefaultTransport has default settings for Transport
|
|
|
|
var DefaultTransport = &Transport{}
|
|
|
|
|
2023-02-22 21:58:17 +00:00
|
|
|
const ID = "/mplex/6.7.0"
|
|
|
|
|
2022-04-01 16:16:46 +00:00
|
|
|
var _ network.Multiplexer = &Transport{}
|
|
|
|
|
2021-06-16 20:19:45 +00:00
|
|
|
// Transport implements mux.Multiplexer that constructs
|
|
|
|
// mplex-backed muxed connections.
|
|
|
|
type Transport struct{}
|
|
|
|
|
2022-04-01 16:16:46 +00:00
|
|
|
func (t *Transport) NewConn(nc net.Conn, isServer bool, scope network.PeerScope) (network.MuxedConn, error) {
|
|
|
|
m, err := mp.NewMultiplex(nc, isServer, scope)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-08-19 16:34:07 +00:00
|
|
|
return NewMuxedConn(m), nil
|
2021-06-16 20:19:45 +00:00
|
|
|
}
|