bee_network/swarm/protocols/iota_gossip/
upgrade.rs1use super::id::IotaGossipIdentifier;
5
6use futures::{future, AsyncRead, AsyncWrite};
7use libp2p::{core::UpgradeInfo, InboundUpgrade, OutboundUpgrade};
8use log::*;
9
10use std::{io, iter};
11
12#[derive(Debug, Clone)]
13pub struct IotaGossipProtocolUpgrade {
14 id: IotaGossipIdentifier,
15}
16
17impl IotaGossipProtocolUpgrade {
18 pub fn new(id: IotaGossipIdentifier) -> Self {
19 Self { id }
20 }
21}
22
23impl UpgradeInfo for IotaGossipProtocolUpgrade {
24 type Info = IotaGossipIdentifier;
25 type InfoIter = iter::Once<Self::Info>;
26
27 fn protocol_info(&self) -> Self::InfoIter {
28 trace!("gossip upgrade: protocol info query: {}", self.id);
29
30 iter::once(self.id.clone())
31 }
32}
33
34impl<S> InboundUpgrade<S> for IotaGossipProtocolUpgrade
35where
36 S: AsyncWrite + AsyncWrite + Unpin + Send,
37{
38 type Output = S;
39 type Error = io::Error;
40 type Future = future::Ready<Result<Self::Output, Self::Error>>;
41
42 fn upgrade_inbound(self, stream: S, info: Self::Info) -> Self::Future {
43 debug!("gossip upgrade: inbound: {}", info);
44
45 future::ok(stream)
46 }
47}
48
49impl<S> OutboundUpgrade<S> for IotaGossipProtocolUpgrade
50where
51 S: AsyncRead + AsyncWrite + Unpin + Send,
52{
53 type Output = S;
54 type Error = io::Error;
55 type Future = future::Ready<Result<Self::Output, Self::Error>>;
56
57 fn upgrade_outbound(self, stream: S, info: Self::Info) -> Self::Future {
58 debug!("gossip upgrade: outbound: {}", info);
59
60 future::ok(stream)
61 }
62}