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

Create a new type for peer id #2159

Closed
wants to merge 2 commits into from
Closed

Conversation

MarcoPolo
Copy link
Collaborator

Protects against fiddling with the peer bytes directly, which is probably wrong. Also fixes the root issues like libp2p/go-libp2p-resource-manager#67 (comment) and #2155.

This change should only be a translation of existing uses and doesn't try to change the semantics. If things needed bytes we update the code to return the bytes.

@@ -45,21 +45,21 @@ func (bwc *BandwidthCounter) LogRecvMessage(size int64) {
// Bandwidth is associated with the given protocol.ID and peer.ID.
func (bwc *BandwidthCounter) LogSentMessageStream(size int64, proto protocol.ID, p peer.ID) {
bwc.protocolOut.Get(string(proto)).Mark(uint64(size))
bwc.peerOut.Get(string(p)).Mark(uint64(size))
bwc.peerOut.Get(string(p.MustMarshalBinary())).Mark(uint64(size))
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not p.String()?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The old code used the bytes. This PR should not change anything semantically. If we used p.String() we would be changing semantics.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed. Let’s keep this change minimal. We can do a follow up PR if we want to change this interface.

@@ -382,7 +382,7 @@ func (as *AmbientAutoNAT) probe(pi *peer.AddrInfo) {
func (as *AmbientAutoNAT) getPeerToProbe() peer.ID {
peers := as.host.Network().Peers()
if len(peers) == 0 {
return ""
return peer.EmptyID
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably more idiomatic:

Suggested change
return peer.EmptyID
return peer.ID{}

@vyzo
Copy link
Contributor

vyzo commented Mar 1, 2023

Oh boy, this is going to wreak havoc in many places... I am not convinced at all that is a good idea.

@marten-seemann
Copy link
Contributor

Oh boy, this is going to wreak havoc in many places... I am not convinced at all that is a good idea.

I suggest trying to bubble it up into Kubo before merging this PR. Then we'll see how bad it is. Design-wise, it's definitely the right thing to do.

@MarcoPolo
Copy link
Collaborator Author

Oh boy, this is going to wreak havoc in many places... I am not convinced at all that is a good idea.

I think on principle it's a good idea. But practically, I'm not sure if the benefit is worth the effort. It'll be a breaking change that will affect most downstream consumers without much benefit to them.

If we were designing this from scratch today I would say yes, it's worth it. At this point however, I'm not sure the benefits outweigh the cost.

@vyzo
Copy link
Contributor

vyzo commented Mar 2, 2023

I am not arguing design wise, type safety not a bad thing. But this is something that should have been done from the beginning.

Also, do not underestimate the convenience. Even if the wrapper type looks desirable design wise, it is still very convenient as it is.

But regardless, my point is this change can cause major pain at this stage.

@marten-seemann
Copy link
Contributor

You're probably right. Kubo seems pretty unhappy when I try to build with PR. Haven't looked at it in detail yet though.

@p-shahi
Copy link
Member

p-shahi commented Mar 14, 2023

Closing per discussion in triage. context for not doing this in above comments

@p-shahi p-shahi closed this Mar 14, 2023
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.

4 participants