Skip to content
Open
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
13 changes: 13 additions & 0 deletions chitchat-test/run-servers.ps1
Original file line number Diff line number Diff line change
@@ -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
13 changes: 6 additions & 7 deletions chitchat/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -26,7 +26,7 @@ pub struct ChitchatHandle {
chitchat_id: ChitchatId,
command_tx: UnboundedSender<Command>,
chitchat: Arc<Mutex<Chitchat>>,
join_handle: JoinHandle<Result<(), anyhow::Error>>,
join_handle: JoinHandle<()>,
}

impl ChitchatHandle {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -233,7 +233,6 @@ impl Server {
}
}
}
Ok(())
}

/// Processes a single UDP datagram.
Expand Down