rpc: Add localaddr and relaytxes to getpeerinfo
This commit is contained in:
parent
3b5bb9fd43
commit
07e1e308f1
4 changed files with 15 additions and 0 deletions
|
@ -164,6 +164,7 @@ type GetPeerInfoResult struct {
|
||||||
Addr string `json:"addr"`
|
Addr string `json:"addr"`
|
||||||
AddrLocal string `json:"addrlocal,omitempty"`
|
AddrLocal string `json:"addrlocal,omitempty"`
|
||||||
Services string `json:"services"`
|
Services string `json:"services"`
|
||||||
|
RelayTxes bool `json:"relaytxes"`
|
||||||
LastSend int64 `json:"lastsend"`
|
LastSend int64 `json:"lastsend"`
|
||||||
LastRecv int64 `json:"lastrecv"`
|
LastRecv int64 `json:"lastrecv"`
|
||||||
BytesSent uint64 `json:"bytessent"`
|
BytesSent uint64 `json:"bytessent"`
|
||||||
|
|
11
peer/peer.go
11
peer/peer.go
|
@ -683,6 +683,17 @@ func (p *Peer) LastRecv() time.Time {
|
||||||
return time.Unix(atomic.LoadInt64(&p.lastRecv), 0)
|
return time.Unix(atomic.LoadInt64(&p.lastRecv), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LocalAddr returns the local address of the connection.
|
||||||
|
//
|
||||||
|
// This function is safe fo concurrent access.
|
||||||
|
func (p *Peer) LocalAddr() net.Addr {
|
||||||
|
var localAddr net.Addr
|
||||||
|
if p.Connected() {
|
||||||
|
localAddr = p.conn.LocalAddr()
|
||||||
|
}
|
||||||
|
return localAddr
|
||||||
|
}
|
||||||
|
|
||||||
// BytesSent returns the total number of bytes sent by the peer.
|
// BytesSent returns the total number of bytes sent by the peer.
|
||||||
//
|
//
|
||||||
// This function is safe for concurrent access.
|
// This function is safe for concurrent access.
|
||||||
|
|
|
@ -2203,7 +2203,9 @@ func handleGetPeerInfo(s *rpcServer, cmd interface{}, closeChan <-chan struct{})
|
||||||
info := &btcjson.GetPeerInfoResult{
|
info := &btcjson.GetPeerInfoResult{
|
||||||
ID: statsSnap.ID,
|
ID: statsSnap.ID,
|
||||||
Addr: statsSnap.Addr,
|
Addr: statsSnap.Addr,
|
||||||
|
AddrLocal: p.LocalAddr().String(),
|
||||||
Services: fmt.Sprintf("%08d", uint64(statsSnap.Services)),
|
Services: fmt.Sprintf("%08d", uint64(statsSnap.Services)),
|
||||||
|
RelayTxes: !p.disableRelayTx,
|
||||||
LastSend: statsSnap.LastSend.Unix(),
|
LastSend: statsSnap.LastSend.Unix(),
|
||||||
LastRecv: statsSnap.LastRecv.Unix(),
|
LastRecv: statsSnap.LastRecv.Unix(),
|
||||||
BytesSent: statsSnap.BytesSent,
|
BytesSent: statsSnap.BytesSent,
|
||||||
|
|
|
@ -376,6 +376,7 @@ var helpDescsEnUS = map[string]string{
|
||||||
"getpeerinforesult-addr": "The ip address and port of the peer",
|
"getpeerinforesult-addr": "The ip address and port of the peer",
|
||||||
"getpeerinforesult-addrlocal": "Local address",
|
"getpeerinforesult-addrlocal": "Local address",
|
||||||
"getpeerinforesult-services": "Services bitmask which represents the services supported by the peer",
|
"getpeerinforesult-services": "Services bitmask which represents the services supported by the peer",
|
||||||
|
"getpeerinforesult-relaytxes": "Peer has requested transactions be relayed to it",
|
||||||
"getpeerinforesult-lastsend": "Time the last message was received in seconds since 1 Jan 1970 GMT",
|
"getpeerinforesult-lastsend": "Time the last message was received in seconds since 1 Jan 1970 GMT",
|
||||||
"getpeerinforesult-lastrecv": "Time the last message was sent in seconds since 1 Jan 1970 GMT",
|
"getpeerinforesult-lastrecv": "Time the last message was sent in seconds since 1 Jan 1970 GMT",
|
||||||
"getpeerinforesult-bytessent": "Total bytes sent",
|
"getpeerinforesult-bytessent": "Total bytes sent",
|
||||||
|
|
Loading…
Reference in a new issue