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:
parent
24e23525fb
commit
4b20d4f86a
1 changed files with 15 additions and 2 deletions
17
server.go
17
server.go
|
@ -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
|
// and is used to negotiate the protocol version details as well as kick start
|
||||||
// the communications.
|
// the communications.
|
||||||
func (sp *serverPeer) OnVersion(_ *peer.Peer, msg *wire.MsgVersion) *wire.MsgReject {
|
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
|
// Ignore peers that have a protcol version that is too old. The peer
|
||||||
// negotiation logic will disconnect it after this callback returns.
|
// negotiation logic will disconnect it after this callback returns.
|
||||||
if msg.ProtocolVersion < int32(peer.MinAcceptableProtocolVersion) {
|
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
|
// to specified peers and actively avoids advertising and connecting to
|
||||||
// discovered peers.
|
// discovered peers.
|
||||||
if !cfg.SimNet {
|
if !cfg.SimNet {
|
||||||
addrManager := sp.server.addrManager
|
|
||||||
|
|
||||||
// Outbound connections.
|
// Outbound connections.
|
||||||
if !sp.Inbound() {
|
if !sp.Inbound() {
|
||||||
// After soft-fork activation, only make outbound
|
// After soft-fork activation, only make outbound
|
||||||
|
|
Loading…
Reference in a new issue