mirror of
https://github.com/btcsuite/btcd.git
synced 2024-11-19 01:40:07 +01:00
Add id and timeoffset to getpeerinfo.
This commit is contained in:
parent
62432a6f90
commit
db8fa6f850
@ -329,14 +329,16 @@ Returns a list of JSON objects containing information about each connected
|
||||
network node. The objects have the following format:
|
||||
[
|
||||
{
|
||||
"id":n, # Unique node ID.
|
||||
"addr":"host:port" # IP and port of the peer as a string.
|
||||
"addrlocal":"ip:port" # Local address as a string.
|
||||
"services":"00000001", # Services bitmask as a string.
|
||||
"lastsend":t, # Time in seconds since epoch since last send.
|
||||
"lastrecv":t, # Time in seconds since epoch since last received message.
|
||||
"bytessent":n, # Total number of bytes sent.
|
||||
"bytesrecv":n, # Total number of bytes received
|
||||
"conntime":t, # Connection time in seconds since epoc.
|
||||
"bytesrecv":n, # Total number of bytes received.
|
||||
"conntime":t, # Connection time in seconds since epoch.
|
||||
"timeoffset":n, # Peer time offset.
|
||||
"pingtime":n, # Ping time
|
||||
"pingwait":n, # Ping wait.
|
||||
"version":n, # The numeric peer version.
|
||||
|
@ -137,6 +137,7 @@ type GetNetworkInfoResult struct {
|
||||
|
||||
// GetPeerInfoResult models the data returned from the getpeerinfo command.
|
||||
type GetPeerInfoResult struct {
|
||||
ID string `json:"id"`
|
||||
Addr string `json:"addr"`
|
||||
AddrLocal string `json:"addrlocal,omitempty"`
|
||||
Services string `json:"services"`
|
||||
@ -144,9 +145,10 @@ type GetPeerInfoResult struct {
|
||||
LastRecv int64 `json:"lastrecv"`
|
||||
BytesSent uint64 `json:"bytessent"`
|
||||
BytesRecv uint64 `json:"bytesrecv"`
|
||||
ConnTime int64 `json:"conntime"`
|
||||
TimeOffset int64 `json:"timeoffset"`
|
||||
PingTime float64 `json:"pingtime"`
|
||||
PingWait float64 `json:"pingwait,omitempty"`
|
||||
ConnTime int64 `json:"conntime"`
|
||||
Version uint32 `json:"version"`
|
||||
SubVer string `json:"subver"`
|
||||
Inbound bool `json:"inbound"`
|
||||
|
@ -136,6 +136,7 @@ type GetNetworkInfoResult struct {
|
||||
|
||||
// GetPeerInfoResult models the data returned from the getpeerinfo command.
|
||||
type GetPeerInfoResult struct {
|
||||
ID int32 `json:"id"`
|
||||
Addr string `json:"addr"`
|
||||
AddrLocal string `json:"addrlocal,omitempty"`
|
||||
Services string `json:"services"`
|
||||
@ -143,9 +144,10 @@ type GetPeerInfoResult struct {
|
||||
LastRecv int64 `json:"lastrecv"`
|
||||
BytesSent uint64 `json:"bytessent"`
|
||||
BytesRecv uint64 `json:"bytesrecv"`
|
||||
ConnTime int64 `json:"conntime"`
|
||||
TimeOffset int64 `json:"timeoffset"`
|
||||
PingTime float64 `json:"pingtime"`
|
||||
PingWait float64 `json:"pingwait,omitempty"`
|
||||
ConnTime int64 `json:"conntime"`
|
||||
Version uint32 `json:"version"`
|
||||
SubVer string `json:"subver"`
|
||||
Inbound bool `json:"inbound"`
|
||||
|
12
peer.go
12
peer.go
@ -56,6 +56,10 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
// nodeCount is the total number of peer connections made since startup
|
||||
// and is used to assign an id to a peer.
|
||||
nodeCount int32
|
||||
|
||||
// userAgentName is the user agent name and is used to help identify
|
||||
// ourselves to other bitcoin peers.
|
||||
userAgentName = "btcd"
|
||||
@ -150,6 +154,7 @@ type peer struct {
|
||||
conn net.Conn
|
||||
addr string
|
||||
na *wire.NetAddress
|
||||
id int32
|
||||
inbound bool
|
||||
persistent bool
|
||||
knownAddresses map[string]struct{}
|
||||
@ -179,6 +184,7 @@ type peer struct {
|
||||
versionKnown bool
|
||||
protocolVersion uint32
|
||||
services wire.ServiceFlag
|
||||
timeOffset int64
|
||||
timeConnected time.Time
|
||||
lastSend time.Time
|
||||
lastRecv time.Time
|
||||
@ -402,6 +408,12 @@ func (p *peer) handleVersionMsg(msg *wire.MsgVersion) {
|
||||
// Set the remote peer's user agent.
|
||||
p.userAgent = msg.UserAgent
|
||||
|
||||
// Set the peer's time offset.
|
||||
p.timeOffset = msg.Timestamp.Unix() - time.Now().Unix()
|
||||
|
||||
// Set the peer's ID.
|
||||
p.id = atomic.AddInt32(&nodeCount, 1)
|
||||
|
||||
p.StatsMtx.Unlock()
|
||||
|
||||
// Choose whether or not to relay transactions before a filter command
|
||||
|
@ -307,6 +307,7 @@ var helpDescsEnUS = map[string]string{
|
||||
"getnettotalsresult-timemillis": "Number of milliseconds since 1 Jan 1970 GMT",
|
||||
|
||||
// GetPeerInfoResult help.
|
||||
"getpeerinforesult-id": "A unique node ID",
|
||||
"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",
|
||||
@ -315,6 +316,7 @@ var helpDescsEnUS = map[string]string{
|
||||
"getpeerinforesult-bytessent": "Total bytes sent",
|
||||
"getpeerinforesult-bytesrecv": "Total bytes received",
|
||||
"getpeerinforesult-conntime": "Time the connection was made in seconds since 1 Jan 1970 GMT",
|
||||
"getpeerinforesult-timeoffset": "The time offset of the peer",
|
||||
"getpeerinforesult-pingtime": "Number of microseconds the last ping took",
|
||||
"getpeerinforesult-pingwait": "Number of microseconds a queued ping has been waiting for a response",
|
||||
"getpeerinforesult-version": "The protocol version of the peer",
|
||||
|
@ -402,6 +402,7 @@ func (s *server) handleQuery(querymsg interface{}, state *peerState) {
|
||||
// version.
|
||||
p.StatsMtx.Lock()
|
||||
info := &btcjson.GetPeerInfoResult{
|
||||
ID: p.id,
|
||||
Addr: p.addr,
|
||||
Services: fmt.Sprintf("%08d", p.services),
|
||||
LastSend: p.lastSend.Unix(),
|
||||
@ -409,6 +410,7 @@ func (s *server) handleQuery(querymsg interface{}, state *peerState) {
|
||||
BytesSent: p.bytesSent,
|
||||
BytesRecv: p.bytesReceived,
|
||||
ConnTime: p.timeConnected.Unix(),
|
||||
TimeOffset: p.timeOffset,
|
||||
Version: p.protocolVersion,
|
||||
SubVer: p.userAgent,
|
||||
Inbound: p.inbound,
|
||||
|
Loading…
Reference in New Issue
Block a user