logging improvements and cleaning up

This commit is contained in:
Giovanni Petrantoni 2020-09-14 14:05:25 +09:00
parent e4da3e4f67
commit b6470707a8
4 changed files with 7 additions and 15 deletions

View File

@ -87,7 +87,7 @@ proc decodeMsg*(buf: seq[byte]): Option[IdentifyInfo] =
iinfo.protoVersion = some(protoVersion)
if r6.get():
iinfo.agentVersion = some(agentVersion)
trace "decodeMsg: decoded message", pubkey = ($pubKey).shortLog,
debug "decodeMsg: decoded message", pubkey = ($pubKey).shortLog,
addresses = $iinfo.addrs, protocols = $iinfo.protos,
observable_address = $iinfo.observedAddr,
proto_version = $iinfo.protoVersion,

View File

@ -181,7 +181,7 @@ proc init*(_: type[GossipSubParams]): GossipSubParams =
decayInterval: 1.seconds,
decayToZero: 0.01,
retainScore: 10.seconds,
appSpecificWeight: 1.0,
appSpecificWeight: 0.0,
ipColocationFactorWeight: 0.0,
ipColocationFactorThreshold: 1.0,
behaviourPenaltyWeight: -1.0,
@ -621,6 +621,8 @@ proc updateScores(g: GossipSub) = # avoid async
for peer, stats in g.peerStats.mpairs:
trace "updating peer score", peer
var n_topics = 0
var is_grafted = 0
if not peer.connected:
if now > stats.expire:
@ -631,11 +633,13 @@ proc updateScores(g: GossipSub) = # avoid async
# Per topic
for topic, topicParams in g.topicParams:
var info = stats.topicInfos.getOrDefault(topic)
inc n_topics
# Scoring
var topicScore = 0'f64
if info.inMesh:
inc is_grafted
info.meshTime = now - info.graftTime
if info.meshTime > topicParams.meshMessageDeliveriesActivation:
info.meshMessageDeliveriesActive = true
@ -701,7 +705,7 @@ proc updateScores(g: GossipSub) = # avoid async
if peer.behaviourPenalty < g.parameters.decayToZero:
peer.behaviourPenalty = 0
trace "updated peer's score", peer, score = peer.score
debug "updated peer's score", peer, score = peer.score, n_topics, is_grafted
for peer in evicting:
g.peerStats.del(peer)

View File

@ -258,11 +258,6 @@ proc upgradeIncoming(s: Switch, conn: Connection) {.async, gcsafe.} =
for muxer in s.muxers.values:
ms.addHandler(muxer.codecs, muxer)
# add the mounted protocols
# notice this should be kept in sync ...
for handler in s.ms.handlers:
ms.handlers &= handler
# handle subsequent secure requests
await ms.handle(sconn)

View File

@ -35,10 +35,3 @@ func shortLog*(item: string): string =
result &= item[0..<split]
result &= "..."
result &= item[(item.len - split)..item.high]
template withLock*(l: auto, body: untyped): untyped =
await l.acquire()
try:
body
finally:
l.release()