rpc: Add localaddr and relaytxes to getpeerinfo

This commit is contained in:
David Hill 2016-10-19 19:48:03 -04:00
parent 3b5bb9fd43
commit 07e1e308f1
4 changed files with 15 additions and 0 deletions

View file

@ -164,6 +164,7 @@ type GetPeerInfoResult struct {
Addr string `json:"addr"`
AddrLocal string `json:"addrlocal,omitempty"`
Services string `json:"services"`
RelayTxes bool `json:"relaytxes"`
LastSend int64 `json:"lastsend"`
LastRecv int64 `json:"lastrecv"`
BytesSent uint64 `json:"bytessent"`

View file

@ -683,6 +683,17 @@ func (p *Peer) LastRecv() time.Time {
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.
//
// This function is safe for concurrent access.

View file

@ -2203,7 +2203,9 @@ func handleGetPeerInfo(s *rpcServer, cmd interface{}, closeChan <-chan struct{})
info := &btcjson.GetPeerInfoResult{
ID: statsSnap.ID,
Addr: statsSnap.Addr,
AddrLocal: p.LocalAddr().String(),
Services: fmt.Sprintf("%08d", uint64(statsSnap.Services)),
RelayTxes: !p.disableRelayTx,
LastSend: statsSnap.LastSend.Unix(),
LastRecv: statsSnap.LastRecv.Unix(),
BytesSent: statsSnap.BytesSent,

View file

@ -376,6 +376,7 @@ var helpDescsEnUS = map[string]string{
"getpeerinforesult-addr": "The ip address and port of the peer",
"getpeerinforesult-addrlocal": "Local address",
"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-lastrecv": "Time the last message was sent in seconds since 1 Jan 1970 GMT",
"getpeerinforesult-bytessent": "Total bytes sent",