diff --git a/src/net/protocol/protocol_registry.rs b/src/net/protocol/protocol_registry.rs index 57ad86724..d1f8f00f3 100644 --- a/src/net/protocol/protocol_registry.rs +++ b/src/net/protocol/protocol_registry.rs @@ -5,11 +5,13 @@ use std::future::Future; use super::protocol_base::ProtocolBase; use std::sync::Arc; -use super::protocol_base::ProtocolBasePtr; +//use super::protocol_base::ProtocolBasePtr; use crate::net::{ChannelPtr, P2pPtr}; +type ProtocolBasePtr = Arc; + type Constructor = Box< - dyn Fn(ChannelPtr, P2pPtr) -> BoxFuture<'static, Arc> + dyn Fn(ChannelPtr, P2pPtr) -> BoxFuture<'static, Arc> + Send + Sync, >; @@ -27,18 +29,18 @@ impl ProtocolRegistry { pub async fn register(&self, constructor: C) where C: 'static + Fn(ChannelPtr, P2pPtr) -> F + Send + Sync, - F: 'static + Future> + Send, + F: 'static + Future> + Send, { let constructor = move |channel, p2p| { - Box::pin(constructor(channel, p2p)) as BoxFuture<'static, ProtocolBasePtr> + Box::pin(constructor(channel, p2p)) as BoxFuture<'static, Arc> }; self.protocol_constructors.lock().await.push(Box::new(constructor)); } - pub async fn attach(&self, channel: ChannelPtr, p2p: P2pPtr) -> Vec { - let mut protocols: Vec> = Vec::new(); + pub async fn attach(&self, channel: ChannelPtr, p2p: P2pPtr) -> Vec> { + let mut protocols: Vec> = Vec::new(); for construct in self.protocol_constructors.lock().await.iter() { - let protocol: Arc = + let protocol: Arc = construct(channel.clone(), p2p.clone()).await; protocols.push(protocol) }