Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Clippy being actually helpful
  • Loading branch information
timorl committed Dec 8, 2022
commit db73a35c6dd98d17fddeb4ccc15a2db5c1625f63
12 changes: 7 additions & 5 deletions finality-aleph/src/network/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,20 @@ use crate::{

type AuthenticationNetworkIO<M, A> = NetworkIO<VersionedAuthentication<M, A>>;

type FullIO<D, M, A, VN> = (
ConnectionManagerIO<D, M, A, VN>,
AuthenticationNetworkIO<M, A>,
SessionManagerIO<D>,
);

pub fn setup<
D: Data,
M: Data + Debug,
A: AddressingInformation + TryFrom<Vec<M>> + Into<Vec<M>>,
VN: ValidatorNetwork<A::PeerId, A, DataInSession<D>>,
>(
validator_network: VN,
) -> (
ConnectionManagerIO<D, M, A, VN>,
AuthenticationNetworkIO<M, A>,
SessionManagerIO<D>,
)
) -> FullIO<D, M, A, VN>
where
A::PeerId: PublicKey,
{
Expand Down
44 changes: 15 additions & 29 deletions finality-aleph/src/network/manager/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ use crate::{
crypto::{AuthorityPen, AuthorityVerifier},
network::{
manager::{
compatibility::{LegacyDiscoveryMessage, PeerAuthentications},
Connections, DataInSession, Discovery, DiscoveryMessage, SessionHandler,
SessionHandlerError, VersionedAuthentication,
compatibility::PeerAuthentications, Connections, DataInSession, Discovery,
DiscoveryMessage, SessionHandler, SessionHandlerError, VersionedAuthentication,
},
AddressedData, AddressingInformation, ConnectionCommand, Data, NetworkIdentity, PeerId,
},
Expand Down Expand Up @@ -354,7 +353,8 @@ where
let session = match self.sessions.get_mut(&pre_session.session_id) {
Some(session) => session,
None => {
return Ok(self.start_nonvalidator_session(pre_session, address).await);
self.start_nonvalidator_session(pre_session, address).await;
return Ok(());
}
};
session
Expand Down Expand Up @@ -655,30 +655,16 @@ where
self.validator_network.send(to_send.0, to_send.1)
}

fn send_authentication(&self, to_send: PeerAuthentications<M, A>) -> Result<(), Error> {
use PeerAuthentications::*;
match to_send {
NewOnly(authentication) => self
.authentications_for_network
.unbounded_send(VersionedAuthentication::V2(authentication))
.map_err(|_| Error::NetworkSend),
LegacyOnly(legacy_authentication) => self
.authentications_for_network
.unbounded_send(VersionedAuthentication::V1(
LegacyDiscoveryMessage::AuthenticationBroadcast(legacy_authentication),
))
.map_err(|_| Error::NetworkSend),
Both(authentication, legacy_authentication) => {
self.authentications_for_network
.unbounded_send(VersionedAuthentication::V2(authentication))
.map_err(|_| Error::NetworkSend)?;
self.authentications_for_network
.unbounded_send(VersionedAuthentication::V1(
LegacyDiscoveryMessage::AuthenticationBroadcast(legacy_authentication),
))
.map_err(|_| Error::NetworkSend)
}
fn send_authentications(
&self,
to_send: Vec<VersionedAuthentication<M, A>>,
) -> Result<(), Error> {
for auth in to_send {
self.authentications_for_network
.unbounded_send(auth)
.map_err(|_| Error::NetworkSend)?;
}
Ok(())
}

fn handle_connection_command(&mut self, connection_command: ConnectionCommand<A>) {
Expand Down Expand Up @@ -708,7 +694,7 @@ where
self.handle_connection_command(command);
}
if let Some(message) = maybe_message {
self.send_authentication(message)?;
self.send_authentications(message.into())?;
}
Ok(())
}
Expand Down Expand Up @@ -778,7 +764,7 @@ where
Err(e) => warn!(target: "aleph-network", "Retry failed to update handler: {:?}", e),
}
for to_send in service.discovery() {
self.send_authentication(to_send.into())?;
self.send_authentications(to_send.into())?;
}
},
_ = status_ticker.tick() => {
Expand Down