kaspad/server/rpc/handle_get_connected_peer_info.go
Ori Newman 749775c7ea
[NOD-1098] Change timestamp precision to one millisecond (#778)
* [NOD-1098] Change timestamps to be millisecond precision

* [NOD-1098] Change lock times to use milliseconds

* [NOD-1098] Use milliseconds precision everywhere

* [NOD-1098] Implement type mstime.Time

* [NOD-1098] Fix block 100000 timestamp

* [NOD-1098] Change orphan child to be one millisecond delay after its parent

* [NOD-1098] Remove test that checks if header timestamps have the right precision, and instead add tests for mstime, and fix genesis for testnet and devnet

* [NOD-1098] Fix comment

* [NOD-1098] Fix comment

* [NOD-1098] Fix testnet genesis

* [NOD-1098] Rename UnixMilli->UnixMilliseconds
2020-07-01 16:09:04 +03:00

45 lines
1.5 KiB
Go

package rpc
import (
"fmt"
"github.com/kaspanet/kaspad/rpcmodel"
"time"
)
// handleGetConnectedPeerInfo implements the getConnectedPeerInfo command.
func handleGetConnectedPeerInfo(s *Server, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
peers := s.cfg.ConnMgr.ConnectedPeers()
syncPeerID := s.cfg.SyncMgr.SyncPeerID()
infos := make([]*rpcmodel.GetConnectedPeerInfoResult, 0, len(peers))
for _, p := range peers {
statsSnap := p.ToPeer().StatsSnapshot()
info := &rpcmodel.GetConnectedPeerInfoResult{
ID: statsSnap.ID,
Addr: statsSnap.Addr,
Services: fmt.Sprintf("%08d", uint64(statsSnap.Services)),
RelayTxes: !p.IsTxRelayDisabled(),
LastSend: statsSnap.LastSend.UnixMilliseconds(),
LastRecv: statsSnap.LastRecv.UnixMilliseconds(),
BytesSent: statsSnap.BytesSent,
BytesRecv: statsSnap.BytesRecv,
ConnTime: statsSnap.ConnTime.UnixMilliseconds(),
PingTime: float64(statsSnap.LastPingMicros),
TimeOffset: statsSnap.TimeOffset,
Version: statsSnap.Version,
SubVer: statsSnap.UserAgent,
Inbound: statsSnap.Inbound,
SelectedTip: statsSnap.SelectedTipHash.String(),
BanScore: int32(p.BanScore()),
FeeFilter: p.FeeFilter(),
SyncNode: statsSnap.ID == syncPeerID,
}
if p.ToPeer().LastPingNonce() != 0 {
wait := float64(time.Since(statsSnap.LastPingTime).Nanoseconds())
// We actually want microseconds.
info.PingWait = wait / 1000
}
infos = append(infos, info)
}
return infos, nil
}