Simplify handling of upgrade information. (#761)

This commit is contained in:
Toralf Wittner
2018-12-11 15:13:10 +01:00
committed by GitHub
parent 2dce4294a0
commit a152e18821
25 changed files with 346 additions and 377 deletions

View File

@ -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);