mirror of
https://github.com/logos-messaging/logos-delivery.git
synced 2026-06-04 13:09:32 +00:00
* bump libp2p pin to release/v2.0.0 (c43199378) * pin nimble.lock: lsquic/websock/boringssl/protobuf_serialization/npeg/jwt * add libp2p_mix dep and point libp2p/protocols/mix -> libp2p_mix * migrate rng to libp2p Rng type (prod, channels, noise, tests) * noise: take Rng, extract bearSslDrbg internally * waku_switch: TransportConfig factory; withMaxInOut; local MaxConnections * waku_relay/rendezvous/discv5/kademlia: v2.0.0 API (rng, config, ServiceDiscovery) * tests: newStandardSwitch shim; PeerId.random(rng); common.rng()/crypto.newRng() * drop libp2p/utils/semaphore (use chronos AsyncSemaphore) * add waku/compat/option_valueor shim where needed * add std/options where transitive re-export dropped
53 lines
1.6 KiB
Nim
53 lines
1.6 KiB
Nim
import waku/compat/option_valueor
|
|
import options, std/[json, strformat]
|
|
import chronicles, chronos, results, ffi
|
|
import
|
|
waku/waku_core/message/message,
|
|
waku/waku_core/codecs,
|
|
waku/factory/waku,
|
|
waku/waku_core/message,
|
|
waku/waku_core/topics/pubsub_topic,
|
|
waku/waku_lightpush_legacy/client,
|
|
waku/node/peer_manager/peer_manager,
|
|
library/events/json_message_event,
|
|
library/declare_lib
|
|
|
|
proc waku_lightpush_publish(
|
|
ctx: ptr FFIContext[Waku],
|
|
callback: FFICallBack,
|
|
userData: pointer,
|
|
pubSubTopic: cstring,
|
|
jsonWakuMessage: cstring,
|
|
) {.ffi.} =
|
|
if ctx.myLib[].node.wakuLightpushClient.isNil():
|
|
let errorMsg = "LightpushRequest waku.node.wakuLightpushClient is nil"
|
|
error "PUBLISH failed", error = errorMsg
|
|
return err(errorMsg)
|
|
|
|
var jsonMessage: JsonMessage
|
|
try:
|
|
let jsonContent = parseJson($jsonWakuMessage)
|
|
jsonMessage = JsonMessage.fromJsonNode(jsonContent).valueOr:
|
|
raise newException(JsonParsingError, $error)
|
|
except JsonParsingError as exc:
|
|
return err(fmt"Error parsing json message: {exc.msg}")
|
|
|
|
let msg = json_message_event.toWakuMessage(jsonMessage).valueOr:
|
|
return err("Problem building the WakuMessage: " & $error)
|
|
|
|
let peerOpt = ctx.myLib[].node.peerManager.selectPeer(WakuLightPushCodec)
|
|
if peerOpt.isNone():
|
|
let errorMsg = "failed to lightpublish message, no suitable remote peers"
|
|
error "PUBLISH failed", error = errorMsg
|
|
return err(errorMsg)
|
|
|
|
let msgHashHex = (
|
|
await ctx.myLib[].node.wakuLegacyLightpushClient.publish(
|
|
$pubsubTopic, msg, peer = peerOpt.get()
|
|
)
|
|
).valueOr:
|
|
error "PUBLISH failed", error = error
|
|
return err($error)
|
|
|
|
return ok(msgHashHex)
|