Browse Source

p2p: do not log err if peer is private (#3474)

* add actionable advice for ErrAddrBookNonRoutable err

Should replace https://github.com/tendermint/tendermint/pull/3463

* reorder checks in addrbook#addAddress so

ErrAddrBookPrivate is returned first

and do not log error in DialPeersAsync if the address is private
because it's not an error
pull/3544/head
Anton Kaliaev 6 years ago
committed by GitHub
parent
commit
bcec8be035
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 11 deletions
  1. +10
    -10
      p2p/pex/addrbook.go
  2. +8
    -0
      p2p/pex/errors.go
  3. +16
    -1
      p2p/switch.go

+ 10
- 10
p2p/pex/addrbook.go View File

@ -586,16 +586,16 @@ func (a *addrBook) addAddress(addr, src *p2p.NetAddress) error {
return ErrAddrBookNilAddr{addr, src} return ErrAddrBookNilAddr{addr, src}
} }
if a.routabilityStrict && !addr.Routable() {
return ErrAddrBookNonRoutable{addr}
if !addr.HasID() {
return ErrAddrBookInvalidAddrNoID{addr}
} }
if !addr.Valid() {
return ErrAddrBookInvalidAddr{addr}
if _, ok := a.privateIDs[addr.ID]; ok {
return ErrAddrBookPrivate{addr}
} }
if !addr.HasID() {
return ErrAddrBookInvalidAddrNoID{addr}
if _, ok := a.privateIDs[src.ID]; ok {
return ErrAddrBookPrivateSrc{src}
} }
// TODO: we should track ourAddrs by ID and by IP:PORT and refuse both. // TODO: we should track ourAddrs by ID and by IP:PORT and refuse both.
@ -603,12 +603,12 @@ func (a *addrBook) addAddress(addr, src *p2p.NetAddress) error {
return ErrAddrBookSelf{addr} return ErrAddrBookSelf{addr}
} }
if _, ok := a.privateIDs[addr.ID]; ok {
return ErrAddrBookPrivate{addr}
if a.routabilityStrict && !addr.Routable() {
return ErrAddrBookNonRoutable{addr}
} }
if _, ok := a.privateIDs[src.ID]; ok {
return ErrAddrBookPrivateSrc{src}
if !addr.Valid() {
return ErrAddrBookInvalidAddr{addr}
} }
ka := a.addrLookup[addr.ID] ka := a.addrLookup[addr.ID]


+ 8
- 0
p2p/pex/errors.go View File

@ -30,6 +30,10 @@ func (err ErrAddrBookPrivate) Error() string {
return fmt.Sprintf("Cannot add private peer with address %v", err.Addr) return fmt.Sprintf("Cannot add private peer with address %v", err.Addr)
} }
func (err ErrAddrBookPrivate) PrivateAddr() bool {
return true
}
type ErrAddrBookPrivateSrc struct { type ErrAddrBookPrivateSrc struct {
Src *p2p.NetAddress Src *p2p.NetAddress
} }
@ -38,6 +42,10 @@ func (err ErrAddrBookPrivateSrc) Error() string {
return fmt.Sprintf("Cannot add peer coming from private peer with address %v", err.Src) return fmt.Sprintf("Cannot add peer coming from private peer with address %v", err.Src)
} }
func (err ErrAddrBookPrivateSrc) PrivateAddr() bool {
return true
}
type ErrAddrBookNilAddr struct { type ErrAddrBookNilAddr struct {
Addr *p2p.NetAddress Addr *p2p.NetAddress
Src *p2p.NetAddress Src *p2p.NetAddress


+ 16
- 1
p2p/switch.go View File

@ -6,6 +6,8 @@ import (
"sync" "sync"
"time" "time"
"github.com/pkg/errors"
"github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/config"
cmn "github.com/tendermint/tendermint/libs/common" cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/p2p/conn" "github.com/tendermint/tendermint/p2p/conn"
@ -390,6 +392,15 @@ func (sw *Switch) MarkPeerAsGood(peer Peer) {
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// Dialing // Dialing
type privateAddr interface {
PrivateAddr() bool
}
func isPrivateAddr(err error) bool {
te, ok := errors.Cause(err).(privateAddr)
return ok && te.PrivateAddr()
}
// DialPeersAsync dials a list of peers asynchronously in random order (optionally, making them persistent). // DialPeersAsync dials a list of peers asynchronously in random order (optionally, making them persistent).
// Used to dial peers from config on startup or from unsafe-RPC (trusted sources). // Used to dial peers from config on startup or from unsafe-RPC (trusted sources).
// TODO: remove addrBook arg since it's now set on the switch // TODO: remove addrBook arg since it's now set on the switch
@ -412,7 +423,11 @@ func (sw *Switch) DialPeersAsync(addrBook AddrBook, peers []string, persistent b
// do not add our address or ID // do not add our address or ID
if !netAddr.Same(ourAddr) { if !netAddr.Same(ourAddr) {
if err := addrBook.AddAddress(netAddr, ourAddr); err != nil { if err := addrBook.AddAddress(netAddr, ourAddr); err != nil {
sw.Logger.Error("Can't add peer's address to addrbook", "err", err)
if isPrivateAddr(err) {
sw.Logger.Debug("Won't add peer's address to addrbook", "err", err)
} else {
sw.Logger.Error("Can't add peer's address to addrbook", "err", err)
}
} }
} }
} }


Loading…
Cancel
Save