mirror of https://github.com/status-im/nim-eth.git
initial statistics collection setup
This commit is contained in:
parent
07484bfc88
commit
799b1a7bb0
|
@ -168,6 +168,9 @@ type
|
||||||
OK
|
OK
|
||||||
Error
|
Error
|
||||||
|
|
||||||
|
NimbusStats* = object
|
||||||
|
num_peers*: int
|
||||||
|
|
||||||
when BlockNumber is int64:
|
when BlockNumber is int64:
|
||||||
## The goal of these templates is to make it easier to switch
|
## The goal of these templates is to make it easier to switch
|
||||||
## the block number type to a different representation
|
## the block number type to a different representation
|
||||||
|
|
|
@ -8,3 +8,5 @@ proc parseAddress*(hexString: string): EthAddress =
|
||||||
proc `$`*(a: EthAddress): string =
|
proc `$`*(a: EthAddress): string =
|
||||||
a.toHex()
|
a.toHex()
|
||||||
|
|
||||||
|
var nimbusStats*: NimbusStats
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
import
|
import
|
||||||
os, tables, times, random, sequtils, options,
|
os, tables, times, random, sequtils, options,
|
||||||
chronos, chronicles, eth/[rlp, keys],
|
chronos, chronicles, eth/[rlp, keys, common],
|
||||||
private/p2p_types, discovery, kademlia, rlpx
|
private/p2p_types, discovery, kademlia, rlpx
|
||||||
|
|
||||||
const
|
const
|
||||||
|
@ -110,6 +110,7 @@ proc getRandomBootnode(p: PeerPool): Option[Node] =
|
||||||
proc addPeer*(pool: PeerPool, peer: Peer) =
|
proc addPeer*(pool: PeerPool, peer: Peer) =
|
||||||
doAssert(peer.remote notin pool.connectedNodes)
|
doAssert(peer.remote notin pool.connectedNodes)
|
||||||
pool.connectedNodes[peer.remote] = peer
|
pool.connectedNodes[peer.remote] = peer
|
||||||
|
inc(nimbusStats.num_peers)
|
||||||
for o in pool.observers.values:
|
for o in pool.observers.values:
|
||||||
if not o.onPeerConnected.isNil:
|
if not o.onPeerConnected.isNil:
|
||||||
if o.protocol.isNil or peer.supports(o.protocol):
|
if o.protocol.isNil or peer.supports(o.protocol):
|
||||||
|
|
|
@ -787,8 +787,9 @@ proc removePeer(network: EthereumNode, peer: Peer) =
|
||||||
# have been dropped already from the peers side.
|
# have been dropped already from the peers side.
|
||||||
# E.g. when receiving a p2p.disconnect message from a peer, a race will happen
|
# E.g. when receiving a p2p.disconnect message from a peer, a race will happen
|
||||||
# between which side disconnects first.
|
# between which side disconnects first.
|
||||||
if network.peerPool != nil and not peer.remote.isNil:
|
if network.peerPool != nil and not peer.remote.isNil and peer.remote in network.peerPool.connectedNodes:
|
||||||
network.peerPool.connectedNodes.del(peer.remote)
|
network.peerPool.connectedNodes.del(peer.remote)
|
||||||
|
dec(nimbusStats.num_peers)
|
||||||
|
|
||||||
# Note: we need to do this check as disconnect (and thus removePeer)
|
# Note: we need to do this check as disconnect (and thus removePeer)
|
||||||
# currently can get called before the dispatcher is initialized.
|
# currently can get called before the dispatcher is initialized.
|
||||||
|
|
Loading…
Reference in New Issue