add peer to addrbook on AddPeer, after handshake

This commit is contained in:
Ethan Buchman
2015-07-11 00:35:24 +00:00
parent fadfc673e3
commit 9521e4e4e7
2 changed files with 7 additions and 4 deletions

View File

@@ -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)
}

View File

@@ -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