code tidy
This commit is contained in:
@@ -102,14 +102,6 @@ impl P2PClientApp {
|
||||
pub fn clear_success(&mut self) {
|
||||
self.success_message = None;
|
||||
}
|
||||
|
||||
fn set_current_total_chunks(&mut self, len: Option<usize>) {
|
||||
self.current_total_chunks = len
|
||||
}
|
||||
|
||||
fn set_current_received_chunks(&mut self, arg: usize) {
|
||||
self.current_received_chunks = arg
|
||||
}
|
||||
}
|
||||
|
||||
impl eframe::App for P2PClientApp {
|
||||
@@ -195,8 +187,8 @@ impl eframe::App for P2PClientApp {
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
NetworkEvent::FileTreeRootReceived(peer_id, root_hash) => {
|
||||
if let Ok(chunknode) = ChunkNode::new(Vec::new()) {
|
||||
NetworkEvent::FileTreeRootReceived(_, root_hash) => {
|
||||
if let Ok(_) = ChunkNode::new(Vec::new()) {
|
||||
let data_map: HashMap<NodeHash, MerkleNode> = HashMap::new();
|
||||
//data_map.insert(root_hash, MerkleNode::Chunk(chunknode));
|
||||
println!("len root: {}", data_map.len());
|
||||
@@ -279,6 +271,13 @@ impl eframe::App for P2PClientApp {
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
if let Some(total) = self.current_total_chunks {
|
||||
// recompute received (safer than incrementing)
|
||||
let received = total.saturating_sub(self.remaining_chunks.len());
|
||||
self.current_received_chunks = received;
|
||||
}
|
||||
|
||||
println!("remaining chunks size: {}", self.remaining_chunks.len());
|
||||
match create_dir("./Download/") {
|
||||
Ok(_) => println!("Directory created successfully!"),
|
||||
@@ -312,17 +311,9 @@ impl eframe::App for P2PClientApp {
|
||||
}
|
||||
println!("bigfile téléchargé {}", self.root_downloading_file);
|
||||
|
||||
if let Some(total) = self.current_total_chunks {
|
||||
// recompute received (safer than incrementing)
|
||||
let received = total.saturating_sub(self.remaining_chunks.len());
|
||||
self.current_received_chunks = received;
|
||||
}
|
||||
|
||||
if self.remaining_chunks.is_empty() {
|
||||
self.current_total_chunks = None;
|
||||
self.current_received_chunks = 0;
|
||||
println!("bigfile téléchargé");
|
||||
}
|
||||
self.current_total_chunks = None;
|
||||
self.current_received_chunks = 0;
|
||||
println!("bigfile téléchargé");
|
||||
}
|
||||
}
|
||||
NetworkEvent::Success(msg, peer_username) => {
|
||||
@@ -440,7 +431,7 @@ impl eframe::App for P2PClientApp {
|
||||
});
|
||||
|
||||
if ui.button("Network").clicked() {
|
||||
self.show_network_window = true;
|
||||
self.show_network_window = !self.show_network_window;
|
||||
}
|
||||
|
||||
if self.show_network_window {
|
||||
@@ -462,6 +453,8 @@ impl eframe::App for P2PClientApp {
|
||||
ServerStatus::NotConnected => {
|
||||
egui::Window::new("Network")
|
||||
.resizable(false)
|
||||
.collapsible(false)
|
||||
.title_bar(false)
|
||||
.show(ctx, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Server IP:");
|
||||
@@ -654,7 +647,7 @@ impl eframe::App for P2PClientApp {
|
||||
_ => {}
|
||||
}
|
||||
if ui.button("Send Ping").clicked() {
|
||||
let res = self.network_cmd_tx.send(NetworkCommand::Ping(
|
||||
let _ = self.network_cmd_tx.send(NetworkCommand::Ping(
|
||||
peer.0.to_string(),
|
||||
self.connected_address.clone(),
|
||||
));
|
||||
@@ -848,7 +841,7 @@ impl P2PClientApp {
|
||||
}
|
||||
});
|
||||
}
|
||||
MerkleNode::Big(node) => {
|
||||
MerkleNode::Big(_) => {
|
||||
if ui
|
||||
.selectable_label(false, format!("📄 (B) {}", name))
|
||||
.on_hover_text("Click to request file chunks...")
|
||||
|
||||
Reference in New Issue
Block a user