-
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
feat: libp2phttp /http-path
#2850
Conversation
@@ -657,12 +660,22 @@ func (h *Host) RoundTrip(r *http.Request) (*http.Response, error) { | |||
return nil, err | |||
} | |||
addr, isHTTP := normalizeHTTPMultiaddr(addr) | |||
parsed, err := parseMultiaddr(addr) |
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.
We need this parsing only if it's a http multiaddr, right? Otherwise we can just use the addr
?
I would prefer calling this only when it's an /http
multiaddr because parseMultiaddr
looks specific to parsing /http
multiaddrs. Having said that, I haven't been able to find any multiaddr that would make parseMultiaddr
do something funny.
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.
We need this parsing only if it's a http multiaddr, right?
Both. We use the http-path, host, and port in both code paths.
Would you prefer we name this something else?
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.
You only need parsed.peer
in that code path so I was wondering if we should just get the peerID from the addr in that code path.
This is fine too though.
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.
We need http path as well
@@ -657,12 +660,22 @@ func (h *Host) RoundTrip(r *http.Request) (*http.Response, error) { | |||
return nil, err | |||
} | |||
addr, isHTTP := normalizeHTTPMultiaddr(addr) | |||
parsed, err := parseMultiaddr(addr) |
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.
You only need parsed.peer
in that code path so I was wondering if we should just get the peerID from the addr in that code path.
This is fine too though.
p2p/http/libp2phttp.go
Outdated
// multiaddr://here-instead. | ||
if relative.OmitHost { | ||
// Not relative (at least we can't tell). Nothing we can do here | ||
return nil, errors.New("not relative") |
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.
You can reuse this error and avoid allocation for all the calls. This looks like it'll be used often.
Adds support for multiaddr URIs that contain
/http-path
components. In other words, this works now: