mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-05 23:43:07 +00:00
Refactor: Put waku_type content where it belongs (#333)
- Separate out types and methods into appropriate module - Add util folder for small utils used in multiple independent places - Update paths
This commit is contained in:
parent
f6f6057c49
commit
37a3a4fadd
@ -1,5 +1,9 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## Next version
|
||||||
|
|
||||||
|
- Refactor: Split out `waku_types` types into right place; create utils folder.
|
||||||
|
|
||||||
## 2021-01-05 v0.2
|
## 2021-01-05 v0.2
|
||||||
|
|
||||||
This release contains the following changes:
|
This release contains the following changes:
|
||||||
|
|||||||
@ -10,11 +10,7 @@ import
|
|||||||
json_rpc/[rpcclient, rpcserver],
|
json_rpc/[rpcclient, rpcserver],
|
||||||
../../waku/v2/node/[config, wakunode2],
|
../../waku/v2/node/[config, wakunode2],
|
||||||
../../waku/common/utils/nat,
|
../../waku/common/utils/nat,
|
||||||
../../waku/v2/waku_types
|
../../waku/v2/protocol/waku_message
|
||||||
|
|
||||||
|
|
||||||
type
|
|
||||||
Topic* = waku_types.Topic
|
|
||||||
|
|
||||||
# Node operations happens asynchronously
|
# Node operations happens asynchronously
|
||||||
proc runBackground() {.async.} =
|
proc runBackground() {.async.} =
|
||||||
|
|||||||
@ -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/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
|
muxers/mplex/mplex] # define some contants and message types for stream multiplexing
|
||||||
import ../../waku/v2/node/[config, wakunode2, waku_payload],
|
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_store/waku_store,
|
||||||
../../waku/v2/protocol/waku_filter/waku_filter,
|
../../waku/v2/protocol/waku_filter/waku_filter,
|
||||||
../../waku/common/utils/nat,
|
../../waku/common/utils/nat
|
||||||
../../waku/v2/waku_types
|
|
||||||
|
|
||||||
const Help = """
|
const Help = """
|
||||||
Commands: /[?|help|connect|disconnect|exit]
|
Commands: /[?|help|connect|disconnect|exit]
|
||||||
@ -52,7 +51,7 @@ type Chat = ref object
|
|||||||
|
|
||||||
type
|
type
|
||||||
PrivateKey* = crypto.PrivateKey
|
PrivateKey* = crypto.PrivateKey
|
||||||
Topic* = waku_types.Topic
|
Topic* = wakunode2.Topic
|
||||||
|
|
||||||
|
|
||||||
# Similarly as Status public chats now.
|
# Similarly as Status public chats now.
|
||||||
|
|||||||
@ -10,7 +10,6 @@ import
|
|||||||
libp2p/protocols/pubsub/pubsub,
|
libp2p/protocols/pubsub/pubsub,
|
||||||
libp2p/protocols/pubsub/rpc/message,
|
libp2p/protocols/pubsub/rpc/message,
|
||||||
../../waku/v1/node/rpc/hexstrings,
|
../../waku/v1/node/rpc/hexstrings,
|
||||||
../../waku/v2/waku_types,
|
|
||||||
../../waku/v2/node/wakunode2,
|
../../waku/v2/node/wakunode2,
|
||||||
../../waku/v2/node/jsonrpc/[store_api,
|
../../waku/v2/node/jsonrpc/[store_api,
|
||||||
relay_api,
|
relay_api,
|
||||||
|
|||||||
@ -5,7 +5,6 @@ import
|
|||||||
../../waku/v2/node/message_store,
|
../../waku/v2/node/message_store,
|
||||||
../../waku/v2/protocol/waku_store/waku_store,
|
../../waku/v2/protocol/waku_store/waku_store,
|
||||||
./utils,
|
./utils,
|
||||||
../../waku/v2/waku_types,
|
|
||||||
../../waku/v2/node/sqlite
|
../../waku/v2/node/sqlite
|
||||||
|
|
||||||
suite "Message Store":
|
suite "Message Store":
|
||||||
|
|||||||
@ -8,7 +8,6 @@ import
|
|||||||
../../waku/v2/node/wakunode2,
|
../../waku/v2/node/wakunode2,
|
||||||
../../waku/v2/node/rpc/wakurpc,
|
../../waku/v2/node/rpc/wakurpc,
|
||||||
../../waku/v2/protocol/waku_relay,
|
../../waku/v2/protocol/waku_relay,
|
||||||
../../waku/v2/waku_types,
|
|
||||||
../test_helpers
|
../test_helpers
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -10,7 +10,6 @@ import
|
|||||||
libp2p/multistream,
|
libp2p/multistream,
|
||||||
../../waku/v2/protocol/[message_notifier],
|
../../waku/v2/protocol/[message_notifier],
|
||||||
../../waku/v2/protocol/waku_filter/waku_filter,
|
../../waku/v2/protocol/waku_filter/waku_filter,
|
||||||
../../waku/v2/waku_types,
|
|
||||||
../test_helpers, ./utils
|
../test_helpers, ./utils
|
||||||
|
|
||||||
procSuite "Waku Filter":
|
procSuite "Waku Filter":
|
||||||
|
|||||||
@ -2,7 +2,6 @@
|
|||||||
import
|
import
|
||||||
std/[unittest,algorithm,options],
|
std/[unittest,algorithm,options],
|
||||||
nimcrypto/sha2,
|
nimcrypto/sha2,
|
||||||
../../waku/v2/waku_types,
|
|
||||||
../../waku/v2/protocol/waku_store/waku_store,
|
../../waku/v2/protocol/waku_store/waku_store,
|
||||||
../test_helpers
|
../test_helpers
|
||||||
|
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import
|
import
|
||||||
std/unittest,
|
std/unittest,
|
||||||
|
../../waku/v2/protocol/waku_message,
|
||||||
../../waku/v2/node/waku_payload,
|
../../waku/v2/node/waku_payload,
|
||||||
../test_helpers
|
../test_helpers
|
||||||
|
|
||||||
|
|||||||
@ -8,11 +8,10 @@ import
|
|||||||
libp2p/stream/[bufferstream, connection],
|
libp2p/stream/[bufferstream, connection],
|
||||||
libp2p/crypto/crypto,
|
libp2p/crypto/crypto,
|
||||||
libp2p/protocols/pubsub/rpc/message,
|
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/protocol/waku_store/waku_store,
|
||||||
../../waku/v2/node/[message_store, sqlite],
|
../../waku/v2/node/[message_store, sqlite],
|
||||||
../test_helpers, ./utils,
|
../test_helpers, ./utils
|
||||||
../../waku/v2/waku_types
|
|
||||||
|
|
||||||
procSuite "Waku Store":
|
procSuite "Waku Store":
|
||||||
asyncTest "handle query":
|
asyncTest "handle query":
|
||||||
|
|||||||
@ -7,12 +7,11 @@ import
|
|||||||
libp2p/crypto/[crypto, secp],
|
libp2p/crypto/[crypto, secp],
|
||||||
libp2p/switch,
|
libp2p/switch,
|
||||||
eth/keys,
|
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_store/waku_store,
|
||||||
../../waku/v2/protocol/waku_swap/waku_swap,
|
../../waku/v2/protocol/waku_swap/waku_swap,
|
||||||
../../waku/v2/node/wakunode2,
|
../../waku/v2/node/wakunode2,
|
||||||
../test_helpers, ./utils,
|
../test_helpers, ./utils
|
||||||
../../waku/v2/waku_types
|
|
||||||
|
|
||||||
procSuite "Waku SWAP Accounting":
|
procSuite "Waku SWAP Accounting":
|
||||||
test "Handshake Encode/Decode":
|
test "Handshake Encode/Decode":
|
||||||
|
|||||||
@ -7,12 +7,11 @@ import
|
|||||||
libp2p/crypto/secp,
|
libp2p/crypto/secp,
|
||||||
libp2p/switch,
|
libp2p/switch,
|
||||||
eth/keys,
|
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_store/waku_store,
|
||||||
../../waku/v2/protocol/waku_filter/waku_filter,
|
../../waku/v2/protocol/waku_filter/waku_filter,
|
||||||
../../waku/v2/node/wakunode2,
|
../../waku/v2/node/wakunode2,
|
||||||
../test_helpers,
|
../test_helpers
|
||||||
../../waku/v2/waku_types
|
|
||||||
|
|
||||||
procSuite "WakuNode":
|
procSuite "WakuNode":
|
||||||
let rng = keys.newRng()
|
let rng = keys.newRng()
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import chronos
|
|||||||
import libp2p/[standard_setup,
|
import libp2p/[standard_setup,
|
||||||
protocols/pubsub/pubsub,
|
protocols/pubsub/pubsub,
|
||||||
protocols/secure/secure]
|
protocols/secure/secure]
|
||||||
import ../../waku/v2/waku_types
|
import ../../waku/v2/protocol/waku_relay
|
||||||
|
|
||||||
export standard_setup
|
export standard_setup
|
||||||
|
|
||||||
|
|||||||
@ -4,7 +4,6 @@ import
|
|||||||
std/[options,sequtils],
|
std/[options,sequtils],
|
||||||
json_rpc/rpcserver,
|
json_rpc/rpcserver,
|
||||||
libp2p/[peerinfo, switch],
|
libp2p/[peerinfo, switch],
|
||||||
../../waku_types,
|
|
||||||
../../protocol/waku_store/[waku_store_types, waku_store],
|
../../protocol/waku_store/[waku_store_types, waku_store],
|
||||||
../../protocol/waku_swap/[waku_swap_types, waku_swap],
|
../../protocol/waku_swap/[waku_swap_types, waku_swap],
|
||||||
../../protocol/waku_filter/[waku_filter_types, waku_filter],
|
../../protocol/waku_filter/[waku_filter_types, waku_filter],
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
import
|
import
|
||||||
json_rpc/rpcserver,
|
json_rpc/rpcserver,
|
||||||
../../waku_types,
|
|
||||||
../wakunode2
|
../wakunode2
|
||||||
|
|
||||||
proc installDebugApiHandlers*(node: WakuNode, rpcsrv: RpcServer) =
|
proc installDebugApiHandlers*(node: WakuNode, rpcsrv: RpcServer) =
|
||||||
|
|||||||
@ -4,7 +4,6 @@ import
|
|||||||
std/[tables,sequtils],
|
std/[tables,sequtils],
|
||||||
json_rpc/rpcserver,
|
json_rpc/rpcserver,
|
||||||
eth/[common, rlp, keys, p2p],
|
eth/[common, rlp, keys, p2p],
|
||||||
../../waku_types,
|
|
||||||
../../protocol/waku_filter/waku_filter_types,
|
../../protocol/waku_filter/waku_filter_types,
|
||||||
../wakunode2,
|
../wakunode2,
|
||||||
./jsonrpc_types
|
./jsonrpc_types
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
import
|
import
|
||||||
|
std/[options,tables],
|
||||||
eth/keys,
|
eth/keys,
|
||||||
../../waku_types,
|
../../protocol/waku_message,
|
||||||
std/[options,tables]
|
../../utils/pagination
|
||||||
|
|
||||||
type
|
type
|
||||||
StoreResponse* = object
|
StoreResponse* = object
|
||||||
|
|||||||
@ -2,7 +2,6 @@ import
|
|||||||
std/options,
|
std/options,
|
||||||
eth/keys,
|
eth/keys,
|
||||||
../../../v1/node/rpc/hexstrings,
|
../../../v1/node/rpc/hexstrings,
|
||||||
../../waku_types,
|
|
||||||
../../protocol/waku_store/waku_store_types,
|
../../protocol/waku_store/waku_store_types,
|
||||||
../wakunode2, ../waku_payload,
|
../wakunode2, ../waku_payload,
|
||||||
./jsonrpc_types
|
./jsonrpc_types
|
||||||
|
|||||||
@ -5,7 +5,6 @@ import
|
|||||||
json_rpc/rpcserver,
|
json_rpc/rpcserver,
|
||||||
nimcrypto/sysrand,
|
nimcrypto/sysrand,
|
||||||
eth/[common, rlp, keys, p2p],
|
eth/[common, rlp, keys, p2p],
|
||||||
../../waku_types,
|
|
||||||
../wakunode2, ../waku_payload,
|
../wakunode2, ../waku_payload,
|
||||||
./jsonrpc_types, ./jsonrpc_utils
|
./jsonrpc_types, ./jsonrpc_utils
|
||||||
|
|
||||||
|
|||||||
@ -5,9 +5,9 @@ import
|
|||||||
json_rpc/rpcserver,
|
json_rpc/rpcserver,
|
||||||
libp2p/protocols/pubsub/pubsub,
|
libp2p/protocols/pubsub/pubsub,
|
||||||
eth/[common, rlp, keys, p2p],
|
eth/[common, rlp, keys, p2p],
|
||||||
../../waku_types,
|
|
||||||
../wakunode2,
|
../wakunode2,
|
||||||
./jsonrpc_types, ./jsonrpc_utils
|
./jsonrpc_types, ./jsonrpc_utils,
|
||||||
|
../../protocol/waku_message
|
||||||
|
|
||||||
export jsonrpc_types
|
export jsonrpc_types
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,6 @@
|
|||||||
import
|
import
|
||||||
std/options,
|
std/options,
|
||||||
json_rpc/rpcserver,
|
json_rpc/rpcserver,
|
||||||
../../waku_types,
|
|
||||||
../../protocol/waku_store/waku_store_types,
|
../../protocol/waku_store/waku_store_types,
|
||||||
../wakunode2,
|
../wakunode2,
|
||||||
./jsonrpc_types, ./jsonrpc_utils
|
./jsonrpc_types, ./jsonrpc_utils
|
||||||
|
|||||||
@ -6,8 +6,9 @@ import
|
|||||||
libp2p/protobuf/minprotobuf,
|
libp2p/protobuf/minprotobuf,
|
||||||
libp2p/stream/connection,
|
libp2p/stream/connection,
|
||||||
stew/results, metrics,
|
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.
|
# 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
|
# https://github.com/status-im/nim-eth/blob/master/eth/db/kvstore_sqlite3.nim
|
||||||
@ -17,6 +18,11 @@ import
|
|||||||
type
|
type
|
||||||
DataProc* = proc(timestamp: uint64, msg: WakuMessage) {.closure.}
|
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] =
|
proc init*(T: type MessageStore, db: SqliteDatabase): MessageStoreResult[T] =
|
||||||
## Table is the SQL query for creating the messages Table.
|
## Table is the SQL query for creating the messages Table.
|
||||||
## It contains:
|
## It contains:
|
||||||
|
|||||||
@ -4,8 +4,7 @@ import
|
|||||||
libp2p/protobuf/minprotobuf,
|
libp2p/protobuf/minprotobuf,
|
||||||
eth/common as eth_common, eth/keys,
|
eth/common as eth_common, eth/keys,
|
||||||
system,
|
system,
|
||||||
options,
|
options
|
||||||
../../waku_types
|
|
||||||
|
|
||||||
from strutils import rsplit
|
from strutils import rsplit
|
||||||
template sourceDir: string = currentSourcePath.rsplit(DirSep, 1)[0]
|
template sourceDir: string = currentSourcePath.rsplit(DirSep, 1)[0]
|
||||||
|
|||||||
@ -4,7 +4,6 @@ import
|
|||||||
nimcrypto/[sysrand, hmac, sha2],
|
nimcrypto/[sysrand, hmac, sha2],
|
||||||
eth/[common, rlp, keys, p2p],
|
eth/[common, rlp, keys, p2p],
|
||||||
../../protocol/waku_relay,
|
../../protocol/waku_relay,
|
||||||
../../waku_types,
|
|
||||||
../../protocol/waku_store/waku_store,
|
../../protocol/waku_store/waku_store,
|
||||||
../../protocol/waku_filter/waku_filter,
|
../../protocol/waku_filter/waku_filter,
|
||||||
../wakunode2
|
../wakunode2
|
||||||
|
|||||||
@ -2,9 +2,9 @@ import
|
|||||||
std/options,
|
std/options,
|
||||||
eth/keys,
|
eth/keys,
|
||||||
eth/p2p/rlpx_protocols/whisper/whisper_types,
|
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
|
type
|
||||||
KeyKind* = enum
|
KeyKind* = enum
|
||||||
@ -21,6 +21,10 @@ type
|
|||||||
of None:
|
of None:
|
||||||
discard
|
discard
|
||||||
|
|
||||||
|
# NOTE: Currently only used here, if we start using it elsewhere pull it out.
|
||||||
|
WakuResult*[T] = Result[T, cstring]
|
||||||
|
|
||||||
|
|
||||||
# TODO:
|
# TODO:
|
||||||
# - This is using `DecodedPayload` from Waku v1 / Whisper and could be altered
|
# - 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
|
# by making that a case object also, e.g. useful for the version 0, but
|
||||||
|
|||||||
@ -14,11 +14,9 @@ import
|
|||||||
../protocol/waku_store/waku_store,
|
../protocol/waku_store/waku_store,
|
||||||
../protocol/waku_swap/waku_swap,
|
../protocol/waku_swap/waku_swap,
|
||||||
../protocol/waku_filter/waku_filter,
|
../protocol/waku_filter/waku_filter,
|
||||||
../waku_types,
|
|
||||||
./message_store,
|
./message_store,
|
||||||
./sqlite
|
./sqlite,
|
||||||
|
../utils/requests
|
||||||
export waku_types
|
|
||||||
|
|
||||||
logScope:
|
logScope:
|
||||||
topics = "wakunode"
|
topics = "wakunode"
|
||||||
@ -32,10 +30,15 @@ type
|
|||||||
PublicKey* = crypto.PublicKey
|
PublicKey* = crypto.PublicKey
|
||||||
PrivateKey* = crypto.PrivateKey
|
PrivateKey* = crypto.PrivateKey
|
||||||
|
|
||||||
# TODO Get rid of this and use waku_types one
|
# XXX: Weird type, should probably be using pubsub Topic object name?
|
||||||
Topic* = waku_types.Topic
|
Topic* = string
|
||||||
Message* = seq[byte]
|
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
|
# NOTE based on Eth2Node in NBC eth2_network.nim
|
||||||
WakuNode* = ref object of RootObj
|
WakuNode* = ref object of RootObj
|
||||||
switch*: Switch
|
switch*: Switch
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import
|
import
|
||||||
std/tables,
|
std/tables,
|
||||||
chronos,
|
chronos,
|
||||||
../waku_types
|
waku_message
|
||||||
|
|
||||||
## The Message Notification system is a method to notify various protocols
|
## The Message Notification system is a method to notify various protocols
|
||||||
## running on a node when a new message was received.
|
## running on a node when a new message was received.
|
||||||
@ -23,6 +23,19 @@ import
|
|||||||
## subscriptions["identifier"] = subscription
|
## subscriptions["identifier"] = subscription
|
||||||
##
|
##
|
||||||
## await subscriptions.notify(topic, WakuMessage(payload: @[byte 1, 2, 3], contentTopic: ContentTopic(1)))
|
## 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) =
|
proc subscribe*(subscriptions: MessageNotificationSubscriptions, name: string, subscription: MessageNotificationSubscription) =
|
||||||
subscriptions.add(name, subscription)
|
subscriptions.add(name, subscription)
|
||||||
|
|
||||||
|
|||||||
@ -11,8 +11,8 @@ import
|
|||||||
libp2p/crypto/crypto,
|
libp2p/crypto/crypto,
|
||||||
libp2p/switch,
|
libp2p/switch,
|
||||||
../message_notifier,
|
../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
|
# 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
|
# should be direct payload exchange (a la req-resp), not be coupled with the
|
||||||
|
|||||||
@ -3,7 +3,9 @@ import
|
|||||||
bearssl,
|
bearssl,
|
||||||
libp2p/[switch, peerinfo],
|
libp2p/[switch, peerinfo],
|
||||||
libp2p/protocols/protocol,
|
libp2p/protocols/protocol,
|
||||||
../../waku_types
|
../waku_message
|
||||||
|
|
||||||
|
export waku_message
|
||||||
|
|
||||||
type
|
type
|
||||||
ContentFilter* = object
|
ContentFilter* = object
|
||||||
|
|||||||
36
waku/v2/protocol/waku_message.nim
Normal file
36
waku/v2/protocol/waku_message.nim
Normal file
@ -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)
|
||||||
@ -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.
|
## See https://github.com/vacp2p/specs/blob/master/specs/waku/v2/waku-relay.md
|
||||||
## Instead, it should likely be on top of GossipSub with a similar interface.
|
## for spec.
|
||||||
|
|
||||||
import
|
import
|
||||||
chronos, chronicles, metrics,
|
chronos, chronicles, metrics,
|
||||||
libp2p/protocols/pubsub/[pubsub, gossipsub],
|
libp2p/protocols/pubsub/[pubsub, gossipsub],
|
||||||
libp2p/protocols/pubsub/rpc/messages,
|
libp2p/protocols/pubsub/rpc/messages,
|
||||||
libp2p/stream/connection,
|
libp2p/stream/connection
|
||||||
../waku_types
|
|
||||||
|
|
||||||
declarePublicGauge total_messages, "number of messages received"
|
declarePublicGauge total_messages, "number of messages received"
|
||||||
|
|
||||||
@ -17,6 +16,9 @@ logScope:
|
|||||||
|
|
||||||
const WakuRelayCodec* = "/vac/waku/relay/2.0.0-beta2"
|
const WakuRelayCodec* = "/vac/waku/relay/2.0.0-beta2"
|
||||||
|
|
||||||
|
type
|
||||||
|
WakuRelay* = ref object of GossipSub
|
||||||
|
|
||||||
method init*(w: WakuRelay) =
|
method init*(w: WakuRelay) =
|
||||||
debug "init"
|
debug "init"
|
||||||
proc handler(conn: Connection, proto: string) {.async.} =
|
proc handler(conn: Connection, proto: string) {.async.} =
|
||||||
|
|||||||
@ -14,8 +14,8 @@ import
|
|||||||
../message_notifier,
|
../message_notifier,
|
||||||
../../node/message_store,
|
../../node/message_store,
|
||||||
../waku_swap/waku_swap,
|
../waku_swap/waku_swap,
|
||||||
../../waku_types,
|
./waku_store_types,
|
||||||
./waku_store_types
|
../../utils/requests
|
||||||
|
|
||||||
export waku_store_types
|
export waku_store_types
|
||||||
|
|
||||||
|
|||||||
@ -4,10 +4,19 @@ import
|
|||||||
bearssl,
|
bearssl,
|
||||||
libp2p/[switch, peerinfo],
|
libp2p/[switch, peerinfo],
|
||||||
libp2p/protocols/protocol,
|
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
|
type
|
||||||
|
|
||||||
QueryHandlerFunc* = proc(response: HistoryResponse) {.gcsafe, closure.}
|
QueryHandlerFunc* = proc(response: HistoryResponse) {.gcsafe, closure.}
|
||||||
|
|
||||||
IndexedWakuMessage* = object
|
IndexedWakuMessage* = object
|
||||||
|
|||||||
4
waku/v2/utils/README.md
Normal file
4
waku/v2/utils/README.md
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# Utils
|
||||||
|
|
||||||
|
Collection of misc utilities that don't fit anywhere else, and are used by
|
||||||
|
multiple independent modules.
|
||||||
11
waku/v2/utils/pagination.nim
Normal file
11
waku/v2/utils/pagination.nim
Normal file
@ -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
|
||||||
8
waku/v2/utils/requests.nim
Normal file
8
waku/v2/utils/requests.nim
Normal file
@ -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)
|
||||||
@ -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)
|
|
||||||
@ -5,7 +5,6 @@
|
|||||||
# - APACHEv2 ([LICENSE-APACHEv2](../LICENSE-APACHEv2) or https://www.apache.org/licenses/LICENSE-2.0)
|
# - 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.
|
## 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 wakunode2
|
||||||
export wakunode1
|
export wakunode1
|
||||||
export waku_types
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user