fix out of boudns
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use client_network::{
|
||||
ChunkNode, MerkleNode, MerkleTree, NetworkCommand, NetworkEvent, NodeHash,
|
||||
big_or_chunk_to_file, filename_to_string, generate_base_tree, node_hash_to_hex_string,
|
||||
remove_null_bytes,
|
||||
node_to_file, remove_null_bytes,
|
||||
};
|
||||
use crossbeam_channel::{Receiver, Sender};
|
||||
use egui::{
|
||||
@@ -258,10 +258,11 @@ impl eframe::App for P2PClientApp {
|
||||
self.loading_peers.retain(|s| s != peer_username.as_str());
|
||||
self.show_error(err, peer_username);
|
||||
}
|
||||
NetworkEvent::InitDownload(hash, ip) => {
|
||||
NetworkEvent::InitDownload(hash, ip, name) => {
|
||||
if let Some(addr) = &self.active_peer {
|
||||
if let Some(roottree) = self.loaded_fs.get(addr) {
|
||||
if let Some(root) = roottree.data.get(&hash) {
|
||||
self.root_downloading_file = name;
|
||||
let _ = self
|
||||
.current_downloading_file_map
|
||||
.data
|
||||
@@ -299,6 +300,29 @@ impl eframe::App for P2PClientApp {
|
||||
_ => {}
|
||||
}
|
||||
if self.remaining_chunks.is_empty() {
|
||||
/*let file = OpenOptions::new()
|
||||
.append(true)
|
||||
.create(true)
|
||||
.open(self.root_downloading_file.clone());
|
||||
|
||||
if let Some(current) = self
|
||||
.current_downloading_file_map
|
||||
.data
|
||||
.get(&self.current_downloading_file_map.root)
|
||||
{
|
||||
match file {
|
||||
Ok(mut fileok) => {
|
||||
big_or_chunk_to_file(
|
||||
&self.current_downloading_file_map,
|
||||
current,
|
||||
&mut fileok,
|
||||
);
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("error creaation file: {}", e);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
println!("bigfile téléchargé");
|
||||
}
|
||||
}
|
||||
@@ -797,10 +821,16 @@ impl P2PClientApp {
|
||||
.on_hover_text("Click to request file chunks...")
|
||||
.clicked()
|
||||
{
|
||||
if let Some(name) = filename {
|
||||
if let Ok(nameb) = String::from_utf8(name.to_vec()) {
|
||||
if let Some(addr) = &self.active_peer {
|
||||
let _ = self
|
||||
.network_cmd_tx
|
||||
.send(NetworkCommand::InitDownload(to_draw, addr.clone()));
|
||||
let _ = self.network_cmd_tx.send(NetworkCommand::InitDownload(
|
||||
to_draw,
|
||||
addr.clone(),
|
||||
nameb,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,8 +154,8 @@ impl MerkleNode {
|
||||
match self {
|
||||
MerkleNode::Chunk(_) => 0,
|
||||
MerkleNode::Directory(_) => 1,
|
||||
MerkleNode::Big(_) => 3,
|
||||
MerkleNode::BigDirectory(_) => 4,
|
||||
MerkleNode::Big(_) => 2,
|
||||
MerkleNode::BigDirectory(_) => 3,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ pub fn parse_received_datum(
|
||||
datum_length: usize,
|
||||
) -> Option<([u8; 32], MerkleNode)> {
|
||||
let hash_name: [u8; 32] = recevied_datum[..32].try_into().expect("error");
|
||||
let value = &recevied_datum[32..datum_length];
|
||||
let value = &recevied_datum[32..recevied_datum.len()];
|
||||
let value_slice = value.to_vec();
|
||||
println!("valueslice: {:?}, {}", value_slice, value_slice.len());
|
||||
let datum_type = value_slice[0];
|
||||
@@ -49,12 +49,22 @@ pub fn parse_received_datum(
|
||||
}
|
||||
}
|
||||
BIG => {
|
||||
let mut bigdir_entries: Vec<NodeHash> = Vec::new();
|
||||
let mut offset = 1 as usize;
|
||||
for i in 0..((value_slice.len() - 1) / 32) as u8 {
|
||||
offset = (1 + 32 * i as usize) as usize;
|
||||
println!("offset:{}, i:{}", offset, i);
|
||||
let hash = &value_slice[offset..offset + 32];
|
||||
|
||||
// envoyer un datum request
|
||||
bigdir_entries.push(hash.try_into().expect("incorrect size"));
|
||||
}
|
||||
|
||||
println!("its a BIG bro");
|
||||
let chlidren: Vec<NodeHash> = Vec::new();
|
||||
Some((
|
||||
hash_name,
|
||||
MerkleNode::Big(crate::BigNode {
|
||||
children_hashes: chlidren,
|
||||
children_hashes: bigdir_entries,
|
||||
}),
|
||||
))
|
||||
}
|
||||
|
||||
@@ -185,7 +185,7 @@ pub enum NetworkCommand {
|
||||
SendDatum(MerkleNode, [u8; 32], String),
|
||||
SendNoDatum(Vec<u8>, String),
|
||||
SendRootReply(Vec<u8>, String),
|
||||
InitDownload([u8; 32], String),
|
||||
InitDownload([u8; 32], String, String),
|
||||
// ...
|
||||
}
|
||||
|
||||
@@ -205,7 +205,7 @@ pub enum NetworkEvent {
|
||||
ServerHandshakeFailed(String),
|
||||
DatumRequest([u8; 32], String),
|
||||
RootRequest(String),
|
||||
InitDownload([u8; 32], String),
|
||||
InitDownload([u8; 32], String, String),
|
||||
// ...
|
||||
}
|
||||
|
||||
@@ -246,11 +246,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) => {
|
||||
NetworkCommand::InitDownload(hash, ip, name) => {
|
||||
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()));
|
||||
let _ = event_tx.send(NetworkEvent::InitDownload(
|
||||
hash,
|
||||
res.ip.to_string(),
|
||||
name.to_string(),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -475,6 +475,7 @@ pub fn parse_message(
|
||||
.try_into()
|
||||
.expect("incorrect size"),
|
||||
);
|
||||
println!("received length:{}", received_length);
|
||||
let received_datum = &received_message[LENGTH..];
|
||||
let parsed_node =
|
||||
parse_received_datum(received_datum.to_vec(), received_length as usize);
|
||||
|
||||
Reference in New Issue
Block a user