mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-06-16 14:39:34 +00:00
* bump nim-libp2p pin to v2.0.0 tag * bump json_rpc to v0.6.1, lsquic to v0.5.1, boringssl to v0.0.8 (latest tags) * add libp2p_mix dep; repoint libp2p/protocols/mix -> libp2p_mix * pin nimble.lock: websock / protobuf_serialization / npeg / jwt * Makefile: add -d:libp2p_quic_support * regenerate nix/deps.nix (adds libp2p_mix, refreshes pins) * migrate rng ref HmacDrbgContext -> libp2p Rng across prod/channels/tests (interface-only; same DRBG) * waku_switch: TransportConfig factory; unified 2.0.0 connection limits (withMaxInOut, withMaxConnections); local MaxConnections * waku_relay/rendezvous/discv5/kademlia: v2.0.0 API (rng, config, ServiceDiscovery rename) * call Service.setup() on post-build switch services (2.0.0 split setup/start) * drop libp2p/utils/semaphore -> chronos AsyncSemaphore * add logos_delivery/waku/compat/option_valueor shim (Option[T] valueOr/withValue, dropped upstream) * add std/options where a transitive re-export was removed * add newStandardSwitch shim (libp2p removed it in 2.0.0); mounts yamux+mplex to match prod muxer * PeerId.random(rng); common.rng()/crypto.newRng(); hoist shared rng (instantiation cleanup) * update expectations for 2.0.0 defaults: DEFAULT_PROTOCOLS += /ipfs/id/push/1.0.0; agent "nim-libp2p" * drop relay reboot/reconnect test (asserted a Switch restart capability that is simply not supported) * fix up a few tests that were flaking on MacOS (libp2p upgrade may have exposed these)
53 lines
1.8 KiB
Nim
53 lines
1.8 KiB
Nim
import logos_delivery/waku/compat/option_valueor
|
|
import options, std/[json, strformat]
|
|
import chronicles, chronos, results, ffi
|
|
import
|
|
logos_delivery/waku/waku_core/message/message,
|
|
logos_delivery/waku/waku_core/codecs,
|
|
logos_delivery/waku/factory/waku,
|
|
logos_delivery/waku/waku_core/message,
|
|
logos_delivery/waku/waku_core/topics/pubsub_topic,
|
|
logos_delivery/waku/waku_lightpush_legacy/client,
|
|
logos_delivery/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)
|