server: Update addrmgr services on outbound conns.

This adds code to update the address manager services for a known
address to the services advertised by peers when they are connected to
via an outbound connection.  It is only done for outbound connections to
help prevent malicious behavior from inbound connections.

Backported from Decred.
This commit is contained in:
Dave Collins 2018-06-03 03:29:22 -05:00
parent 24e23525fb
commit 4b20d4f86a
No known key found for this signature in database
GPG Key ID: B8904D9D9C93D1F2

View File

@ -395,6 +395,21 @@ func hasServices(advertised, desired wire.ServiceFlag) bool {
// and is used to negotiate the protocol version details as well as kick start
// the communications.
func (sp *serverPeer) OnVersion(_ *peer.Peer, msg *wire.MsgVersion) *wire.MsgReject {
// Update the address manager with the advertised services for outbound
// connections in case they have changed. This is not done for inbound
// connections to help prevent malicious behavior and is skipped when
// running on the simulation test network since it is only intended to
// connect to specified peers and actively avoids advertising and
// connecting to discovered peers.
//
// NOTE: This is done before rejecting peers that are too old to ensure
// it is updated regardless in the case a new minimum protocol version is
// enforced and the remote node has not upgraded yet.
addrManager := sp.server.addrManager
if !cfg.SimNet && !sp.Inbound() {
addrManager.SetServices(sp.NA(), msg.Services)
}
// Ignore peers that have a protcol version that is too old. The peer
// negotiation logic will disconnect it after this callback returns.
if msg.ProtocolVersion < int32(peer.MinAcceptableProtocolVersion) {
@ -430,8 +445,6 @@ func (sp *serverPeer) OnVersion(_ *peer.Peer, msg *wire.MsgVersion) *wire.MsgRej
// to specified peers and actively avoids advertising and connecting to
// discovered peers.
if !cfg.SimNet {
addrManager := sp.server.addrManager
// Outbound connections.
if !sp.Inbound() {
// After soft-fork activation, only make outbound