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

@ -18,7 +18,7 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
use bytes::{BufMut, Bytes, BytesMut};
use bytes::{BufMut, BytesMut};
use crate::rpc_proto;
use futures::future;
use libp2p_core::{InboundUpgrade, OutboundUpgrade, UpgradeInfo, PeerId};
@ -42,12 +42,12 @@ impl FloodsubConfig {
}
impl UpgradeInfo for FloodsubConfig {
type UpgradeId = ();
type NamesIter = iter::Once<(Bytes, Self::UpgradeId)>;
type Info = &'static [u8];
type InfoIter = iter::Once<Self::Info>;
#[inline]
fn protocol_names(&self) -> Self::NamesIter {
iter::once(("/floodsub/1.0.0".into(), ()))
fn protocol_info(&self) -> Self::InfoIter {
iter::once(b"/floodsub/1.0.0")
}
}
@ -60,7 +60,7 @@ where
type Future = future::FutureResult<Self::Output, Self::Error>;
#[inline]
fn upgrade_inbound(self, socket: TSocket, _: Self::UpgradeId) -> Self::Future {
fn upgrade_inbound(self, socket: TSocket, _: Self::Info) -> Self::Future {
future::ok(Framed::new(socket, FloodsubCodec { length_prefix: Default::default() }))
}
}
@ -74,7 +74,7 @@ where
type Future = future::FutureResult<Self::Output, Self::Error>;
#[inline]
fn upgrade_outbound(self, socket: TSocket, _: Self::UpgradeId) -> Self::Future {
fn upgrade_outbound(self, socket: TSocket, _: Self::Info) -> Self::Future {
future::ok(Framed::new(socket, FloodsubCodec { length_prefix: Default::default() }))
}
}