Browse Source

add peer to addrbook on AddPeer, after handshake

pull/110/head
Ethan Buchman 10 years ago
parent
commit
9521e4e4e7
2 changed files with 7 additions and 4 deletions
  1. +4
    -1
      p2p/pex_reactor.go
  2. +3
    -3
      p2p/switch.go

+ 4
- 1
p2p/pex_reactor.go 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)
}


+ 3
- 3
p2p/switch.go 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


Loading…
Cancel
Save