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

Pass the host name in libp2p-websockets #177

Merged
merged 3 commits into from
May 8, 2018
Merged

Conversation

tomaka
Copy link
Member

@tomaka tomaka commented May 6, 2018

If the multiaddr is /dns4/.../ws for example, then the corresponding hostname will be passed in the headers of the websocket HTTP request.

This is important if the listener is behind an HTTP reverse proxy, as the same IP address may dispatch to multiple websites.

This means that the WebSockets layer should be on top of the DNS layer in the transport. The fact that the user can make a mistake here sucks, but I don't see any better solution.

@ghost ghost assigned tomaka May 6, 2018
@ghost ghost added the in progress label May 6, 2018
@ghost
Copy link

ghost commented May 6, 2018

The even more correct :) solution is to properly define the /http and /ws multiaddrs as including data for a Host header. URLs are a mess in this regard, their hostname is used for 3 (!) things at once: DNS resolution, TLS SNI header, and the HTTP Host header.

Related: multiformats/multiaddr#63 (comment)

@tomaka
Copy link
Member Author

tomaka commented May 6, 2018

@lgierth It's not very clear, but including the hostname in the Host header is exactly what this PR does!
As for the path, our implementation doesn't handle them at all yet, exactly because of multiformats/multiaddr#63

let protocols: Vec<_> = client_addr.iter().collect();

if protocols.len() != 2 {
"127.0.0.1".to_owned()
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we error in case the address does not conform to the required format?

Copy link
Member Author

Choose a reason for hiding this comment

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

Whatever this function returns, what we do in reality is pass the inner multiaddress to the underlying transport, then negotiate websockets over the socket provided by the underlying transport. Therefore the actual IP address here doesn't matter.

@tomaka tomaka merged commit 37881d5 into libp2p:master May 8, 2018
@tomaka tomaka deleted the ws-hostname branch May 8, 2018 20:07
@ghost ghost removed the in progress label May 8, 2018
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.

2 participants