mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-02 05:53:11 +00:00
* introduce createNode # Conflicts: # apps/wakunode2/cli_args.nim * remove confutils dependency on the library * test: remove websocket in default test config * update to latest specs * test: cli_args * align to spec changes (sovereign, message conf, entrypoints * accept enr, entree and multiaddr as entry points * post rebase * format * change from "sovereign" to "core" * add example * get example to continue running * nitpicks * idiomatic constructors * fix enum naming * replace procs with consts * remove messageConfirmation * use pure enum * rename example file
30 lines
1.0 KiB
Nim
30 lines
1.0 KiB
Nim
import results, options, chronos
|
|
import waku/[waku_node, waku_core, waku_lightpush, waku_lightpush/common]
|
|
import publisher_base
|
|
|
|
type V3Publisher* = ref object of PublisherBase
|
|
|
|
proc new*(T: type V3Publisher, wakuNode: WakuNode): T =
|
|
if isNil(wakuNode.wakuLightpushClient):
|
|
wakuNode.mountLightPushClient()
|
|
|
|
return V3Publisher(wakuNode: wakuNode)
|
|
|
|
method send*(
|
|
self: V3Publisher,
|
|
topic: PubsubTopic,
|
|
message: WakuMessage,
|
|
servicePeer: RemotePeerInfo,
|
|
): Future[Result[void, string]] {.async.} =
|
|
# when error it must return original error desc due the text is used for distinction between error types in metrics.
|
|
discard (
|
|
await self.wakuNode.lightpushPublish(some(topic), message, some(servicePeer))
|
|
).valueOr:
|
|
if error.code == LightPushErrorCode.NO_PEERS_TO_RELAY and
|
|
error.desc != some("No peers for topic, skipping publish"):
|
|
# TODO: We need better separation of errors happening on the client side or the server side.-
|
|
return err("dial_failure")
|
|
else:
|
|
return err($error.code)
|
|
return ok()
|