wip updateScores
This commit is contained in:
parent
6f638259ee
commit
9e3f70896a
|
@ -314,11 +314,33 @@ proc getGossipPeers(g: GossipSub): Table[string, ControlMessage] {.gcsafe.} =
|
|||
|
||||
result[peer.id].ihave.add(ihave)
|
||||
|
||||
proc updateScores(g: GossipSub) = # avoid async
|
||||
debug "updating scores", peers = g.peers.len
|
||||
|
||||
let now = Moment.now()
|
||||
|
||||
for id, peer in g.peers:
|
||||
# TODO
|
||||
|
||||
# Per topic
|
||||
for topic in peer.topics:
|
||||
# Defect on purpose, no magic here please, this should not fail!
|
||||
let topicParams = g.topics[topic].parameters
|
||||
var info = peer.topicInfos[topic]
|
||||
if info.inMesh:
|
||||
info.meshTime = now - info.graftTime
|
||||
if info.meshTime > topicParams.meshMessageDeliveriesActivation:
|
||||
info.meshMessageDeliveriesActive = true
|
||||
# debug assert to check nim compiler is doing what we are asking...
|
||||
assert(peer.topicInfos[topic].meshTime == info.meshTime)
|
||||
|
||||
proc heartbeat(g: GossipSub) {.async.} =
|
||||
while g.heartbeatRunning:
|
||||
try:
|
||||
trace "running heartbeat"
|
||||
|
||||
g.updateScores()
|
||||
|
||||
for t in toSeq(g.topics.keys):
|
||||
await g.rebalanceMesh(t)
|
||||
|
||||
|
|
|
@ -31,10 +31,12 @@ type
|
|||
onRecv*: proc(peer: PubSubPeer; msgs: var RPCMsg) {.gcsafe, raises: [Defect].}
|
||||
onSend*: proc(peer: PubSubPeer; msgs: var RPCMsg) {.gcsafe, raises: [Defect].}
|
||||
|
||||
TopicInfo = object
|
||||
TopicInfo* = object
|
||||
# gossip 1.1 related
|
||||
graftTime*: Moment
|
||||
meshTime*: Duration
|
||||
inMesh*: bool
|
||||
meshMessageDeliveriesActive*: bool
|
||||
|
||||
PubSubPeer* = ref object of RootObj
|
||||
proto*: string # the protocol that this peer joined from
|
||||
|
@ -47,7 +49,7 @@ type
|
|||
onConnect*: AsyncEvent
|
||||
observers*: ref seq[PubSubObserver] # ref as in smart_ptr
|
||||
refs: int # how many active connections this peer has
|
||||
topicInfos: Table[string, TopicInfo]
|
||||
topicInfos*: Table[string, TopicInfo]
|
||||
|
||||
RPCHandler* = proc(peer: PubSubPeer, msg: seq[RPCMsg]): Future[void] {.gcsafe.}
|
||||
|
||||
|
@ -228,7 +230,6 @@ proc pruned*(p: PubSubPeer, topic: string) =
|
|||
var _ = p.topicInfos.mgetOrPut(topic, TopicInfo())
|
||||
# TODO
|
||||
|
||||
|
||||
proc newPubSubPeer*(peerInfo: PeerInfo,
|
||||
proto: string): PubSubPeer =
|
||||
new result
|
||||
|
|
Loading…
Reference in New Issue