diff --git a/chitchat-test/run-servers.ps1 b/chitchat-test/run-servers.ps1 new file mode 100644 index 0000000..7f79923 --- /dev/null +++ b/chitchat-test/run-servers.ps1 @@ -0,0 +1,13 @@ +Get-Process "chitchat-test" | Stop-Process + +cargo build --release + +for ($i = 10000; $i -lt 10100; $i++) +{ + $listen_addr = "127.0.0.1:$i"; + Write-Host $listen_addr; + + Start-Process -NoNewWindow "cargo" -ArgumentList "run --release -- --listen_addr $listen_addr --seed 127.0.0.1:10002 --node_id node_$i" +} + +Read-Host diff --git a/chitchat/src/server.rs b/chitchat/src/server.rs index 81bc446..9d7c464 100644 --- a/chitchat/src/server.rs +++ b/chitchat/src/server.rs @@ -7,7 +7,7 @@ use rand::prelude::*; use tokio::net::lookup_host; use tokio::sync::mpsc::{self, UnboundedReceiver, UnboundedSender}; use tokio::sync::{watch, Mutex}; -use tokio::task::JoinHandle; +use tokio::task::{JoinError, JoinHandle}; use tokio::time; use tracing::{debug, info, warn}; @@ -26,7 +26,7 @@ pub struct ChitchatHandle { chitchat_id: ChitchatId, command_tx: UnboundedSender, chitchat: Arc>, - join_handle: JoinHandle>, + join_handle: JoinHandle<()>, } impl ChitchatHandle { @@ -175,9 +175,9 @@ impl ChitchatHandle { } /// Shuts the server down. - pub async fn shutdown(self) -> Result<(), anyhow::Error> { + pub async fn shutdown(self) -> Result<(), JoinError> { let _ = self.command_tx.send(Command::Shutdown); - self.join_handle.await? + self.join_handle.await } /// Performs a Chitchat "handshake" with another UDP server. @@ -211,7 +211,7 @@ impl Server { } /// Listen for new Chitchat messages. - async fn run(&mut self) -> anyhow::Result<()> { + async fn run(&mut self) { let gossip_interval = self.chitchat.lock().await.config.gossip_interval; let mut gossip_interval = time::interval(gossip_interval); loop { @@ -220,7 +220,7 @@ impl Server { Ok((from_addr, message)) => { let _ = self.handle_message(from_addr, message).await; } - Err(err) => return Err(err), + Err(err) => warn!("communication error: {:#?}", err) }, _ = gossip_interval.tick() => { self.gossip_multiple().await @@ -233,7 +233,6 @@ impl Server { } } } - Ok(()) } /// Processes a single UDP datagram.