mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-25 06:42:16 +00:00
p2p: NewMultiplexTransport takes an MConnConfig (#2869)
* p2p: NewMultiplexTransport takes an MConnConfig * changelog * move test func to test file
This commit is contained in:
parent
e6fc10faf6
commit
6168b404a7
@ -39,3 +39,5 @@ program](https://hackerone.com/tendermint).
|
|||||||
- [p2p] \#2857 "Send failed" is logged at debug level instead of error.
|
- [p2p] \#2857 "Send failed" is logged at debug level instead of error.
|
||||||
|
|
||||||
### BUG FIXES:
|
### BUG FIXES:
|
||||||
|
|
||||||
|
- [p2p] \#2869 Set connection config properly instead of always using default
|
||||||
|
@ -371,7 +371,8 @@ func NewNode(config *cfg.Config,
|
|||||||
|
|
||||||
// Setup Transport.
|
// Setup Transport.
|
||||||
var (
|
var (
|
||||||
transport = p2p.NewMultiplexTransport(nodeInfo, *nodeKey)
|
mConnConfig = p2p.MConnConfig(config.P2P)
|
||||||
|
transport = p2p.NewMultiplexTransport(nodeInfo, *nodeKey, mConnConfig)
|
||||||
connFilters = []p2p.ConnFilterFunc{}
|
connFilters = []p2p.ConnFilterFunc{}
|
||||||
peerFilters = []p2p.PeerFilterFunc{}
|
peerFilters = []p2p.PeerFilterFunc{}
|
||||||
)
|
)
|
||||||
|
@ -8,7 +8,6 @@ import (
|
|||||||
cmn "github.com/tendermint/tendermint/libs/common"
|
cmn "github.com/tendermint/tendermint/libs/common"
|
||||||
"github.com/tendermint/tendermint/libs/log"
|
"github.com/tendermint/tendermint/libs/log"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/config"
|
|
||||||
tmconn "github.com/tendermint/tendermint/p2p/conn"
|
tmconn "github.com/tendermint/tendermint/p2p/conn"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -42,7 +41,6 @@ type Peer interface {
|
|||||||
type peerConn struct {
|
type peerConn struct {
|
||||||
outbound bool
|
outbound bool
|
||||||
persistent bool
|
persistent bool
|
||||||
config *config.P2PConfig
|
|
||||||
conn net.Conn // source connection
|
conn net.Conn // source connection
|
||||||
|
|
||||||
originalAddr *NetAddress // nil for inbound connections
|
originalAddr *NetAddress // nil for inbound connections
|
||||||
@ -53,7 +51,6 @@ type peerConn struct {
|
|||||||
|
|
||||||
func newPeerConn(
|
func newPeerConn(
|
||||||
outbound, persistent bool,
|
outbound, persistent bool,
|
||||||
config *config.P2PConfig,
|
|
||||||
conn net.Conn,
|
conn net.Conn,
|
||||||
originalAddr *NetAddress,
|
originalAddr *NetAddress,
|
||||||
) peerConn {
|
) peerConn {
|
||||||
@ -61,7 +58,6 @@ func newPeerConn(
|
|||||||
return peerConn{
|
return peerConn{
|
||||||
outbound: outbound,
|
outbound: outbound,
|
||||||
persistent: persistent,
|
persistent: persistent,
|
||||||
config: config,
|
|
||||||
conn: conn,
|
conn: conn,
|
||||||
originalAddr: originalAddr,
|
originalAddr: originalAddr,
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,17 @@ const (
|
|||||||
reconnectBackOffBaseSeconds = 3
|
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
|
// An AddrBook represents an address book from the pex package, which is used
|
||||||
@ -70,8 +81,6 @@ type Switch struct {
|
|||||||
filterTimeout time.Duration
|
filterTimeout time.Duration
|
||||||
peerFilters []PeerFilterFunc
|
peerFilters []PeerFilterFunc
|
||||||
|
|
||||||
mConfig conn.MConnConfig
|
|
||||||
|
|
||||||
rng *cmn.Rand // seed for randomizing dial times and orders
|
rng *cmn.Rand // seed for randomizing dial times and orders
|
||||||
|
|
||||||
metrics *Metrics
|
metrics *Metrics
|
||||||
@ -102,14 +111,6 @@ func NewSwitch(
|
|||||||
// Ensure we have a completely undeterministic PRNG.
|
// Ensure we have a completely undeterministic PRNG.
|
||||||
sw.rng = cmn.NewRand()
|
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)
|
sw.BaseService = *cmn.NewBaseService(nil, "P2P Switch", sw)
|
||||||
|
|
||||||
for _, option := range options {
|
for _, option := range options {
|
||||||
|
@ -135,7 +135,7 @@ func (sw *Switch) addPeerWithConnection(conn net.Conn) error {
|
|||||||
|
|
||||||
p := newPeer(
|
p := newPeer(
|
||||||
pc,
|
pc,
|
||||||
sw.mConfig,
|
MConnConfig(sw.config),
|
||||||
ni,
|
ni,
|
||||||
sw.reactorsByCh,
|
sw.reactorsByCh,
|
||||||
sw.chDescs,
|
sw.chDescs,
|
||||||
@ -175,7 +175,7 @@ func MakeSwitch(
|
|||||||
}
|
}
|
||||||
nodeInfo := testNodeInfo(nodeKey.ID(), fmt.Sprintf("node%d", i))
|
nodeInfo := testNodeInfo(nodeKey.ID(), fmt.Sprintf("node%d", i))
|
||||||
|
|
||||||
t := NewMultiplexTransport(nodeInfo, nodeKey)
|
t := NewMultiplexTransport(nodeInfo, nodeKey, MConnConfig(cfg))
|
||||||
|
|
||||||
addr := nodeInfo.NetAddress()
|
addr := nodeInfo.NetAddress()
|
||||||
if err := t.Listen(*addr); err != nil {
|
if err := t.Listen(*addr); err != nil {
|
||||||
@ -232,7 +232,6 @@ func testPeerConn(
|
|||||||
|
|
||||||
// Only the information we already have
|
// Only the information we already have
|
||||||
return peerConn{
|
return peerConn{
|
||||||
config: cfg,
|
|
||||||
outbound: outbound,
|
outbound: outbound,
|
||||||
persistent: persistent,
|
persistent: persistent,
|
||||||
conn: conn,
|
conn: conn,
|
||||||
|
@ -6,7 +6,6 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/config"
|
|
||||||
"github.com/tendermint/tendermint/crypto"
|
"github.com/tendermint/tendermint/crypto"
|
||||||
"github.com/tendermint/tendermint/p2p/conn"
|
"github.com/tendermint/tendermint/p2p/conn"
|
||||||
)
|
)
|
||||||
@ -129,11 +128,10 @@ type MultiplexTransport struct {
|
|||||||
nodeKey NodeKey
|
nodeKey NodeKey
|
||||||
resolver IPResolver
|
resolver IPResolver
|
||||||
|
|
||||||
// TODO(xla): Those configs are still needed as we parameterise peerConn and
|
// TODO(xla): This config is still needed as we parameterise peerConn and
|
||||||
// peer currently. All relevant configuration should be refactored into options
|
// peer currently. All relevant configuration should be refactored into options
|
||||||
// with sane defaults.
|
// with sane defaults.
|
||||||
mConfig conn.MConnConfig
|
mConfig conn.MConnConfig
|
||||||
p2pConfig config.P2PConfig
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test multiplexTransport for interface completeness.
|
// Test multiplexTransport for interface completeness.
|
||||||
@ -144,6 +142,7 @@ var _ transportLifecycle = (*MultiplexTransport)(nil)
|
|||||||
func NewMultiplexTransport(
|
func NewMultiplexTransport(
|
||||||
nodeInfo NodeInfo,
|
nodeInfo NodeInfo,
|
||||||
nodeKey NodeKey,
|
nodeKey NodeKey,
|
||||||
|
mConfig conn.MConnConfig,
|
||||||
) *MultiplexTransport {
|
) *MultiplexTransport {
|
||||||
return &MultiplexTransport{
|
return &MultiplexTransport{
|
||||||
acceptc: make(chan accept),
|
acceptc: make(chan accept),
|
||||||
@ -151,7 +150,7 @@ func NewMultiplexTransport(
|
|||||||
dialTimeout: defaultDialTimeout,
|
dialTimeout: defaultDialTimeout,
|
||||||
filterTimeout: defaultFilterTimeout,
|
filterTimeout: defaultFilterTimeout,
|
||||||
handshakeTimeout: defaultHandshakeTimeout,
|
handshakeTimeout: defaultHandshakeTimeout,
|
||||||
mConfig: conn.DefaultMConnConfig(),
|
mConfig: mConfig,
|
||||||
nodeInfo: nodeInfo,
|
nodeInfo: nodeInfo,
|
||||||
nodeKey: nodeKey,
|
nodeKey: nodeKey,
|
||||||
conns: NewConnSet(),
|
conns: NewConnSet(),
|
||||||
@ -405,7 +404,6 @@ func (mt *MultiplexTransport) wrapPeer(
|
|||||||
peerConn := newPeerConn(
|
peerConn := newPeerConn(
|
||||||
cfg.outbound,
|
cfg.outbound,
|
||||||
cfg.persistent,
|
cfg.persistent,
|
||||||
&mt.p2pConfig,
|
|
||||||
c,
|
c,
|
||||||
dialedAddr,
|
dialedAddr,
|
||||||
)
|
)
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||||
|
"github.com/tendermint/tendermint/p2p/conn"
|
||||||
)
|
)
|
||||||
|
|
||||||
var defaultNodeName = "host_peer"
|
var defaultNodeName = "host_peer"
|
||||||
@ -17,8 +18,20 @@ func emptyNodeInfo() NodeInfo {
|
|||||||
return DefaultNodeInfo{}
|
return DefaultNodeInfo{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// newMultiplexTransport returns a tcp connected multiplexed peer
|
||||||
|
// using the default MConnConfig. It's a convenience function used
|
||||||
|
// for testing.
|
||||||
|
func newMultiplexTransport(
|
||||||
|
nodeInfo NodeInfo,
|
||||||
|
nodeKey NodeKey,
|
||||||
|
) *MultiplexTransport {
|
||||||
|
return NewMultiplexTransport(
|
||||||
|
nodeInfo, nodeKey, conn.DefaultMConnConfig(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
func TestTransportMultiplexConnFilter(t *testing.T) {
|
func TestTransportMultiplexConnFilter(t *testing.T) {
|
||||||
mt := NewMultiplexTransport(
|
mt := newMultiplexTransport(
|
||||||
emptyNodeInfo(),
|
emptyNodeInfo(),
|
||||||
NodeKey{
|
NodeKey{
|
||||||
PrivKey: ed25519.GenPrivKey(),
|
PrivKey: ed25519.GenPrivKey(),
|
||||||
@ -75,7 +88,7 @@ func TestTransportMultiplexConnFilter(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestTransportMultiplexConnFilterTimeout(t *testing.T) {
|
func TestTransportMultiplexConnFilterTimeout(t *testing.T) {
|
||||||
mt := NewMultiplexTransport(
|
mt := newMultiplexTransport(
|
||||||
emptyNodeInfo(),
|
emptyNodeInfo(),
|
||||||
NodeKey{
|
NodeKey{
|
||||||
PrivKey: ed25519.GenPrivKey(),
|
PrivKey: ed25519.GenPrivKey(),
|
||||||
@ -140,7 +153,7 @@ func TestTransportMultiplexAcceptMultiple(t *testing.T) {
|
|||||||
go func() {
|
go func() {
|
||||||
var (
|
var (
|
||||||
pv = ed25519.GenPrivKey()
|
pv = ed25519.GenPrivKey()
|
||||||
dialer = NewMultiplexTransport(
|
dialer = newMultiplexTransport(
|
||||||
testNodeInfo(PubKeyToID(pv.PubKey()), defaultNodeName),
|
testNodeInfo(PubKeyToID(pv.PubKey()), defaultNodeName),
|
||||||
NodeKey{
|
NodeKey{
|
||||||
PrivKey: pv,
|
PrivKey: pv,
|
||||||
@ -261,7 +274,7 @@ func TestTransportMultiplexAcceptNonBlocking(t *testing.T) {
|
|||||||
<-slowc
|
<-slowc
|
||||||
|
|
||||||
var (
|
var (
|
||||||
dialer = NewMultiplexTransport(
|
dialer = newMultiplexTransport(
|
||||||
fastNodeInfo,
|
fastNodeInfo,
|
||||||
NodeKey{
|
NodeKey{
|
||||||
PrivKey: fastNodePV,
|
PrivKey: fastNodePV,
|
||||||
@ -307,7 +320,7 @@ func TestTransportMultiplexValidateNodeInfo(t *testing.T) {
|
|||||||
go func() {
|
go func() {
|
||||||
var (
|
var (
|
||||||
pv = ed25519.GenPrivKey()
|
pv = ed25519.GenPrivKey()
|
||||||
dialer = NewMultiplexTransport(
|
dialer = newMultiplexTransport(
|
||||||
testNodeInfo(PubKeyToID(pv.PubKey()), ""), // Should not be empty
|
testNodeInfo(PubKeyToID(pv.PubKey()), ""), // Should not be empty
|
||||||
NodeKey{
|
NodeKey{
|
||||||
PrivKey: pv,
|
PrivKey: pv,
|
||||||
@ -350,7 +363,7 @@ func TestTransportMultiplexRejectMissmatchID(t *testing.T) {
|
|||||||
errc := make(chan error)
|
errc := make(chan error)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
dialer := NewMultiplexTransport(
|
dialer := newMultiplexTransport(
|
||||||
testNodeInfo(
|
testNodeInfo(
|
||||||
PubKeyToID(ed25519.GenPrivKey().PubKey()), "dialer",
|
PubKeyToID(ed25519.GenPrivKey().PubKey()), "dialer",
|
||||||
),
|
),
|
||||||
@ -396,7 +409,7 @@ func TestTransportMultiplexRejectIncompatible(t *testing.T) {
|
|||||||
go func() {
|
go func() {
|
||||||
var (
|
var (
|
||||||
pv = ed25519.GenPrivKey()
|
pv = ed25519.GenPrivKey()
|
||||||
dialer = NewMultiplexTransport(
|
dialer = newMultiplexTransport(
|
||||||
testNodeInfoWithNetwork(PubKeyToID(pv.PubKey()), "dialer", "incompatible-network"),
|
testNodeInfoWithNetwork(PubKeyToID(pv.PubKey()), "dialer", "incompatible-network"),
|
||||||
NodeKey{
|
NodeKey{
|
||||||
PrivKey: pv,
|
PrivKey: pv,
|
||||||
@ -553,7 +566,7 @@ func TestTransportHandshake(t *testing.T) {
|
|||||||
func testSetupMultiplexTransport(t *testing.T) *MultiplexTransport {
|
func testSetupMultiplexTransport(t *testing.T) *MultiplexTransport {
|
||||||
var (
|
var (
|
||||||
pv = ed25519.GenPrivKey()
|
pv = ed25519.GenPrivKey()
|
||||||
mt = NewMultiplexTransport(
|
mt = newMultiplexTransport(
|
||||||
testNodeInfo(
|
testNodeInfo(
|
||||||
PubKeyToID(pv.PubKey()), "transport",
|
PubKeyToID(pv.PubKey()), "transport",
|
||||||
),
|
),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user