Browse Source

Log adding of addresses to book

pull/39/head
Jae Kwon 10 years ago
parent
commit
5c8e69d6de
2 changed files with 14 additions and 11 deletions
  1. +3
    -1
      p2p/addrbook.go
  2. +11
    -10
      p2p/pex_reactor.go

+ 3
- 1
p2p/addrbook.go View File

@ -144,6 +144,7 @@ func (a *AddrBook) Stop() {
func (a *AddrBook) AddOurAddress(addr *NetAddress) {
a.mtx.Lock()
defer a.mtx.Unlock()
log.Debug("Add our address to book", "addr", addr)
a.ourAddrs[addr.String()] = addr
}
@ -158,6 +159,7 @@ func (a *AddrBook) OurAddresses() []*NetAddress {
func (a *AddrBook) AddAddress(addr *NetAddress, src *NetAddress) {
a.mtx.Lock()
defer a.mtx.Unlock()
log.Debug("Add address to book", "addr", addr, "src", src)
a.addAddress(addr, src)
}
@ -546,7 +548,7 @@ func (a *AddrBook) addAddress(addr, src *NetAddress) {
bucket := a.calcNewBucket(addr, src)
a.addToNewBucket(ka, bucket)
log.Info(Fmt("Added new address %s for a total of %d addresses", addr, a.size()))
log.Info("Added new address", "address", addr, "total", a.size())
}
// Make space in the new buckets by expiring the really bad entries.


+ 11
- 10
p2p/pex_reactor.go View File

@ -99,12 +99,7 @@ func (pexR *PEXReactor) Receive(chId byte, src *Peer, msgBytes []byte) {
case *pexRequestMessage:
// src requested some peers.
// TODO: prevent abuse.
addrs := pexR.book.GetSelection()
msg := &pexAddrsMessage{Addrs: addrs}
queued := src.TrySend(PexCh, msg)
if !queued {
// ignore
}
pexR.SendAddrs(src, pexR.book.GetSelection())
case *pexAddrsMessage:
// We received some peer addresses from src.
// TODO: prevent abuse.
@ -121,7 +116,7 @@ func (pexR *PEXReactor) Receive(chId byte, src *Peer, msgBytes []byte) {
// Asks peer for more addresses.
func (pexR *PEXReactor) RequestPEX(peer *Peer) {
peer.TrySend(PexCh, &pexRequestMessage{})
peer.Send(PexCh, &pexRequestMessage{})
}
func (pexR *PEXReactor) SendAddrs(peer *Peer, addrs []*NetAddress) {
@ -170,11 +165,17 @@ func (pexR *PEXReactor) ensurePeers() {
if try == nil {
break
}
if toDial.Has(try.String()) ||
pexR.sw.IsDialing(try) ||
pexR.sw.Peers().Has(try.String()) {
alreadySelected := toDial.Has(try.String())
alreadyDialing := pexR.sw.IsDialing(try)
alreadyConnected := pexR.sw.Peers().Has(try.String())
if alreadySelected || alreadyDialing || alreadyConnected {
log.Debug("Cannot dial address", "addr", try,
"alreadySelected", alreadySelected,
"alreadyDialing", alreadyDialing,
"alreadyConnected", alreadyConnected)
continue
} else {
log.Debug("Will dial address", "addr", try)
picked = try
break
}


Loading…
Cancel
Save