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
adding UserAgent to Nat for description of port mapping #2310
Open
master255
wants to merge
12
commits into
libp2p:master
Choose a base branch
from
master255:2307-nat-useragent
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+58
−17
Open
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
9deed9d
Adding UserAgent to Nat for description of port mapping
master255 996c3eb
Adding UserAgent to Nat for description of port mapping
master255 721799b
Adding UserAgent to Nat for description of port mapping
master255 41d0843
Adding UserAgent to Nat for description of port mapping
master255 f84217d
Adding UserAgent to Nat for description of port mapping
master255 6c1e4e3
Adding UserAgent to Nat for description of port mapping
master255 087c446
Merge pull request #1 from libp2p/master
master255 89290fe
Merge branch 'master' into 2307-nat-useragent
master255 be95951
Adding UserAgent to Nat for description of port mapping
master255 75f4c11
Merge pull request #2 from master255/master
master255 9ce892b
Merge pull request #3 from master255/master
master255 f4c6c04
Adding UserAgent to Nat for description of port mapping
master255 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package basichost | ||
|
||
type Option func(*natManager) error | ||
|
||
// WithUserAgent is a natManager option that sets specific user agent for the NAT manager. | ||
func WithUserAgent(userAgent string) Option { | ||
return func(nmgr *natManager) error { | ||
if userAgent != "" { | ||
nmgr.userAgent = userAgent | ||
} | ||
return nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to change the interface of this public method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are the alternatives?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Introducing a new func.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we create a new function, we need to designate a default userAgent somewhere in this file. The default value is set in another file.
So this constructor has no sense without the userAgent string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default should be in this file. That was the old behavior. If users want to change it they can call the new function (maybe call it
DiscoverNATWithUserAgent
).This change as is is a breaking API change. I like to avoid them unless necessary. I don't think it's necessary here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MarcoPolo Okay. Then what to do with this one?
https://github.com/libp2p/go-libp2p/pull/2310/files#diff-a5aa28aae96d02e4316747f7950909f36d447f7833e5a70121c3808852e5e440R80
What to pass in this line? What will be the default value here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And then what will be in this place? "if" and two constructors?
https://github.com/libp2p/go-libp2p/pull/2310/files#diff-a5aa28aae96d02e4316747f7950909f36d447f7833e5a70121c3808852e5e440R117
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MarcoPolo Okay. Why shouldn't there be an incoming userAgent parameter in this function? After all, we cannot communicate with NAT without userAgent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because it's a breaking API change. Users of this function, when they update go-libp2p will need to update their usage of this function and pass in a userAgent.
It'd be nicer if we add another function
DiscoverNATWithUserAgent
andNatManager
switches betweenDiscoverNAT
andDiscoverNATWithUserAgent
based on whether it has a user configured UserAgent or notThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sukunrt Okay. I fixed it.