rust-libp2p/libp2p-websocket
Pierre Krieger 39dde305b4
Rework libp2p-identify (#116)
* Add a proper PeerId to Peerstore

* Turn identify into a transport layer

* Expose the dialed multiaddress

* Add identified nodes to the peerstore

* Allow configuring the TTL of the addresses

* Split identify in two modules

* Some comments and tweaks

* Run rustfmt

* Add test and bugfix

* Fix wrong address reported when dialing

* Fix websocket browser code

* Support the p2p protocol in libp2p-identify

* Fix concerns

* Fix libp2p-dns

* More concerns
2018-03-07 10:49:11 +01:00
..
2018-03-07 10:49:11 +01:00
2018-01-11 16:06:11 +01:00
2018-01-11 11:07:17 +01:00

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 BrowserWsConfig object with BrowserWsConfig::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.

use libp2p_websocket::BrowserWsConfig;

let ws_config = BrowserWsConfig::new();
// let _ = ws_config.dial("/ip4/40.41.42.43/tcp/12345/ws".parse().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 put inside a WsConfig object through the WsConfig::new() function.

extern crate libp2p_swarm;
extern crate libp2p_tcp_transport;
extern crate libp2p_websocket;
extern crate tokio_core;

use libp2p_swarm::{Multiaddr, Transport};
use libp2p_tcp_transport::TcpConfig;
use libp2p_websocket::WsConfig;
use tokio_core::reactor::Core;

let core = Core::new().unwrap();
let ws_config = WsConfig::new(TcpConfig::new(core.handle()));
let _ = ws_config.dial("/ip4/40.41.42.43/tcp/12345/ws".parse().unwrap());