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

swarm/src/connection: Test max_negotiating_inbound_streams #2785

Merged
merged 8 commits into from Aug 16, 2022

Conversation

mxinden
Copy link
Member

@mxinden mxinden commented Jul 31, 2022

Description

Test that HandlerWrapper upholds the provided
max_negotiating_inbound_streams limit.

Links to any relevant issues

Feature introduced in #2697.

Open Questions

Change checklist

  • I have performed a self-review of my own code
  • [ ] I have made corresponding changes to the documentation
  • [ ] I have added tests that prove my fix is effective or that my feature works
  • [ ] A changelog entry has been made in the appropriate crates

Test that `HandlerWrapper` upholds the provided
`max_negotiating_inbound_streams` limit.
@mxinden
Copy link
Member Author

mxinden commented Aug 8, 2022

@thomaseizinger @elenaf9 could one of you give this pull request a review?

Copy link
Contributor

@thomaseizinger thomaseizinger left a comment

Choose a reason for hiding this comment

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

LGTM overall, a few questions.

use std::num::NonZeroU8;
use std::sync::Arc;

struct DummySubstream(Arc<()>);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
struct DummySubstream(Arc<()>);
struct PendingSubstream(Arc<()>);

Copy link
Contributor

Choose a reason for hiding this comment

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

Plus, I'd prefer such kind of infrastructure to be at the bottom of the module. More generally, items in a module / file should be sorted by priority / likelihood of wanting to see them as you open the file and read it top to bottom.

Having imports at the top somewhat contradicts this rule but I think that is too controversial to adopt :D

Copy link
Member Author

Choose a reason for hiding this comment

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

👍 62f5e4c

);
}

QuickCheck::new().quickcheck(prop as fn(_));
Copy link
Contributor

Choose a reason for hiding this comment

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

Have you ever considered using the #[quickcheck] macro?

Copy link
Member Author

Choose a reason for hiding this comment

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

I haven't. Looks handy to me. Though I would prefer being consistent, i.e. move the entire code base to #[quickcheck] at once instead of diverging on a couple of pull requests.

swarm/src/connection/handler_wrapper.rs Outdated Show resolved Hide resolved
swarm/src/connection/handler_wrapper.rs Outdated Show resolved Hide resolved
/// Implementation of [`UpgradeInfo`], [`InboundUpgrade`] and [`OutboundUpgrade`] that always
/// returns a pending upgrade.
#[derive(Debug, Copy, Clone)]
pub struct PendingUpgrade<P> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need this to be generic?

Copy link
Member Author

Choose a reason for hiding this comment

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

Are you suggesting to use a String instead? What if a user wants to use it with a type other than String that implements ProtocolName?

Copy link
Member Author

Choose a reason for hiding this comment

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

With "user" I mean am thinking of potential users beyond the test introduced in this pull request.

Copy link
Contributor

Choose a reason for hiding this comment

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

Are you suggesting to use a String instead? What if a user wants to use it with a type other than String that implements ProtocolName?

&'static str would probably be my preference and I'd say we can make it generic once needed? For tests, a static protocol name is probably good enough for many if not all cases.

Copy link
Member Author

Choose a reason for hiding this comment

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

libp2p-core has the ProtocolName abstraction. Thus I would suggest all of libp2p-core should use that abstraction. I am happy to design an alternative approach. Though I think that should happen in a different pull request.

swarm/src/handler/pending.rs Outdated Show resolved Hide resolved
@mxinden
Copy link
Member Author

mxinden commented Aug 10, 2022

Thanks for the review @thomaseizinger. I addressed all your comments. Let me know what you think.

Copy link
Contributor

@thomaseizinger thomaseizinger left a comment

Choose a reason for hiding this comment

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

One suggestion but don't feel strongly about it.

Comment on lines +70 to +76
_info: Self::OutboundOpenInfo,
) {
void::unreachable(protocol);
#[allow(unreachable_code)]
{
void::unreachable(_info);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
_info: Self::OutboundOpenInfo,
) {
void::unreachable(protocol);
#[allow(unreachable_code)]
{
void::unreachable(_info);
}
_: Self::OutboundOpenInfo,
) {
void::unreachable(protocol);

I'd almost suggest to not use void::unreachable for the info part if we have to use #[allow(unreachable_code)] for it to work.

Copy link
Member Author

Choose a reason for hiding this comment

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

I prefer the additional void::unreachable, just in case we refactor this part of the codebase in the future.

@mxinden mxinden merged commit 8dc0188 into libp2p:master Aug 16, 2022
@mxinden
Copy link
Member Author

mxinden commented Aug 16, 2022

Thanks for the help @thomaseizinger!

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.

None yet

2 participants