Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

fix: add per-connection stream limit #173

Merged
merged 3 commits into from
Jun 8, 2022
Merged

Conversation

achingbrain
Copy link
Member

Limits the total number of streams that can be opened to 1024 per connection.

This can be overridden by passing an option to the constructor.

Limits the total number of streams that can be opened to 1024 per connection.

This can be overridden by passing an option to the constructor.
README.md Outdated

`options` is an optional `Object` that may have the following properties:

* `maxMsgSize` - a number that defines how large mplex data messages can be in bytes, if messages are larger than this they will be sent as multiple messages (default: 1 << 20)
Copy link
Member

Choose a reason for hiding this comment

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

minor thing, i think describing the default as a power of 2 is more readable (eg: 2 ** 20)
or just writing the number

@achingbrain achingbrain merged commit 21371e7 into master Jun 8, 2022
@achingbrain achingbrain deleted the fix/add-stream-limit branch June 8, 2022 15:10
github-actions bot pushed a commit that referenced this pull request Jun 8, 2022
### [1.1.2](v1.1.1...v1.1.2) (2022-06-08)

### Bug Fixes

* add per-connection stream limit ([#173](#173)) ([21371e7](21371e7))
@github-actions
Copy link

github-actions bot commented Jun 8, 2022

🎉 This PR is included in version 1.1.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Copy link

@BigLep BigLep left a comment

Choose a reason for hiding this comment

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

Mostly newbie questions. Feel free to point me if these have been discussed elsewhere.


const log = logger('libp2p:mplex')

const MAX_STREAMS_PER_CONNECTION = 1024
Copy link

Choose a reason for hiding this comment

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

newbie question: is the TypeScript way of doing things to define defaults here rather than where the override can be set? For example, I was surprised not to see this closer to MplexInit.

Copy link

Choose a reason for hiding this comment

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

Also, how did we pick this default? How do we know it's a good value?

Copy link
Member Author

Choose a reason for hiding this comment

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

MplexInit is defined in index.ts, exporting it for import into mplex.ts would also expose it to people importing @libp2p/mplex. It could be the other way round though, defined in mplex.ts and imported into index.ts.

Copy link
Member Author

Choose a reason for hiding this comment

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

Also, how did we pick this default?

Completely arbitrary. It's a lot bigger than go-libp2p but we need to start somewhere. We might end up splitting it into separate incoming/outgoing stream limits too.

* The maximum number of multiplexed streams that can be open at any
* one time. An attempt to open more than this will throw.
*/
maxStreamsPerConnection?: number
Copy link

Choose a reason for hiding this comment

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

newbie question here: I assume it's not possible to just put the default here?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, the interface is removed at compile time so it can't have default values.

`options` is an optional `Object` that may have the following properties:

* `maxMsgSize` - a number that defines how large mplex data messages can be in bytes, if messages are larger than this they will be sent as multiple messages (default: 1048576 - e.g. 1MB)
* `maxStreamsPerConnection` - a number that defines how many streams are allowed per connection (default: 1024)
Copy link

Choose a reason for hiding this comment

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

The default values listed in these docs can get out of date. Can/should we link to the authoritative source?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, generating docs from the interface might be a better approach here.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants