mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-07 14:46:44 +00:00
Switch over to new btcjson.GetPeerInfoResult.
Rather than using a type specifically in btcd for the getpeerinfo, this commit, along with a recent commit to btcjson, changes the code over to use the type from btcjson. This is more consistent with other RPC results and provides a few extra benefits such as the ability for btcjson to automatically unmarshal the results into a concrete type with proper field types as opposed to a generic interface.
This commit is contained in:
parent
8ebbee1f05
commit
41da7ae606
30
server.go
30
server.go
@ -9,6 +9,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/conformal/btcdb"
|
"github.com/conformal/btcdb"
|
||||||
|
"github.com/conformal/btcjson"
|
||||||
"github.com/conformal/btcwire"
|
"github.com/conformal/btcwire"
|
||||||
"net"
|
"net"
|
||||||
"runtime"
|
"runtime"
|
||||||
@ -261,31 +262,12 @@ func (s *server) handleBroadcastMsg(state *peerState, bmsg *broadcastMsg) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// PeerInfo represents the information requested by the getpeerinfo rpc command.
|
|
||||||
type PeerInfo struct {
|
|
||||||
Addr string `json:"addr"`
|
|
||||||
Services string `json:"services"`
|
|
||||||
LastSend int64 `json:"lastsend"`
|
|
||||||
LastRecv int64 `json:"lastrecv"`
|
|
||||||
BytesSent uint64 `json:"bytessent"`
|
|
||||||
BytesRecv uint64 `json:"bytesrecv"`
|
|
||||||
PingTime int64 `json:"pingtime"`
|
|
||||||
PingWait int64 `json:"pingwait,omitempty"`
|
|
||||||
ConnTime int64 `json:"conntime"`
|
|
||||||
Version uint32 `json:"version"`
|
|
||||||
SubVer string `json:"subver"`
|
|
||||||
Inbound bool `json:"inbound"`
|
|
||||||
StartingHeight int32 `json:"startingheight"`
|
|
||||||
BanScore int `json:"banscore,omitempty"`
|
|
||||||
SyncNode bool `json:"syncnode"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type getConnCountMsg struct {
|
type getConnCountMsg struct {
|
||||||
reply chan int
|
reply chan int
|
||||||
}
|
}
|
||||||
|
|
||||||
type getPeerInfoMsg struct {
|
type getPeerInfoMsg struct {
|
||||||
reply chan []*PeerInfo
|
reply chan []*btcjson.GetPeerInfoResult
|
||||||
}
|
}
|
||||||
|
|
||||||
type addNodeMsg struct {
|
type addNodeMsg struct {
|
||||||
@ -318,7 +300,7 @@ func (s *server) handleQuery(querymsg interface{}, state *peerState) {
|
|||||||
|
|
||||||
case getPeerInfoMsg:
|
case getPeerInfoMsg:
|
||||||
syncPeer := s.blockManager.SyncPeer()
|
syncPeer := s.blockManager.SyncPeer()
|
||||||
infos := make([]*PeerInfo, 0, state.peers.Len())
|
infos := make([]*btcjson.GetPeerInfoResult, 0, state.peers.Len())
|
||||||
state.forAllPeers(func(p *peer) {
|
state.forAllPeers(func(p *peer) {
|
||||||
if !p.Connected() {
|
if !p.Connected() {
|
||||||
return
|
return
|
||||||
@ -328,7 +310,7 @@ func (s *server) handleQuery(querymsg interface{}, state *peerState) {
|
|||||||
// however it is statistics for purely informational purposes
|
// however it is statistics for purely informational purposes
|
||||||
// and we don't really care if they are raced to get the new
|
// and we don't really care if they are raced to get the new
|
||||||
// version.
|
// version.
|
||||||
info := &PeerInfo{
|
info := &btcjson.GetPeerInfoResult{
|
||||||
Addr: p.addr,
|
Addr: p.addr,
|
||||||
Services: fmt.Sprintf("%08d", p.services),
|
Services: fmt.Sprintf("%08d", p.services),
|
||||||
LastSend: p.lastSend.Unix(),
|
LastSend: p.lastSend.Unix(),
|
||||||
@ -668,8 +650,8 @@ func (s *server) AddedNodeInfo() []*peer {
|
|||||||
|
|
||||||
// PeerInfo returns an array of PeerInfo structures describing all connected
|
// PeerInfo returns an array of PeerInfo structures describing all connected
|
||||||
// peers.
|
// peers.
|
||||||
func (s *server) PeerInfo() []*PeerInfo {
|
func (s *server) PeerInfo() []*btcjson.GetPeerInfoResult {
|
||||||
replyChan := make(chan []*PeerInfo)
|
replyChan := make(chan []*btcjson.GetPeerInfoResult)
|
||||||
|
|
||||||
s.query <- getPeerInfoMsg{reply: replyChan}
|
s.query <- getPeerInfoMsg{reply: replyChan}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user