From 9521e4e4e740c4a696316b0144a6a9ed1ee438f4 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Sat, 11 Jul 2015 00:35:24 +0000 Subject: [PATCH] add peer to addrbook on AddPeer, after handshake --- p2p/pex_reactor.go | 5 ++++- p2p/switch.go | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/p2p/pex_reactor.go b/p2p/pex_reactor.go index d32888ff8..5376e2527 100644 --- a/p2p/pex_reactor.go +++ b/p2p/pex_reactor.go @@ -76,8 +76,11 @@ func (pexR *PEXReactor) GetChannels() []*ChannelDescriptor { // Implements Reactor func (pexR *PEXReactor) AddPeer(peer *Peer) { + // Add the peer to the address book + netAddr := NewNetAddressString(fmt.Sprintf("%s:%d", peer.Host, peer.P2PPort)) + pexR.book.AddAddress(netAddr, netAddr) // the peer is its own source + if peer.IsOutbound() { - pexR.SendAddrs(peer, pexR.book.OurAddresses()) if pexR.book.NeedMoreAddrs() { pexR.RequestPEX(peer) } diff --git a/p2p/switch.go b/p2p/switch.go index 2702f5930..a7c683089 100644 --- a/p2p/switch.go +++ b/p2p/switch.go @@ -202,8 +202,8 @@ func (sw *Switch) AddPeerWithConnection(conn net.Conn, outbound bool) (*Peer, er } func (sw *Switch) startInitPeer(peer *Peer) { - peer.start() - sw.addPeerToReactors(peer) + peer.start() // spawn send/recv routines + sw.addPeerToReactors(peer) // run AddPeer on each reactor } func (sw *Switch) DialPeerWithAddress(addr *NetAddress) (*Peer, error) { @@ -306,7 +306,7 @@ func (sw *Switch) listenerRoutine(l Listener) { } // NOTE: We don't yet have the external address of the // remote (if they have a listener at all). - // PEXReactor's pexRoutine will handle that. + // The peerHandshake will take care of that } // cleanup