mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-21 13:51:33 +00:00
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:
@ -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 {
|
||||
|
Reference in New Issue
Block a user