Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AeFqV96dVeBX94inzcgZKw
34 lines
1.2 KiB
Go
34 lines
1.2 KiB
Go
package p2p
|
|
|
|
// Stats is a snapshot of what the node counts about the network, for the
|
|
// metrics endpoint. The totals count from the start of the process.
|
|
type Stats struct {
|
|
Peers int // connected peers
|
|
RegionPeers map[string]int // peers known to follow each region we follow
|
|
|
|
MessagesDropped uint64 // gossip dropped for exceeding a peer's rate
|
|
MessagesInvalid uint64 // gossip rejected as invalid
|
|
PeersBanned uint64 // peers banned for sending invalid messages
|
|
SyncRefused uint64 // sync requests refused (rate, streams, banned)
|
|
ConnectionsFull uint64 // inbound connections refused: source address at its limit
|
|
ConnectionsBanned uint64 // inbound connections refused: peer banned
|
|
}
|
|
|
|
// Stats returns the current counters.
|
|
func (n *Node) Stats() Stats {
|
|
s := Stats{
|
|
Peers: n.PeerCount(),
|
|
RegionPeers: map[string]int{},
|
|
MessagesDropped: n.guard.dropped.Load(),
|
|
MessagesInvalid: n.guard.invalid.Load(),
|
|
PeersBanned: n.guard.bans.Load(),
|
|
SyncRefused: n.guard.syncRefused.Load(),
|
|
ConnectionsFull: n.gate.refusedFull.Load(),
|
|
ConnectionsBanned: n.gate.refusedBanned.Load(),
|
|
}
|
|
for _, r := range n.Regions() {
|
|
s.RegionPeers[r] = len(n.RegionPeers(r))
|
|
}
|
|
return s
|
|
}
|