mirror of
https://github.com/waku-org/nwaku.git
synced 2025-02-12 15:06:38 +00:00
deploy: e8dd0140795df49deb4aee767a4bc1da6b727dc6
This commit is contained in:
parent
b93bc084c0
commit
2e84315f87
@ -2,16 +2,15 @@
|
||||
import
|
||||
std/[unittest, options, tables, sets],
|
||||
chronos, chronicles,
|
||||
../../waku/v2/node/message_store,
|
||||
../../waku/v2/node/message_store/waku_message_store,
|
||||
../../waku/v2/protocol/waku_store/waku_store,
|
||||
./utils,
|
||||
../../waku/v2/node/sqlite
|
||||
./utils
|
||||
|
||||
suite "Message Store":
|
||||
test "set and get works":
|
||||
let
|
||||
database = SqliteDatabase.init("", inMemory = true)[]
|
||||
store = MessageStore.init(database)[]
|
||||
store = WakuMessageStore.init(database)[]
|
||||
topic = ContentTopic(1)
|
||||
|
||||
var msgs = @[
|
||||
|
@ -10,7 +10,7 @@ import
|
||||
libp2p/protocols/pubsub/rpc/message,
|
||||
../../waku/v2/protocol/[waku_message, message_notifier],
|
||||
../../waku/v2/protocol/waku_store/waku_store,
|
||||
../../waku/v2/node/[message_store, sqlite],
|
||||
../../waku/v2/node/message_store/waku_message_store,
|
||||
../test_helpers, ./utils
|
||||
|
||||
procSuite "Waku Store":
|
||||
@ -62,7 +62,7 @@ procSuite "Waku Store":
|
||||
peer = PeerInfo.init(key)
|
||||
topic = ContentTopic(1)
|
||||
database = SqliteDatabase.init("", inMemory = true)[]
|
||||
store = MessageStore.init(database)[]
|
||||
store = WakuMessageStore.init(database)[]
|
||||
msg = WakuMessage(payload: @[byte 1, 2, 3], contentTopic: topic)
|
||||
msg2 = WakuMessage(payload: @[byte 1, 2, 3], contentTopic: ContentTopic(2))
|
||||
|
||||
|
@ -10,11 +10,11 @@ generated by GNU Autoconf 2.69. Invocation command line was
|
||||
## Platform. ##
|
||||
## --------- ##
|
||||
|
||||
hostname = fv-az56-274
|
||||
hostname = fv-az16-906
|
||||
uname -m = x86_64
|
||||
uname -r = 5.4.0-1036-azure
|
||||
uname -r = 5.4.0-1032-azure
|
||||
uname -s = Linux
|
||||
uname -v = #38~18.04.1-Ubuntu SMP Wed Jan 6 18:26:30 UTC 2021
|
||||
uname -v = #33~18.04.1-Ubuntu SMP Tue Nov 17 11:40:52 UTC 2020
|
||||
|
||||
/usr/bin/uname -p = unknown
|
||||
/bin/uname -X = unknown
|
||||
@ -841,7 +841,7 @@ configure:12482: $? = 0
|
||||
configure:12482: result: yes
|
||||
configure:12499: checking for getexecname
|
||||
configure:12499: gcc -o conftest -g -O3 -std=gnu11 -pipe -Wall -Wextra -fPIC conftest.c >&5
|
||||
/tmp/cc5d7aku.o: In function `main':
|
||||
/tmp/ccVHmrIL.o: In function `main':
|
||||
/home/runner/work/nim-waku/nim-waku/vendor/nim-libbacktrace/vendor/libbacktrace-upstream/conftest.c:73: undefined reference to `getexecname'
|
||||
collect2: error: ld returned 1 exit status
|
||||
configure:12499: $? = 1
|
||||
@ -1134,7 +1134,7 @@ generated by GNU Autoconf 2.69. Invocation command line was
|
||||
CONFIG_COMMANDS =
|
||||
$ ./config.status
|
||||
|
||||
on fv-az56-274
|
||||
on fv-az16-906
|
||||
|
||||
config.status:1150: creating Makefile
|
||||
config.status:1150: creating backtrace-supported.h
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
# libtool - Provide generalized library-building support services.
|
||||
# Generated automatically by config.status (libbacktrace) version-unused
|
||||
# Libtool was configured on host fv-az56-274:
|
||||
# Libtool was configured on host fv-az16-906:
|
||||
# NOTE: Changes made to this file will be lost: look at ltmain.sh.
|
||||
#
|
||||
# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005,
|
||||
|
@ -3,7 +3,7 @@ import
|
||||
eth/keys,
|
||||
../../../v1/node/rpc/hexstrings,
|
||||
../../protocol/waku_store/waku_store_types,
|
||||
../wakunode2, ../waku_payload,
|
||||
../waku_payload,
|
||||
./jsonrpc_types
|
||||
|
||||
export hexstrings
|
||||
|
19
waku/v2/node/message_store/message_store.nim
Normal file
19
waku/v2/node/message_store/message_store.nim
Normal file
@ -0,0 +1,19 @@
|
||||
import
|
||||
stew/results,
|
||||
../../protocol/waku_message,
|
||||
../../utils/pagination
|
||||
|
||||
## This module defines a message store interface. Implementations of
|
||||
## MessageStore are used by the `WakuStore` protocol to store and re-
|
||||
## trieve historical messages
|
||||
|
||||
type
|
||||
DataProc* = proc(timestamp: uint64, msg: WakuMessage) {.closure.}
|
||||
|
||||
MessageStoreResult*[T] = Result[T, string]
|
||||
|
||||
MessageStore* = ref object of RootObj
|
||||
|
||||
# MessageStore interface
|
||||
method put*(db: MessageStore, cursor: Index, message: WakuMessage): MessageStoreResult[void] {.base.} = discard
|
||||
method getAll*(db: MessageStore, onData: DataProc): MessageStoreResult[bool] {.base.} = discard
|
@ -1,14 +1,17 @@
|
||||
import
|
||||
sqlite3_abi,
|
||||
chronos, metrics, stew/results,
|
||||
chronos, metrics,
|
||||
libp2p/crypto/crypto,
|
||||
libp2p/protocols/protocol,
|
||||
libp2p/protobuf/minprotobuf,
|
||||
libp2p/stream/connection,
|
||||
stew/results, metrics,
|
||||
./sqlite,
|
||||
../protocol/waku_message,
|
||||
../utils/pagination
|
||||
./message_store,
|
||||
../../protocol/waku_message,
|
||||
../../utils/pagination
|
||||
|
||||
export sqlite
|
||||
|
||||
# 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
|
||||
@ -16,14 +19,10 @@ import
|
||||
# Most of it is a direct copy, the only unique functions being `get` and `put`.
|
||||
|
||||
type
|
||||
DataProc* = proc(timestamp: uint64, msg: WakuMessage) {.closure.}
|
||||
|
||||
MessageStoreResult*[T] = Result[T, string]
|
||||
|
||||
MessageStore* = ref object of RootObj
|
||||
WakuMessageStore* = ref object of MessageStore
|
||||
database*: SqliteDatabase
|
||||
|
||||
proc init*(T: type MessageStore, db: SqliteDatabase): MessageStoreResult[T] =
|
||||
proc init*(T: type WakuMessageStore, db: SqliteDatabase): MessageStoreResult[T] =
|
||||
## Table is the SQL query for creating the messages Table.
|
||||
## It contains:
|
||||
## - 4-Byte ContentTopic stored as an Integer
|
||||
@ -44,9 +43,9 @@ proc init*(T: type MessageStore, db: SqliteDatabase): MessageStoreResult[T] =
|
||||
if res.isErr:
|
||||
return err("failed to exec")
|
||||
|
||||
ok(MessageStore(database: db))
|
||||
ok(WakuMessageStore(database: db))
|
||||
|
||||
proc put*(db: MessageStore, cursor: Index, message: WakuMessage): MessageStoreResult[void] =
|
||||
method put*(db: WakuMessageStore, cursor: Index, message: WakuMessage): MessageStoreResult[void] =
|
||||
## Adds a message to the storage.
|
||||
##
|
||||
## **Example:**
|
||||
@ -71,7 +70,7 @@ proc put*(db: MessageStore, cursor: Index, message: WakuMessage): MessageStoreRe
|
||||
|
||||
ok()
|
||||
|
||||
proc getAll*(db: MessageStore, onData: DataProc): MessageStoreResult[bool] =
|
||||
method getAll*(db: WakuMessageStore, onData: message_store.DataProc): MessageStoreResult[bool] =
|
||||
## Retreives all messages from the storage.
|
||||
##
|
||||
## **Example:**
|
||||
@ -100,6 +99,6 @@ proc getAll*(db: MessageStore, onData: DataProc): MessageStoreResult[bool] =
|
||||
|
||||
ok gotMessages
|
||||
|
||||
proc close*(db: MessageStore) =
|
||||
proc close*(db: WakuMessageStore) =
|
||||
## Closes the database.
|
||||
db.database.close()
|
@ -14,8 +14,7 @@ import
|
||||
../protocol/waku_store/waku_store,
|
||||
../protocol/waku_swap/waku_swap,
|
||||
../protocol/waku_filter/waku_filter,
|
||||
./message_store,
|
||||
./sqlite,
|
||||
./message_store/message_store,
|
||||
../utils/requests
|
||||
|
||||
logScope:
|
||||
@ -406,6 +405,7 @@ when isMainModule:
|
||||
private_api,
|
||||
relay_api,
|
||||
store_api],
|
||||
./message_store/waku_message_store,
|
||||
../../common/utils/nat
|
||||
|
||||
proc startRpc(node: WakuNode, rpcIp: ValidIpAddress, rpcPort: Port, conf: WakuNodeConf) =
|
||||
@ -473,16 +473,16 @@ when isMainModule:
|
||||
# TODO Set swap peer, for now should be same as store peer
|
||||
|
||||
if conf.store:
|
||||
var store: MessageStore
|
||||
var store: WakuMessageStore
|
||||
|
||||
if conf.dbpath != "":
|
||||
let dbRes = SqliteDatabase.init(conf.dbpath)
|
||||
if dbRes.isErr:
|
||||
warn "failed to init database", err = dbRes.error
|
||||
|
||||
let res = MessageStore.init(dbRes.value)
|
||||
let res = WakuMessageStore.init(dbRes.value)
|
||||
if res.isErr:
|
||||
warn "failed to init MessageStore", err = res.error
|
||||
warn "failed to init WakuMessageStore", err = res.error
|
||||
else:
|
||||
store = res.value
|
||||
|
||||
|
@ -12,7 +12,7 @@ import
|
||||
libp2p/protobuf/minprotobuf,
|
||||
libp2p/stream/connection,
|
||||
../message_notifier,
|
||||
../../node/message_store,
|
||||
../../node/message_store/message_store,
|
||||
../waku_swap/waku_swap,
|
||||
./waku_store_types,
|
||||
../../utils/requests
|
||||
|
@ -6,7 +6,7 @@ import
|
||||
libp2p/protocols/protocol,
|
||||
../waku_swap/waku_swap_types,
|
||||
../waku_message,
|
||||
../../node/message_store,
|
||||
../../node/message_store/message_store,
|
||||
../../utils/pagination
|
||||
|
||||
export waku_message
|
||||
|
Loading…
x
Reference in New Issue
Block a user