mirror of https://github.com/status-im/nim-eth.git
Merge branch 'stats'
This commit is contained in:
commit
69de12e636
|
@ -168,6 +168,9 @@ type
|
|||
OK
|
||||
Error
|
||||
|
||||
NimbusStats* = object
|
||||
num_peers*: int
|
||||
|
||||
when BlockNumber is int64:
|
||||
## The goal of these templates is to make it easier to switch
|
||||
## the block number type to a different representation
|
||||
|
|
|
@ -8,3 +8,5 @@ proc parseAddress*(hexString: string): EthAddress =
|
|||
proc `$`*(a: EthAddress): string =
|
||||
a.toHex()
|
||||
|
||||
var nimbusStats*: NimbusStats
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
import
|
||||
os, tables, times, random, sequtils, options,
|
||||
chronos, chronicles, eth/[rlp, keys],
|
||||
chronos, chronicles, eth/[rlp, keys, common],
|
||||
private/p2p_types, discovery, kademlia, rlpx
|
||||
|
||||
const
|
||||
|
@ -110,6 +110,7 @@ proc getRandomBootnode(p: PeerPool): Option[Node] =
|
|||
proc addPeer*(pool: PeerPool, peer: Peer) =
|
||||
doAssert(peer.remote notin pool.connectedNodes)
|
||||
pool.connectedNodes[peer.remote] = peer
|
||||
inc(nimbusStats.num_peers)
|
||||
for o in pool.observers.values:
|
||||
if not o.onPeerConnected.isNil:
|
||||
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.
|
||||
# E.g. when receiving a p2p.disconnect message from a peer, a race will happen
|
||||
# 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)
|
||||
dec(nimbusStats.num_peers)
|
||||
|
||||
# Note: we need to do this check as disconnect (and thus removePeer)
|
||||
# currently can get called before the dispatcher is initialized.
|
||||
|
|
Loading…
Reference in New Issue