-
Notifications
You must be signed in to change notification settings - Fork 999
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
Add a websocket transport #84
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c211d6b
Add a websocket transport
tomaka c60fb98
Merge remote-tracking branch 'upstream/master' into websockets
tomaka 2783c57
Fix concerns
tomaka b8829d7
More concerns
tomaka 6837a39
Rustfmt and use tabs
tomaka 6c737c6
Add support for WSS for dialing
tomaka 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
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,21 @@ | ||
[package] | ||
name = "libp2p-websocket" | ||
version = "0.1.0" | ||
authors = ["Parity Technologies <[email protected]>"] | ||
|
||
[dependencies] | ||
libp2p-swarm = { path = "../libp2p-swarm" } | ||
futures = "0.1" | ||
multiaddr = "0.2.0" | ||
rw-stream-sink = { path = "../rw-stream-sink" } | ||
tokio-io = "0.1" | ||
|
||
[target.'cfg(not(target_os = "emscripten"))'.dependencies] | ||
websocket = { version = "0.20.2", default-features = false, features = ["async"] } | ||
|
||
[target.'cfg(target_os = "emscripten")'.dependencies] | ||
stdweb = { version = "0.1.3", default-features = false } | ||
|
||
[target.'cfg(not(target_os = "emscripten"))'.dev-dependencies] | ||
libp2p-tcp-transport = { path = "../libp2p-tcp-transport" } | ||
tokio-core = "0.1" |
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,43 @@ | ||
Implementation of the libp2p `Transport` trait for Websockets. | ||
|
||
See the documentation of `swarm` and of libp2p in general to learn how to use the `Transport` | ||
trait. | ||
|
||
This library is used in a different way depending on whether you are compiling for emscripten | ||
or for a different operating system. | ||
|
||
# Emscripten | ||
|
||
On emscripten, you can create a `WsConfig` object with `WsConfig::new()`. It can then be used | ||
as a transport. | ||
|
||
Listening on a websockets multiaddress isn't supported on emscripten. Dialing a multiaddress | ||
which uses `ws` on top of TCP/IP will automatically use the `XMLHttpRequest` Javascript object. | ||
|
||
```rust | ||
use libp2p_websocket::WsConfig; | ||
|
||
let ws_config = WsConfig::new(); | ||
// let _ = ws_config.dial(Multiaddr::new("/ip4/40.41.42.43/tcp/12345/ws").unwrap()); | ||
``` | ||
|
||
# Other operating systems | ||
|
||
On other operating systems, this library doesn't open any socket by itself. Instead it must be | ||
plugged on top of another implementation of `Transport` such as TCP/IP. | ||
|
||
This underlying transport must be passed to the `WsConfig::new()` function. | ||
|
||
```rust | ||
extern crate libp2p_tcp_transport; | ||
extern crate libp2p_websocket; | ||
extern crate tokio_core; | ||
|
||
use libp2p_websocket::WsConfig; | ||
use libp2p_tcp_transport::TcpConfig; | ||
use tokio_core::reactor::Core; | ||
|
||
let core = Core::new().unwrap(); | ||
let ws_config = WsConfig::new(TcpConfig::new(core.handle())); | ||
// let _ = ws_config.dial(Multiaddr::new("/ip4/40.41.42.43/tcp/12345/ws").unwrap()); | ||
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. A nicer way to do this would be
But that doesn't work outside of rustdoc |
||
``` |
Oops, something went wrong.
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.
Println left in