Skip to content

Commit c6b2553

Browse files
committed
rpcserver: expose v2 connection status in getpeerinfo
This commit adds a new boolean field, `V2Connection`, to the `getpeerinfo` RPC result. This field indicates whether the connection to the peer is using the v2 encrypted transport protocol. The `peer.StatsSnap` struct is updated to include this `V2Connection` field, which is populated based on the `UsingV2Conn` field in the peer's configuration. The `btcjson.GetPeerInfoResult` struct is also updated to include the corresponding JSON field `v2_connection`. Finally, the `handleGetPeerInfo` RPC handler is modified to copy this value from the peer's stats snapshot into the RPC response.
1 parent 2d2bf57 commit c6b2553

File tree

4 files changed

+5
-0
lines changed

4 files changed

+5
-0
lines changed

btcjson/chainsvrresults.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,7 @@ type GetPeerInfoResult struct {
460460
BanScore int32 `json:"banscore"`
461461
FeeFilter int64 `json:"feefilter"`
462462
SyncNode bool `json:"syncnode"`
463+
V2Connection bool `json:"v2_connection"`
463464
}
464465

465466
// GetRawMempoolVerboseResult models the data returned from the getrawmempool

peer/peer.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ type StatsSnap struct {
398398
LastPingNonce uint64
399399
LastPingTime time.Time
400400
LastPingMicros int64
401+
V2Connection bool
401402
}
402403

403404
// HashFunc is a function which returns a block hash, height and error
@@ -580,6 +581,7 @@ func (p *Peer) StatsSnapshot() *StatsSnap {
580581
LastPingNonce: p.lastPingNonce,
581582
LastPingMicros: p.lastPingMicros,
582583
LastPingTime: p.lastPingTime,
584+
V2Connection: p.cfg.UsingV2Conn,
583585
}
584586

585587
p.statsMtx.RUnlock()

rpcserver.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2588,6 +2588,7 @@ func handleGetPeerInfo(s *rpcServer, cmd interface{}, closeChan <-chan struct{})
25882588
BanScore: int32(p.BanScore()),
25892589
FeeFilter: p.FeeFilter(),
25902590
SyncNode: statsSnap.ID == syncPeerID,
2591+
V2Connection: statsSnap.V2Connection,
25912592
}
25922593
if p.ToPeer().LastPingNonce() != 0 {
25932594
wait := float64(time.Since(statsSnap.LastPingTime).Nanoseconds())

rpcserverhelp.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,7 @@ var helpDescsEnUS = map[string]string{
500500
"getpeerinforesult-banscore": "The ban score",
501501
"getpeerinforesult-feefilter": "The requested minimum fee a transaction must have to be announced to the peer",
502502
"getpeerinforesult-syncnode": "Whether or not the peer is the sync peer",
503+
"getpeerinforesult-v2_connection": "Whether or not the peer is a v2 connection",
503504

504505
// GetPeerInfoCmd help.
505506
"getpeerinfo--synopsis": "Returns data about each connected network peer as an array of json objects.",

0 commit comments

Comments
 (0)