forked from ckousik/go-libp2p
-
Notifications
You must be signed in to change notification settings - Fork 0
/
transport.go
56 lines (47 loc) · 1.43 KB
/
transport.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package yamux
import (
"io"
"math"
"net"
"github.com/John-LittleBearLabs/go-libp2p/core/network"
"github.com/libp2p/go-yamux/v3"
)
var DefaultTransport *Transport
func init() {
config := yamux.DefaultConfig()
// We've bumped this to 16MiB as this critically limits throughput.
//
// 1MiB means a best case of 10MiB/s (83.89Mbps) on a connection with
// 100ms latency. The default gave us 2.4MiB *best case* which was
// totally unacceptable.
config.MaxStreamWindowSize = uint32(16 * 1024 * 1024)
// don't spam
config.LogOutput = io.Discard
// We always run over a security transport that buffers internally
// (i.e., uses a block cipher).
config.ReadBufSize = 0
// Effectively disable the incoming streams limit.
// This is now dynamically limited by the resource manager.
config.MaxIncomingStreams = math.MaxUint32
DefaultTransport = (*Transport)(config)
}
// Transport implements mux.Multiplexer that constructs
// yamux-backed muxed connections.
type Transport yamux.Config
var _ network.Multiplexer = &Transport{}
func (t *Transport) NewConn(nc net.Conn, isServer bool, scope network.PeerScope) (network.MuxedConn, error) {
var s *yamux.Session
var err error
if isServer {
s, err = yamux.Server(nc, t.Config(), scope)
} else {
s, err = yamux.Client(nc, t.Config(), scope)
}
if err != nil {
return nil, err
}
return NewMuxedConn(s), nil
}
func (t *Transport) Config() *yamux.Config {
return (*yamux.Config)(t)
}