From 4d1e1db9eae33fd30421b7048be1cc936609b69a Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Fri, 10 Aug 2018 21:40:01 -0500 Subject: [PATCH] peer: Improve net address service adverts. This modifies the peer code which deals with advertising service flags via the net address fields of the version message as follows: - For outgoing connections: - Set the local netaddress services to what the local peer supports - Set the remote netaddress services to 0 to indicate no services as they are still unknown - For incoming connections: - Set the local netaddress services to what the local peer supports - Set the remote netaddress services to the what was advertised by the remote peer in its version message --- peer/peer.go | 28 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/peer/peer.go b/peer/peer.go index afb14173..61bc619f 100644 --- a/peer/peer.go +++ b/peer/peer.go @@ -1995,7 +1995,8 @@ func (p *Peer) localVersionMsg() (*wire.MsgVersion, error) { proxyaddress, _, err := net.SplitHostPort(p.cfg.Proxy) // invalid proxy means poorly configured, be on the safe side. if err != nil || p.na.IP.String() == proxyaddress { - theirNA = wire.NewNetAddressIPPort(net.IP([]byte{0, 0, 0, 0}), 0, 0) + theirNA = wire.NewNetAddressIPPort(net.IP([]byte{0, 0, 0, 0}), 0, + theirNA.Services) } } @@ -2023,25 +2024,7 @@ func (p *Peer) localVersionMsg() (*wire.MsgVersion, error) { msg.AddUserAgent(p.cfg.UserAgentName, p.cfg.UserAgentVersion, p.cfg.UserAgentComments...) - // XXX: bitcoind appears to always enable the full node services flag - // of the remote peer netaddress field in the version message regardless - // of whether it knows it supports it or not. Also, bitcoind sets - // the services field of the local peer to 0 regardless of support. - // - // Realistically, this should be set as follows: - // - For outgoing connections: - // - Set the local netaddress services to what the local peer - // actually supports - // - Set the remote netaddress services to 0 to indicate no services - // as they are still unknown - // - For incoming connections: - // - Set the local netaddress services to what the local peer - // actually supports - // - Set the remote netaddress services to the what was advertised by - // by the remote peer in its version message - msg.AddrYou.Services = wire.SFNodeNetwork - - // Advertise the services flag + // Advertise local services. msg.Services = p.cfg.Services // Advertise our max supported protocol version. @@ -2229,14 +2212,13 @@ func NewOutboundPeer(cfg *Config, addr string) (*Peer, error) { } if cfg.HostToNetAddress != nil { - na, err := cfg.HostToNetAddress(host, uint16(port), cfg.Services) + na, err := cfg.HostToNetAddress(host, uint16(port), 0) if err != nil { return nil, err } p.na = na } else { - p.na = wire.NewNetAddressIPPort(net.ParseIP(host), uint16(port), - cfg.Services) + p.na = wire.NewNetAddressIPPort(net.ParseIP(host), uint16(port), 0) } return p, nil