Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: store v3 proto field numbers #2632

Merged
merged 1 commit into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions waku/node/waku_node.nim
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,7 @@ proc toStoreResult(res: ArchiveResult): StoreQueryResult =
var res = StoreQueryResponse()

res.statusCode = 200
res.statusDesc = "OK"
res.messages = response.hashes.zip(response.messages).mapIt(
WakuMessageKeyValue(messageHash: it[0], message: it[1])
)
Expand Down
1 change: 1 addition & 0 deletions waku/waku_store/protocol.nim
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ proc handleQueryRequest*(

res.requestId = requestId
res.statusCode = 200
res.statusDesc = "OK"

info "sending store query response",
peerId = requestor, requestId = requestId, messages = res.messages.len
Expand Down
48 changes: 24 additions & 24 deletions waku/waku_store/rpc_codec.nim
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,32 @@ proc encode*(req: StoreQueryRequest): ProtoBuffer =
pb.write3(1, req.requestId)
pb.write3(2, req.includeData)

pb.write3(3, req.pubsubTopic)
pb.write3(10, req.pubsubTopic)

for contentTopic in req.contentTopics:
pb.write3(4, contentTopic)
pb.write3(11, contentTopic)

pb.write3(
5,
12,
req.startTime.map(
proc(time: int64): zint64 =
zint64(time)
),
)
pb.write3(
6,
13,
req.endTime.map(
proc(time: int64): zint64 =
zint64(time)
),
)

for hash in req.messagehashes:
pb.write3(7, hash)
pb.write3(20, hash)

pb.write3(8, req.paginationCursor)
pb.write3(9, uint32(req.paginationForward))
pb.write3(10, req.paginationLimit)
pb.write3(51, req.paginationCursor)
pb.write3(52, uint32(req.paginationForward))
pb.write3(53, req.paginationLimit)

pb.finish3()

Expand All @@ -63,31 +63,31 @@ proc decode*(
req.includeData = inclData == 1

var pubsubTopic: string
if not ?pb.getField(3, pubsubTopic):
if not ?pb.getField(10, pubsubTopic):
req.pubsubTopic = none(string)
else:
req.pubsubTopic = some(pubsubTopic)

var topics: seq[string]
if not ?pb.getRepeatedField(4, topics):
if not ?pb.getRepeatedField(11, topics):
req.contentTopics = @[]
else:
req.contentTopics = topics

var start: zint64
if not ?pb.getField(5, start):
if not ?pb.getField(12, start):
req.startTime = none(Timestamp)
else:
req.startTime = some(Timestamp(int64(start)))

var endTime: zint64
if not ?pb.getField(6, endTime):
if not ?pb.getField(13, endTime):
req.endTime = none(Timestamp)
else:
req.endTime = some(Timestamp(int64(endTime)))

var buffer: seq[seq[byte]]
if not ?pb.getRepeatedField(7, buffer):
if not ?pb.getRepeatedField(20, buffer):
req.messageHashes = @[]
else:
req.messageHashes = newSeqOfCap[WakuMessageHash](buffer.len)
Expand All @@ -97,21 +97,21 @@ proc decode*(
req.messageHashes.add(hash)

var cursor: seq[byte]
if not ?pb.getField(8, cursor):
if not ?pb.getField(51, cursor):
req.paginationCursor = none(WakuMessageHash)
else:
var hash: WakuMessageHash
discard copyFrom[byte](hash, cursor)
req.paginationCursor = some(hash)

var paging: uint32
if not ?pb.getField(9, paging):
if not ?pb.getField(52, paging):
req.paginationForward = PagingDirection.default()
else:
req.paginationForward = PagingDirection(paging)

var limit: uint64
if not ?pb.getField(10, limit):
if not ?pb.getField(53, limit):
req.paginationLimit = none(uint64)
else:
req.paginationLimit = some(limit)
Expand All @@ -135,13 +135,13 @@ proc encode*(res: StoreQueryResponse): ProtoBuffer =

pb.write3(1, res.requestId)

pb.write3(2, res.statusCode)
pb.write3(3, res.statusDesc)
pb.write3(10, res.statusCode)
pb.write3(11, res.statusDesc)

for msg in res.messages:
pb.write3(4, msg.encode())
pb.write3(20, msg.encode())

pb.write3(5, res.paginationCursor)
pb.write3(51, res.paginationCursor)

pb.finish3()

Expand Down Expand Up @@ -179,19 +179,19 @@ proc decode*(
return err(ProtobufError.missingRequiredField("request_id"))

var code: uint32
if not ?pb.getField(2, code):
if not ?pb.getField(10, code):
return err(ProtobufError.missingRequiredField("status_code"))
else:
res.statusCode = code

var desc: string
if not ?pb.getField(3, desc):
if not ?pb.getField(11, desc):
return err(ProtobufError.missingRequiredField("status_desc"))
else:
res.statusDesc = desc

var buffer: seq[seq[byte]]
if not ?pb.getRepeatedField(4, buffer):
if not ?pb.getRepeatedField(20, buffer):
res.messages = @[]
else:
res.messages = newSeqOfCap[WakuMessageKeyValue](buffer.len)
Expand All @@ -200,7 +200,7 @@ proc decode*(
res.messages.add(msg)

var cursor: seq[byte]
if not ?pb.getField(5, cursor):
if not ?pb.getField(51, cursor):
res.paginationCursor = none(WakuMessageHash)
else:
var hash: WakuMessageHash
Expand Down
Loading