From 918fe7c4c54ea98d7bcd84916bfdef9fe9daeb20 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Thu, 27 Oct 2016 18:40:06 -0500 Subject: [PATCH] peer: Track and return advertised protocol version This adds a new field to the peer struct which stores the protocol version advertised by the remote peer and updates the StatsSnapshot to return the advertised version instead of the negotiated version. --- peer/peer.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/peer/peer.go b/peer/peer.go index 221fc875..6758dc19 100644 --- a/peer/peer.go +++ b/peer/peer.go @@ -417,8 +417,9 @@ type Peer struct { userAgent string services wire.ServiceFlag versionKnown bool - protocolVersion uint32 - sendHeadersPreferred bool // peer sent a sendheaders message + advertisedProtoVer uint32 // protocol version advertised by remote + protocolVersion uint32 // negotiated protocol version + sendHeadersPreferred bool // peer sent a sendheaders message versionSent bool verAckReceived bool @@ -504,7 +505,7 @@ func (p *Peer) StatsSnapshot() *StatsSnap { addr := p.addr userAgent := p.userAgent services := p.services - protocolVersion := p.protocolVersion + protocolVersion := p.advertisedProtoVer p.flagsMtx.Unlock() // Get a copy of all relevant flags and stats. @@ -647,7 +648,7 @@ func (p *Peer) VerAckReceived() bool { return p.verAckReceived } -// ProtocolVersion returns the peer protocol version. +// ProtocolVersion returns the negotiated peer protocol version. // // This function is safe for concurrent access. func (p *Peer) ProtocolVersion() uint32 { @@ -1022,7 +1023,8 @@ func (p *Peer) handleRemoteVersionMsg(msg *wire.MsgVersion) error { // Negotiate the protocol version. p.flagsMtx.Lock() - p.protocolVersion = minUint32(p.protocolVersion, uint32(msg.ProtocolVersion)) + p.advertisedProtoVer = uint32(msg.ProtocolVersion) + p.protocolVersion = minUint32(p.protocolVersion, p.advertisedProtoVer) p.versionKnown = true log.Debugf("Negotiated protocol version %d for peer %s", p.protocolVersion, p)