Skip to content

Commit

Permalink
server: Update addrmgr services on outbound conns.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
davecgh authored and cpacia committed Oct 13, 2018
1 parent e2ce604 commit 2ca5c1c
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,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) {
Expand Down Expand Up @@ -436,8 +451,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() {
// TODO(davec): Only do this if not doing the initial block
Expand Down

0 comments on commit 2ca5c1c

Please sign in to comment.