mirror of https://github.com/waku-org/nwaku.git
Tiny cleanup and more encapsulation in protocol.nim files (#2488)
This commit is contained in:
parent
5b174fb392
commit
a2e28a04f7
|
@ -120,14 +120,6 @@ proc new*(T: type WakuFilterLegacy,
|
||||||
wf.initProtocolHandler()
|
wf.initProtocolHandler()
|
||||||
return wf
|
return wf
|
||||||
|
|
||||||
proc init*(T: type WakuFilterLegacy,
|
|
||||||
peerManager: PeerManager,
|
|
||||||
rng: ref rand.HmacDrbgContext,
|
|
||||||
timeout: Duration = WakuLegacyFilterTimeout): T {.
|
|
||||||
deprecated: "WakuFilterLegacy.new()' instead".} =
|
|
||||||
WakuFilterLegacy.new(peerManager, rng, timeout)
|
|
||||||
|
|
||||||
|
|
||||||
proc sendFilterRpc(wf: WakuFilterLegacy, rpc: FilterRPC, peer: PeerId|RemotePeerInfo): Future[WakuFilterResult[void]] {.async, gcsafe.}=
|
proc sendFilterRpc(wf: WakuFilterLegacy, rpc: FilterRPC, peer: PeerId|RemotePeerInfo): Future[WakuFilterResult[void]] {.async, gcsafe.}=
|
||||||
let connOpt = await wf.peerManager.dialPeer(peer, WakuLegacyFilterCodec)
|
let connOpt = await wf.peerManager.dialPeer(peer, WakuLegacyFilterCodec)
|
||||||
if connOpt.isNone():
|
if connOpt.isNone():
|
||||||
|
|
|
@ -261,7 +261,7 @@ proc new*(T: type WakuFilter,
|
||||||
|
|
||||||
const MaintainSubscriptionsInterval* = 1.minutes
|
const MaintainSubscriptionsInterval* = 1.minutes
|
||||||
|
|
||||||
proc startMaintainingSubscriptions*(wf: WakuFilter, interval: Duration) =
|
proc startMaintainingSubscriptions(wf: WakuFilter, interval: Duration) =
|
||||||
trace "starting to maintain subscriptions"
|
trace "starting to maintain subscriptions"
|
||||||
var maintainSubs: CallbackFunc
|
var maintainSubs: CallbackFunc
|
||||||
maintainSubs = CallbackFunc(
|
maintainSubs = CallbackFunc(
|
||||||
|
|
|
@ -62,7 +62,7 @@ proc handleRequest*(wl: WakuLightPush, peerId: PeerId, buffer: seq[byte]): Futur
|
||||||
let rpc = PushRPC(requestId: requestId, response: some(response))
|
let rpc = PushRPC(requestId: requestId, response: some(response))
|
||||||
return rpc
|
return rpc
|
||||||
|
|
||||||
proc initProtocolHandler*(wl: WakuLightPush) =
|
proc initProtocolHandler(wl: WakuLightPush) =
|
||||||
proc handle(conn: Connection, proto: string) {.async.} =
|
proc handle(conn: Connection, proto: string) {.async.} =
|
||||||
let buffer = await conn.readLp(MaxRpcSize.int)
|
let buffer = await conn.readLp(MaxRpcSize.int)
|
||||||
let rpc = await handleRequest(wl, conn.peerId, buffer)
|
let rpc = await handleRequest(wl, conn.peerId, buffer)
|
||||||
|
|
|
@ -68,7 +68,7 @@ proc request*(m: WakuMetadata, conn: Connection): Future[Result[WakuMetadataResp
|
||||||
|
|
||||||
return ok(response)
|
return ok(response)
|
||||||
|
|
||||||
proc initProtocolHandler*(m: WakuMetadata) =
|
proc initProtocolHandler(m: WakuMetadata) =
|
||||||
proc handle(conn: Connection, proto: string) {.async, gcsafe, closure.} =
|
proc handle(conn: Connection, proto: string) {.async, gcsafe, closure.} =
|
||||||
let res = catch: await conn.readLp(RpcResponseMaxBytes)
|
let res = catch: await conn.readLp(RpcResponseMaxBytes)
|
||||||
let buffer = res.valueOr:
|
let buffer = res.valueOr:
|
||||||
|
|
|
@ -196,7 +196,7 @@ proc isSubscribed*(w: WakuRelay, topic: PubsubTopic): bool =
|
||||||
proc subscribedTopics*(w: WakuRelay): seq[PubsubTopic] =
|
proc subscribedTopics*(w: WakuRelay): seq[PubsubTopic] =
|
||||||
return toSeq(GossipSub(w).topics.keys())
|
return toSeq(GossipSub(w).topics.keys())
|
||||||
|
|
||||||
proc generateOrderedValidator*(w: WakuRelay): auto {.gcsafe.} =
|
proc generateOrderedValidator(w: WakuRelay): auto {.gcsafe.} =
|
||||||
# rejects messages that are not WakuMessage
|
# rejects messages that are not WakuMessage
|
||||||
let wrappedValidator = proc(pubsubTopic: string,
|
let wrappedValidator = proc(pubsubTopic: string,
|
||||||
message: messages.Message): Future[ValidationResult] {.async.} =
|
message: messages.Message): Future[ValidationResult] {.async.} =
|
||||||
|
|
Loading…
Reference in New Issue