Browse Source

p2p: some comments and a log line

pull/1519/head
Ethan Buchman 6 years ago
parent
commit
aaa81092e7
3 changed files with 12 additions and 7 deletions
  1. +1
    -4
      docs/specification/new-spec/reactors/pex/pex.md
  2. +2
    -0
      p2p/pex/addrbook.go
  3. +9
    -3
      p2p/pex/pex_reactor.go

+ 1
- 4
docs/specification/new-spec/reactors/pex/pex.md View File

@ -83,10 +83,7 @@ Connection attempts are made with exponential backoff (plus jitter). Because
the selection process happens every `ensurePeersPeriod`, we might not end up
dialing a peer for much longer than the backoff duration.
TODO
PEX: if we fail to conenct to the peer after 16 tries (with exponential backoff), we remove from address book completely.
If we fail to conenct to the peer after 16 tries (with exponential backoff), we remove from address book completely.
## Select Peers to Exchange


+ 2
- 0
p2p/pex/addrbook.go View File

@ -295,6 +295,7 @@ func (a *addrBook) MarkBad(addr *p2p.NetAddress) {
// GetSelection implements AddrBook.
// It randomly selects some addresses (old & new). Suitable for peer-exchange protocols.
// Must never return a nil address.
func (a *addrBook) GetSelection() []*p2p.NetAddress {
a.mtx.Lock()
defer a.mtx.Unlock()
@ -332,6 +333,7 @@ func (a *addrBook) GetSelection() []*p2p.NetAddress {
// GetSelectionWithBias implements AddrBook.
// It randomly selects some addresses (old & new). Suitable for peer-exchange protocols.
// Must never return a nil address.
//
// Each address is picked randomly from an old or new bucket according to the
// biasTowardsNewAddrs argument, which must be between [0, 100] (or else is truncated to


+ 9
- 3
p2p/pex/pex_reactor.go View File

@ -301,7 +301,7 @@ func (r *PEXReactor) ReceiveAddrs(addrs []*p2p.NetAddress, src Peer) error {
srcAddr := src.NodeInfo().NetAddress()
for _, netAddr := range addrs {
// TODO: make sure correct nodes never send nil and return error
// NOTE: GetSelection methods should never return nil addrs
if netAddr == nil {
return cmn.NewError("received nil addr")
}
@ -316,7 +316,13 @@ func (r *PEXReactor) ReceiveAddrs(addrs []*p2p.NetAddress, src Peer) error {
err := r.book.AddAddress(netAddr, srcAddr)
if err != nil {
r.Logger.Error("Failed to add new address", "err", err)
switch err.(type) {
case ErrAddrBookNilAddr:
r.Logger.Error("Failed to add new address", "err", err)
default:
// Could be non-routable, self, or full book. But not worth logging an Error
r.Logger.Debug("Failed to add new address", "err", err)
}
}
}
return nil
@ -410,7 +416,7 @@ func (r *PEXReactor) ensurePeers() {
}
// TODO: consider moving some checks from toDial into here
// so we don't even consider dialing peers that we want to wait
// before dialling again, or have dialled too many times already
// before dialling again, or have dialed too many times already
r.Logger.Info("Will dial address", "addr", try)
toDial[try.ID] = try
}


Loading…
Cancel
Save