mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-06-20 00:20:07 +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)
96 lines
3.1 KiB
Nim
96 lines
3.1 KiB
Nim
import logos_delivery/waku/compat/option_valueor
|
|
import std/[json, sugar, strutils, options]
|
|
import chronos, chronicles, results, stew/byteutils, ffi
|
|
import
|
|
logos_delivery/waku/factory/waku,
|
|
library/utils,
|
|
logos_delivery/waku/waku_core/peers,
|
|
logos_delivery/waku/waku_core/message/digest,
|
|
logos_delivery/waku/waku_store/common,
|
|
logos_delivery/waku/waku_store/client,
|
|
logos_delivery/waku/common/paging,
|
|
library/declare_lib
|
|
|
|
func fromJsonNode(jsonContent: JsonNode): Result[StoreQueryRequest, string] =
|
|
var contentTopics: seq[string]
|
|
if jsonContent.contains("contentTopics"):
|
|
contentTopics = collect(newSeq):
|
|
for cTopic in jsonContent["contentTopics"].getElems():
|
|
cTopic.getStr()
|
|
|
|
var msgHashes: seq[WakuMessageHash]
|
|
if jsonContent.contains("messageHashes"):
|
|
for hashJsonObj in jsonContent["messageHashes"].getElems():
|
|
let hash = hashJsonObj.getStr().hexToHash().valueOr:
|
|
return err("Failed converting message hash hex string to bytes: " & error)
|
|
msgHashes.add(hash)
|
|
|
|
let pubsubTopic =
|
|
if jsonContent.contains("pubsubTopic"):
|
|
some(jsonContent["pubsubTopic"].getStr())
|
|
else:
|
|
none(string)
|
|
|
|
let paginationCursor =
|
|
if jsonContent.contains("paginationCursor"):
|
|
let hash = jsonContent["paginationCursor"].getStr().hexToHash().valueOr:
|
|
return err("Failed converting paginationCursor hex string to bytes: " & error)
|
|
some(hash)
|
|
else:
|
|
none(WakuMessageHash)
|
|
|
|
let paginationForwardBool = jsonContent["paginationForward"].getBool()
|
|
let paginationForward =
|
|
if paginationForwardBool: PagingDirection.FORWARD else: PagingDirection.BACKWARD
|
|
|
|
let paginationLimit =
|
|
if jsonContent.contains("paginationLimit"):
|
|
some(uint64(jsonContent["paginationLimit"].getInt()))
|
|
else:
|
|
none(uint64)
|
|
|
|
let startTime = ?jsonContent.getProtoInt64("timeStart")
|
|
let endTime = ?jsonContent.getProtoInt64("timeEnd")
|
|
|
|
return ok(
|
|
StoreQueryRequest(
|
|
requestId: jsonContent["requestId"].getStr(),
|
|
includeData: jsonContent["includeData"].getBool(),
|
|
pubsubTopic: pubsubTopic,
|
|
contentTopics: contentTopics,
|
|
startTime: startTime,
|
|
endTime: endTime,
|
|
messageHashes: msgHashes,
|
|
paginationCursor: paginationCursor,
|
|
paginationForward: paginationForward,
|
|
paginationLimit: paginationLimit,
|
|
)
|
|
)
|
|
|
|
proc waku_store_query(
|
|
ctx: ptr FFIContext[Waku],
|
|
callback: FFICallBack,
|
|
userData: pointer,
|
|
jsonQuery: cstring,
|
|
peerAddr: cstring,
|
|
timeoutMs: cint,
|
|
) {.ffi.} =
|
|
let jsonContentRes = catch:
|
|
parseJson($jsonQuery)
|
|
|
|
if jsonContentRes.isErr():
|
|
return err("StoreRequest failed parsing store request: " & jsonContentRes.error.msg)
|
|
|
|
let storeQueryRequest = ?fromJsonNode(jsonContentRes.get())
|
|
|
|
let peer = peers.parsePeerInfo(($peerAddr).split(",")).valueOr:
|
|
return err("StoreRequest failed to parse peer addr: " & $error)
|
|
|
|
let queryResponse = (
|
|
await ctx.myLib[].node.wakuStoreClient.query(storeQueryRequest, peer)
|
|
).valueOr:
|
|
return err("StoreRequest failed store query: " & $error)
|
|
|
|
let res = $(%*(queryResponse.toHex()))
|
|
return ok(res) ## returning the response in json format
|