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

View File

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

View File

@ -3,13 +3,12 @@
## This file should eventually correspond to waku_protocol as RLPx subprotocol. ## This file should eventually correspond to waku_protocol as RLPx subprotocol.
## Instead, it should likely be on top of GossipSub with a similar interface. ## Instead, it should likely be on top of GossipSub with a similar interface.
import unittest import strutils
import sequtils, tables, options, sets, strutils
import chronos, chronicles import chronos, chronicles
import libp2p/protocols/pubsub/pubsub, import libp2p/protocols/pubsub/pubsub,
libp2p/protocols/pubsub/pubsubpeer, libp2p/protocols/pubsub/pubsubpeer,
libp2p/protocols/pubsub/floodsub, libp2p/protocols/pubsub/floodsub,
libp2p/protocols/pubsub/rpc/[messages, message], libp2p/protocols/pubsub/rpc/[messages],
libp2p/connection libp2p/connection
logScope: logScope:
@ -20,8 +19,6 @@ const WakuSubCodec* = "/wakusub/0.0.1"
#const wakuVersionStr = "2.0.0-alpha1" #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 type
WakuSub* = ref object of FloodSub WakuSub* = ref object of FloodSub
# XXX: just playing # XXX: just playing
@ -35,24 +32,17 @@ method init(w: WakuSub) =
## e.g. ``/wakusub/0.0.1``, etc... ## e.g. ``/wakusub/0.0.1``, etc...
## ##
echo "Incoming WakuSub connection" debug "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?
await w.handleConn(conn, proto) await w.handleConn(conn, proto)
# XXX: Handler hijack FloodSub here? # XXX: Handler hijack FloodSub here?
w.handler = handler w.handler = handler
w.codec = WakuSubCodec w.codec = WakuSubCodec
#
method initPubSub*(w: WakuSub) = method initPubSub*(w: WakuSub) =
debug "initWakuSub" debug "initWakuSub"
w.text = "Foobar" w.text = "Foobar"
echo "w.text", w.text debug "w.text", text = w.text
# XXX # XXX
procCall FloodSub(w).initPubSub() procCall FloodSub(w).initPubSub()
w.init() w.init()
@ -65,7 +55,7 @@ method subscribeTopic*(w: WakuSub,
procCall FloodSub(w).subscribeTopic(topic, subscribe, peerId) procCall FloodSub(w).subscribeTopic(topic, subscribe, peerId)
method handleDisconnect*(w: WakuSub, peer: PubSubPeer) {.async.} = method handleDisconnect*(w: WakuSub, peer: PubSubPeer) {.async.} =
debug "handleDisconnect NYI" debug "handleDisconnect (NYI)"
method rpcHandler*(w: WakuSub, method rpcHandler*(w: WakuSub,
peer: PubSubPeer, peer: PubSubPeer,