wip big download
This commit is contained in:
@@ -25,6 +25,7 @@ use crate::{
|
||||
server_communication::{generate_id, get_peer_list},
|
||||
threads_handling::Worker,
|
||||
};
|
||||
use std::collections::HashSet;
|
||||
use std::{
|
||||
clone,
|
||||
io::Error,
|
||||
@@ -149,10 +150,11 @@ pub enum NetworkCommand {
|
||||
Disconnect(),
|
||||
ResetServerPeer(),
|
||||
Discover(String, String, String),
|
||||
GetChildren([u8; 32], String),
|
||||
GetChildren([u8; 32], String, bool),
|
||||
SendDatum(MerkleNode, [u8; 32], String),
|
||||
SendNoDatum(Vec<u8>, String),
|
||||
SendRootReply(Vec<u8>, String),
|
||||
InitDownload([u8; 32], String),
|
||||
// ...
|
||||
}
|
||||
|
||||
@@ -165,12 +167,13 @@ pub enum NetworkEvent {
|
||||
PeerConnected(String),
|
||||
PeerListUpdated(Vec<(String, bool)>),
|
||||
FileTreeReceived([u8; 32], MerkleNode, String), // peer_id, content
|
||||
DataReceived(String, MerkleNode),
|
||||
DataReceived([u8; 32], MerkleNode, String),
|
||||
FileTreeRootReceived(String, NodeHash),
|
||||
HandshakeFailed(),
|
||||
ServerHandshakeFailed(String),
|
||||
DatumRequest([u8; 32], String),
|
||||
RootRequest(String),
|
||||
InitDownload([u8; 32], String),
|
||||
// ...
|
||||
}
|
||||
|
||||
@@ -211,6 +214,14 @@ pub fn start_p2p_executor(
|
||||
// Check for commands from the GUI
|
||||
if let Ok(cmd) = cmd_rx.try_recv() {
|
||||
match cmd {
|
||||
NetworkCommand::InitDownload(hash, ip) => {
|
||||
if let Some(sd) = shared_data.as_ref() {
|
||||
if let Some(res) = sd.handshake_peers.get_peer_info_username(ip) {
|
||||
let _ = event_tx
|
||||
.send(NetworkEvent::InitDownload(hash, res.ip.to_string()));
|
||||
}
|
||||
}
|
||||
}
|
||||
NetworkCommand::SendRootReply(node_hash, addr) => {
|
||||
if let Some(sd) = shared_data.as_mut() {
|
||||
let mut payload = Vec::new();
|
||||
@@ -363,7 +374,7 @@ pub fn start_p2p_executor(
|
||||
println!("no shared data");
|
||||
}
|
||||
}
|
||||
NetworkCommand::GetChildren(hash, ip) => {
|
||||
NetworkCommand::GetChildren(hash, ip, is_file) => {
|
||||
if let Some(sd) = shared_data.as_ref() {
|
||||
let mut payload = Vec::new();
|
||||
payload.extend_from_slice(&hash);
|
||||
@@ -377,7 +388,11 @@ pub fn start_p2p_executor(
|
||||
match datumreqest {
|
||||
None => {}
|
||||
Some(resp_msg) => {
|
||||
sd.add_message(new_id, EventType::DatumRequest);
|
||||
if is_file {
|
||||
sd.add_message(new_id, EventType::DatumRequestBig);
|
||||
} else {
|
||||
sd.add_message(new_id, EventType::DatumRequest);
|
||||
}
|
||||
println!("msg_sent:{:?}", resp_msg);
|
||||
sd.senders_ref().add_message_to_retry_queue(
|
||||
resp_msg.clone(),
|
||||
|
||||
Reference in New Issue
Block a user