|
@ -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", |
|
|
), |
|
|
), |
|
|