2024-01-31 16:43:59 +00:00
|
|
|
##
|
|
|
|
## This file is aimed to attend the requests that come directly
|
|
|
|
## from the 'self' node. It is expected to attend the store requests that
|
|
|
|
## come from REST-store endpoint when those requests don't indicate
|
|
|
|
## any store-peer address.
|
|
|
|
##
|
|
|
|
## Notice that the REST-store requests normally assume that the REST
|
|
|
|
## server is acting as a store-client. In this module, we allow that
|
|
|
|
## such REST-store node can act as store-server as well by retrieving
|
|
|
|
## its own stored messages. The typical use case for that is when
|
|
|
|
## using `nwaku-compose`, which spawn a Waku node connected to a local
|
|
|
|
## database, and the user is interested in retrieving the messages
|
|
|
|
## stored by that local store node.
|
|
|
|
##
|
|
|
|
|
2024-07-09 11:14:28 +00:00
|
|
|
import results, chronos
|
2024-03-15 23:08:47 +00:00
|
|
|
import ./protocol, ./common
|
2024-01-31 16:43:59 +00:00
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
proc handleSelfStoreRequest*(
|
2024-04-25 13:09:52 +00:00
|
|
|
self: WakuStore, req: StoreQueryRequest
|
|
|
|
): Future[WakuStoreResult[StoreQueryResponse]] {.async.} =
|
2024-01-31 16:43:59 +00:00
|
|
|
## Handles the store requests made by the node to itself.
|
|
|
|
## Normally used in REST-store requests
|
|
|
|
|
2024-04-25 13:09:52 +00:00
|
|
|
let handlerResult = catch:
|
|
|
|
await self.requestHandler(req)
|
2024-01-31 16:43:59 +00:00
|
|
|
|
2024-04-25 13:09:52 +00:00
|
|
|
let resResult =
|
|
|
|
if handlerResult.isErr():
|
|
|
|
return err("exception in handleSelfStoreRequest: " & handlerResult.error.msg)
|
|
|
|
else:
|
|
|
|
handlerResult.get()
|
|
|
|
|
|
|
|
let res = resResult.valueOr:
|
|
|
|
return err("error in handleSelfStoreRequest: " & $error)
|
|
|
|
|
|
|
|
return ok(res)
|