peer count in UI
This commit is contained in:
@@ -128,6 +128,7 @@ pub enum PeerEvent {
|
||||
PeerDisconnected(SocketAddr),
|
||||
PeerDiscovered(SocketAddr),
|
||||
PeerLost(SocketAddr),
|
||||
PeerCountUpdated(usize),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
@@ -560,6 +561,7 @@ pub enum PeerCommand {
|
||||
file_descriptions: Vec<GameFileDescription>,
|
||||
},
|
||||
SetGameDir(String),
|
||||
GetPeerCount,
|
||||
}
|
||||
|
||||
async fn initial_peer_alive_check(conn: &mut Connection) -> bool {
|
||||
@@ -1312,6 +1314,9 @@ pub async fn run_peer(
|
||||
PeerCommand::SetGameDir(game_dir) => {
|
||||
handle_set_game_dir_command(&ctx, game_dir).await;
|
||||
}
|
||||
PeerCommand::GetPeerCount => {
|
||||
handle_get_peer_count_command(&ctx, &tx_notify_ui).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1605,6 +1610,14 @@ async fn handle_set_game_dir_command(ctx: &Ctx, game_dir: String) {
|
||||
});
|
||||
}
|
||||
|
||||
async fn handle_get_peer_count_command(ctx: &Ctx, tx_notify_ui: &UnboundedSender<PeerEvent>) {
|
||||
log::info!("GetPeerCount command received");
|
||||
let peer_count = { ctx.peer_game_db.read().await.get_peer_addresses().len() };
|
||||
if let Err(e) = tx_notify_ui.send(PeerEvent::PeerCountUpdated(peer_count)) {
|
||||
log::error!("Failed to send PeerCountUpdated event: {e}");
|
||||
}
|
||||
}
|
||||
|
||||
async fn handle_peer_connection(
|
||||
mut connection: Connection,
|
||||
ctx: PeerCtx,
|
||||
@@ -1836,6 +1849,15 @@ async fn run_peer_discovery(
|
||||
log::error!("Failed to send PeerDiscovered event: {e}");
|
||||
}
|
||||
|
||||
// Send updated peer count
|
||||
let current_peer_count =
|
||||
{ peer_game_db.read().await.get_peer_addresses().len() };
|
||||
if let Err(e) =
|
||||
tx_notify_ui.send(PeerEvent::PeerCountUpdated(current_peer_count))
|
||||
{
|
||||
log::error!("Failed to send PeerCountUpdated event: {e}");
|
||||
}
|
||||
|
||||
// Request games from this peer
|
||||
let tx_notify_ui_clone = tx_notify_ui.clone();
|
||||
let peer_game_db_clone = peer_game_db.clone();
|
||||
@@ -2014,6 +2036,15 @@ async fn run_ping_service(
|
||||
{
|
||||
log::error!("Failed to send PeerLost event: {e}");
|
||||
}
|
||||
|
||||
// Send updated peer count
|
||||
let current_peer_count =
|
||||
{ peer_game_db_clone.read().await.get_peer_addresses().len() };
|
||||
if let Err(e) = tx_notify_ui_clone
|
||||
.send(PeerEvent::PeerCountUpdated(current_peer_count))
|
||||
{
|
||||
log::error!("Failed to send PeerCountUpdated event: {e}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2028,6 +2059,15 @@ async fn run_ping_service(
|
||||
{
|
||||
log::error!("Failed to send PeerLost event: {e}");
|
||||
}
|
||||
|
||||
// Send updated peer count
|
||||
let current_peer_count =
|
||||
{ peer_game_db_clone.read().await.get_peer_addresses().len() };
|
||||
if let Err(e) = tx_notify_ui_clone
|
||||
.send(PeerEvent::PeerCountUpdated(current_peer_count))
|
||||
{
|
||||
log::error!("Failed to send PeerCountUpdated event: {e}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2048,6 +2088,12 @@ async fn run_ping_service(
|
||||
if let Err(e) = tx_notify_ui.send(PeerEvent::PeerLost(stale_addr)) {
|
||||
log::error!("Failed to send PeerLost event: {e}");
|
||||
}
|
||||
|
||||
// Send updated peer count
|
||||
let current_peer_count = { peer_game_db.read().await.get_peer_addresses().len() };
|
||||
if let Err(e) = tx_notify_ui.send(PeerEvent::PeerCountUpdated(current_peer_count)) {
|
||||
log::error!("Failed to send PeerCountUpdated event: {e}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user