Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A0-1574: Remove unnecessary implementations in the substrate network #726

Merged
merged 3 commits into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions finality-aleph/src/network/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ impl<T> Default for Channel<T> {
}
}

pub type MockEvent = Event<MockMultiaddress>;
pub type MockEvent = Event<MockMultiaddress, MockPeerId>;

pub type MockData = Vec<u8>;
type MessageForUser<D, M> = (NetworkData<D, M>, DataCommand<<M as Multiaddress>::PeerId>);
Expand Down Expand Up @@ -183,7 +183,7 @@ impl<M: Multiaddress + 'static> MockIO<M> {
pub struct MockEventStream(mpsc::UnboundedReceiver<MockEvent>);

#[async_trait]
impl EventStream<MockMultiaddress> for MockEventStream {
impl EventStream<MockMultiaddress, MockPeerId> for MockEventStream {
async fn next_event(&mut self) -> Option<MockEvent> {
self.0.next().await
}
Expand Down
18 changes: 9 additions & 9 deletions finality-aleph/src/network/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,26 +89,26 @@ pub trait NetworkSender: Send + Sync + 'static {
}

#[derive(Clone)]
pub enum Event<M: Multiaddress> {
pub enum Event<M, P> {
Connected(M),
Disconnected(M::PeerId),
StreamOpened(M::PeerId, Protocol),
StreamClosed(M::PeerId, Protocol),
Disconnected(P),
StreamOpened(P, Protocol),
StreamClosed(P, Protocol),
Messages(Vec<(Protocol, Bytes)>),
}

#[async_trait]
pub trait EventStream<M: Multiaddress> {
async fn next_event(&mut self) -> Option<Event<M>>;
pub trait EventStream<M, P> {
async fn next_event(&mut self) -> Option<Event<M, P>>;
}

/// Abstraction over a network.
pub trait Network: Clone + Send + Sync + 'static {
type SenderError: std::error::Error;
type NetworkSender: NetworkSender;
type PeerId: PeerId;
type Multiaddress: Multiaddress<PeerId = Self::PeerId>;
type EventStream: EventStream<Self::Multiaddress>;
type PeerId: Clone + Debug + Eq + Hash + Send;
type Multiaddress: Debug + Eq + Hash;
type EventStream: EventStream<Self::Multiaddress, Self::PeerId>;

/// Returns a stream of events representing what happens on the network.
fn event_stream(&self) -> Self::EventStream;
Expand Down
2 changes: 1 addition & 1 deletion finality-aleph/src/network/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ impl<

fn handle_network_event(
&mut self,
event: Event<N::Multiaddress>,
event: Event<N::Multiaddress, N::PeerId>,
) -> Result<(), mpsc::TrySendError<NetworkData<D, A>>> {
use Event::*;
match event {
Expand Down
Loading