2015-10-25 18:21:51 -07:00
|
|
|
package p2p
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2016-08-10 02:33:38 -04:00
|
|
|
"fmt"
|
2016-06-25 21:59:52 -04:00
|
|
|
"net"
|
2015-10-25 18:21:51 -07:00
|
|
|
"sync"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2017-04-07 14:57:03 +04:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
2017-11-27 21:48:15 +00:00
|
|
|
|
2017-04-07 14:57:03 +04:00
|
|
|
crypto "github.com/tendermint/go-crypto"
|
2017-11-27 21:48:15 +00:00
|
|
|
"github.com/tendermint/tmlibs/log"
|
2017-05-04 22:33:08 -04:00
|
|
|
|
|
|
|
cfg "github.com/tendermint/tendermint/config"
|
2018-01-21 00:33:53 -05:00
|
|
|
"github.com/tendermint/tendermint/p2p/conn"
|
2015-10-25 18:21:51 -07:00
|
|
|
)
|
|
|
|
|
2016-05-12 00:08:41 -04:00
|
|
|
var (
|
2017-05-04 22:33:08 -04:00
|
|
|
config *cfg.P2PConfig
|
2016-05-12 00:08:41 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2017-05-04 22:33:08 -04:00
|
|
|
config = cfg.DefaultP2PConfig()
|
2017-05-01 22:05:26 -04:00
|
|
|
config.PexReactor = true
|
2016-05-12 00:08:41 -04:00
|
|
|
}
|
|
|
|
|
2015-10-25 18:21:51 -07:00
|
|
|
type PeerMessage struct {
|
2018-01-21 00:33:53 -05:00
|
|
|
PeerID ID
|
2015-10-25 18:21:51 -07:00
|
|
|
Bytes []byte
|
|
|
|
Counter int
|
|
|
|
}
|
|
|
|
|
|
|
|
type TestReactor struct {
|
|
|
|
BaseReactor
|
|
|
|
|
|
|
|
mtx sync.Mutex
|
2018-01-21 00:33:53 -05:00
|
|
|
channels []*conn.ChannelDescriptor
|
2015-10-25 18:21:51 -07:00
|
|
|
logMessages bool
|
|
|
|
msgsCounter int
|
|
|
|
msgsReceived map[byte][]PeerMessage
|
|
|
|
}
|
|
|
|
|
2018-01-21 00:33:53 -05:00
|
|
|
func NewTestReactor(channels []*conn.ChannelDescriptor, logMessages bool) *TestReactor {
|
2015-10-25 18:21:51 -07:00
|
|
|
tr := &TestReactor{
|
|
|
|
channels: channels,
|
|
|
|
logMessages: logMessages,
|
|
|
|
msgsReceived: make(map[byte][]PeerMessage),
|
|
|
|
}
|
2017-05-02 11:53:32 +04:00
|
|
|
tr.BaseReactor = *NewBaseReactor("TestReactor", tr)
|
|
|
|
tr.SetLogger(log.TestingLogger())
|
2015-10-25 18:21:51 -07:00
|
|
|
return tr
|
|
|
|
}
|
|
|
|
|
2018-01-21 00:33:53 -05:00
|
|
|
func (tr *TestReactor) GetChannels() []*conn.ChannelDescriptor {
|
2015-10-25 18:21:51 -07:00
|
|
|
return tr.channels
|
|
|
|
}
|
|
|
|
|
2018-03-22 09:54:32 +01:00
|
|
|
func (tr *TestReactor) AddPeer(peer Peer) {}
|
2015-10-25 18:21:51 -07:00
|
|
|
|
2018-03-22 09:54:32 +01:00
|
|
|
func (tr *TestReactor) RemovePeer(peer Peer, reason interface{}) {}
|
2015-10-25 18:21:51 -07:00
|
|
|
|
2017-09-12 20:49:22 -04:00
|
|
|
func (tr *TestReactor) Receive(chID byte, peer Peer, msgBytes []byte) {
|
2015-10-25 18:21:51 -07:00
|
|
|
if tr.logMessages {
|
|
|
|
tr.mtx.Lock()
|
|
|
|
defer tr.mtx.Unlock()
|
|
|
|
//fmt.Printf("Received: %X, %X\n", chID, msgBytes)
|
2018-01-01 21:27:38 -05:00
|
|
|
tr.msgsReceived[chID] = append(tr.msgsReceived[chID], PeerMessage{peer.ID(), msgBytes, tr.msgsCounter})
|
2015-10-25 18:21:51 -07:00
|
|
|
tr.msgsCounter++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 14:35:29 -04:00
|
|
|
func (tr *TestReactor) getMsgs(chID byte) []PeerMessage {
|
|
|
|
tr.mtx.Lock()
|
|
|
|
defer tr.mtx.Unlock()
|
|
|
|
return tr.msgsReceived[chID]
|
|
|
|
}
|
|
|
|
|
2015-10-25 18:21:51 -07:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// convenience method for creating two switches connected to each other.
|
2016-06-25 21:59:52 -04:00
|
|
|
// XXX: note this uses net.Pipe and not a proper TCP conn
|
2018-01-20 21:12:04 -05:00
|
|
|
func MakeSwitchPair(t testing.TB, initSwitch func(int, *Switch) *Switch) (*Switch, *Switch) {
|
2015-10-25 18:21:51 -07:00
|
|
|
// Create two switches that will be interconnected.
|
2017-05-01 22:05:26 -04:00
|
|
|
switches := MakeConnectedSwitches(config, 2, initSwitch, Connect2Switches)
|
2016-06-25 21:59:52 -04:00
|
|
|
return switches[0], switches[1]
|
2015-10-25 18:21:51 -07:00
|
|
|
}
|
|
|
|
|
2016-08-10 02:33:38 -04:00
|
|
|
func initSwitchFunc(i int, sw *Switch) *Switch {
|
2018-04-05 15:21:11 +02:00
|
|
|
sw.SetAddrBook(&addrBookMock{
|
2018-04-06 13:26:05 +02:00
|
|
|
addrs: make(map[string]struct{}),
|
|
|
|
ourAddrs: make(map[string]struct{})})
|
2018-03-22 16:58:57 +01:00
|
|
|
|
2016-08-10 02:33:38 -04:00
|
|
|
// Make two reactors of two channels each
|
2018-01-21 00:33:53 -05:00
|
|
|
sw.AddReactor("foo", NewTestReactor([]*conn.ChannelDescriptor{
|
2017-09-05 16:37:20 -04:00
|
|
|
{ID: byte(0x00), Priority: 10},
|
|
|
|
{ID: byte(0x01), Priority: 10},
|
2016-08-10 02:33:38 -04:00
|
|
|
}, true))
|
2018-01-21 00:33:53 -05:00
|
|
|
sw.AddReactor("bar", NewTestReactor([]*conn.ChannelDescriptor{
|
2017-09-05 16:37:20 -04:00
|
|
|
{ID: byte(0x02), Priority: 10},
|
|
|
|
{ID: byte(0x03), Priority: 10},
|
2016-08-10 02:33:38 -04:00
|
|
|
}, true))
|
2018-03-22 16:58:57 +01:00
|
|
|
|
2016-08-10 02:33:38 -04:00
|
|
|
return sw
|
|
|
|
}
|
|
|
|
|
2015-10-25 18:21:51 -07:00
|
|
|
func TestSwitches(t *testing.T) {
|
2018-01-20 21:12:04 -05:00
|
|
|
s1, s2 := MakeSwitchPair(t, initSwitchFunc)
|
2015-10-25 18:21:51 -07:00
|
|
|
defer s1.Stop()
|
|
|
|
defer s2.Stop()
|
|
|
|
|
|
|
|
if s1.Peers().Size() != 1 {
|
|
|
|
t.Errorf("Expected exactly 1 peer in s1, got %v", s1.Peers().Size())
|
|
|
|
}
|
|
|
|
if s2.Peers().Size() != 1 {
|
|
|
|
t.Errorf("Expected exactly 1 peer in s2, got %v", s2.Peers().Size())
|
|
|
|
}
|
|
|
|
|
2016-08-10 02:33:38 -04:00
|
|
|
// Lets send some messages
|
2018-03-26 06:40:02 +02:00
|
|
|
ch0Msg := []byte("channel zero")
|
|
|
|
ch1Msg := []byte("channel foo")
|
|
|
|
ch2Msg := []byte("channel bar")
|
2015-10-25 18:21:51 -07:00
|
|
|
|
|
|
|
s1.Broadcast(byte(0x00), ch0Msg)
|
|
|
|
s1.Broadcast(byte(0x01), ch1Msg)
|
|
|
|
s1.Broadcast(byte(0x02), ch2Msg)
|
|
|
|
|
2017-11-07 15:02:42 -05:00
|
|
|
assertMsgReceivedWithTimeout(t, ch0Msg, byte(0x00), s2.Reactor("foo").(*TestReactor), 10*time.Millisecond, 5*time.Second)
|
|
|
|
assertMsgReceivedWithTimeout(t, ch1Msg, byte(0x01), s2.Reactor("foo").(*TestReactor), 10*time.Millisecond, 5*time.Second)
|
|
|
|
assertMsgReceivedWithTimeout(t, ch2Msg, byte(0x02), s2.Reactor("bar").(*TestReactor), 10*time.Millisecond, 5*time.Second)
|
|
|
|
}
|
2015-10-25 18:21:51 -07:00
|
|
|
|
2018-03-26 06:40:02 +02:00
|
|
|
func assertMsgReceivedWithTimeout(t *testing.T, msgBytes []byte, channel byte, reactor *TestReactor, checkPeriod, timeout time.Duration) {
|
2017-11-07 15:02:42 -05:00
|
|
|
ticker := time.NewTicker(checkPeriod)
|
2017-11-07 18:08:45 -05:00
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-ticker.C:
|
|
|
|
msgs := reactor.getMsgs(channel)
|
|
|
|
if len(msgs) > 0 {
|
2018-03-26 06:40:02 +02:00
|
|
|
if !bytes.Equal(msgs[0].Bytes, msgBytes) {
|
|
|
|
t.Fatalf("Unexpected message bytes. Wanted: %X, Got: %X", msgBytes, msgs[0].Bytes)
|
2017-11-07 18:08:45 -05:00
|
|
|
}
|
|
|
|
return
|
2017-11-07 15:02:42 -05:00
|
|
|
}
|
2017-11-07 18:08:45 -05:00
|
|
|
case <-time.After(timeout):
|
|
|
|
t.Fatalf("Expected to have received 1 message in channel #%v, got zero", channel)
|
2017-11-07 15:02:42 -05:00
|
|
|
}
|
2015-10-25 18:21:51 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-10 02:33:38 -04:00
|
|
|
func TestConnAddrFilter(t *testing.T) {
|
2018-01-20 21:12:04 -05:00
|
|
|
s1 := MakeSwitch(config, 1, "testing", "123.123.123", initSwitchFunc)
|
|
|
|
s2 := MakeSwitch(config, 1, "testing", "123.123.123", initSwitchFunc)
|
2017-11-07 15:02:42 -05:00
|
|
|
defer s1.Stop()
|
|
|
|
defer s2.Stop()
|
2016-08-10 02:33:38 -04:00
|
|
|
|
2018-01-21 00:33:53 -05:00
|
|
|
c1, c2 := conn.NetPipe()
|
2016-08-10 02:33:38 -04:00
|
|
|
|
|
|
|
s1.SetAddrFilter(func(addr net.Addr) error {
|
|
|
|
if addr.String() == c1.RemoteAddr().String() {
|
|
|
|
return fmt.Errorf("Error: pipe is blacklisted")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
// connect to good peer
|
2017-04-07 14:57:03 +04:00
|
|
|
go func() {
|
2017-11-27 21:48:15 +00:00
|
|
|
err := s1.addPeerWithConnection(c1)
|
|
|
|
assert.NotNil(t, err, "expected err")
|
2017-04-07 14:57:03 +04:00
|
|
|
}()
|
|
|
|
go func() {
|
2017-11-27 21:48:15 +00:00
|
|
|
err := s2.addPeerWithConnection(c2)
|
|
|
|
assert.NotNil(t, err, "expected err")
|
2017-04-07 14:57:03 +04:00
|
|
|
}()
|
2016-08-10 02:33:38 -04:00
|
|
|
|
2017-11-07 18:08:45 -05:00
|
|
|
assertNoPeersAfterTimeout(t, s1, 400*time.Millisecond)
|
|
|
|
assertNoPeersAfterTimeout(t, s2, 400*time.Millisecond)
|
2017-11-07 15:02:42 -05:00
|
|
|
}
|
2016-08-10 02:33:38 -04:00
|
|
|
|
2018-03-22 09:55:21 +01:00
|
|
|
func TestSwitchFiltersOutItself(t *testing.T) {
|
|
|
|
s1 := MakeSwitch(config, 1, "127.0.0.2", "123.123.123", initSwitchFunc)
|
2018-04-05 15:21:11 +02:00
|
|
|
// addr := s1.NodeInfo().NetAddress()
|
2018-03-22 16:58:57 +01:00
|
|
|
|
2018-04-05 15:21:11 +02:00
|
|
|
// // add ourselves like we do in node.go#427
|
|
|
|
// s1.addrBook.AddOurAddress(addr)
|
2018-03-22 09:55:21 +01:00
|
|
|
|
|
|
|
// simulate s1 having a public IP by creating a remote peer with the same ID
|
|
|
|
rp := &remotePeer{PrivKey: s1.nodeKey.PrivKey, Config: DefaultPeerConfig()}
|
|
|
|
rp.Start()
|
|
|
|
|
|
|
|
// addr should be rejected in addPeer based on the same ID
|
2018-04-05 15:21:11 +02:00
|
|
|
err := s1.DialPeerWithAddress(rp.Addr(), false)
|
2018-03-22 09:55:21 +01:00
|
|
|
if assert.Error(t, err) {
|
2018-05-07 17:15:12 +02:00
|
|
|
assert.EqualValues(t, ErrSwitchConnectToSelf{}, err)
|
2018-03-22 09:55:21 +01:00
|
|
|
}
|
|
|
|
|
2018-04-05 15:21:11 +02:00
|
|
|
assert.True(t, s1.addrBook.OurAddress(rp.Addr()))
|
|
|
|
|
|
|
|
assert.False(t, s1.addrBook.HasAddress(rp.Addr()))
|
2018-03-22 09:55:21 +01:00
|
|
|
|
|
|
|
rp.Stop()
|
|
|
|
|
|
|
|
assertNoPeersAfterTimeout(t, s1, 100*time.Millisecond)
|
|
|
|
}
|
|
|
|
|
2017-11-07 18:08:45 -05:00
|
|
|
func assertNoPeersAfterTimeout(t *testing.T, sw *Switch, timeout time.Duration) {
|
|
|
|
time.Sleep(timeout)
|
|
|
|
if sw.Peers().Size() != 0 {
|
|
|
|
t.Fatalf("Expected %v to not connect to some peers, got %d", sw, sw.Peers().Size())
|
2016-08-10 02:33:38 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
p2p: introduce peerConn to simplify peer creation (#1226)
* expose AuthEnc in the P2P config
if AuthEnc is true, dialed peers must have a node ID in the address and
it must match the persistent pubkey from the secret handshake.
Refs #1157
* fixes after my own review
* fix docs
* fix build failure
```
p2p/pex/pex_reactor_test.go:288:88: cannot use seed.NodeInfo().NetAddress() (type *p2p.NetAddress) as type string in array or slice literal
```
* p2p: introduce peerConn to simplify peer creation
* Introduce `peerConn` containing the known fields of `peer`
* `peer` only created in `sw.addPeer` once handshake is complete and NodeInfo is checked
* Eliminates some mutable variables and makes the code flow better
* Simplifies the `newXxxPeer` funcs
* Use ID instead of PubKey where possible.
* SetPubKeyFilter -> SetIDFilter
* nodeInfo.Validate takes ID
* remove peer.PubKey()
* persistent node ids
* fixes from review
* test: use ip_plus_id.sh more
* fix invalid memory panic during fast_sync test
```
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: panic: runtime error: invalid memory address or nil pointer dereference
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: [signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x98dd3e]
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]:
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: goroutine 3432 [running]:
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.newOutboundPeerConn(0xc423fd1380, 0xc420933e00, 0x1, 0x1239a60, 0
xc420128c40, 0x2, 0x42caf6, 0xc42001f300, 0xc422831d98, 0xc4227951c0, ...)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/peer.go:123 +0x31e
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.(*Switch).addOutboundPeerWithConfig(0xc4200ad040, 0xc423fd1380, 0
xc420933e00, 0xc423f48801, 0x28, 0x2)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:455 +0x12b
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.(*Switch).DialPeerWithAddress(0xc4200ad040, 0xc423fd1380, 0x1, 0x
0, 0x0)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:371 +0xdc
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.(*Switch).reconnectToPeer(0xc4200ad040, 0x123e000, 0xc42007bb00)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:290 +0x25f
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: created by github.com/tendermint/tendermint/p2p.(*Switch).StopPeerForError
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:256 +0x1b7
```
2018-02-27 06:54:40 -05:00
|
|
|
func TestConnIDFilter(t *testing.T) {
|
2018-01-20 21:12:04 -05:00
|
|
|
s1 := MakeSwitch(config, 1, "testing", "123.123.123", initSwitchFunc)
|
|
|
|
s2 := MakeSwitch(config, 1, "testing", "123.123.123", initSwitchFunc)
|
2017-11-07 15:02:42 -05:00
|
|
|
defer s1.Stop()
|
|
|
|
defer s2.Stop()
|
2016-08-10 02:33:38 -04:00
|
|
|
|
2018-01-21 00:33:53 -05:00
|
|
|
c1, c2 := conn.NetPipe()
|
2016-08-10 02:33:38 -04:00
|
|
|
|
p2p: introduce peerConn to simplify peer creation (#1226)
* expose AuthEnc in the P2P config
if AuthEnc is true, dialed peers must have a node ID in the address and
it must match the persistent pubkey from the secret handshake.
Refs #1157
* fixes after my own review
* fix docs
* fix build failure
```
p2p/pex/pex_reactor_test.go:288:88: cannot use seed.NodeInfo().NetAddress() (type *p2p.NetAddress) as type string in array or slice literal
```
* p2p: introduce peerConn to simplify peer creation
* Introduce `peerConn` containing the known fields of `peer`
* `peer` only created in `sw.addPeer` once handshake is complete and NodeInfo is checked
* Eliminates some mutable variables and makes the code flow better
* Simplifies the `newXxxPeer` funcs
* Use ID instead of PubKey where possible.
* SetPubKeyFilter -> SetIDFilter
* nodeInfo.Validate takes ID
* remove peer.PubKey()
* persistent node ids
* fixes from review
* test: use ip_plus_id.sh more
* fix invalid memory panic during fast_sync test
```
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: panic: runtime error: invalid memory address or nil pointer dereference
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: [signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x98dd3e]
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]:
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: goroutine 3432 [running]:
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.newOutboundPeerConn(0xc423fd1380, 0xc420933e00, 0x1, 0x1239a60, 0
xc420128c40, 0x2, 0x42caf6, 0xc42001f300, 0xc422831d98, 0xc4227951c0, ...)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/peer.go:123 +0x31e
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.(*Switch).addOutboundPeerWithConfig(0xc4200ad040, 0xc423fd1380, 0
xc420933e00, 0xc423f48801, 0x28, 0x2)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:455 +0x12b
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.(*Switch).DialPeerWithAddress(0xc4200ad040, 0xc423fd1380, 0x1, 0x
0, 0x0)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:371 +0xdc
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.(*Switch).reconnectToPeer(0xc4200ad040, 0x123e000, 0xc42007bb00)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:290 +0x25f
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: created by github.com/tendermint/tendermint/p2p.(*Switch).StopPeerForError
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:256 +0x1b7
```
2018-02-27 06:54:40 -05:00
|
|
|
s1.SetIDFilter(func(id ID) error {
|
2018-04-11 11:11:11 +03:00
|
|
|
if id == s2.nodeInfo.ID {
|
p2p: introduce peerConn to simplify peer creation (#1226)
* expose AuthEnc in the P2P config
if AuthEnc is true, dialed peers must have a node ID in the address and
it must match the persistent pubkey from the secret handshake.
Refs #1157
* fixes after my own review
* fix docs
* fix build failure
```
p2p/pex/pex_reactor_test.go:288:88: cannot use seed.NodeInfo().NetAddress() (type *p2p.NetAddress) as type string in array or slice literal
```
* p2p: introduce peerConn to simplify peer creation
* Introduce `peerConn` containing the known fields of `peer`
* `peer` only created in `sw.addPeer` once handshake is complete and NodeInfo is checked
* Eliminates some mutable variables and makes the code flow better
* Simplifies the `newXxxPeer` funcs
* Use ID instead of PubKey where possible.
* SetPubKeyFilter -> SetIDFilter
* nodeInfo.Validate takes ID
* remove peer.PubKey()
* persistent node ids
* fixes from review
* test: use ip_plus_id.sh more
* fix invalid memory panic during fast_sync test
```
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: panic: runtime error: invalid memory address or nil pointer dereference
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: [signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x98dd3e]
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]:
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: goroutine 3432 [running]:
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.newOutboundPeerConn(0xc423fd1380, 0xc420933e00, 0x1, 0x1239a60, 0
xc420128c40, 0x2, 0x42caf6, 0xc42001f300, 0xc422831d98, 0xc4227951c0, ...)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/peer.go:123 +0x31e
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.(*Switch).addOutboundPeerWithConfig(0xc4200ad040, 0xc423fd1380, 0
xc420933e00, 0xc423f48801, 0x28, 0x2)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:455 +0x12b
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.(*Switch).DialPeerWithAddress(0xc4200ad040, 0xc423fd1380, 0x1, 0x
0, 0x0)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:371 +0xdc
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.(*Switch).reconnectToPeer(0xc4200ad040, 0x123e000, 0xc42007bb00)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:290 +0x25f
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: created by github.com/tendermint/tendermint/p2p.(*Switch).StopPeerForError
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:256 +0x1b7
```
2018-02-27 06:54:40 -05:00
|
|
|
return fmt.Errorf("Error: pipe is blacklisted")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
s2.SetIDFilter(func(id ID) error {
|
2018-04-11 11:11:11 +03:00
|
|
|
if id == s1.nodeInfo.ID {
|
2016-08-10 02:33:38 -04:00
|
|
|
return fmt.Errorf("Error: pipe is blacklisted")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
2017-04-07 14:57:03 +04:00
|
|
|
go func() {
|
2017-11-27 21:48:15 +00:00
|
|
|
err := s1.addPeerWithConnection(c1)
|
|
|
|
assert.NotNil(t, err, "expected error")
|
2017-04-07 14:57:03 +04:00
|
|
|
}()
|
|
|
|
go func() {
|
2017-11-27 21:48:15 +00:00
|
|
|
err := s2.addPeerWithConnection(c2)
|
|
|
|
assert.NotNil(t, err, "expected error")
|
2017-04-07 14:57:03 +04:00
|
|
|
}()
|
2016-08-10 02:33:38 -04:00
|
|
|
|
2017-11-07 18:08:45 -05:00
|
|
|
assertNoPeersAfterTimeout(t, s1, 400*time.Millisecond)
|
|
|
|
assertNoPeersAfterTimeout(t, s2, 400*time.Millisecond)
|
2016-08-10 02:33:38 -04:00
|
|
|
}
|
|
|
|
|
2017-04-07 14:57:03 +04:00
|
|
|
func TestSwitchStopsNonPersistentPeerOnError(t *testing.T) {
|
|
|
|
assert, require := assert.New(t), require.New(t)
|
|
|
|
|
2018-01-20 21:12:04 -05:00
|
|
|
sw := MakeSwitch(config, 1, "testing", "123.123.123", initSwitchFunc)
|
2017-11-06 13:20:39 -05:00
|
|
|
err := sw.Start()
|
2017-09-21 12:38:48 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2017-04-07 14:57:03 +04:00
|
|
|
defer sw.Stop()
|
|
|
|
|
2017-04-11 19:47:05 +04:00
|
|
|
// simulate remote peer
|
2018-03-26 06:40:02 +02:00
|
|
|
rp := &remotePeer{PrivKey: crypto.GenPrivKeyEd25519(), Config: DefaultPeerConfig()}
|
2017-04-11 19:47:05 +04:00
|
|
|
rp.Start()
|
|
|
|
defer rp.Stop()
|
2017-04-07 14:57:03 +04:00
|
|
|
|
p2p: introduce peerConn to simplify peer creation (#1226)
* expose AuthEnc in the P2P config
if AuthEnc is true, dialed peers must have a node ID in the address and
it must match the persistent pubkey from the secret handshake.
Refs #1157
* fixes after my own review
* fix docs
* fix build failure
```
p2p/pex/pex_reactor_test.go:288:88: cannot use seed.NodeInfo().NetAddress() (type *p2p.NetAddress) as type string in array or slice literal
```
* p2p: introduce peerConn to simplify peer creation
* Introduce `peerConn` containing the known fields of `peer`
* `peer` only created in `sw.addPeer` once handshake is complete and NodeInfo is checked
* Eliminates some mutable variables and makes the code flow better
* Simplifies the `newXxxPeer` funcs
* Use ID instead of PubKey where possible.
* SetPubKeyFilter -> SetIDFilter
* nodeInfo.Validate takes ID
* remove peer.PubKey()
* persistent node ids
* fixes from review
* test: use ip_plus_id.sh more
* fix invalid memory panic during fast_sync test
```
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: panic: runtime error: invalid memory address or nil pointer dereference
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: [signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x98dd3e]
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]:
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: goroutine 3432 [running]:
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.newOutboundPeerConn(0xc423fd1380, 0xc420933e00, 0x1, 0x1239a60, 0
xc420128c40, 0x2, 0x42caf6, 0xc42001f300, 0xc422831d98, 0xc4227951c0, ...)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/peer.go:123 +0x31e
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.(*Switch).addOutboundPeerWithConfig(0xc4200ad040, 0xc423fd1380, 0
xc420933e00, 0xc423f48801, 0x28, 0x2)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:455 +0x12b
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.(*Switch).DialPeerWithAddress(0xc4200ad040, 0xc423fd1380, 0x1, 0x
0, 0x0)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:371 +0xdc
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.(*Switch).reconnectToPeer(0xc4200ad040, 0x123e000, 0xc42007bb00)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:290 +0x25f
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: created by github.com/tendermint/tendermint/p2p.(*Switch).StopPeerForError
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:256 +0x1b7
```
2018-02-27 06:54:40 -05:00
|
|
|
pc, err := newOutboundPeerConn(rp.Addr(), DefaultPeerConfig(), false, sw.nodeKey.PrivKey)
|
2017-04-07 14:57:03 +04:00
|
|
|
require.Nil(err)
|
p2p: introduce peerConn to simplify peer creation (#1226)
* expose AuthEnc in the P2P config
if AuthEnc is true, dialed peers must have a node ID in the address and
it must match the persistent pubkey from the secret handshake.
Refs #1157
* fixes after my own review
* fix docs
* fix build failure
```
p2p/pex/pex_reactor_test.go:288:88: cannot use seed.NodeInfo().NetAddress() (type *p2p.NetAddress) as type string in array or slice literal
```
* p2p: introduce peerConn to simplify peer creation
* Introduce `peerConn` containing the known fields of `peer`
* `peer` only created in `sw.addPeer` once handshake is complete and NodeInfo is checked
* Eliminates some mutable variables and makes the code flow better
* Simplifies the `newXxxPeer` funcs
* Use ID instead of PubKey where possible.
* SetPubKeyFilter -> SetIDFilter
* nodeInfo.Validate takes ID
* remove peer.PubKey()
* persistent node ids
* fixes from review
* test: use ip_plus_id.sh more
* fix invalid memory panic during fast_sync test
```
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: panic: runtime error: invalid memory address or nil pointer dereference
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: [signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x98dd3e]
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]:
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: goroutine 3432 [running]:
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.newOutboundPeerConn(0xc423fd1380, 0xc420933e00, 0x1, 0x1239a60, 0
xc420128c40, 0x2, 0x42caf6, 0xc42001f300, 0xc422831d98, 0xc4227951c0, ...)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/peer.go:123 +0x31e
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.(*Switch).addOutboundPeerWithConfig(0xc4200ad040, 0xc423fd1380, 0
xc420933e00, 0xc423f48801, 0x28, 0x2)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:455 +0x12b
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.(*Switch).DialPeerWithAddress(0xc4200ad040, 0xc423fd1380, 0x1, 0x
0, 0x0)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:371 +0xdc
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.(*Switch).reconnectToPeer(0xc4200ad040, 0x123e000, 0xc42007bb00)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:290 +0x25f
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: created by github.com/tendermint/tendermint/p2p.(*Switch).StopPeerForError
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:256 +0x1b7
```
2018-02-27 06:54:40 -05:00
|
|
|
err = sw.addPeer(pc)
|
2017-04-07 14:57:03 +04:00
|
|
|
require.Nil(err)
|
|
|
|
|
p2p: introduce peerConn to simplify peer creation (#1226)
* expose AuthEnc in the P2P config
if AuthEnc is true, dialed peers must have a node ID in the address and
it must match the persistent pubkey from the secret handshake.
Refs #1157
* fixes after my own review
* fix docs
* fix build failure
```
p2p/pex/pex_reactor_test.go:288:88: cannot use seed.NodeInfo().NetAddress() (type *p2p.NetAddress) as type string in array or slice literal
```
* p2p: introduce peerConn to simplify peer creation
* Introduce `peerConn` containing the known fields of `peer`
* `peer` only created in `sw.addPeer` once handshake is complete and NodeInfo is checked
* Eliminates some mutable variables and makes the code flow better
* Simplifies the `newXxxPeer` funcs
* Use ID instead of PubKey where possible.
* SetPubKeyFilter -> SetIDFilter
* nodeInfo.Validate takes ID
* remove peer.PubKey()
* persistent node ids
* fixes from review
* test: use ip_plus_id.sh more
* fix invalid memory panic during fast_sync test
```
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: panic: runtime error: invalid memory address or nil pointer dereference
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: [signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x98dd3e]
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]:
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: goroutine 3432 [running]:
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.newOutboundPeerConn(0xc423fd1380, 0xc420933e00, 0x1, 0x1239a60, 0
xc420128c40, 0x2, 0x42caf6, 0xc42001f300, 0xc422831d98, 0xc4227951c0, ...)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/peer.go:123 +0x31e
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.(*Switch).addOutboundPeerWithConfig(0xc4200ad040, 0xc423fd1380, 0
xc420933e00, 0xc423f48801, 0x28, 0x2)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:455 +0x12b
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.(*Switch).DialPeerWithAddress(0xc4200ad040, 0xc423fd1380, 0x1, 0x
0, 0x0)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:371 +0xdc
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.(*Switch).reconnectToPeer(0xc4200ad040, 0x123e000, 0xc42007bb00)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:290 +0x25f
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: created by github.com/tendermint/tendermint/p2p.(*Switch).StopPeerForError
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:256 +0x1b7
```
2018-02-27 06:54:40 -05:00
|
|
|
peer := sw.Peers().Get(rp.ID())
|
2018-03-06 15:32:52 +01:00
|
|
|
require.NotNil(peer)
|
p2p: introduce peerConn to simplify peer creation (#1226)
* expose AuthEnc in the P2P config
if AuthEnc is true, dialed peers must have a node ID in the address and
it must match the persistent pubkey from the secret handshake.
Refs #1157
* fixes after my own review
* fix docs
* fix build failure
```
p2p/pex/pex_reactor_test.go:288:88: cannot use seed.NodeInfo().NetAddress() (type *p2p.NetAddress) as type string in array or slice literal
```
* p2p: introduce peerConn to simplify peer creation
* Introduce `peerConn` containing the known fields of `peer`
* `peer` only created in `sw.addPeer` once handshake is complete and NodeInfo is checked
* Eliminates some mutable variables and makes the code flow better
* Simplifies the `newXxxPeer` funcs
* Use ID instead of PubKey where possible.
* SetPubKeyFilter -> SetIDFilter
* nodeInfo.Validate takes ID
* remove peer.PubKey()
* persistent node ids
* fixes from review
* test: use ip_plus_id.sh more
* fix invalid memory panic during fast_sync test
```
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: panic: runtime error: invalid memory address or nil pointer dereference
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: [signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x98dd3e]
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]:
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: goroutine 3432 [running]:
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.newOutboundPeerConn(0xc423fd1380, 0xc420933e00, 0x1, 0x1239a60, 0
xc420128c40, 0x2, 0x42caf6, 0xc42001f300, 0xc422831d98, 0xc4227951c0, ...)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/peer.go:123 +0x31e
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.(*Switch).addOutboundPeerWithConfig(0xc4200ad040, 0xc423fd1380, 0
xc420933e00, 0xc423f48801, 0x28, 0x2)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:455 +0x12b
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.(*Switch).DialPeerWithAddress(0xc4200ad040, 0xc423fd1380, 0x1, 0x
0, 0x0)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:371 +0xdc
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.(*Switch).reconnectToPeer(0xc4200ad040, 0x123e000, 0xc42007bb00)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:290 +0x25f
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: created by github.com/tendermint/tendermint/p2p.(*Switch).StopPeerForError
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:256 +0x1b7
```
2018-02-27 06:54:40 -05:00
|
|
|
|
2017-04-07 14:57:03 +04:00
|
|
|
// simulate failure by closing connection
|
p2p: introduce peerConn to simplify peer creation (#1226)
* expose AuthEnc in the P2P config
if AuthEnc is true, dialed peers must have a node ID in the address and
it must match the persistent pubkey from the secret handshake.
Refs #1157
* fixes after my own review
* fix docs
* fix build failure
```
p2p/pex/pex_reactor_test.go:288:88: cannot use seed.NodeInfo().NetAddress() (type *p2p.NetAddress) as type string in array or slice literal
```
* p2p: introduce peerConn to simplify peer creation
* Introduce `peerConn` containing the known fields of `peer`
* `peer` only created in `sw.addPeer` once handshake is complete and NodeInfo is checked
* Eliminates some mutable variables and makes the code flow better
* Simplifies the `newXxxPeer` funcs
* Use ID instead of PubKey where possible.
* SetPubKeyFilter -> SetIDFilter
* nodeInfo.Validate takes ID
* remove peer.PubKey()
* persistent node ids
* fixes from review
* test: use ip_plus_id.sh more
* fix invalid memory panic during fast_sync test
```
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: panic: runtime error: invalid memory address or nil pointer dereference
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: [signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x98dd3e]
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]:
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: goroutine 3432 [running]:
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.newOutboundPeerConn(0xc423fd1380, 0xc420933e00, 0x1, 0x1239a60, 0
xc420128c40, 0x2, 0x42caf6, 0xc42001f300, 0xc422831d98, 0xc4227951c0, ...)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/peer.go:123 +0x31e
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.(*Switch).addOutboundPeerWithConfig(0xc4200ad040, 0xc423fd1380, 0
xc420933e00, 0xc423f48801, 0x28, 0x2)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:455 +0x12b
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.(*Switch).DialPeerWithAddress(0xc4200ad040, 0xc423fd1380, 0x1, 0x
0, 0x0)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:371 +0xdc
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.(*Switch).reconnectToPeer(0xc4200ad040, 0x123e000, 0xc42007bb00)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:290 +0x25f
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: created by github.com/tendermint/tendermint/p2p.(*Switch).StopPeerForError
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:256 +0x1b7
```
2018-02-27 06:54:40 -05:00
|
|
|
pc.CloseConn()
|
2017-04-07 14:57:03 +04:00
|
|
|
|
2017-11-07 18:08:45 -05:00
|
|
|
assertNoPeersAfterTimeout(t, sw, 100*time.Millisecond)
|
2017-04-07 14:57:03 +04:00
|
|
|
assert.False(peer.IsRunning())
|
|
|
|
}
|
|
|
|
|
2017-04-10 15:59:32 -04:00
|
|
|
func TestSwitchReconnectsToPersistentPeer(t *testing.T) {
|
2017-04-07 14:57:03 +04:00
|
|
|
assert, require := assert.New(t), require.New(t)
|
|
|
|
|
2018-01-20 21:12:04 -05:00
|
|
|
sw := MakeSwitch(config, 1, "testing", "123.123.123", initSwitchFunc)
|
2017-11-06 13:20:39 -05:00
|
|
|
err := sw.Start()
|
2017-09-21 12:38:48 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2017-04-07 14:57:03 +04:00
|
|
|
defer sw.Stop()
|
|
|
|
|
2017-04-11 19:47:05 +04:00
|
|
|
// simulate remote peer
|
2018-03-26 06:40:02 +02:00
|
|
|
rp := &remotePeer{PrivKey: crypto.GenPrivKeyEd25519(), Config: DefaultPeerConfig()}
|
2017-04-11 19:47:05 +04:00
|
|
|
rp.Start()
|
|
|
|
defer rp.Stop()
|
2017-04-07 14:57:03 +04:00
|
|
|
|
p2p: introduce peerConn to simplify peer creation (#1226)
* expose AuthEnc in the P2P config
if AuthEnc is true, dialed peers must have a node ID in the address and
it must match the persistent pubkey from the secret handshake.
Refs #1157
* fixes after my own review
* fix docs
* fix build failure
```
p2p/pex/pex_reactor_test.go:288:88: cannot use seed.NodeInfo().NetAddress() (type *p2p.NetAddress) as type string in array or slice literal
```
* p2p: introduce peerConn to simplify peer creation
* Introduce `peerConn` containing the known fields of `peer`
* `peer` only created in `sw.addPeer` once handshake is complete and NodeInfo is checked
* Eliminates some mutable variables and makes the code flow better
* Simplifies the `newXxxPeer` funcs
* Use ID instead of PubKey where possible.
* SetPubKeyFilter -> SetIDFilter
* nodeInfo.Validate takes ID
* remove peer.PubKey()
* persistent node ids
* fixes from review
* test: use ip_plus_id.sh more
* fix invalid memory panic during fast_sync test
```
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: panic: runtime error: invalid memory address or nil pointer dereference
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: [signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x98dd3e]
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]:
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: goroutine 3432 [running]:
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.newOutboundPeerConn(0xc423fd1380, 0xc420933e00, 0x1, 0x1239a60, 0
xc420128c40, 0x2, 0x42caf6, 0xc42001f300, 0xc422831d98, 0xc4227951c0, ...)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/peer.go:123 +0x31e
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.(*Switch).addOutboundPeerWithConfig(0xc4200ad040, 0xc423fd1380, 0
xc420933e00, 0xc423f48801, 0x28, 0x2)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:455 +0x12b
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.(*Switch).DialPeerWithAddress(0xc4200ad040, 0xc423fd1380, 0x1, 0x
0, 0x0)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:371 +0xdc
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.(*Switch).reconnectToPeer(0xc4200ad040, 0x123e000, 0xc42007bb00)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:290 +0x25f
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: created by github.com/tendermint/tendermint/p2p.(*Switch).StopPeerForError
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:256 +0x1b7
```
2018-02-27 06:54:40 -05:00
|
|
|
pc, err := newOutboundPeerConn(rp.Addr(), DefaultPeerConfig(), true, sw.nodeKey.PrivKey)
|
|
|
|
// sw.reactorsByCh, sw.chDescs, sw.StopPeerForError, sw.nodeKey.PrivKey,
|
2017-04-07 14:57:03 +04:00
|
|
|
require.Nil(err)
|
2018-03-06 15:32:52 +01:00
|
|
|
|
|
|
|
require.Nil(sw.addPeer(pc))
|
2017-04-07 14:57:03 +04:00
|
|
|
|
p2p: introduce peerConn to simplify peer creation (#1226)
* expose AuthEnc in the P2P config
if AuthEnc is true, dialed peers must have a node ID in the address and
it must match the persistent pubkey from the secret handshake.
Refs #1157
* fixes after my own review
* fix docs
* fix build failure
```
p2p/pex/pex_reactor_test.go:288:88: cannot use seed.NodeInfo().NetAddress() (type *p2p.NetAddress) as type string in array or slice literal
```
* p2p: introduce peerConn to simplify peer creation
* Introduce `peerConn` containing the known fields of `peer`
* `peer` only created in `sw.addPeer` once handshake is complete and NodeInfo is checked
* Eliminates some mutable variables and makes the code flow better
* Simplifies the `newXxxPeer` funcs
* Use ID instead of PubKey where possible.
* SetPubKeyFilter -> SetIDFilter
* nodeInfo.Validate takes ID
* remove peer.PubKey()
* persistent node ids
* fixes from review
* test: use ip_plus_id.sh more
* fix invalid memory panic during fast_sync test
```
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: panic: runtime error: invalid memory address or nil pointer dereference
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: [signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x98dd3e]
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]:
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: goroutine 3432 [running]:
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.newOutboundPeerConn(0xc423fd1380, 0xc420933e00, 0x1, 0x1239a60, 0
xc420128c40, 0x2, 0x42caf6, 0xc42001f300, 0xc422831d98, 0xc4227951c0, ...)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/peer.go:123 +0x31e
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.(*Switch).addOutboundPeerWithConfig(0xc4200ad040, 0xc423fd1380, 0
xc420933e00, 0xc423f48801, 0x28, 0x2)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:455 +0x12b
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.(*Switch).DialPeerWithAddress(0xc4200ad040, 0xc423fd1380, 0x1, 0x
0, 0x0)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:371 +0xdc
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.(*Switch).reconnectToPeer(0xc4200ad040, 0x123e000, 0xc42007bb00)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:290 +0x25f
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: created by github.com/tendermint/tendermint/p2p.(*Switch).StopPeerForError
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:256 +0x1b7
```
2018-02-27 06:54:40 -05:00
|
|
|
peer := sw.Peers().Get(rp.ID())
|
2018-03-06 15:32:52 +01:00
|
|
|
require.NotNil(peer)
|
p2p: introduce peerConn to simplify peer creation (#1226)
* expose AuthEnc in the P2P config
if AuthEnc is true, dialed peers must have a node ID in the address and
it must match the persistent pubkey from the secret handshake.
Refs #1157
* fixes after my own review
* fix docs
* fix build failure
```
p2p/pex/pex_reactor_test.go:288:88: cannot use seed.NodeInfo().NetAddress() (type *p2p.NetAddress) as type string in array or slice literal
```
* p2p: introduce peerConn to simplify peer creation
* Introduce `peerConn` containing the known fields of `peer`
* `peer` only created in `sw.addPeer` once handshake is complete and NodeInfo is checked
* Eliminates some mutable variables and makes the code flow better
* Simplifies the `newXxxPeer` funcs
* Use ID instead of PubKey where possible.
* SetPubKeyFilter -> SetIDFilter
* nodeInfo.Validate takes ID
* remove peer.PubKey()
* persistent node ids
* fixes from review
* test: use ip_plus_id.sh more
* fix invalid memory panic during fast_sync test
```
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: panic: runtime error: invalid memory address or nil pointer dereference
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: [signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x98dd3e]
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]:
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: goroutine 3432 [running]:
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.newOutboundPeerConn(0xc423fd1380, 0xc420933e00, 0x1, 0x1239a60, 0
xc420128c40, 0x2, 0x42caf6, 0xc42001f300, 0xc422831d98, 0xc4227951c0, ...)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/peer.go:123 +0x31e
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.(*Switch).addOutboundPeerWithConfig(0xc4200ad040, 0xc423fd1380, 0
xc420933e00, 0xc423f48801, 0x28, 0x2)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:455 +0x12b
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.(*Switch).DialPeerWithAddress(0xc4200ad040, 0xc423fd1380, 0x1, 0x
0, 0x0)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:371 +0xdc
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.(*Switch).reconnectToPeer(0xc4200ad040, 0x123e000, 0xc42007bb00)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:290 +0x25f
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: created by github.com/tendermint/tendermint/p2p.(*Switch).StopPeerForError
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:256 +0x1b7
```
2018-02-27 06:54:40 -05:00
|
|
|
|
2017-04-07 14:57:03 +04:00
|
|
|
// simulate failure by closing connection
|
p2p: introduce peerConn to simplify peer creation (#1226)
* expose AuthEnc in the P2P config
if AuthEnc is true, dialed peers must have a node ID in the address and
it must match the persistent pubkey from the secret handshake.
Refs #1157
* fixes after my own review
* fix docs
* fix build failure
```
p2p/pex/pex_reactor_test.go:288:88: cannot use seed.NodeInfo().NetAddress() (type *p2p.NetAddress) as type string in array or slice literal
```
* p2p: introduce peerConn to simplify peer creation
* Introduce `peerConn` containing the known fields of `peer`
* `peer` only created in `sw.addPeer` once handshake is complete and NodeInfo is checked
* Eliminates some mutable variables and makes the code flow better
* Simplifies the `newXxxPeer` funcs
* Use ID instead of PubKey where possible.
* SetPubKeyFilter -> SetIDFilter
* nodeInfo.Validate takes ID
* remove peer.PubKey()
* persistent node ids
* fixes from review
* test: use ip_plus_id.sh more
* fix invalid memory panic during fast_sync test
```
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: panic: runtime error: invalid memory address or nil pointer dereference
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: [signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x98dd3e]
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]:
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: goroutine 3432 [running]:
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.newOutboundPeerConn(0xc423fd1380, 0xc420933e00, 0x1, 0x1239a60, 0
xc420128c40, 0x2, 0x42caf6, 0xc42001f300, 0xc422831d98, 0xc4227951c0, ...)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/peer.go:123 +0x31e
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.(*Switch).addOutboundPeerWithConfig(0xc4200ad040, 0xc423fd1380, 0
xc420933e00, 0xc423f48801, 0x28, 0x2)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:455 +0x12b
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.(*Switch).DialPeerWithAddress(0xc4200ad040, 0xc423fd1380, 0x1, 0x
0, 0x0)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:371 +0xdc
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.(*Switch).reconnectToPeer(0xc4200ad040, 0x123e000, 0xc42007bb00)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:290 +0x25f
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: created by github.com/tendermint/tendermint/p2p.(*Switch).StopPeerForError
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:256 +0x1b7
```
2018-02-27 06:54:40 -05:00
|
|
|
pc.CloseConn()
|
2017-04-07 14:57:03 +04:00
|
|
|
|
2017-12-11 13:41:09 -05:00
|
|
|
// TODO: remove sleep, detect the disconnection, wait for reconnect
|
2017-11-14 22:31:23 +00:00
|
|
|
npeers := sw.Peers().Size()
|
|
|
|
for i := 0; i < 20; i++ {
|
2017-12-11 13:41:09 -05:00
|
|
|
time.Sleep(250 * time.Millisecond)
|
2017-11-14 22:31:23 +00:00
|
|
|
npeers = sw.Peers().Size()
|
|
|
|
if npeers > 0 {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert.NotZero(npeers)
|
2017-04-07 14:57:03 +04:00
|
|
|
assert.False(peer.IsRunning())
|
2018-04-02 10:15:02 +05:30
|
|
|
|
|
|
|
// simulate another remote peer
|
2018-05-23 00:24:40 +02:00
|
|
|
rp = &remotePeer{
|
|
|
|
PrivKey: crypto.GenPrivKeyEd25519(),
|
|
|
|
Config: DefaultPeerConfig(),
|
|
|
|
// Use different interface to prevent duplicate IP filter, this will break
|
|
|
|
// beyond two peers.
|
2018-05-23 01:35:03 +02:00
|
|
|
listenAddr: "127.0.0.2:0",
|
2018-05-23 00:24:40 +02:00
|
|
|
}
|
2018-04-02 10:15:02 +05:30
|
|
|
rp.Start()
|
|
|
|
defer rp.Stop()
|
|
|
|
|
|
|
|
// simulate first time dial failure
|
|
|
|
peerConfig := DefaultPeerConfig()
|
2018-04-28 01:02:39 -04:00
|
|
|
peerConfig.DialFail = true
|
2018-04-02 10:15:02 +05:30
|
|
|
err = sw.addOutboundPeerWithConfig(rp.Addr(), peerConfig, true)
|
|
|
|
require.NotNil(err)
|
|
|
|
|
|
|
|
// DialPeerWithAddres - sw.peerConfig resets the dialer
|
|
|
|
|
|
|
|
// TODO: same as above
|
|
|
|
for i := 0; i < 20; i++ {
|
|
|
|
time.Sleep(250 * time.Millisecond)
|
|
|
|
npeers = sw.Peers().Size()
|
|
|
|
if npeers > 1 {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert.EqualValues(2, npeers)
|
2017-04-07 14:57:03 +04:00
|
|
|
}
|
|
|
|
|
2017-11-07 18:31:46 -05:00
|
|
|
func TestSwitchFullConnectivity(t *testing.T) {
|
|
|
|
switches := MakeConnectedSwitches(config, 3, initSwitchFunc, Connect2Switches)
|
|
|
|
defer func() {
|
|
|
|
for _, sw := range switches {
|
|
|
|
sw.Stop()
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
for i, sw := range switches {
|
|
|
|
if sw.Peers().Size() != 2 {
|
|
|
|
t.Fatalf("Expected each switch to be connected to 2 other, but %d switch only connected to %d", sw.Peers().Size(), i)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-11 18:24:28 -06:00
|
|
|
func BenchmarkSwitchBroadcast(b *testing.B) {
|
2018-01-23 13:11:44 +04:00
|
|
|
s1, s2 := MakeSwitchPair(b, func(i int, sw *Switch) *Switch {
|
2015-10-25 18:21:51 -07:00
|
|
|
// Make bar reactors of bar channels each
|
2018-01-21 00:33:53 -05:00
|
|
|
sw.AddReactor("foo", NewTestReactor([]*conn.ChannelDescriptor{
|
2017-09-05 16:37:20 -04:00
|
|
|
{ID: byte(0x00), Priority: 10},
|
|
|
|
{ID: byte(0x01), Priority: 10},
|
2015-10-25 18:21:51 -07:00
|
|
|
}, false))
|
2018-01-21 00:33:53 -05:00
|
|
|
sw.AddReactor("bar", NewTestReactor([]*conn.ChannelDescriptor{
|
2017-09-05 16:37:20 -04:00
|
|
|
{ID: byte(0x02), Priority: 10},
|
|
|
|
{ID: byte(0x03), Priority: 10},
|
2015-10-25 18:21:51 -07:00
|
|
|
}, false))
|
|
|
|
return sw
|
|
|
|
})
|
|
|
|
defer s1.Stop()
|
|
|
|
defer s2.Stop()
|
|
|
|
|
|
|
|
// Allow time for goroutines to boot up
|
2017-11-07 15:02:42 -05:00
|
|
|
time.Sleep(1 * time.Second)
|
2018-01-11 18:24:28 -06:00
|
|
|
|
|
|
|
b.ResetTimer()
|
2015-10-25 18:21:51 -07:00
|
|
|
|
|
|
|
numSuccess, numFailure := 0, 0
|
|
|
|
|
2017-11-08 18:22:51 -05:00
|
|
|
// Send random message from foo channel to another
|
2015-10-25 18:21:51 -07:00
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
chID := byte(i % 4)
|
2018-03-26 06:40:02 +02:00
|
|
|
successChan := s1.Broadcast(chID, []byte("test data"))
|
2018-01-11 17:15:04 -06:00
|
|
|
for s := range successChan {
|
|
|
|
if s {
|
2017-04-07 14:57:03 +04:00
|
|
|
numSuccess++
|
2015-10-25 18:21:51 -07:00
|
|
|
} else {
|
2017-04-07 14:57:03 +04:00
|
|
|
numFailure++
|
2015-10-25 18:21:51 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-08 18:22:51 -05:00
|
|
|
b.Logf("success: %v, failure: %v", numSuccess, numFailure)
|
2015-10-25 18:21:51 -07:00
|
|
|
}
|
2018-03-22 16:58:57 +01:00
|
|
|
|
|
|
|
type addrBookMock struct {
|
2018-04-05 15:21:11 +02:00
|
|
|
addrs map[string]struct{}
|
2018-03-22 16:58:57 +01:00
|
|
|
ourAddrs map[string]struct{}
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ AddrBook = (*addrBookMock)(nil)
|
|
|
|
|
2018-04-05 15:21:11 +02:00
|
|
|
func (book *addrBookMock) AddAddress(addr *NetAddress, src *NetAddress) error {
|
|
|
|
book.addrs[addr.String()] = struct{}{}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
func (book *addrBookMock) AddOurAddress(addr *NetAddress) { book.ourAddrs[addr.String()] = struct{}{} }
|
2018-03-22 16:58:57 +01:00
|
|
|
func (book *addrBookMock) OurAddress(addr *NetAddress) bool {
|
|
|
|
_, ok := book.ourAddrs[addr.String()]
|
|
|
|
return ok
|
|
|
|
}
|
|
|
|
func (book *addrBookMock) MarkGood(*NetAddress) {}
|
2018-04-05 15:21:11 +02:00
|
|
|
func (book *addrBookMock) HasAddress(addr *NetAddress) bool {
|
|
|
|
_, ok := book.addrs[addr.String()]
|
|
|
|
return ok
|
|
|
|
}
|
|
|
|
func (book *addrBookMock) RemoveAddress(addr *NetAddress) {
|
|
|
|
delete(book.addrs, addr.String())
|
|
|
|
}
|
|
|
|
func (book *addrBookMock) Save() {}
|