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
This commit is contained in:
parent
9151ebc90b
commit
4d1e1db9ea
1 changed files with 5 additions and 23 deletions
28
peer/peer.go
28
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
|
||||
|
|
Loading…
Add table
Reference in a new issue