Bring back NodeInfo NetAddress form the dead (#3545)

A prior change to address accidental DNS lookups introduced the
SocketAddr on peer, which was then used to add it to the addressbook.
Which in turn swallowed the self reported port of the peer, which is
important on a reconnect. This change revives the NetAddress on NodeInfo
which the Peer carries, but now returns an error to avoid nil
dereferencing another issue observed in the past. Additionally we could
potentially address #3532, yet the original problem statemenf of that
issue stands.

As a drive-by optimisation `MarkAsGood` now takes only a `p2p.ID` which
makes it interface a bit stricter and leaner.

(cherry picked from commit b5b3b85697)
Signed-off-by: Ismail Khoffi <Ismail.Khoffi@gmail.com>
This commit is contained in:
Alexander Simmerl
2019-04-12 12:31:02 +02:00
committed by Ismail Khoffi
parent 91fd55343e
commit 362ef77eb0
8 changed files with 31 additions and 28 deletions

View File

@@ -46,7 +46,7 @@ type AddrBook interface {
AddAddress(addr *NetAddress, src *NetAddress) error
AddOurAddress(*NetAddress)
OurAddress(*NetAddress) bool
MarkGood(*NetAddress)
MarkGood(ID)
RemoveAddress(*NetAddress)
HasAddress(*NetAddress) bool
Save()
@@ -378,7 +378,7 @@ func (sw *Switch) SetAddrBook(addrBook AddrBook) {
// like contributed to consensus.
func (sw *Switch) MarkPeerAsGood(peer Peer) {
if sw.addrBook != nil {
sw.addrBook.MarkGood(peer.SocketAddr())
sw.addrBook.MarkGood(peer.ID())
}
}