mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-12 09:06:52 +00:00

* [NOD-652] Add selectedTip and getSelectedTip messages * [NOD-652] Remove peerSyncState.isSelectedTipKnown * [NOD-652] Do nothing on OnSelectedTip if the peer selected tip hasn't changed * [NOD-652] Handle selected tip message with block handler * [NOD-652] Add comments * [NOD-652] go mod tidy * [NOD-652] Fix TestVersion * [NOD-652] Use dag.AdjustedTime instead of dag.timeSource.AdjustedTime * [NOD-652] Create shouldQueryPeerSelectedTips and queueMsgGetSelectedTip functions * [NOD-652] Change selectedTip to selectedTipHash where needed * [NOD-652] add minDAGTimeDelay constant * [NOD-652] add comments * [NOD-652] Fix names and comments * [NOD-652] Put msg.reply push in the right place * [NOD-652] Fix comments and names
45 lines
1.4 KiB
Go
45 lines
1.4 KiB
Go
package rpc
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/kaspanet/kaspad/rpcmodel"
|
|
"time"
|
|
)
|
|
|
|
// handleGetPeerInfo implements the getPeerInfo command.
|
|
func handleGetPeerInfo(s *Server, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
|
|
peers := s.cfg.ConnMgr.ConnectedPeers()
|
|
syncPeerID := s.cfg.SyncMgr.SyncPeerID()
|
|
infos := make([]*rpcmodel.GetPeerInfoResult, 0, len(peers))
|
|
for _, p := range peers {
|
|
statsSnap := p.ToPeer().StatsSnapshot()
|
|
info := &rpcmodel.GetPeerInfoResult{
|
|
ID: statsSnap.ID,
|
|
Addr: statsSnap.Addr,
|
|
Services: fmt.Sprintf("%08d", uint64(statsSnap.Services)),
|
|
RelayTxes: !p.IsTxRelayDisabled(),
|
|
LastSend: statsSnap.LastSend.Unix(),
|
|
LastRecv: statsSnap.LastRecv.Unix(),
|
|
BytesSent: statsSnap.BytesSent,
|
|
BytesRecv: statsSnap.BytesRecv,
|
|
ConnTime: statsSnap.ConnTime.Unix(),
|
|
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
|
|
}
|