@@ -34,26 +34,27 @@ import
3434logScope:
3535 topics = " waku node lightpush api"
3636
37+ const MountWithoutRelayError * = " cannot mount lightpush because relay is not mounted"
38+
3739# # Waku lightpush
3840proc mountLegacyLightPush * (
3941 node: WakuNode , rateLimit: RateLimitSetting = DefaultGlobalNonRelayRateLimit
40- ) {.async .} =
42+ ): Future [ Result [ void , string ]] {.async .} =
4143 info " mounting legacy light push"
4244
43- let pushHandler =
44- if node.wakuRelay.isNil:
45- info " mounting legacy lightpush without relay (nil)"
46- legacy_lightpush_protocol.getNilPushHandler ()
45+ if node.wakuRelay.isNil ():
46+ return err (MountWithoutRelayError )
47+
48+ info " mounting legacy lightpush with relay"
49+ let rlnPeer =
50+ if node.wakuRlnRelay.isNil ():
51+ info " mounting legacy lightpush without rln-relay"
52+ none (WakuRLNRelay )
4753 else :
48- info " mounting legacy lightpush with relay"
49- let rlnPeer =
50- if isNil (node.wakuRlnRelay):
51- info " mounting legacy lightpush without rln-relay"
52- none (WakuRLNRelay )
53- else :
54- info " mounting legacy lightpush with rln-relay"
55- some (node.wakuRlnRelay)
56- legacy_lightpush_protocol.getRelayPushHandler (node.wakuRelay, rlnPeer)
54+ info " mounting legacy lightpush with rln-relay"
55+ some (node.wakuRlnRelay)
56+ let pushHandler =
57+ legacy_lightpush_protocol.getRelayPushHandler (node.wakuRelay, rlnPeer)
5758
5859 node.wakuLegacyLightPush =
5960 WakuLegacyLightPush .new (node.peerManager, node.rng, pushHandler, some (rateLimit))
@@ -64,6 +65,9 @@ proc mountLegacyLightPush*(
6465
6566 node.switch.mount (node.wakuLegacyLightPush, protocolMatcher (WakuLegacyLightPushCodec ))
6667
68+ info " legacy lightpush mounted successfully"
69+ return ok ()
70+
6771proc mountLegacyLightPushClient * (node: WakuNode ) =
6872 info " mounting legacy light push client"
6973
@@ -146,23 +150,21 @@ proc legacyLightpushPublish*(
146150
147151proc mountLightPush * (
148152 node: WakuNode , rateLimit: RateLimitSetting = DefaultGlobalNonRelayRateLimit
149- ) {.async .} =
153+ ): Future [ Result [ void , string ]] {.async .} =
150154 info " mounting light push"
151155
152- let pushHandler =
153- if node.wakuRelay.isNil ():
154- info " mounting lightpush v2 without relay (nil)"
155- lightpush_protocol.getNilPushHandler ()
156+ if node.wakuRelay.isNil ():
157+ return err (MountWithoutRelayError )
158+
159+ info " mounting lightpush with relay"
160+ let rlnPeer =
161+ if node.wakuRlnRelay.isNil ():
162+ info " mounting lightpush without rln-relay"
163+ none (WakuRLNRelay )
156164 else :
157- info " mounting lightpush with relay"
158- let rlnPeer =
159- if isNil (node.wakuRlnRelay):
160- info " mounting lightpush without rln-relay"
161- none (WakuRLNRelay )
162- else :
163- info " mounting lightpush with rln-relay"
164- some (node.wakuRlnRelay)
165- lightpush_protocol.getRelayPushHandler (node.wakuRelay, rlnPeer)
165+ info " mounting lightpush with rln-relay"
166+ some (node.wakuRlnRelay)
167+ let pushHandler = lightpush_protocol.getRelayPushHandler (node.wakuRelay, rlnPeer)
166168
167169 node.wakuLightPush = WakuLightPush .new (
168170 node.peerManager, node.rng, pushHandler, node.wakuAutoSharding, some (rateLimit)
@@ -174,6 +176,9 @@ proc mountLightPush*(
174176
175177 node.switch.mount (node.wakuLightPush, protocolMatcher (WakuLightPushCodec ))
176178
179+ info " lightpush mounted successfully"
180+ return ok ()
181+
177182proc mountLightPushClient * (node: WakuNode ) =
178183 info " mounting light push client"
179184
0 commit comments