mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-20 21:36:31 +00:00
Add a websocket transport
This commit is contained in:
@ -23,6 +23,7 @@ extern crate futures;
|
||||
extern crate libp2p_secio as secio;
|
||||
extern crate libp2p_swarm as swarm;
|
||||
extern crate libp2p_tcp_transport as tcp;
|
||||
extern crate libp2p_websocket as websocket;
|
||||
extern crate multiplex;
|
||||
extern crate tokio_core;
|
||||
extern crate tokio_io;
|
||||
@ -34,6 +35,7 @@ use swarm::{UpgradeExt, SimpleProtocol, Transport, MuxedTransport};
|
||||
use tcp::TcpConfig;
|
||||
use tokio_core::reactor::Core;
|
||||
use tokio_io::codec::length_delimited;
|
||||
use websocket::WsConfig;
|
||||
|
||||
fn main() {
|
||||
// Determine which address to dial.
|
||||
@ -46,6 +48,11 @@ fn main() {
|
||||
// We start by creating a `TcpConfig` that indicates that we want TCP/IP.
|
||||
let transport = TcpConfig::new(core.handle())
|
||||
|
||||
// In addition to TCP/IP, we also want to support the Websockets protocol on top of TCP/IP.
|
||||
// The parameter passed to `WsConfig::new()` must be an implementation of `Transport` to be
|
||||
// used for the underlying multiaddress.
|
||||
.or_transport(WsConfig::new(TcpConfig::new(core.handle())))
|
||||
|
||||
// On top of TCP/IP, we will use either the plaintext protocol or the secio protocol,
|
||||
// depending on which one the remote supports.
|
||||
.with_upgrade({
|
||||
|
@ -23,6 +23,7 @@ extern crate futures;
|
||||
extern crate libp2p_secio as secio;
|
||||
extern crate libp2p_swarm as swarm;
|
||||
extern crate libp2p_tcp_transport as tcp;
|
||||
extern crate libp2p_websocket as websocket;
|
||||
extern crate multiplex;
|
||||
extern crate tokio_core;
|
||||
extern crate tokio_io;
|
||||
@ -34,6 +35,7 @@ use swarm::{Transport, UpgradeExt, SimpleProtocol};
|
||||
use tcp::TcpConfig;
|
||||
use tokio_core::reactor::Core;
|
||||
use tokio_io::codec::length_delimited;
|
||||
use websocket::WsConfig;
|
||||
|
||||
fn main() {
|
||||
// Determine which address to listen to.
|
||||
@ -45,6 +47,10 @@ fn main() {
|
||||
// Now let's build the transport stack.
|
||||
// We start by creating a `TcpConfig` that indicates that we want TCP/IP.
|
||||
let transport = TcpConfig::new(core.handle())
|
||||
// In addition to TCP/IP, we also want to support the Websockets protocol on top of TCP/IP.
|
||||
// The parameter passed to `WsConfig::new()` must be an implementation of `Transport` to be
|
||||
// used for the underlying multiaddress.
|
||||
.or_transport(WsConfig::new(TcpConfig::new(core.handle())))
|
||||
|
||||
// On top of TCP/IP, we will use either the plaintext protocol or the secio protocol,
|
||||
// depending on which one the remote supports.
|
||||
|
Reference in New Issue
Block a user