From a1f014c9e180a5ae53e3a60d53b1b2ecfeccf664 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 cc25966b..4a3a51da 100644 --- a/peer/peer.go +++ b/peer/peer.go @@ -402,8 +402,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 @@ -488,7 +489,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. @@ -644,7 +645,7 @@ func (p *Peer) VerAckReceived() bool { return 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 { @@ -1029,7 +1030,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)