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
1 changed files with 6 additions and 24 deletions
30
server.go
30
server.go
|
@ -9,6 +9,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"github.com/conformal/btcdb"
|
||||
"github.com/conformal/btcjson"
|
||||
"github.com/conformal/btcwire"
|
||||
"net"
|
||||
"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 {
|
||||
reply chan int
|
||||
}
|
||||
|
||||
type getPeerInfoMsg struct {
|
||||
reply chan []*PeerInfo
|
||||
reply chan []*btcjson.GetPeerInfoResult
|
||||
}
|
||||
|
||||
type addNodeMsg struct {
|
||||
|
@ -318,7 +300,7 @@ func (s *server) handleQuery(querymsg interface{}, state *peerState) {
|
|||
|
||||
case getPeerInfoMsg:
|
||||
syncPeer := s.blockManager.SyncPeer()
|
||||
infos := make([]*PeerInfo, 0, state.peers.Len())
|
||||
infos := make([]*btcjson.GetPeerInfoResult, 0, state.peers.Len())
|
||||
state.forAllPeers(func(p *peer) {
|
||||
if !p.Connected() {
|
||||
return
|
||||
|
@ -328,7 +310,7 @@ func (s *server) handleQuery(querymsg interface{}, state *peerState) {
|
|||
// however it is statistics for purely informational purposes
|
||||
// and we don't really care if they are raced to get the new
|
||||
// version.
|
||||
info := &PeerInfo{
|
||||
info := &btcjson.GetPeerInfoResult{
|
||||
Addr: p.addr,
|
||||
Services: fmt.Sprintf("%08d", p.services),
|
||||
LastSend: p.lastSend.Unix(),
|
||||
|
@ -668,8 +650,8 @@ func (s *server) AddedNodeInfo() []*peer {
|
|||
|
||||
// PeerInfo returns an array of PeerInfo structures describing all connected
|
||||
// peers.
|
||||
func (s *server) PeerInfo() []*PeerInfo {
|
||||
replyChan := make(chan []*PeerInfo)
|
||||
func (s *server) PeerInfo() []*btcjson.GetPeerInfoResult {
|
||||
replyChan := make(chan []*btcjson.GetPeerInfoResult)
|
||||
|
||||
s.query <- getPeerInfoMsg{reply: replyChan}
|
||||
|
||||
|
|
Loading…
Reference in a new issue