Merge branch 'stats'

This commit is contained in:
Ștefan Talpalaru 2019-06-26 15:41:37 +02:00
commit 69de12e636
No known key found for this signature in database
GPG Key ID: CBF7934204F1B6F9
4 changed files with 9 additions and 2 deletions

View File

@ -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

View File

@ -8,3 +8,5 @@ proc parseAddress*(hexString: string): EthAddress =
proc `$`*(a: EthAddress): string =
a.toHex()
var nimbusStats*: NimbusStats

View File

@ -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):

View File

@ -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.