p2pRequestComplete parameters are not a separate list

This commit is contained in:
kdeme 2019-12-19 23:23:06 +01:00
parent 48c9adbb6a
commit 4dde3af2d5
No known key found for this signature in database
GPG Key ID: 4E8DD21420AF43F5
3 changed files with 26 additions and 27 deletions

View File

@ -64,12 +64,12 @@ proc requestMail*(node: EthereumNode, peerId: NodeId, request: MailRequest,
# TODO: I guess the idea is to check requestId (Hash) also? # TODO: I guess the idea is to check requestId (Hash) also?
let requests = requests - 1 let requests = requests - 1
# If there is cursor data, do another request # If there is cursor data, do another request
if response.data.cursor.len > 0 and requests > 0: if response.cursor.len > 0 and requests > 0:
var newRequest = request var newRequest = request
newRequest.cursor = response.data.cursor newRequest.cursor = response.cursor
return await requestMail(node, peerId, newRequest, symKey, requests) return await requestMail(node, peerId, newRequest, symKey, requests)
else: else:
return some(response.data.cursor) return some(response.cursor)
else: else:
error "p2pRequestComplete timeout" error "p2pRequestComplete timeout"
return result return result

View File

@ -114,17 +114,6 @@ type
config*: WakuConfig config*: WakuConfig
p2pRequestHandler*: P2PRequestHandler p2pRequestHandler*: P2PRequestHandler
# TODO: In the current specification this is not wrapped in a regular envelope
# as is done for the P2P Request packet. If we could alter this in the spec it
# would be a cleaner separation between Waku and Mail server / client and then
# this could be moved to waku_mail.nim
# Also, the requestId could live at layer lower. And the protocol DSL
# currently supports this, if used in a requestResponse block.
P2PRequestCompleteObject* = object
requestId*: Hash
lastEnvelopeHash*: Hash
cursor*: Bytes
RateLimits* = object RateLimits* = object
# TODO: uint or specifically uint32? # TODO: uint or specifically uint32?
limitIp*: uint limitIp*: uint
@ -352,13 +341,21 @@ p2pProtocol Waku(version = wakuVersion,
proc p2pSyncRequest(peer: Peer) = discard proc p2pSyncRequest(peer: Peer) = discard
proc p2pSyncResponse(peer: Peer) = discard proc p2pSyncResponse(peer: Peer) = discard
proc p2pRequestComplete(peer: Peer, data: P2PRequestCompleteObject) = discard
# TODO: This is actually rather a requestResponse in combination with proc p2pRequestComplete(peer: Peer, requestId: Hash, lastEnvelopeHash: Hash,
# p2pRequest. However, we can't use that system due to the unfortunate fact cursor: Bytes) = discard
# that the packet IDs are not consecutive, and nextID is not recognized in # TODO:
# between these. The nextID behaviour could be fixed, however it would be # In the current specification the parameters are not wrapped in a regular
# cleaner if the specification could be changed to have these IDs to be # envelope as is done for the P2P Request packet. If we could alter this in
# consecutive. # the spec it would be a cleaner separation between Waku and Mail server /
# client.
# Also, if a requestResponse block is used, a reqestId will automatically
# be added by the protocol DSL.
# However the requestResponse block in combination with p2pRequest cannot be
# used due to the unfortunate fact that the packet IDs are not consecutive,
# and nextID is not recognized in between these. The nextID behaviour could
# be fixed, however it would be cleaner if the specification could be
# changed to have these IDs to be consecutive.
# 'Runner' calls --------------------------------------------------------------- # 'Runner' calls ---------------------------------------------------------------

View File

@ -58,8 +58,8 @@ suite "Waku Mail Client":
output.bloom == bloom output.bloom == bloom
output.limit == limit output.limit == limit
var test: P2PRequestCompleteObject var dummy: Hash
await peer.p2pRequestComplete(test) await peer.p2pRequestComplete(dummy, dummy, @[])
check await cursorFut.withTimeout(transmissionTimeout) check await cursorFut.withTimeout(transmissionTimeout)
@ -93,13 +93,15 @@ suite "Waku Mail Client":
var envelopes: seq[Envelope] var envelopes: seq[Envelope]
traceAsyncErrors peer.p2pMessage(envelopes) traceAsyncErrors peer.p2pMessage(envelopes)
var test: P2PRequestCompleteObject var cursor: Bytes
count = count - 1 count = count - 1
if count == 0: if count == 0:
test.cursor = @[] cursor = @[]
else: else:
test.cursor = @[byte count] cursor = @[byte count]
traceAsyncErrors peer.p2pRequestComplete(test)
var dummy: Hash
traceAsyncErrors peer.p2pRequestComplete(dummy, dummy, cursor)
simpleServer.enableMailServer(customHandler) simpleServer.enableMailServer(customHandler)
check client.setPeerTrusted(simpleServerNode.id) check client.setPeerTrusted(simpleServerNode.id)