-
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
swarm: fix selection of transport for dialing #1653
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,25 +19,23 @@ func (s *Swarm) TransportForDialing(a ma.Multiaddr) transport.Transport { | |
|
||
s.transports.RLock() | ||
defer s.transports.RUnlock() | ||
|
||
if len(s.transports.m) == 0 { | ||
// make sure we're not just shutting down. | ||
if s.transports.m != nil { | ||
log.Error("you have no transports configured") | ||
} | ||
return nil | ||
} | ||
|
||
for _, p := range protocols { | ||
transport, ok := s.transports.m[p.Code] | ||
if !ok { | ||
continue | ||
} | ||
if transport.Proxy() { | ||
return transport | ||
if isRelayAddr(a) { | ||
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 don't really like this logic here. Instead, we could have transports reject 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. Let's not change this just yet since that would involve changing every transport. Let's revisit after discussing multiformats/multiaddr#140 |
||
return s.transports.m[ma.P_CIRCUIT] | ||
} | ||
for _, t := range s.transports.m { | ||
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 think in general this needs to go the other way. We should be interpreting this right to left. 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 don't understand this comment. We're iterating over a 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 misunderstood. I thought we were iterating of the multiaddr components. I see now that we're iterating over all registered transports. I think this isn't ideal because:
I'll draft a patch of what I'm thinking here and how it relates to multiformats/multiaddr#140 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. Here's concretely what I mean: https://github.com/libp2p/go-libp2p/compare/fix-dial-transport-selection...marco/layered-transports?expand=1#diff-1d9e588fd7c4fedee40f7f985be2346b02ba540389251f4603cbc13e8f8fc371R94 Notice this gives us the benefit of removing the "extract certhash" logic out of webtransport completely both in the |
||
if t.CanDial(a) { | ||
return t | ||
} | ||
} | ||
|
||
return s.transports.m[protocols[len(protocols)-1].Code] | ||
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. What if we have a This function could be a method of an interface and components could implement this interface. The certhash component would simply return the next transport in the multiaddr along with the certhash parameters. 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. That would be a layer violation, wouldn't it? |
||
return nil | ||
} | ||
|
||
// TransportForListening retrieves the appropriate transport for listening on | ||
|
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.
I'm slightly concerned about the amount of dependencies that this test adds. Not that much of a problem, now that we have a mono-repo, but maybe this would be nicer if we used a mock
transport.Transport
interface?