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.
This commit is contained in:
parent
14b51fc5f8
commit
a1f014c9e1
1 changed files with 7 additions and 5 deletions
10
peer/peer.go
10
peer/peer.go
|
@ -402,7 +402,8 @@ type Peer struct {
|
||||||
userAgent string
|
userAgent string
|
||||||
services wire.ServiceFlag
|
services wire.ServiceFlag
|
||||||
versionKnown bool
|
versionKnown bool
|
||||||
protocolVersion uint32
|
advertisedProtoVer uint32 // protocol version advertised by remote
|
||||||
|
protocolVersion uint32 // negotiated protocol version
|
||||||
sendHeadersPreferred bool // peer sent a sendheaders message
|
sendHeadersPreferred bool // peer sent a sendheaders message
|
||||||
versionSent bool
|
versionSent bool
|
||||||
verAckReceived bool
|
verAckReceived bool
|
||||||
|
@ -488,7 +489,7 @@ func (p *Peer) StatsSnapshot() *StatsSnap {
|
||||||
addr := p.addr
|
addr := p.addr
|
||||||
userAgent := p.userAgent
|
userAgent := p.userAgent
|
||||||
services := p.services
|
services := p.services
|
||||||
protocolVersion := p.protocolVersion
|
protocolVersion := p.advertisedProtoVer
|
||||||
p.flagsMtx.Unlock()
|
p.flagsMtx.Unlock()
|
||||||
|
|
||||||
// Get a copy of all relevant flags and stats.
|
// Get a copy of all relevant flags and stats.
|
||||||
|
@ -644,7 +645,7 @@ func (p *Peer) VerAckReceived() bool {
|
||||||
return verAckReceived
|
return verAckReceived
|
||||||
}
|
}
|
||||||
|
|
||||||
// ProtocolVersion returns the peer protocol version.
|
// ProtocolVersion returns the negotiated peer protocol version.
|
||||||
//
|
//
|
||||||
// This function is safe for concurrent access.
|
// This function is safe for concurrent access.
|
||||||
func (p *Peer) ProtocolVersion() uint32 {
|
func (p *Peer) ProtocolVersion() uint32 {
|
||||||
|
@ -1029,7 +1030,8 @@ func (p *Peer) handleRemoteVersionMsg(msg *wire.MsgVersion) error {
|
||||||
|
|
||||||
// Negotiate the protocol version.
|
// Negotiate the protocol version.
|
||||||
p.flagsMtx.Lock()
|
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
|
p.versionKnown = true
|
||||||
log.Debugf("Negotiated protocol version %d for peer %s",
|
log.Debugf("Negotiated protocol version %d for peer %s",
|
||||||
p.protocolVersion, p)
|
p.protocolVersion, p)
|
||||||
|
|
Loading…
Reference in a new issue