mirror of
https://github.com/waku-org/nwaku.git
synced 2025-01-15 01:14:56 +00:00
feat: Added message size check before relay for lightpush (#2695)
This commit is contained in:
parent
3a2caaec6f
commit
9dfdfa2774
@ -6,6 +6,7 @@ import
|
|||||||
testutils/unittests,
|
testutils/unittests,
|
||||||
chronos,
|
chronos,
|
||||||
chronicles,
|
chronicles,
|
||||||
|
std/strformat,
|
||||||
os,
|
os,
|
||||||
libp2p/[peerstore, crypto/crypto]
|
libp2p/[peerstore, crypto/crypto]
|
||||||
|
|
||||||
@ -23,7 +24,8 @@ import
|
|||||||
waku_lightpush/protocol_metrics,
|
waku_lightpush/protocol_metrics,
|
||||||
waku_lightpush/rpc,
|
waku_lightpush/rpc,
|
||||||
],
|
],
|
||||||
../testlib/[assertions, common, wakucore, wakunode, testasync, futures, testutils]
|
../testlib/[assertions, common, wakucore, wakunode, testasync, futures, testutils],
|
||||||
|
../resources/payloads
|
||||||
|
|
||||||
suite "Waku Lightpush - End To End":
|
suite "Waku Lightpush - End To End":
|
||||||
var
|
var
|
||||||
@ -85,3 +87,20 @@ suite "Waku Lightpush - End To End":
|
|||||||
|
|
||||||
# Then the message is relayed to the server
|
# Then the message is relayed to the server
|
||||||
assertResultOk publishResponse
|
assertResultOk publishResponse
|
||||||
|
|
||||||
|
suite "Waku LightPush Validation Tests":
|
||||||
|
asyncTest "Validate message size exceeds limit":
|
||||||
|
let
|
||||||
|
msgOverLimit = fakeWakuMessage(
|
||||||
|
contentTopic = contentTopic,
|
||||||
|
payload = getByteSequence(DefaultMaxWakuMessageSize + 64 * 1024),
|
||||||
|
)
|
||||||
|
|
||||||
|
# When the client publishes an over-limit message
|
||||||
|
let publishResponse = await client.lightpushPublish(
|
||||||
|
some(pubsubTopic), msgOverLimit, serverRemotePeerInfo
|
||||||
|
)
|
||||||
|
|
||||||
|
check:
|
||||||
|
publishResponse.isErr()
|
||||||
|
publishResponse.error == fmt"Message size exceeded maximum of {DefaultMaxWakuMessageSize} bytes"
|
@ -917,6 +917,10 @@ proc mountLightPush*(
|
|||||||
pushHandler = proc(
|
pushHandler = proc(
|
||||||
peer: PeerId, pubsubTopic: string, message: WakuMessage
|
peer: PeerId, pubsubTopic: string, message: WakuMessage
|
||||||
): Future[WakuLightPushResult[void]] {.async.} =
|
): Future[WakuLightPushResult[void]] {.async.} =
|
||||||
|
let validationRes = await node.wakuRelay.validateMessage(pubSubTopic, message)
|
||||||
|
if validationRes.isErr():
|
||||||
|
return err(validationRes.error)
|
||||||
|
|
||||||
let publishedCount =
|
let publishedCount =
|
||||||
await node.wakuRelay.publish(pubsubTopic, message.encode().buffer)
|
await node.wakuRelay.publish(pubsubTopic, message.encode().buffer)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user