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

Add echo broadcast service #25

Merged
merged 7 commits into from
Oct 5, 2024
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
20 changes: 19 additions & 1 deletion src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
// along with Frost-Federation. If not, see
// <https://www.gnu.org/licenses/>.

use self::echo_broadcast::{start_echo_broadcast, EchoBroadcastHandle};
use self::{membership::MembershipHandle, protocol::Message};
use crate::node::echo_broadcast::service::EchoBroadcast;
use crate::node::protocol::PingMessage;
use crate::node::reliable_sender::service::ReliableSend;
use crate::node::reliable_sender::ReliableNetworkMessage;
#[mockall_double::double]
Expand All @@ -28,6 +31,7 @@ use crate::node::{
};
#[mockall_double::double]
use connection::ConnectionHandle;
use protocol::message_id_generator::MessageIdGenerator;
use std::error::Error;
use tokio::{
net::{
Expand All @@ -54,12 +58,15 @@ pub struct Node {
pub static_key_pem: String,
pub delivery_timeout: u64,
pub(crate) state: State,
pub(crate) echo_broadcast_handle: EchoBroadcastHandle,
}

impl Node {
/// Use builder pattern
pub async fn new() -> Self {
let bind_address = "localhost".to_string();
let message_id_generator = MessageIdGenerator::new(bind_address.clone());
let echo_broadcast_handle = start_echo_broadcast(message_id_generator).await;
Node {
seeds: vec!["localhost:6680".to_string()],
bind_address: bind_address.clone(),
Expand All @@ -68,6 +75,7 @@ impl Node {
state: State {
membership_handle: MembershipHandle::start(bind_address).await,
},
echo_broadcast_handle,
}
}

Expand Down Expand Up @@ -179,7 +187,7 @@ impl Node {
}
let node_id = self.get_node_id();

let handshake_service = protocol::Protocol::new(node_id);
let handshake_service = protocol::Protocol::new(node_id.clone());
let reliable_sender_service =
ReliableSend::new(handshake_service, reliable_sender_handle);
let timeout_layer = tower::timeout::TimeoutLayer::new(
Expand All @@ -189,6 +197,16 @@ impl Node {
.layer(reliable_sender_service)
.oneshot(HandshakeMessage::default_as_message())
.await;

let ping_service = protocol::Protocol::new(node_id.clone());
let echo_broadcast_service = EchoBroadcast::new(
ping_service,
self.echo_broadcast_handle.clone(),
self.state.clone(),
);
let _ = echo_broadcast_service
.oneshot(PingMessage::default_as_message())
.await;
}
}

Expand Down
Loading
Loading