mirror of https://github.com/vacp2p/nim-libp2p.git
fixing some key not found exceptions (#231)
This commit is contained in:
parent
5b28e8c488
commit
7a1c1c2ea6
|
@ -52,7 +52,8 @@ method handleDisconnect*(f: FloodSub, peer: PubSubPeer) {.async.} =
|
||||||
await procCall PubSub(f).handleDisconnect(peer)
|
await procCall PubSub(f).handleDisconnect(peer)
|
||||||
|
|
||||||
## handle peer disconnects
|
## handle peer disconnects
|
||||||
for t in f.floodsub.keys:
|
for t in toSeq(f.floodsub.keys):
|
||||||
|
if t in f.floodsub:
|
||||||
f.floodsub[t].excl(peer.id)
|
f.floodsub[t].excl(peer.id)
|
||||||
|
|
||||||
method rpcHandler*(f: FloodSub,
|
method rpcHandler*(f: FloodSub,
|
||||||
|
@ -131,7 +132,8 @@ method publish*(f: FloodSub,
|
||||||
let msg = newMessage(f.peerInfo, data, topic, f.sign)
|
let msg = newMessage(f.peerInfo, data, topic, f.sign)
|
||||||
var sent: seq[Future[void]]
|
var sent: seq[Future[void]]
|
||||||
# start the future but do not wait yet
|
# start the future but do not wait yet
|
||||||
for p in f.floodsub[topic]:
|
for p in f.floodsub.getOrDefault(topic):
|
||||||
|
if p in f.peers:
|
||||||
trace "publishing message", name = topic, peer = p, data = data.shortLog
|
trace "publishing message", name = topic, peer = p, data = data.shortLog
|
||||||
sent.add(f.peers[p].send(@[RPCMsg(messages: @[msg])]))
|
sent.add(f.peers[p].send(@[RPCMsg(messages: @[msg])]))
|
||||||
|
|
||||||
|
|
|
@ -200,6 +200,7 @@ proc getGossipPeers(g: GossipSub): Table[string, ControlMessage] {.gcsafe.} =
|
||||||
break
|
break
|
||||||
|
|
||||||
let id = toSeq(g.gossipsub.getOrDefault(topic)).sample()
|
let id = toSeq(g.gossipsub.getOrDefault(topic)).sample()
|
||||||
|
if id in g.gossipsub.getOrDefault(topic):
|
||||||
g.gossipsub[topic].excl(id)
|
g.gossipsub[topic].excl(id)
|
||||||
if id notin gossipPeers:
|
if id notin gossipPeers:
|
||||||
if id notin result:
|
if id notin result:
|
||||||
|
@ -222,12 +223,14 @@ proc heartbeat(g: GossipSub) {.async.} =
|
||||||
let peers = g.getGossipPeers()
|
let peers = g.getGossipPeers()
|
||||||
var sent: seq[Future[void]]
|
var sent: seq[Future[void]]
|
||||||
for peer in peers.keys:
|
for peer in peers.keys:
|
||||||
|
if peer in g.peers:
|
||||||
sent &= g.peers[peer].send(@[RPCMsg(control: some(peers[peer]))])
|
sent &= g.peers[peer].send(@[RPCMsg(control: some(peers[peer]))])
|
||||||
checkFutures(await allFinished(sent))
|
checkFutures(await allFinished(sent))
|
||||||
|
|
||||||
g.mcache.shift() # shift the cache
|
g.mcache.shift() # shift the cache
|
||||||
except CatchableError as exc:
|
except CatchableError as exc:
|
||||||
trace "exception ocurred in gossipsub heartbeat", exc = exc.msg
|
trace "exception ocurred in gossipsub heartbeat", exc = exc.msg
|
||||||
|
continue
|
||||||
finally:
|
finally:
|
||||||
g.heartbeatLock.release()
|
g.heartbeatLock.release()
|
||||||
|
|
||||||
|
@ -239,21 +242,27 @@ method handleDisconnect*(g: GossipSub, peer: PubSubPeer) {.async.} =
|
||||||
|
|
||||||
await procCall FloodSub(g).handleDisconnect(peer)
|
await procCall FloodSub(g).handleDisconnect(peer)
|
||||||
|
|
||||||
for t in g.gossipsub.keys:
|
for t in toSeq(g.gossipsub.keys):
|
||||||
|
if t in g.gossipsub:
|
||||||
g.gossipsub[t].excl(peer.id)
|
g.gossipsub[t].excl(peer.id)
|
||||||
|
|
||||||
libp2p_gossipsub_peers_per_topic_gossipsub
|
libp2p_gossipsub_peers_per_topic_gossipsub
|
||||||
.set(g.gossipsub[t].len.int64, labelValues = [t])
|
.set(g.gossipsub.getOrDefault(t).len.int64, labelValues = [t])
|
||||||
|
|
||||||
# mostly for metrics
|
# mostly for metrics
|
||||||
await procCall PubSub(g).subscribeTopic(t, false, peer.id)
|
await procCall PubSub(g).subscribeTopic(t, false, peer.id)
|
||||||
|
|
||||||
for t in g.mesh.keys:
|
for t in toSeq(g.mesh.keys):
|
||||||
|
if t in g.mesh:
|
||||||
g.mesh[t].excl(peer.id)
|
g.mesh[t].excl(peer.id)
|
||||||
|
|
||||||
libp2p_gossipsub_peers_per_topic_mesh
|
libp2p_gossipsub_peers_per_topic_mesh
|
||||||
.set(g.mesh[t].len.int64, labelValues = [t])
|
.set(g.mesh[t].len.int64, labelValues = [t])
|
||||||
|
|
||||||
for t in g.fanout.keys:
|
for t in toSeq(g.fanout.keys):
|
||||||
|
if t in g.fanout:
|
||||||
g.fanout[t].excl(peer.id)
|
g.fanout[t].excl(peer.id)
|
||||||
|
|
||||||
libp2p_gossipsub_peers_per_topic_fanout
|
libp2p_gossipsub_peers_per_topic_fanout
|
||||||
.set(g.fanout[t].len.int64, labelValues = [t])
|
.set(g.fanout[t].len.int64, labelValues = [t])
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue