p2p: NewMultiplexTransport takes an MConnConfig (#2869)

* p2p: NewMultiplexTransport takes an MConnConfig

* changelog

* move test func to test file
This commit is contained in:
Ethan Buchman
2018-11-17 03:16:49 -05:00
committed by GitHub
parent e6fc10faf6
commit 6168b404a7
7 changed files with 42 additions and 32 deletions

View File

@ -27,6 +27,17 @@ const (
reconnectBackOffBaseSeconds = 3
)
// MConnConfig returns an MConnConfig with fields updated
// from the P2PConfig.
func MConnConfig(cfg *config.P2PConfig) conn.MConnConfig {
mConfig := conn.DefaultMConnConfig()
mConfig.FlushThrottle = cfg.FlushThrottleTimeout
mConfig.SendRate = cfg.SendRate
mConfig.RecvRate = cfg.RecvRate
mConfig.MaxPacketMsgPayloadSize = cfg.MaxPacketMsgPayloadSize
return mConfig
}
//-----------------------------------------------------------------------------
// An AddrBook represents an address book from the pex package, which is used
@ -70,8 +81,6 @@ type Switch struct {
filterTimeout time.Duration
peerFilters []PeerFilterFunc
mConfig conn.MConnConfig
rng *cmn.Rand // seed for randomizing dial times and orders
metrics *Metrics
@ -102,14 +111,6 @@ func NewSwitch(
// Ensure we have a completely undeterministic PRNG.
sw.rng = cmn.NewRand()
mConfig := conn.DefaultMConnConfig()
mConfig.FlushThrottle = cfg.FlushThrottleTimeout
mConfig.SendRate = cfg.SendRate
mConfig.RecvRate = cfg.RecvRate
mConfig.MaxPacketMsgPayloadSize = cfg.MaxPacketMsgPayloadSize
sw.mConfig = mConfig
sw.BaseService = *cmn.NewBaseService(nil, "P2P Switch", sw)
for _, option := range options {