diff --git a/Cargo.lock b/Cargo.lock index 12c8fc6..e445b17 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -220,9 +220,9 @@ checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" [[package]] name = "jiff" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a194df1107f33c79f4f93d02c80798520551949d59dfad22b6157048a88cca93" +checksum = "be1f93b8b1eb69c77f24bbb0afdf66f54b632ee39af40ca21c4365a1d7347e49" dependencies = [ "jiff-static", "log", @@ -233,9 +233,9 @@ dependencies = [ [[package]] name = "jiff-static" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c6e1db7ed32c6c71b759497fae34bf7933636f75a251b9e736555da426f6442" +checksum = "03343451ff899767262ec32146f6d559dd759fdadf42ff0e227c7c48f72594b4" dependencies = [ "proc-macro2", "quote", @@ -244,9 +244,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.172" +version = "0.2.174" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa" +checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776" [[package]] name = "log" @@ -263,7 +263,7 @@ checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0" [[package]] name = "messages" version = "0.1.0" -source = "git+https://github.com/Rustastic/Messages.git#3ea77fb9c53e52421b6c7fdb99431b6ee8dcdaa4" +source = "git+https://github.com/Rustastic/Messages.git#8846d524e2f05c45021e19c0ea5a27053b7c3a67" dependencies = [ "bincode", "crossbeam-channel", @@ -332,9 +332,9 @@ dependencies = [ [[package]] name = "r-efi" -version = "5.2.0" +version = "5.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74765f6d916ee2faa39bc8e68e4f3ed8949b48cccdac59983d287a7cb71ce9c5" +checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" [[package]] name = "rand" @@ -456,7 +456,7 @@ dependencies = [ [[package]] name = "source_routing" version = "0.1.0" -source = "git+https://github.com/Rustastic/source_routing.git#9747a832d2ef44a2bd624d6e361aa38984f644a1" +source = "git+https://github.com/Rustastic/source_routing.git?branch=network_caching#b8232459d99bc87fff87bef39d2d9c1011d063ef" dependencies = [ "colored", "crossbeam-channel", @@ -470,9 +470,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.102" +version = "2.0.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6397daf94fa90f058bd0fd88429dd9e5738999cca8d701813c80723add80462" +checksum = "e4307e30089d6fd6aff212f2da3a1f9e32f3223b1f010fb09b7c95f90f3ca1e8" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 4483c67..71c0320 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" wg_2024 = { git = "https://github.com/WGL-2024/WGL_repo_2024.git", features = ["serialize", "debug"] } messages = { git = "https://github.com/Rustastic/Messages.git"} assembler = { git = "https://github.com/Rustastic/Assembler.git"} -source_routing = { git = "https://github.com/Rustastic/source_routing.git"} +source_routing = { git = "https://github.com/Rustastic/source_routing.git", branch = "network_caching"} crossbeam-channel = "0.5.13" toml = "0.8.19" rand = "0.8.0" diff --git a/src/chat_client/handle_command/flooding.rs b/src/chat_client/handle_command/flooding.rs deleted file mode 100644 index ce8aabf..0000000 --- a/src/chat_client/handle_command/flooding.rs +++ /dev/null @@ -1,28 +0,0 @@ -use colored::Colorize; -use log::{error, info}; - -use crate::ChatClient; - -impl ChatClient { - pub fn start_flooding(&mut self) { - let flood_request_packet = self.router.get_flood_request(); - self.router.clear_routing_table(); - for (neighbor, channel) in &self.packet_send { - if let Ok(()) = channel.send(flood_request_packet.clone()) { - info!( - "{} [ ChatClient {} ]: FloodRequest sent to [ Drone {} ]", - "✓".green(), - self.id, - neighbor - ); - } else { - error!( - "{} [ ChatClient {} ]: Failed to send FloodRequest to [ Drone {} ]", - "✗".red(), - self.id, - neighbor - ); - } - } - } -} diff --git a/src/chat_client/handle_command/mod.rs b/src/chat_client/handle_command/mod.rs index df465e9..1451349 100644 --- a/src/chat_client/handle_command/mod.rs +++ b/src/chat_client/handle_command/mod.rs @@ -4,10 +4,10 @@ use messages::{ client_commands::{ChatClientCommand, ChatClientEvent}, high_level_messages::{ClientMessage, MessageContent}, }; +use std::{thread, time::Duration}; use super::ChatClient; -mod flooding; mod send_message; impl ChatClient { @@ -25,6 +25,7 @@ impl ChatClient { self.id, ); e.insert(sender); + self.router.add_neighbour(node_id); } else { warn!( "{} [ ChatClient {} ] is already connected to [ Drone {} ]", @@ -43,6 +44,7 @@ impl ChatClient { self.id ); self.packet_send.remove(&node_id); + self.router.remove_neighbour(node_id); } else { warn!( "{} [ ChatClient {} ] is already disconnected from [ Drone {} ]", @@ -58,7 +60,17 @@ impl ChatClient { "ℹ".blue(), self.id ); - self.start_flooding(); + let requests = self.router.get_flood_requests(self.packet_send.len()); + for (sender, request) in self.packet_send.values().zip(requests) { + if sender.send(request).is_err() { + error!( + "{} [ ChatClient {} ]: Failed to send floodrequest", + "✓".green(), + self.id + ); + } + } + thread::sleep(Duration::from_secs(2)); } ChatClientCommand::StartChatClient => { self.running = true; diff --git a/src/chat_client/handle_packet/mod.rs b/src/chat_client/handle_packet/mod.rs index 72917bf..97a1433 100644 --- a/src/chat_client/handle_packet/mod.rs +++ b/src/chat_client/handle_packet/mod.rs @@ -1,3 +1,5 @@ +use std::{thread, time::Duration}; + use super::ChatClient; use colored::Colorize; use log::{error, info, warn}; @@ -391,14 +393,13 @@ impl ChatClient { self.router.dropped_fragment(unreachable_node); - if let Some(incorrect_packet) = - self - .msgfactory - .take_packet(packet.session_id, nack.fragment_index) + if let Some(incorrect_packet) = self + .msgfactory + .take_packet(packet.session_id, nack.fragment_index) { let dest = incorrect_packet.routing_header.destination().unwrap(); - let _ = self.router.drone_crashed(unreachable_node); + self.router.drone_crashed(unreachable_node); if let Ok(new_routing_header) = self.router.get_source_routing_header(dest) { let new_packet = Packet { @@ -424,7 +425,6 @@ impl ChatClient { self.id, dest ); - self.reinit_network(); } } } @@ -438,14 +438,30 @@ impl ChatClient { ); } NackType::Dropped => { - - self.router.dropped_fragment(nack_src); if let Some((dropped_packet, requests)) = self .msgfactory .get_packet(packet.session_id, nack.fragment_index) { + if requests > 100 { + info!( + "{} [ ChatClient {} ]: Reinitializing network due to excessive dropped requests", + "ℹ".blue(), + self.id + ); + let requests = self.router.get_flood_requests(self.packet_send.len()); + for (sender, request) in self.packet_send.values().zip(requests) { + if sender.send(request).is_err() { + error!( + "{} [ ChatClient {} ]: Failed to send floodrequest", + "✓".green(), + self.id + ); + } + } + thread::sleep(Duration::from_secs(2)); + } error!( "{} [ ChatClient {} ]: Packet with session_id: {} and fragment_index: {} has been dropped", "✗".red(), @@ -453,17 +469,6 @@ impl ChatClient { dropped_packet.session_id, nack.fragment_index ); - - if requests > 100 { - error!( - "{} [ ChatClient {} ]: Packet with session_id: {} and fragment_index: {} has been dropped more than 100 times. Dropping permanently.", - "✗".red(), - self.id, - dropped_packet.session_id, - nack.fragment_index - ); - return; - } let destination = dropped_packet.routing_header.destination().unwrap(); @@ -494,7 +499,6 @@ impl ChatClient { self.id, destination ); - self.reinit_network(); } } } diff --git a/src/chat_client/mod.rs b/src/chat_client/mod.rs index 84841ca..00bdc5a 100644 --- a/src/chat_client/mod.rs +++ b/src/chat_client/mod.rs @@ -1,14 +1,11 @@ use assembler::HighLevelMessageFactory; -use colored::Colorize; use crossbeam_channel::{select_biased, Receiver, Sender}; -use log::info; use messages::{ client_commands::{ChatClientCommand, ChatClientEvent}, high_level_messages::Message, }; use source_routing::Router; -use std::thread; -use std::{collections::HashMap, time::Duration}; +use std::collections::HashMap; use wg_2024::{ network::NodeId, packet::{NodeType, Packet}, @@ -107,14 +104,4 @@ impl ChatClient { } } } - - fn reinit_network(&mut self) { - info!( - "{} [ ChatClient {} ]: reinitializing the network...", - "✓".green(), - self.id - ); - self.start_flooding(); - thread::sleep(Duration::from_secs(2)); - } }