Skip to content

Introduce PeerId for stricter type meaning across the crate#286

Merged
rustaceanrob merged 2 commits intomasterfrom
peer-id-2-6
Feb 7, 2025
Merged

Introduce PeerId for stricter type meaning across the crate#286
rustaceanrob merged 2 commits intomasterfrom
peer-id-2-6

Conversation

@rustaceanrob
Copy link
Collaborator

@rustaceanrob rustaceanrob commented Feb 7, 2025

There is a u32 nonce that is used to identify peers when we open a connection to them and want to send a specific peer a message. Refactoring this to a wrapper type is hopefully easier to read, especially for folks not familiar with the library but would potentially want to submit a patch.

You'll notice I used wrapping_add to prevent an overflow as well. Funny enough Bitcoin Core had the same problem of using plain old u32 math that could be exploited.

cc @nyonson


use crate::core::messages::RejectPayload;

use super::PeerId;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't see super used much beyond unit test modules pulling in the code they are testing. I think it is a little less maintainable then a full crate namespace? Not a blocker or anything, just curious on the style.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Just the LSP auto complete. Could potentially make an issue for a greater refactor to tackle then. super is used quite a bit across the crate.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will go ahead and punt on this here, but feel free to make a meta issue.

Copy link
Collaborator

@nyonson nyonson left a comment

Choose a reason for hiding this comment

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

ACK cf0617c

@rustaceanrob rustaceanrob merged commit 9158441 into master Feb 7, 2025
14 checks passed
@rustaceanrob rustaceanrob deleted the peer-id-2-6 branch February 7, 2025 05:12
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.

2 participants