mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-26 16:21:39 +00:00
Swarm rework (#182)
* Rename Transport::RawConn to Output * Remove AsyncRead + AsyncWrite bound on Transport::Output * UpgradedNode now always implements Transport * Add and tweak modifiers for Transport and ConnectionUpgrade * Secio upgrade now returns the pubkey in its output * Add upgrade::apply * Add Transport::and_then * Rework the swarm * Rustfmt * Fix concerns
This commit is contained in:
@ -33,7 +33,7 @@ use futures::Future;
|
||||
use futures::sync::oneshot;
|
||||
use std::env;
|
||||
use swarm::Transport;
|
||||
use swarm::upgrade::{self, DeniedConnectionUpgrade, UpgradeExt};
|
||||
use swarm::upgrade::{self, DeniedConnectionUpgrade};
|
||||
use tcp::TcpConfig;
|
||||
use tokio_core::reactor::Core;
|
||||
|
||||
@ -65,7 +65,7 @@ fn main() {
|
||||
}
|
||||
};
|
||||
|
||||
plain_text.or_upgrade(secio)
|
||||
upgrade::or(plain_text, upgrade::map(secio, |(socket, _)| socket))
|
||||
})
|
||||
|
||||
// On top of plaintext or secio, we will use the multiplex protocol.
|
||||
@ -81,8 +81,7 @@ fn main() {
|
||||
// by the listening part. We don't want to accept anything, so we pass a dummy object that
|
||||
// represents a connection that is always denied.
|
||||
let (swarm_controller, swarm_future) = swarm::swarm(
|
||||
transport,
|
||||
DeniedConnectionUpgrade,
|
||||
transport.clone().with_upgrade(DeniedConnectionUpgrade),
|
||||
|_socket, _client_addr| -> Result<(), _> {
|
||||
unreachable!("All incoming connections should have been denied")
|
||||
},
|
||||
@ -91,7 +90,8 @@ fn main() {
|
||||
// We now use the controller to dial to the address.
|
||||
let (tx, rx) = oneshot::channel();
|
||||
swarm_controller
|
||||
.dial_custom_handler(target_addr.parse().expect("invalid multiaddr"), ping::Ping,
|
||||
.dial_custom_handler(target_addr.parse().expect("invalid multiaddr"),
|
||||
transport.with_upgrade(ping::Ping),
|
||||
|(mut pinger, future), _| {
|
||||
let ping = pinger.ping().map_err(|_| unreachable!()).inspect(|_| {
|
||||
println!("Received pong from the remote");
|
||||
|
Reference in New Issue
Block a user