mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-24 23:31:33 +00:00
Simplify handling of upgrade information. (#761)
This commit is contained in:
@ -46,11 +46,11 @@ impl Observed {
|
||||
}
|
||||
|
||||
impl UpgradeInfo for Observed {
|
||||
type UpgradeId = ();
|
||||
type NamesIter = iter::Once<(Bytes, Self::UpgradeId)>;
|
||||
type Info = &'static [u8];
|
||||
type InfoIter = iter::Once<Self::Info>;
|
||||
|
||||
fn protocol_names(&self) -> Self::NamesIter {
|
||||
iter::once((Bytes::from("/paritytech/observed-address/0.1.0"), ()))
|
||||
fn protocol_info(&self) -> Self::InfoIter {
|
||||
iter::once(b"/paritytech/observed-address/0.1.0")
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,7 +62,7 @@ where
|
||||
type Error = io::Error;
|
||||
type Future = Box<dyn Future<Item=Self::Output, Error=Self::Error> + Send>;
|
||||
|
||||
fn upgrade_inbound(self, conn: C, _: ()) -> Self::Future {
|
||||
fn upgrade_inbound(self, conn: C, _: Self::Info) -> Self::Future {
|
||||
let io = FramedWrite::new(conn, UviBytes::default());
|
||||
Box::new(future::ok(Sender { io }))
|
||||
}
|
||||
@ -76,7 +76,7 @@ where
|
||||
type Error = io::Error;
|
||||
type Future = Box<dyn Future<Item=Self::Output, Error=Self::Error> + Send>;
|
||||
|
||||
fn upgrade_outbound(self, conn: C, _: ()) -> Self::Future {
|
||||
fn upgrade_outbound(self, conn: C, _: Self::Info) -> Self::Future {
|
||||
let io = FramedRead::new(conn, UviBytes::default());
|
||||
let future = io.into_future()
|
||||
.map_err(|(e, _): (io::Error, FramedRead<C, UviBytes>)| e)
|
||||
@ -126,14 +126,14 @@ mod tests {
|
||||
.into_future()
|
||||
.map_err(|(e, _)| e.into())
|
||||
.and_then(move |(conn, _)| {
|
||||
Observed::new().upgrade_inbound(conn.unwrap(), ())
|
||||
Observed::new().upgrade_inbound(conn.unwrap(), b"/paritytech/observed-address/0.1.0")
|
||||
})
|
||||
.and_then(move |sender| sender.send_address(observed_addr1));
|
||||
|
||||
let client = TcpStream::connect(&server_addr)
|
||||
.map_err(|e| e.into())
|
||||
.and_then(|conn| {
|
||||
Observed::new().upgrade_outbound(conn, ())
|
||||
Observed::new().upgrade_outbound(conn, b"/paritytech/observed-address/0.1.0")
|
||||
})
|
||||
.map(move |addr| {
|
||||
eprintln!("{} {}", addr, observed_addr2);
|
||||
|
Reference in New Issue
Block a user