p2p: some comments and a log line
This commit is contained in:
parent
3ee1d7909e
commit
aaa81092e7
|
@ -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
|
the selection process happens every `ensurePeersPeriod`, we might not end up
|
||||||
dialing a peer for much longer than the backoff duration.
|
dialing a peer for much longer than the backoff duration.
|
||||||
|
|
||||||
|
If we fail to conenct to the peer after 16 tries (with exponential backoff), we remove from address book completely.
|
||||||
TODO
|
|
||||||
PEX: if we fail to conenct to the peer after 16 tries (with exponential backoff), we remove from address book completely.
|
|
||||||
|
|
||||||
|
|
||||||
## Select Peers to Exchange
|
## Select Peers to Exchange
|
||||||
|
|
||||||
|
|
|
@ -295,6 +295,7 @@ func (a *addrBook) MarkBad(addr *p2p.NetAddress) {
|
||||||
|
|
||||||
// GetSelection implements AddrBook.
|
// GetSelection implements AddrBook.
|
||||||
// It randomly selects some addresses (old & new). Suitable for peer-exchange protocols.
|
// It randomly selects some addresses (old & new). Suitable for peer-exchange protocols.
|
||||||
|
// Must never return a nil address.
|
||||||
func (a *addrBook) GetSelection() []*p2p.NetAddress {
|
func (a *addrBook) GetSelection() []*p2p.NetAddress {
|
||||||
a.mtx.Lock()
|
a.mtx.Lock()
|
||||||
defer a.mtx.Unlock()
|
defer a.mtx.Unlock()
|
||||||
|
@ -332,6 +333,7 @@ func (a *addrBook) GetSelection() []*p2p.NetAddress {
|
||||||
|
|
||||||
// GetSelectionWithBias implements AddrBook.
|
// GetSelectionWithBias implements AddrBook.
|
||||||
// It randomly selects some addresses (old & new). Suitable for peer-exchange protocols.
|
// 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
|
// 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
|
// biasTowardsNewAddrs argument, which must be between [0, 100] (or else is truncated to
|
||||||
|
|
|
@ -301,7 +301,7 @@ func (r *PEXReactor) ReceiveAddrs(addrs []*p2p.NetAddress, src Peer) error {
|
||||||
|
|
||||||
srcAddr := src.NodeInfo().NetAddress()
|
srcAddr := src.NodeInfo().NetAddress()
|
||||||
for _, netAddr := range addrs {
|
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 {
|
if netAddr == nil {
|
||||||
return cmn.NewError("received nil addr")
|
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)
|
err := r.book.AddAddress(netAddr, srcAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
switch err.(type) {
|
||||||
|
case ErrAddrBookNilAddr:
|
||||||
r.Logger.Error("Failed to add new address", "err", err)
|
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
|
return nil
|
||||||
|
@ -410,7 +416,7 @@ func (r *PEXReactor) ensurePeers() {
|
||||||
}
|
}
|
||||||
// TODO: consider moving some checks from toDial into here
|
// TODO: consider moving some checks from toDial into here
|
||||||
// so we don't even consider dialing peers that we want to wait
|
// 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)
|
r.Logger.Info("Will dial address", "addr", try)
|
||||||
toDial[try.ID] = try
|
toDial[try.ID] = try
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue