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

Add maxMessageSize option to pubsub #634

Merged
merged 11 commits into from
Oct 25, 2021
Merged

Add maxMessageSize option to pubsub #634

merged 11 commits into from
Oct 25, 2021

Conversation

Menduist
Copy link
Contributor

No description provided.

@Menduist Menduist marked this pull request as ready for review October 13, 2021 06:46
@jm-clius
Copy link
Contributor

Thanks! Will integrate in Waku once merged.

@@ -106,6 +106,7 @@ type
anonymize*: bool # if we omit fromPeer and seqno from RPC messages we send
subscriptionValidator*: SubscriptionValidator # callback used to validate subscriptions
topicsHigh*: int # the maximum number of topics a peer is allowed to subscribe to
maxRecvMessageSize*: int
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs documentation: unless all nodes in the mesh need the same message size constraint, the nodes that have a higher setting will be descored / disconnected because they'll be sending invalid messages.

I'm not sure the peer is the right granularity for this setting due to the above - instead, it seems better to set it per topic? Since the application has to know the payload kind on each topic, it will also be able to set a reasonable limit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs documentation

👍

it seems better to set it per topic

That would not be the right place to do it, we cannot "peek" to see which topics is it on
Instead, the application should add a validator per-topic, and reject too big messages here. We'll still read too-big-for-topic messages, but this way it won't be relayed at least

@@ -106,6 +106,11 @@ type
anonymize*: bool # if we omit fromPeer and seqno from RPC messages we send
subscriptionValidator*: SubscriptionValidator # callback used to validate subscriptions
topicsHigh*: int # the maximum number of topics a peer is allowed to subscribe to
maxRecvMessageSize*: int ##\
## the maximum raw message size we'll globally allow
## for finer tuning, check message size on topic validator
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still needs a deeper explanation, for the risk of getting descored on networks with different limits

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But note that this limit doesn't apply to sending message, even with a low maxRecvMessageSize, you could still send big messages

arnetheduck
arnetheduck previously approved these changes Oct 19, 2021
@Menduist
Copy link
Contributor Author

  • Switched default to 1mb
  • Renamed option to maxMessageSize
  • Moved option to PubSub.init
  • Also check outgoing messages
  • Added test

@Menduist Menduist changed the title Add maxRecvSize option to pubsub Add maxMessageSize option to pubsub Oct 21, 2021
@Menduist Menduist requested a review from arnetheduck October 21, 2021 14:11
@@ -538,6 +546,7 @@ proc init*[PubParams: object | bool](
sign: bool = true,
msgIdProvider: MsgIdProvider = defaultMsgIdProvider,
subscriptionValidator: SubscriptionValidator = nil,
maxMessageSize: int = 1024 * 1024,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is the 1mb limit from? we used to have 64 kb - ideally we'd use the same limit as "Defaults" in other impls

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spec half-says it, and it's the default in go-libp2p.
I would have kept it to 64 kB to avoid breaking changes, but both nim-waku and nimbus wants 1mb, so let's harmonize with the other libp2ps :)

arnetheduck
arnetheduck previously approved these changes Oct 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants