Remove dial_custom_handler (#203)

* Remove dial_custom_handler

* Rename dial_to_handler to dial
This commit is contained in:
Pierre Krieger
2018-05-22 18:58:27 +02:00
committed by GitHub
parent 6d41923ca5
commit e5f23c74c0
6 changed files with 45 additions and 74 deletions

View File

@ -131,17 +131,11 @@ fn run_dialer(opts: DialerOpts) -> Result<(), Box<Error>> {
RelayTransport::new(opts.me, tcp, store, iter::once(opts.relay)).with_dummy_muxing()
};
let (control, future) = libp2p::core::swarm(transport.clone(), |_, _| {
future::ok(())
});
let echo = SimpleProtocol::new("/echo/1.0.0", |socket| {
Ok(AsyncRead::framed(socket, BytesCodec::new()))
});
let address = format!("/p2p-circuit/p2p/{}", opts.dest.to_base58()).parse()?;
control.dial_custom_handler(address, transport.with_upgrade(echo), |socket, _| {
let (control, future) = libp2p::core::swarm(transport.clone().with_upgrade(echo.clone()), |socket, _| {
println!("sending \"hello world\"");
socket.send("hello world".into())
.and_then(|socket| socket.into_future().map_err(|(e, _)| e).map(|(m, _)| m))
@ -149,7 +143,11 @@ fn run_dialer(opts: DialerOpts) -> Result<(), Box<Error>> {
println!("received message: {:?}", message);
Ok(())
})
}).map_err(|_| "failed to dial")?;
});
let address = format!("/p2p-circuit/p2p/{}", opts.dest.to_base58()).parse()?;
control.dial(address, transport.with_upgrade(echo)).map_err(|_| "failed to dial")?;
core.run(future).map_err(From::from)
}