Simplify trait bounds on NetworkBehaviour (#1405)

* Simplify trait bounds requirements

* More work

* Moar

* Finish

* Fix final tests

* More simplification

* Use separate traits for Inbound/Outbound

* Update gossipsub and remove warnings

* Add documentation to swarm

* Remove BoxSubstream

* Fix tests not compiling

* Fix stack overflow

* Address concerns

* For some reason my IDE ignored libp2p-kad
This commit is contained in:
Pierre Krieger
2020-02-07 16:29:30 +01:00
committed by GitHub
parent 69852a580b
commit 1eff4b9823
32 changed files with 580 additions and 652 deletions

View File

@ -38,7 +38,6 @@ use std::{
collections::HashSet,
collections::VecDeque,
iter,
marker::PhantomData,
sync::Arc,
task::{Context, Poll},
};
@ -47,7 +46,7 @@ use wasm_timer::{Instant, Interval};
mod tests;
/// Network behaviour that handles the gossipsub protocol.
pub struct Gossipsub<TSubstream> {
pub struct Gossipsub {
/// Configuration providing gossipsub performance parameters.
config: GossipsubConfig,
@ -84,12 +83,9 @@ pub struct Gossipsub<TSubstream> {
/// Heartbeat interval stream.
heartbeat: Interval,
/// Marker to pin the generics.
marker: PhantomData<TSubstream>,
}
impl<TSubstream> Gossipsub<TSubstream> {
impl Gossipsub {
/// Creates a `Gossipsub` struct given a set of parameters specified by `gs_config`.
pub fn new(local_peer_id: PeerId, gs_config: GossipsubConfig) -> Self {
let local_peer_id = if gs_config.no_source_id {
@ -118,7 +114,6 @@ impl<TSubstream> Gossipsub<TSubstream> {
Instant::now() + gs_config.heartbeat_initial_delay,
gs_config.heartbeat_interval,
),
marker: PhantomData,
}
}
@ -987,11 +982,8 @@ impl<TSubstream> Gossipsub<TSubstream> {
}
}
impl<TSubstream> NetworkBehaviour for Gossipsub<TSubstream>
where
TSubstream: AsyncRead + AsyncWrite + Unpin + Send + 'static,
{
type ProtocolsHandler = GossipsubHandler<TSubstream>;
impl NetworkBehaviour for Gossipsub {
type ProtocolsHandler = GossipsubHandler;
type OutEvent = GossipsubEvent;
fn new_handler(&mut self) -> Self::ProtocolsHandler {