mirror of https://github.com/waku-org/nwaku.git
enhancement/request-id-to-uuid (#113)
This commit is contained in:
parent
705b4b32a1
commit
1924bcc96c
|
@ -22,7 +22,7 @@ procSuite "Waku Store":
|
||||||
peer = PeerInfo.init(PrivateKey.random(ECDSA, rng[]).get())
|
peer = PeerInfo.init(PrivateKey.random(ECDSA, rng[]).get())
|
||||||
msg = Message.init(peer, @[byte 1, 2, 3], "topic", 3, false)
|
msg = Message.init(peer, @[byte 1, 2, 3], "topic", 3, false)
|
||||||
|
|
||||||
rpc = StoreRPC(query: @[HistoryQuery(requestID: 1, topics: @["foo"])], response: @[HistoryResponse(requestID: 1, messages: @[msg])])
|
rpc = StoreRPC(query: @[HistoryQuery(uuid: "1", topics: @["foo"])], response: @[HistoryResponse(uuid: "1", messages: @[msg])])
|
||||||
|
|
||||||
let buf = rpc.encode()
|
let buf = rpc.encode()
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ procSuite "Waku Store":
|
||||||
let transport2: TcpTransport = TcpTransport.init()
|
let transport2: TcpTransport = TcpTransport.init()
|
||||||
let conn = await transport2.dial(transport1.ma)
|
let conn = await transport2.dial(transport1.ma)
|
||||||
|
|
||||||
var rpc = StoreRPC(query: @[HistoryQuery(requestID: 1, topics: @["topic"])])
|
var rpc = StoreRPC(query: @[HistoryQuery(uuid: "1234", topics: @["topic"])])
|
||||||
discard await msDial.select(conn, WakuStoreCodec)
|
discard await msDial.select(conn, WakuStoreCodec)
|
||||||
await conn.writeLP(rpc.encode().buffer)
|
await conn.writeLP(rpc.encode().buffer)
|
||||||
|
|
||||||
|
@ -79,6 +79,6 @@ procSuite "Waku Store":
|
||||||
|
|
||||||
check:
|
check:
|
||||||
response.isErr == false
|
response.isErr == false
|
||||||
response.value.response[0].requestID == rpc.query[0].requestID
|
response.value.response[0].uuid == rpc.query[0].uuid
|
||||||
response.value.response[0].messages.len() == 1
|
response.value.response[0].messages.len() == 1
|
||||||
response.value.response[0].messages[0] == msg
|
response.value.response[0].messages[0] == msg
|
||||||
|
|
|
@ -23,11 +23,11 @@ type
|
||||||
response*: seq[HistoryResponse]
|
response*: seq[HistoryResponse]
|
||||||
|
|
||||||
HistoryQuery* = object
|
HistoryQuery* = object
|
||||||
requestID*: uint64
|
uuid*: string
|
||||||
topics*: seq[string]
|
topics*: seq[string]
|
||||||
|
|
||||||
HistoryResponse* = object
|
HistoryResponse* = object
|
||||||
requestID*: uint64
|
uuid*: string
|
||||||
messages*: seq[Message]
|
messages*: seq[Message]
|
||||||
|
|
||||||
WakuStore* = ref object of LPProtocol
|
WakuStore* = ref object of LPProtocol
|
||||||
|
@ -39,7 +39,7 @@ method init*(T: type HistoryQuery, buffer: seq[byte]): ProtoResult[T] =
|
||||||
|
|
||||||
var topics: seq[string]
|
var topics: seq[string]
|
||||||
|
|
||||||
discard ? pb.getField(1, msg.requestID)
|
discard ? pb.getField(1, msg.uuid)
|
||||||
discard ? pb.getRepeatedField(2, topics)
|
discard ? pb.getRepeatedField(2, topics)
|
||||||
|
|
||||||
msg.topics = topics
|
msg.topics = topics
|
||||||
|
@ -51,7 +51,7 @@ proc init*(T: type HistoryResponse, buffer: seq[byte]): ProtoResult[T] =
|
||||||
|
|
||||||
var messages: seq[seq[byte]]
|
var messages: seq[seq[byte]]
|
||||||
|
|
||||||
discard ? pb.getField(1, msg.requestID)
|
discard ? pb.getField(1, msg.uuid)
|
||||||
discard ? pb.getRepeatedField(2, messages)
|
discard ? pb.getRepeatedField(2, messages)
|
||||||
|
|
||||||
for buf in messages:
|
for buf in messages:
|
||||||
|
@ -80,7 +80,7 @@ proc init*(T: type StoreRPC, buffer: seq[byte]): ProtoResult[T] =
|
||||||
method encode*(query: HistoryQuery): ProtoBuffer =
|
method encode*(query: HistoryQuery): ProtoBuffer =
|
||||||
result = initProtoBuffer()
|
result = initProtoBuffer()
|
||||||
|
|
||||||
result.write(1, query.requestID)
|
result.write(1, query.uuid)
|
||||||
|
|
||||||
for topic in query.topics:
|
for topic in query.topics:
|
||||||
result.write(2, topic)
|
result.write(2, topic)
|
||||||
|
@ -88,7 +88,7 @@ method encode*(query: HistoryQuery): ProtoBuffer =
|
||||||
method encode*(response: HistoryResponse): ProtoBuffer =
|
method encode*(response: HistoryResponse): ProtoBuffer =
|
||||||
result = initProtoBuffer()
|
result = initProtoBuffer()
|
||||||
|
|
||||||
result.write(1, response.requestID)
|
result.write(1, response.uuid)
|
||||||
|
|
||||||
for msg in response.messages:
|
for msg in response.messages:
|
||||||
result.write(2, msg.encodeMessage())
|
result.write(2, msg.encodeMessage())
|
||||||
|
@ -103,7 +103,7 @@ method encode*(response: StoreRPC): ProtoBuffer =
|
||||||
result.write(2, response.encode().buffer)
|
result.write(2, response.encode().buffer)
|
||||||
|
|
||||||
proc query(w: WakuStore, query: HistoryQuery): HistoryResponse =
|
proc query(w: WakuStore, query: HistoryQuery): HistoryResponse =
|
||||||
result = HistoryResponse(requestID: query.requestID, messages: newSeq[Message]())
|
result = HistoryResponse(uuid: query.uuid, messages: newSeq[Message]())
|
||||||
for msg in w.messages:
|
for msg in w.messages:
|
||||||
for topic in query.topics:
|
for topic in query.topics:
|
||||||
if topic in msg.topicIDs:
|
if topic in msg.topicIDs:
|
||||||
|
|
Loading…
Reference in New Issue