-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
correctly handle WebTransport addresses without certhashes #2239
Merged
Merged
Changes from 7 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
4039cf5
Add helpers to transform webtransport multiaddrs in AddrsFactory
MarcoPolo 3e0b6c7
Remove unused line
MarcoPolo dd7cc53
PR nits
MarcoPolo fa0e2e6
Add wrapper around AddrsFactory to fill in missing certhash
MarcoPolo 22c403d
PR nits
MarcoPolo eeea389
Handle WebTransport multiaddrs in observed addr manager
MarcoPolo 5ec52c6
Remove unneccessary change
MarcoPolo 94d03be
Remove unused func
MarcoPolo a7f5b93
Use SplitLast
MarcoPolo e946419
Add comment
MarcoPolo f168a8e
Clone multiaddr before splitting last
MarcoPolo 7b20c04
Revert "Clone multiaddr before splitting last"
MarcoPolo b3b258f
Wait for certmanager to be instantiated
MarcoPolo 1e98606
Copy addrs slice before modifying
MarcoPolo 03e929d
Fix stalled test
MarcoPolo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ import ( | |
"github.com/libp2p/go-libp2p/core/peerstore" | ||
"github.com/libp2p/go-libp2p/core/protocol" | ||
"github.com/libp2p/go-libp2p/core/record" | ||
"github.com/libp2p/go-libp2p/core/transport" | ||
"github.com/libp2p/go-libp2p/p2p/host/autonat" | ||
"github.com/libp2p/go-libp2p/p2p/host/eventbus" | ||
"github.com/libp2p/go-libp2p/p2p/host/pstoremanager" | ||
|
@@ -27,11 +28,13 @@ import ( | |
"github.com/libp2p/go-libp2p/p2p/protocol/holepunch" | ||
"github.com/libp2p/go-libp2p/p2p/protocol/identify" | ||
"github.com/libp2p/go-libp2p/p2p/protocol/ping" | ||
libp2pwebtransport "github.com/libp2p/go-libp2p/p2p/transport/webtransport" | ||
"github.com/prometheus/client_golang/prometheus" | ||
|
||
"github.com/libp2p/go-netroute" | ||
|
||
logging "github.com/ipfs/go-log/v2" | ||
"github.com/multiformats/go-multiaddr" | ||
ma "github.com/multiformats/go-multiaddr" | ||
madns "github.com/multiformats/go-multiaddr-dns" | ||
manet "github.com/multiformats/go-multiaddr/net" | ||
|
@@ -760,7 +763,48 @@ func (h *BasicHost) ConnManager() connmgr.ConnManager { | |
// Addrs returns listening addresses that are safe to announce to the network. | ||
// The output is the same as AllAddrs, but processed by AddrsFactory. | ||
func (h *BasicHost) Addrs() []ma.Multiaddr { | ||
return h.AddrsFactory(h.AllAddrs()) | ||
type transportForListeninger interface { | ||
MarcoPolo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
TransportForListening(a ma.Multiaddr) transport.Transport | ||
} | ||
type addCertHasher interface { | ||
AddCertHashes(m ma.Multiaddr) ma.Multiaddr | ||
} | ||
|
||
addrs := h.AddrsFactory(h.AllAddrs()) | ||
|
||
s, ok := h.Network().(transportForListeninger) | ||
if !ok { | ||
return addrs | ||
} | ||
|
||
for i, addr := range addrs { | ||
if ok, n := libp2pwebtransport.IsWebtransportMultiaddr(addr); ok && n == 0 { | ||
t := s.TransportForListening(addr) | ||
tpt, ok := t.(addCertHasher) | ||
if !ok { | ||
continue | ||
} | ||
addrs[i] = tpt.AddCertHashes(addr) | ||
} | ||
} | ||
return addrs | ||
} | ||
|
||
// NormalizeMultiaddr returns a multiaddr suitable for equality checks. | ||
// If the multiaddr is a webtransport component, it removes the certhashes. | ||
func (h *BasicHost) NormalizeMultiaddr(addr ma.Multiaddr) ma.Multiaddr { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume this would move into the address pipeline, once we have it, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure! Anywhere that isn't adding another method to BasicHost |
||
if ok, n := libp2pwebtransport.IsWebtransportMultiaddr(addr); ok && n > 0 { | ||
var firstCerthash ma.Multiaddr | ||
MarcoPolo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
multiaddr.ForEach(addr, func(c ma.Component) bool { | ||
if c.Protocol().Code == ma.P_CERTHASH { | ||
firstCerthash = &c | ||
return false | ||
} | ||
return true | ||
}) | ||
return addr.Decapsulate(firstCerthash) | ||
} | ||
return addr | ||
} | ||
|
||
// mergeAddrs merges input address lists, leave only unique addresses | ||
|
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
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.