Clean up logging and imports

This commit is contained in:
Oskar Thoren 2020-05-15 11:35:32 +08:00
parent 2070f65828
commit 7d51244ffe
No known key found for this signature in database
GPG Key ID: B2ECCFD3BC2EF77E
3 changed files with 10 additions and 21 deletions

View File

@ -3,7 +3,7 @@ const
libp2p_secure {.strdefine.} = ""
import
options, tables,
options, tables, chronicles,
libp2p/[switch, peer, peerinfo, connection, multiaddress, crypto/crypto],
libp2p/transports/[transport, tcptransport],
libp2p/muxers/[muxer, mplex/mplex, mplex/types],
@ -42,7 +42,7 @@ proc newStandardSwitch*(privKey = none(PrivateKey),
else:
# Creating switch from generate node
# XXX: Hacky test, hijacking WakuSub here
echo "Using WakuSub here"
debug "Using WakuSub here"
#PubSub newPubSub(FloodSub, peerInfo, triggerSelf)
PubSub newPubSub(WakuSub, peerInfo, triggerSelf)

View File

@ -7,8 +7,8 @@
# Apache License, version 2.0, (LICENSE-APACHEv2)
# MIT license (LICENSE-MIT)
import unittest, sequtils, options, tables, sets
import chronos
import unittest, options, tables, sets
import chronos, chronicles
import utils,
libp2p/[errors,
switch,
@ -29,7 +29,6 @@ proc waitSub(sender, receiver: auto; key: string) {.async, gcsafe.} =
# turn things deterministic
# this is for testing purposes only
var ceil = 15
#echo "isa thing", repr(sender.pubSub.get())
let fsub = cast[WakuSub](sender.pubSub.get())
while not fsub.floodsub.hasKey(key) or
not fsub.floodsub[key].contains(receiver.peerInfo.id):
@ -56,7 +55,7 @@ suite "FloodSub":
proc runTests(): Future[bool] {.async.} =
var completionFut = newFuture[bool]()
proc handler(topic: string, data: seq[byte]) {.async, gcsafe.} =
echo "Hit handler", topic
debug "Hit handler", topic
check topic == "foobar"
completionFut.complete(true)

View File

@ -3,13 +3,12 @@
## This file should eventually correspond to waku_protocol as RLPx subprotocol.
## Instead, it should likely be on top of GossipSub with a similar interface.
import unittest
import sequtils, tables, options, sets, strutils
import strutils
import chronos, chronicles
import libp2p/protocols/pubsub/pubsub,
libp2p/protocols/pubsub/pubsubpeer,
libp2p/protocols/pubsub/floodsub,
libp2p/protocols/pubsub/rpc/[messages, message],
libp2p/protocols/pubsub/rpc/[messages],
libp2p/connection
logScope:
@ -20,8 +19,6 @@ const WakuSubCodec* = "/wakusub/0.0.1"
#const wakuVersionStr = "2.0.0-alpha1"
# So this should already have floodsub table, seen, as well as peerinfo, topics, peers, etc
# How do we verify that in nim?
type
WakuSub* = ref object of FloodSub
# XXX: just playing
@ -35,24 +32,17 @@ method init(w: WakuSub) =
## e.g. ``/wakusub/0.0.1``, etc...
##
echo "Incoming WakuSub connection"
assert(w of FloodSub)
echo "asserted w of floodsub"
assert(w of PubSub)
echo "asserted w of pubsub"
# Defer to parent object (I think)
# This isn't hit, possibly cause double link here?
debug "Incoming WakuSub connection"
await w.handleConn(conn, proto)
# XXX: Handler hijack FloodSub here?
w.handler = handler
w.codec = WakuSubCodec
#
method initPubSub*(w: WakuSub) =
debug "initWakuSub"
w.text = "Foobar"
echo "w.text", w.text
debug "w.text", text = w.text
# XXX
procCall FloodSub(w).initPubSub()
w.init()
@ -65,7 +55,7 @@ method subscribeTopic*(w: WakuSub,
procCall FloodSub(w).subscribeTopic(topic, subscribe, peerId)
method handleDisconnect*(w: WakuSub, peer: PubSubPeer) {.async.} =
debug "handleDisconnect NYI"
debug "handleDisconnect (NYI)"
method rpcHandler*(w: WakuSub,
peer: PubSubPeer,