properly initialize hashsets

This commit is contained in:
Dmitriy Ryajov 2019-09-12 04:08:11 -06:00
parent 9f3b80b60c
commit 68d50a97f8
2 changed files with 19 additions and 13 deletions

View File

@ -7,7 +7,8 @@
## This file may not be copied, modified, or distributed except according to
## those terms.
import sequtils, tables, options, sets, sequtils, strutils, sets
import sequtils, tables, options,
sets, sequtils, strutils, sets
import chronos, chronicles
import pubsub,
pubsubpeer,
@ -65,15 +66,15 @@ proc rpcHandler(f: FloodSub,
f.peerTopics[s.topic].incl(id)
else:
debug "unsubscribing to topic", peer = id, subscriptions = m.subscriptions, topic = s.topic
# unsubscribe the peer to the topic
# unsubscribe the peer from the topic
f.peerTopics[s.topic].excl(id)
# send subscriptions to every peer
for p in f.peers.values:
await p.send(@[RPCMsg(subscriptions: m.subscriptions)])
if m.messages.len > 0: # if there are any messages
var toSendPeers: HashSet[string] = initSet[string]()
if m.messages.len > 0: # if there are any messages
for msg in m.messages: # for every message
for t in msg.topicIDs: # for every topic in the message
toSendPeers.incl(f.peerTopics[t]) # get all the peers interested in this topic
@ -84,7 +85,9 @@ proc rpcHandler(f: FloodSub,
for p in toSendPeers:
await f.peers[p].send(@[RPCMsg(messages: m.messages)])
proc handleConn(f: FloodSub, conn: Connection) {.async, gcsafe.} =
proc handleConn(f: FloodSub,
conn: Connection)
{.async, gcsafe.} =
## handle incoming/outgoing connections
##
## this proc will:

View File

@ -44,7 +44,10 @@ proc encodeMessage(msg: Message, buff: var ProtoBuffer) {.gcsafe.} =
for t in msg.topicIDs:
buff.write(initProtoField(4, t))
if msg.signature.len > 0:
buff.write(initProtoField(5, msg.signature))
if msg.key.len > 0:
buff.write(initProtoField(6, msg.key))
buff.finish()
@ -134,7 +137,7 @@ proc decodeRpcMsg*(msg: seq[byte]): RPCMsg {.gcsafe.} =
result.messages.add(msg)
else:
raise newException(CatchableError, "message type not recognizedd")
raise newException(CatchableError, "message type not recognized")
var prefix {.threadvar.}: seq[byte]
proc getPreix(): var seq[byte] =