diff --git a/CHANGELOG.md b/CHANGELOG.md index b1df01a28..d64471edc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## Next version + +- Refactor: Split out `waku_types` types into right place; create utils folder. + ## 2021-01-05 v0.2 This release contains the following changes: diff --git a/examples/v2/basic2.nim b/examples/v2/basic2.nim index bf64703a3..1deddcbb3 100644 --- a/examples/v2/basic2.nim +++ b/examples/v2/basic2.nim @@ -10,11 +10,7 @@ import json_rpc/[rpcclient, rpcserver], ../../waku/v2/node/[config, wakunode2], ../../waku/common/utils/nat, - ../../waku/v2/waku_types - - -type - Topic* = waku_types.Topic + ../../waku/v2/protocol/waku_message # Node operations happens asynchronously proc runBackground() {.async.} = diff --git a/examples/v2/chat2.nim b/examples/v2/chat2.nim index d04d7c006..459abdf3f 100644 --- a/examples/v2/chat2.nim +++ b/examples/v2/chat2.nim @@ -19,11 +19,10 @@ import libp2p/[switch, # manage transports, a single entry poi muxers/muxer, # define an interface for stream multiplexing, allowing peers to offer many protocols over a single connection muxers/mplex/mplex] # define some contants and message types for stream multiplexing import ../../waku/v2/node/[config, wakunode2, waku_payload], - ../../waku/v2/protocol/[waku_relay], + ../../waku/v2/protocol/[waku_relay, waku_message], ../../waku/v2/protocol/waku_store/waku_store, ../../waku/v2/protocol/waku_filter/waku_filter, - ../../waku/common/utils/nat, - ../../waku/v2/waku_types + ../../waku/common/utils/nat const Help = """ Commands: /[?|help|connect|disconnect|exit] @@ -52,7 +51,7 @@ type Chat = ref object type PrivateKey* = crypto.PrivateKey - Topic* = waku_types.Topic + Topic* = wakunode2.Topic # Similarly as Status public chats now. diff --git a/tests/v2/test_jsonrpc_waku.nim b/tests/v2/test_jsonrpc_waku.nim index 1877d9c5a..dd4caba2c 100644 --- a/tests/v2/test_jsonrpc_waku.nim +++ b/tests/v2/test_jsonrpc_waku.nim @@ -10,7 +10,6 @@ import libp2p/protocols/pubsub/pubsub, libp2p/protocols/pubsub/rpc/message, ../../waku/v1/node/rpc/hexstrings, - ../../waku/v2/waku_types, ../../waku/v2/node/wakunode2, ../../waku/v2/node/jsonrpc/[store_api, relay_api, diff --git a/tests/v2/test_message_store.nim b/tests/v2/test_message_store.nim index 0c4dc50c4..bdc5487c3 100644 --- a/tests/v2/test_message_store.nim +++ b/tests/v2/test_message_store.nim @@ -5,7 +5,6 @@ import ../../waku/v2/node/message_store, ../../waku/v2/protocol/waku_store/waku_store, ./utils, - ../../waku/v2/waku_types, ../../waku/v2/node/sqlite suite "Message Store": diff --git a/tests/v2/test_rpc_waku.nim b/tests/v2/test_rpc_waku.nim index d75194cac..307a8369c 100644 --- a/tests/v2/test_rpc_waku.nim +++ b/tests/v2/test_rpc_waku.nim @@ -8,7 +8,6 @@ import ../../waku/v2/node/wakunode2, ../../waku/v2/node/rpc/wakurpc, ../../waku/v2/protocol/waku_relay, - ../../waku/v2/waku_types, ../test_helpers diff --git a/tests/v2/test_waku_filter.nim b/tests/v2/test_waku_filter.nim index c80211526..dfab9838e 100644 --- a/tests/v2/test_waku_filter.nim +++ b/tests/v2/test_waku_filter.nim @@ -10,7 +10,6 @@ import libp2p/multistream, ../../waku/v2/protocol/[message_notifier], ../../waku/v2/protocol/waku_filter/waku_filter, - ../../waku/v2/waku_types, ../test_helpers, ./utils procSuite "Waku Filter": diff --git a/tests/v2/test_waku_pagination.nim b/tests/v2/test_waku_pagination.nim index 4523ac919..a30eddf68 100644 --- a/tests/v2/test_waku_pagination.nim +++ b/tests/v2/test_waku_pagination.nim @@ -2,7 +2,6 @@ import std/[unittest,algorithm,options], nimcrypto/sha2, - ../../waku/v2/waku_types, ../../waku/v2/protocol/waku_store/waku_store, ../test_helpers diff --git a/tests/v2/test_waku_payload.nim b/tests/v2/test_waku_payload.nim index ac2666cc9..5674ce10d 100644 --- a/tests/v2/test_waku_payload.nim +++ b/tests/v2/test_waku_payload.nim @@ -2,6 +2,7 @@ import std/unittest, + ../../waku/v2/protocol/waku_message, ../../waku/v2/node/waku_payload, ../test_helpers diff --git a/tests/v2/test_waku_store.nim b/tests/v2/test_waku_store.nim index a101fe4f3..40372009b 100644 --- a/tests/v2/test_waku_store.nim +++ b/tests/v2/test_waku_store.nim @@ -8,11 +8,10 @@ import libp2p/stream/[bufferstream, connection], libp2p/crypto/crypto, libp2p/protocols/pubsub/rpc/message, - ../../waku/v2/protocol/message_notifier, + ../../waku/v2/protocol/[waku_message, message_notifier], ../../waku/v2/protocol/waku_store/waku_store, ../../waku/v2/node/[message_store, sqlite], - ../test_helpers, ./utils, - ../../waku/v2/waku_types + ../test_helpers, ./utils procSuite "Waku Store": asyncTest "handle query": diff --git a/tests/v2/test_waku_swap.nim b/tests/v2/test_waku_swap.nim index 040e69634..8fdc99db3 100644 --- a/tests/v2/test_waku_swap.nim +++ b/tests/v2/test_waku_swap.nim @@ -7,12 +7,11 @@ import libp2p/crypto/[crypto, secp], libp2p/switch, eth/keys, - ../../waku/v2/protocol/[message_notifier], + ../../waku/v2/protocol/[waku_message, message_notifier], ../../waku/v2/protocol/waku_store/waku_store, ../../waku/v2/protocol/waku_swap/waku_swap, ../../waku/v2/node/wakunode2, - ../test_helpers, ./utils, - ../../waku/v2/waku_types + ../test_helpers, ./utils procSuite "Waku SWAP Accounting": test "Handshake Encode/Decode": diff --git a/tests/v2/test_wakunode.nim b/tests/v2/test_wakunode.nim index b2e27a890..b5d9dc0a2 100644 --- a/tests/v2/test_wakunode.nim +++ b/tests/v2/test_wakunode.nim @@ -7,12 +7,11 @@ import libp2p/crypto/secp, libp2p/switch, eth/keys, - ../../waku/v2/protocol/[waku_relay, message_notifier], + ../../waku/v2/protocol/[waku_relay, waku_message, message_notifier], ../../waku/v2/protocol/waku_store/waku_store, ../../waku/v2/protocol/waku_filter/waku_filter, ../../waku/v2/node/wakunode2, - ../test_helpers, - ../../waku/v2/waku_types + ../test_helpers procSuite "WakuNode": let rng = keys.newRng() diff --git a/tests/v2/utils.nim b/tests/v2/utils.nim index ac32c2dae..9d220f536 100644 --- a/tests/v2/utils.nim +++ b/tests/v2/utils.nim @@ -8,7 +8,7 @@ import chronos import libp2p/[standard_setup, protocols/pubsub/pubsub, protocols/secure/secure] -import ../../waku/v2/waku_types +import ../../waku/v2/protocol/waku_relay export standard_setup diff --git a/waku/v2/node/jsonrpc/admin_api.nim b/waku/v2/node/jsonrpc/admin_api.nim index 835510f88..ee8745aa5 100644 --- a/waku/v2/node/jsonrpc/admin_api.nim +++ b/waku/v2/node/jsonrpc/admin_api.nim @@ -4,7 +4,6 @@ import std/[options,sequtils], json_rpc/rpcserver, libp2p/[peerinfo, switch], - ../../waku_types, ../../protocol/waku_store/[waku_store_types, waku_store], ../../protocol/waku_swap/[waku_swap_types, waku_swap], ../../protocol/waku_filter/[waku_filter_types, waku_filter], diff --git a/waku/v2/node/jsonrpc/debug_api.nim b/waku/v2/node/jsonrpc/debug_api.nim index cea37b172..fcb8cd7f1 100644 --- a/waku/v2/node/jsonrpc/debug_api.nim +++ b/waku/v2/node/jsonrpc/debug_api.nim @@ -1,6 +1,5 @@ import json_rpc/rpcserver, - ../../waku_types, ../wakunode2 proc installDebugApiHandlers*(node: WakuNode, rpcsrv: RpcServer) = diff --git a/waku/v2/node/jsonrpc/filter_api.nim b/waku/v2/node/jsonrpc/filter_api.nim index d5f1796bf..d2477ab26 100644 --- a/waku/v2/node/jsonrpc/filter_api.nim +++ b/waku/v2/node/jsonrpc/filter_api.nim @@ -4,7 +4,6 @@ import std/[tables,sequtils], json_rpc/rpcserver, eth/[common, rlp, keys, p2p], - ../../waku_types, ../../protocol/waku_filter/waku_filter_types, ../wakunode2, ./jsonrpc_types diff --git a/waku/v2/node/jsonrpc/jsonrpc_types.nim b/waku/v2/node/jsonrpc/jsonrpc_types.nim index c80349068..80aadbb43 100644 --- a/waku/v2/node/jsonrpc/jsonrpc_types.nim +++ b/waku/v2/node/jsonrpc/jsonrpc_types.nim @@ -1,7 +1,8 @@ import + std/[options,tables], eth/keys, - ../../waku_types, - std/[options,tables] + ../../protocol/waku_message, + ../../utils/pagination type StoreResponse* = object diff --git a/waku/v2/node/jsonrpc/jsonrpc_utils.nim b/waku/v2/node/jsonrpc/jsonrpc_utils.nim index caca98f0e..064ccef67 100644 --- a/waku/v2/node/jsonrpc/jsonrpc_utils.nim +++ b/waku/v2/node/jsonrpc/jsonrpc_utils.nim @@ -2,7 +2,6 @@ import std/options, eth/keys, ../../../v1/node/rpc/hexstrings, - ../../waku_types, ../../protocol/waku_store/waku_store_types, ../wakunode2, ../waku_payload, ./jsonrpc_types diff --git a/waku/v2/node/jsonrpc/private_api.nim b/waku/v2/node/jsonrpc/private_api.nim index fb0c6be80..dc76742e0 100644 --- a/waku/v2/node/jsonrpc/private_api.nim +++ b/waku/v2/node/jsonrpc/private_api.nim @@ -5,7 +5,6 @@ import json_rpc/rpcserver, nimcrypto/sysrand, eth/[common, rlp, keys, p2p], - ../../waku_types, ../wakunode2, ../waku_payload, ./jsonrpc_types, ./jsonrpc_utils diff --git a/waku/v2/node/jsonrpc/relay_api.nim b/waku/v2/node/jsonrpc/relay_api.nim index 8959cfb5e..6cabe77cb 100644 --- a/waku/v2/node/jsonrpc/relay_api.nim +++ b/waku/v2/node/jsonrpc/relay_api.nim @@ -5,9 +5,9 @@ import json_rpc/rpcserver, libp2p/protocols/pubsub/pubsub, eth/[common, rlp, keys, p2p], - ../../waku_types, ../wakunode2, - ./jsonrpc_types, ./jsonrpc_utils + ./jsonrpc_types, ./jsonrpc_utils, + ../../protocol/waku_message export jsonrpc_types diff --git a/waku/v2/node/jsonrpc/store_api.nim b/waku/v2/node/jsonrpc/store_api.nim index b579264cd..39928818b 100644 --- a/waku/v2/node/jsonrpc/store_api.nim +++ b/waku/v2/node/jsonrpc/store_api.nim @@ -3,7 +3,6 @@ import std/options, json_rpc/rpcserver, - ../../waku_types, ../../protocol/waku_store/waku_store_types, ../wakunode2, ./jsonrpc_types, ./jsonrpc_utils diff --git a/waku/v2/node/message_store.nim b/waku/v2/node/message_store.nim index b42a9108b..3c191f13d 100644 --- a/waku/v2/node/message_store.nim +++ b/waku/v2/node/message_store.nim @@ -6,8 +6,9 @@ import libp2p/protobuf/minprotobuf, libp2p/stream/connection, stew/results, metrics, - ../waku_types, - ./sqlite + ./sqlite, + ../protocol/waku_message, + ../utils/pagination # The code in this file is an adaptation of the Sqlite KV Store found in nim-eth. # https://github.com/status-im/nim-eth/blob/master/eth/db/kvstore_sqlite3.nim @@ -17,6 +18,11 @@ import type DataProc* = proc(timestamp: uint64, msg: WakuMessage) {.closure.} + MessageStoreResult*[T] = Result[T, string] + + MessageStore* = ref object of RootObj + database*: SqliteDatabase + proc init*(T: type MessageStore, db: SqliteDatabase): MessageStoreResult[T] = ## Table is the SQL query for creating the messages Table. ## It contains: diff --git a/waku/v2/node/rpc/rpc_publish.nim b/waku/v2/node/rpc/rpc_publish.nim index b4971cd95..bfea46b2c 100644 --- a/waku/v2/node/rpc/rpc_publish.nim +++ b/waku/v2/node/rpc/rpc_publish.nim @@ -4,8 +4,7 @@ import libp2p/protobuf/minprotobuf, eth/common as eth_common, eth/keys, system, - options, - ../../waku_types + options from strutils import rsplit template sourceDir: string = currentSourcePath.rsplit(DirSep, 1)[0] diff --git a/waku/v2/node/rpc/wakurpc.nim b/waku/v2/node/rpc/wakurpc.nim index c5e05feae..79b7a7310 100644 --- a/waku/v2/node/rpc/wakurpc.nim +++ b/waku/v2/node/rpc/wakurpc.nim @@ -4,7 +4,6 @@ import nimcrypto/[sysrand, hmac, sha2], eth/[common, rlp, keys, p2p], ../../protocol/waku_relay, - ../../waku_types, ../../protocol/waku_store/waku_store, ../../protocol/waku_filter/waku_filter, ../wakunode2 diff --git a/waku/v2/node/waku_payload.nim b/waku/v2/node/waku_payload.nim index ac0821d29..936992c55 100644 --- a/waku/v2/node/waku_payload.nim +++ b/waku/v2/node/waku_payload.nim @@ -2,9 +2,9 @@ import std/options, eth/keys, eth/p2p/rlpx_protocols/whisper/whisper_types, - ../waku_types + ../protocol/waku_message -export whisper_types, waku_types, keys, options +export whisper_types, keys, options type KeyKind* = enum @@ -21,6 +21,10 @@ type of None: discard + # NOTE: Currently only used here, if we start using it elsewhere pull it out. + WakuResult*[T] = Result[T, cstring] + + # TODO: # - This is using `DecodedPayload` from Waku v1 / Whisper and could be altered # by making that a case object also, e.g. useful for the version 0, but diff --git a/waku/v2/node/wakunode2.nim b/waku/v2/node/wakunode2.nim index 96ce32885..7945a3585 100644 --- a/waku/v2/node/wakunode2.nim +++ b/waku/v2/node/wakunode2.nim @@ -14,11 +14,9 @@ import ../protocol/waku_store/waku_store, ../protocol/waku_swap/waku_swap, ../protocol/waku_filter/waku_filter, - ../waku_types, ./message_store, - ./sqlite - -export waku_types + ./sqlite, + ../utils/requests logScope: topics = "wakunode" @@ -32,10 +30,15 @@ type PublicKey* = crypto.PublicKey PrivateKey* = crypto.PrivateKey - # TODO Get rid of this and use waku_types one - Topic* = waku_types.Topic + # XXX: Weird type, should probably be using pubsub Topic object name? + Topic* = string Message* = seq[byte] + WakuInfo* = object + # NOTE One for simplicity, can extend later as needed + listenStr*: string + #multiaddrStrings*: seq[string] + # NOTE based on Eth2Node in NBC eth2_network.nim WakuNode* = ref object of RootObj switch*: Switch diff --git a/waku/v2/protocol/message_notifier.nim b/waku/v2/protocol/message_notifier.nim index 9f48a6581..14b9f8fb9 100644 --- a/waku/v2/protocol/message_notifier.nim +++ b/waku/v2/protocol/message_notifier.nim @@ -1,7 +1,7 @@ import std/tables, chronos, - ../waku_types + waku_message ## The Message Notification system is a method to notify various protocols ## running on a node when a new message was received. @@ -23,6 +23,19 @@ import ## subscriptions["identifier"] = subscription ## ## await subscriptions.notify(topic, WakuMessage(payload: @[byte 1, 2, 3], contentTopic: ContentTopic(1))) + +type + MessageNotificationHandler* = proc(topic: string, msg: WakuMessage): Future[ + void] {.gcsafe, closure.} + + MessageNotificationSubscriptionIdentifier* = string + + MessageNotificationSubscription* = object + topics*: seq[string] # @TODO TOPIC + handler*: MessageNotificationHandler + + MessageNotificationSubscriptions* = TableRef[MessageNotificationSubscriptionIdentifier, MessageNotificationSubscription] + proc subscribe*(subscriptions: MessageNotificationSubscriptions, name: string, subscription: MessageNotificationSubscription) = subscriptions.add(name, subscription) diff --git a/waku/v2/protocol/waku_filter/waku_filter.nim b/waku/v2/protocol/waku_filter/waku_filter.nim index 35f2ab062..82524e1b4 100644 --- a/waku/v2/protocol/waku_filter/waku_filter.nim +++ b/waku/v2/protocol/waku_filter/waku_filter.nim @@ -11,8 +11,8 @@ import libp2p/crypto/crypto, libp2p/switch, ../message_notifier, - ../../waku_types, - waku_filter_types + waku_filter_types, + ../../utils/requests # NOTE This is just a start, the design of this protocol isn't done yet. It # should be direct payload exchange (a la req-resp), not be coupled with the diff --git a/waku/v2/protocol/waku_filter/waku_filter_types.nim b/waku/v2/protocol/waku_filter/waku_filter_types.nim index 2c7eaa4ab..d22064c84 100644 --- a/waku/v2/protocol/waku_filter/waku_filter_types.nim +++ b/waku/v2/protocol/waku_filter/waku_filter_types.nim @@ -3,7 +3,9 @@ import bearssl, libp2p/[switch, peerinfo], libp2p/protocols/protocol, - ../../waku_types + ../waku_message + +export waku_message type ContentFilter* = object diff --git a/waku/v2/protocol/waku_message.nim b/waku/v2/protocol/waku_message.nim new file mode 100644 index 000000000..3a2f679bc --- /dev/null +++ b/waku/v2/protocol/waku_message.nim @@ -0,0 +1,36 @@ +## Waku Message module. +## +## See https://github.com/vacp2p/specs/blob/master/specs/waku/v2/waku-message.md +## for spec. +## +## For payload content and encryption, see waku/v2/node/waku_payload.nim + + +import + libp2p/protobuf/minprotobuf + +type + ContentTopic* = uint32 + + WakuMessage* = object + payload*: seq[byte] + contentTopic*: ContentTopic + version*: uint32 + +# Encoding and decoding ------------------------------------------------------- +proc init*(T: type WakuMessage, buffer: seq[byte]): ProtoResult[T] = + var msg = WakuMessage() + let pb = initProtoBuffer(buffer) + + discard ? pb.getField(1, msg.payload) + discard ? pb.getField(2, msg.contentTopic) + discard ? pb.getField(3, msg.version) + + ok(msg) + +proc encode*(message: WakuMessage): ProtoBuffer = + result = initProtoBuffer() + + result.write(1, message.payload) + result.write(2, message.contentTopic) + result.write(3, message.version) diff --git a/waku/v2/protocol/waku_relay.nim b/waku/v2/protocol/waku_relay.nim index 68e5ac27b..8fe4bddad 100644 --- a/waku/v2/protocol/waku_relay.nim +++ b/waku/v2/protocol/waku_relay.nim @@ -1,14 +1,13 @@ -## Waku on libp2p +## Waku Relay module. Thin layer on top of GossipSub. ## -## This file should eventually correspond to waku_protocol as RLPx subprotocol. -## Instead, it should likely be on top of GossipSub with a similar interface. +## See https://github.com/vacp2p/specs/blob/master/specs/waku/v2/waku-relay.md +## for spec. import chronos, chronicles, metrics, libp2p/protocols/pubsub/[pubsub, gossipsub], libp2p/protocols/pubsub/rpc/messages, - libp2p/stream/connection, - ../waku_types + libp2p/stream/connection declarePublicGauge total_messages, "number of messages received" @@ -17,6 +16,9 @@ logScope: const WakuRelayCodec* = "/vac/waku/relay/2.0.0-beta2" +type + WakuRelay* = ref object of GossipSub + method init*(w: WakuRelay) = debug "init" proc handler(conn: Connection, proto: string) {.async.} = diff --git a/waku/v2/protocol/waku_store/waku_store.nim b/waku/v2/protocol/waku_store/waku_store.nim index df23b15f0..ec365881a 100644 --- a/waku/v2/protocol/waku_store/waku_store.nim +++ b/waku/v2/protocol/waku_store/waku_store.nim @@ -14,8 +14,8 @@ import ../message_notifier, ../../node/message_store, ../waku_swap/waku_swap, - ../../waku_types, - ./waku_store_types + ./waku_store_types, + ../../utils/requests export waku_store_types diff --git a/waku/v2/protocol/waku_store/waku_store_types.nim b/waku/v2/protocol/waku_store/waku_store_types.nim index 273ecb21a..0b2793df0 100644 --- a/waku/v2/protocol/waku_store/waku_store_types.nim +++ b/waku/v2/protocol/waku_store/waku_store_types.nim @@ -4,10 +4,19 @@ import bearssl, libp2p/[switch, peerinfo], libp2p/protocols/protocol, - ../../waku_types, - ../waku_swap/waku_swap_types + ../waku_swap/waku_swap_types, + ../waku_message, + ../../node/message_store, + ../../utils/pagination + +export waku_message +export pagination + +# Constants required for pagination ------------------------------------------- +const MaxPageSize* = 100 # Maximum number of waku messages in each page type + QueryHandlerFunc* = proc(response: HistoryResponse) {.gcsafe, closure.} IndexedWakuMessage* = object diff --git a/waku/v2/utils/README.md b/waku/v2/utils/README.md new file mode 100644 index 000000000..8a021e7d8 --- /dev/null +++ b/waku/v2/utils/README.md @@ -0,0 +1,4 @@ +# Utils + +Collection of misc utilities that don't fit anywhere else, and are used by +multiple independent modules. diff --git a/waku/v2/utils/pagination.nim b/waku/v2/utils/pagination.nim new file mode 100644 index 000000000..02ad5a3df --- /dev/null +++ b/waku/v2/utils/pagination.nim @@ -0,0 +1,11 @@ +## Contains types and utilities for pagination. +## +## Used by both message store and store protocol. + +import nimcrypto/hash + +type + Index* = object + ## This type contains the description of an Index used in the pagination of WakuMessages + digest*: MDigest[256] + receivedTime*: float64 diff --git a/waku/v2/utils/requests.nim b/waku/v2/utils/requests.nim new file mode 100644 index 000000000..e49b1c2ea --- /dev/null +++ b/waku/v2/utils/requests.nim @@ -0,0 +1,8 @@ +# Request utils. + +import bearssl, stew/byteutils + +proc generateRequestId*(rng: ref BrHmacDrbgContext): string = + var bytes: array[10, byte] + brHmacDrbgGenerate(rng[], bytes) + toHex(bytes) diff --git a/waku/v2/waku_types.nim b/waku/v2/waku_types.nim deleted file mode 100644 index d034c5a97..000000000 --- a/waku/v2/waku_types.nim +++ /dev/null @@ -1,90 +0,0 @@ -## Core Waku data types are defined here to avoid recursive dependencies. -## -## TODO Move types here into their appropriate place - -import - std/tables, - chronos, bearssl, stew/byteutils, - libp2p/[switch, peerinfo, multiaddress, crypto/crypto], - libp2p/protobuf/minprotobuf, - libp2p/protocols/protocol, - libp2p/switch, - libp2p/stream/connection, - libp2p/protocols/pubsub/[pubsub, gossipsub], - nimcrypto/sha2, - ./node/sqlite - -# Constants required for pagination ------------------------------------------- -const MaxPageSize* = 100 # Maximum number of waku messages in each page - -# Common data types ----------------------------------------------------------- -type - - # Message ------------------------------------------------------------------- - - Index* = object - ## This type contains the description of an Index used in the pagination of WakuMessages - digest*: MDigest[256] - receivedTime*: float64 - - ContentTopic* = uint32 - - Topic* = string - Message* = seq[byte] - - WakuMessage* = object - payload*: seq[byte] - contentTopic*: ContentTopic - version*: uint32 - - MessageNotificationHandler* = proc(topic: string, msg: WakuMessage): Future[ - void] {.gcsafe, closure.} - - MessageNotificationSubscriptionIdentifier* = string - - MessageNotificationSubscription* = object - topics*: seq[string] # @TODO TOPIC - handler*: MessageNotificationHandler - - MessageNotificationSubscriptions* = TableRef[MessageNotificationSubscriptionIdentifier, MessageNotificationSubscription] - - # Relay protocol types ------------------------------------------------------- - - WakuRelay* = ref object of GossipSub - - WakuInfo* = object - # NOTE One for simplicity, can extend later as needed - listenStr*: string - #multiaddrStrings*: seq[string] - - WakuResult*[T] = Result[T, cstring] - - MessageStoreResult*[T] = Result[T, string] - - MessageStore* = ref object of RootObj - database*: SqliteDatabase - -# Encoding and decoding ------------------------------------------------------- -# TODO Move out to to waku_message module -# Possibly same with util functions -proc init*(T: type WakuMessage, buffer: seq[byte]): ProtoResult[T] = - var msg = WakuMessage() - let pb = initProtoBuffer(buffer) - - discard ? pb.getField(1, msg.payload) - discard ? pb.getField(2, msg.contentTopic) - discard ? pb.getField(3, msg.version) - - ok(msg) - -proc encode*(message: WakuMessage): ProtoBuffer = - result = initProtoBuffer() - - result.write(1, message.payload) - result.write(2, message.contentTopic) - result.write(3, message.version) - -proc generateRequestId*(rng: ref BrHmacDrbgContext): string = - var bytes: array[10, byte] - brHmacDrbgGenerate(rng[], bytes) - toHex(bytes) diff --git a/waku/waku.nim b/waku/waku.nim index 530614235..4f9210825 100644 --- a/waku/waku.nim +++ b/waku/waku.nim @@ -5,7 +5,6 @@ # - APACHEv2 ([LICENSE-APACHEv2](../LICENSE-APACHEv2) or https://www.apache.org/licenses/LICENSE-2.0) ## An implementation of the [Waku v1](https://specs.vac.dev/specs/waku/waku.html) and [Waku v2](https://specs.vac.dev/specs/waku/v2/waku-v2.html) in nim. -import v2/node/wakunode2, v1/node/wakunode1, waku_types +import v2/node/wakunode2, v1/node/wakunode1 export wakunode2 export wakunode1 -export waku_types