Compare commits
4 Commits
nat_transv
...
341f8f123d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
341f8f123d | ||
|
|
c59ce1be55 | ||
|
|
f735ab34fc | ||
|
|
b54e044ab1 |
@@ -1,5 +1,5 @@
|
|||||||
use client_network::{
|
use client_network::{
|
||||||
ChunkNode, MerkleNode, MerkleTree, NetworkCommand, NetworkEvent, NodeHash, filename_to_string,
|
MerkleNode, MerkleTree, NetworkCommand, NetworkEvent, NodeHash, filename_to_string,
|
||||||
node_hash_to_hex_string,
|
node_hash_to_hex_string,
|
||||||
};
|
};
|
||||||
use crossbeam_channel::{Receiver, Sender};
|
use crossbeam_channel::{Receiver, Sender};
|
||||||
@@ -49,11 +49,11 @@ pub struct P2PClientApp {
|
|||||||
|
|
||||||
impl P2PClientApp {
|
impl P2PClientApp {
|
||||||
pub fn new(cmd_tx: Sender<NetworkCommand>, event_rx: Receiver<NetworkEvent>) -> Self {
|
pub fn new(cmd_tx: Sender<NetworkCommand>, event_rx: Receiver<NetworkEvent>) -> Self {
|
||||||
//let (root_hash, tree_content) = MerkleNode::generate_base_tree();
|
let (root_hash, tree_content) = MerkleNode::generate_base_tree();
|
||||||
|
|
||||||
let mut loaded_fs = HashMap::new();
|
let mut loaded_fs = HashMap::new();
|
||||||
//let tree = MerkleTree::new(tree_content, root_hash);
|
let tree = MerkleTree::new(tree_content, root_hash);
|
||||||
//loaded_fs.insert("bob".to_string(), tree);
|
loaded_fs.insert("bob".to_string(), tree);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
remaining: std::time::Duration::from_secs(0),
|
remaining: std::time::Duration::from_secs(0),
|
||||||
@@ -123,41 +123,23 @@ impl eframe::App for P2PClientApp {
|
|||||||
NetworkEvent::FileTreeReceived(_peer_id, _) => {
|
NetworkEvent::FileTreeReceived(_peer_id, _) => {
|
||||||
todo!();
|
todo!();
|
||||||
|
|
||||||
//self.loaded_tree_nodes.insert(_peer_id, tree);
|
// self.loaded_tree_nodes.insert(_peer_id, tree);
|
||||||
//self.status_message = "🔄 File tree updated successfully.".to_string();
|
self.status_message = "🔄 File tree updated successfully.".to_string();
|
||||||
}
|
}
|
||||||
NetworkEvent::FileTreeRootReceived(peer_id, root_hash) => {
|
NetworkEvent::FileTreeRootReceived(peer_id, root_hash) => {
|
||||||
// todo!();
|
todo!();
|
||||||
|
|
||||||
/*self.status_message = format!(
|
// self.status_message = format!("🔄 Received Merkle Root from {}: {}", peer_id, &root_hash[..8]);
|
||||||
"🔄 Received Merkle Root from {}: {}",
|
//
|
||||||
peer_id,
|
//
|
||||||
&root_hash[..8]
|
// self.active_peer_id = Some(peer_id.clone());
|
||||||
);*/
|
//
|
||||||
|
//
|
||||||
if let Ok(chunknode) = ChunkNode::new(Vec::new()) {
|
// // Request the content of the root directory immediately
|
||||||
let mut data_map: HashMap<NodeHash, MerkleNode> = HashMap::new();
|
// let _ = self.network_cmd_tx.send(NetworkCommand::RequestDirectoryContent(
|
||||||
data_map.insert(root_hash, MerkleNode::Chunk(chunknode));
|
// peer_id,
|
||||||
let tree = MerkleTree {
|
// root_hash,
|
||||||
data: data_map,
|
// ));
|
||||||
root: root_hash,
|
|
||||||
};
|
|
||||||
match &self.active_peer {
|
|
||||||
Some(activepeer) => {
|
|
||||||
self.loaded_fs.insert(activepeer.clone(), tree);
|
|
||||||
}
|
|
||||||
None => {}
|
|
||||||
}
|
|
||||||
|
|
||||||
println!("tree created");
|
|
||||||
}
|
|
||||||
|
|
||||||
//self.active_peer_id = Some(peer_id.clone());
|
|
||||||
|
|
||||||
// Request the content of the root directory immediately
|
|
||||||
/*let _ = self
|
|
||||||
.network_cmd_tx
|
|
||||||
.send(NetworkCommand::RequestDirectoryContent(peer_id, root_hash));*/
|
|
||||||
}
|
}
|
||||||
NetworkEvent::Connected(ip) => {
|
NetworkEvent::Connected(ip) => {
|
||||||
self.server_status = ServerStatus::Connected;
|
self.server_status = ServerStatus::Connected;
|
||||||
@@ -378,12 +360,9 @@ impl eframe::App for P2PClientApp {
|
|||||||
.loaded_fs
|
.loaded_fs
|
||||||
.contains_key(self.active_peer.as_ref().unwrap())
|
.contains_key(self.active_peer.as_ref().unwrap())
|
||||||
{
|
{
|
||||||
//todo!();
|
let _ = self
|
||||||
let _ = self.network_cmd_tx.send(NetworkCommand::Discover(
|
.network_cmd_tx
|
||||||
peer.0.clone(),
|
.send(NetworkCommand::ConnectPeer(peer.clone()));
|
||||||
"root".to_string(),
|
|
||||||
self.connected_address.clone(),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
selectable.context_menu(|ui| {
|
selectable.context_menu(|ui| {
|
||||||
@@ -546,13 +525,7 @@ impl P2PClientApp {
|
|||||||
entry.content_hash,
|
entry.content_hash,
|
||||||
tree,
|
tree,
|
||||||
depth + 1,
|
depth + 1,
|
||||||
Some(
|
Some(entry.filename),
|
||||||
entry
|
|
||||||
.filename
|
|
||||||
.as_slice()
|
|
||||||
.try_into()
|
|
||||||
.expect("incorrect size"),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -573,7 +546,7 @@ impl P2PClientApp {
|
|||||||
.enabled(true)
|
.enabled(true)
|
||||||
.show(ui, |ui| {
|
.show(ui, |ui| {
|
||||||
for child in &node.children_hashes {
|
for child in &node.children_hashes {
|
||||||
self.draw_file_node(ui, child.content_hash, tree, depth + 1, None);
|
self.draw_file_node(ui, child.clone(), tree, depth + 1, None);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ use p256::ecdsa::{
|
|||||||
signature::{Signer, Verifier},
|
signature::{Signer, Verifier},
|
||||||
};
|
};
|
||||||
use rand_core::OsRng;
|
use rand_core::OsRng;
|
||||||
use reqwest::Error;
|
|
||||||
use sha2::{Digest, Sha256};
|
use sha2::{Digest, Sha256};
|
||||||
|
|
||||||
///
|
///
|
||||||
@@ -51,24 +50,19 @@ pub async fn get_peer_key(username: &String) -> Result<VerifyingKey, reqwest::Er
|
|||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::new();
|
||||||
let uri = format!("https://jch.irif.fr:8443/peers/{}/key", username);
|
let uri = format!("https://jch.irif.fr:8443/peers/{}/key", username);
|
||||||
let res = client.get(uri).send().await?;
|
let res = client.get(uri).send().await?;
|
||||||
|
if res.status().is_success() {
|
||||||
match res.error_for_status_ref() {
|
println!("Successfully retreived the peers key.");
|
||||||
Ok(_) => {
|
} else {
|
||||||
println!("Successfully retreived the peers key.");
|
eprintln!(
|
||||||
let body: Bytes = res.bytes().await?;
|
"Failed to get the peers key from the server. Status: {}",
|
||||||
let slice: &[u8] = body.as_ref();
|
res.status()
|
||||||
let body_bytes: &[u8; 64] = slice.try_into().expect("size error");
|
);
|
||||||
let received_key = convert_verifyingkey(body_bytes);
|
|
||||||
Ok(received_key)
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
eprintln!(
|
|
||||||
"Failed to get the peers key from the server. Status: {}",
|
|
||||||
res.status()
|
|
||||||
);
|
|
||||||
Err(e)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
let body: Bytes = res.bytes().await?;
|
||||||
|
let slice: &[u8] = body.as_ref();
|
||||||
|
let body_bytes: &[u8; 64] = slice.try_into().expect("size error");
|
||||||
|
let received_key = convert_verifyingkey(body_bytes);
|
||||||
|
Ok(received_key)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn convert_verifyingkey(raw_xy: &[u8; 64]) -> VerifyingKey {
|
fn convert_verifyingkey(raw_xy: &[u8; 64]) -> VerifyingKey {
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ impl MerkleTree {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*fn generate_random_file_node(
|
fn generate_random_file_node(
|
||||||
storage: &mut HashMap<NodeHash, MerkleNode>,
|
storage: &mut HashMap<NodeHash, MerkleNode>,
|
||||||
) -> Result<NodeHash, String> {
|
) -> Result<NodeHash, String> {
|
||||||
let mut rng = rng();
|
let mut rng = rng();
|
||||||
@@ -110,9 +110,9 @@ impl MerkleTree {
|
|||||||
storage.insert(hash, node);
|
storage.insert(hash, node);
|
||||||
Ok(hash)
|
Ok(hash)
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
|
|
||||||
/*fn generate_random_directory_node(
|
fn generate_random_directory_node(
|
||||||
depth: u32,
|
depth: u32,
|
||||||
max_depth: u32,
|
max_depth: u32,
|
||||||
storage: &mut HashMap<NodeHash, MerkleNode>,
|
storage: &mut HashMap<NodeHash, MerkleNode>,
|
||||||
@@ -172,7 +172,7 @@ impl MerkleTree {
|
|||||||
storage.insert(hash, node);
|
storage.insert(hash, node);
|
||||||
Ok(hash)
|
Ok(hash)
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct ChunkNode {
|
pub struct ChunkNode {
|
||||||
@@ -208,7 +208,7 @@ impl ChunkNode {
|
|||||||
// Helper struct
|
// Helper struct
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct DirectoryEntry {
|
pub struct DirectoryEntry {
|
||||||
pub filename: Vec<u8>,
|
pub filename: [u8; FILENAME_HASH_SIZE],
|
||||||
pub content_hash: NodeHash,
|
pub content_hash: NodeHash,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -240,7 +240,7 @@ pub struct BigNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl BigNode {
|
impl BigNode {
|
||||||
/*pub fn new(children_hashes: Vec<NodeHash>) -> Result<Self, String> {
|
pub fn new(children_hashes: Vec<NodeHash>) -> Result<Self, String> {
|
||||||
let n = children_hashes.len();
|
let n = children_hashes.len();
|
||||||
if n < MIN_BIG_CHILDREN || n > MAX_BIG_CHILDREN {
|
if n < MIN_BIG_CHILDREN || n > MAX_BIG_CHILDREN {
|
||||||
return Err(format!(
|
return Err(format!(
|
||||||
@@ -249,17 +249,16 @@ impl BigNode {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
Ok(BigNode { children_hashes })
|
Ok(BigNode { children_hashes })
|
||||||
}*/
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct BigDirectoryNode {
|
pub struct BigDirectoryNode {
|
||||||
//pub children_hashes: Vec<NodeHash>,
|
pub children_hashes: Vec<NodeHash>,
|
||||||
pub children_hashes: Vec<DirectoryEntry>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BigDirectoryNode {
|
impl BigDirectoryNode {
|
||||||
/*pub fn new(children_hashes: Vec<NodeHash>) -> Result<Self, String> {
|
pub fn new(children_hashes: Vec<NodeHash>) -> Result<Self, String> {
|
||||||
let n = children_hashes.len();
|
let n = children_hashes.len();
|
||||||
if n < MIN_BIG_CHILDREN || n > MAX_BIG_CHILDREN {
|
if n < MIN_BIG_CHILDREN || n > MAX_BIG_CHILDREN {
|
||||||
return Err(format!(
|
return Err(format!(
|
||||||
@@ -268,14 +267,6 @@ impl BigDirectoryNode {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
Ok(BigDirectoryNode { children_hashes })
|
Ok(BigDirectoryNode { children_hashes })
|
||||||
}*/
|
|
||||||
pub fn new(entries: Vec<DirectoryEntry>) -> Result<Self, String> {
|
|
||||||
if entries.len() > MAX_DIRECTORY_ENTRIES {
|
|
||||||
return Err(format!("Directory exceeds {} bytes", entries.len()));
|
|
||||||
}
|
|
||||||
Ok(BigDirectoryNode {
|
|
||||||
children_hashes: entries,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -310,14 +301,14 @@ impl MerkleNode {
|
|||||||
}
|
}
|
||||||
MerkleNode::BigDirectory(node) => {
|
MerkleNode::BigDirectory(node) => {
|
||||||
for hash in &node.children_hashes {
|
for hash in &node.children_hashes {
|
||||||
bytes.extend_from_slice(&hash.content_hash);
|
bytes.extend_from_slice(hash);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bytes
|
bytes
|
||||||
}
|
}
|
||||||
|
|
||||||
/*pub fn generate_random_tree(
|
pub fn generate_random_tree(
|
||||||
max_depth: u32,
|
max_depth: u32,
|
||||||
) -> Result<(NodeHash, HashMap<NodeHash, MerkleNode>), String> {
|
) -> Result<(NodeHash, HashMap<NodeHash, MerkleNode>), String> {
|
||||||
let mut storage = HashMap::new();
|
let mut storage = HashMap::new();
|
||||||
@@ -326,9 +317,9 @@ impl MerkleNode {
|
|||||||
let root_hash = generate_random_directory_node(0, max_depth, &mut storage)?;
|
let root_hash = generate_random_directory_node(0, max_depth, &mut storage)?;
|
||||||
|
|
||||||
Ok((root_hash, storage))
|
Ok((root_hash, storage))
|
||||||
}*/
|
}
|
||||||
|
|
||||||
/*pub fn generate_base_tree() -> (NodeHash, HashMap<NodeHash, MerkleNode>) {
|
pub fn generate_base_tree() -> (NodeHash, HashMap<NodeHash, MerkleNode>) {
|
||||||
let mut res = HashMap::new();
|
let mut res = HashMap::new();
|
||||||
|
|
||||||
let node1 = MerkleNode::Chunk(ChunkNode::new_random());
|
let node1 = MerkleNode::Chunk(ChunkNode::new_random());
|
||||||
@@ -378,5 +369,5 @@ impl MerkleNode {
|
|||||||
res.insert(root_hash, root);
|
res.insert(root_hash, root);
|
||||||
|
|
||||||
(root_hash, res)
|
(root_hash, res)
|
||||||
}*/
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,96 +1 @@
|
|||||||
use crate::{BigDirectoryNode, DirectoryEntry, DirectoryNode, MerkleNode, MerkleTree, NodeHash};
|
fn parse_received_datum(recevied_datum: Vec<u8>) {}
|
||||||
use sha2::{Digest, Sha256};
|
|
||||||
|
|
||||||
const CHUNK: u8 = 0;
|
|
||||||
const DIRECTORY: u8 = 1;
|
|
||||||
const BIG: u8 = 2;
|
|
||||||
const BIGDIRECTORY: u8 = 3;
|
|
||||||
|
|
||||||
fn parse_received_datum(recevied_datum: Vec<u8>, datum_length: usize, mut tree: MerkleTree) {
|
|
||||||
if datum_length > recevied_datum.len() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if datum_length < 32 + 64 {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let hash_name: [u8; 32] = recevied_datum[..32].try_into().expect("error");
|
|
||||||
let sigstart = datum_length - 64;
|
|
||||||
let value = &recevied_datum[32..sigstart];
|
|
||||||
let value_slice = value.to_vec();
|
|
||||||
let signature: [u8; 32] = recevied_datum[sigstart..datum_length]
|
|
||||||
.try_into()
|
|
||||||
.expect("Taille incorrecte");
|
|
||||||
let datum_type = value_slice[0];
|
|
||||||
match datum_type {
|
|
||||||
CHUNK => {
|
|
||||||
tree.data.insert(
|
|
||||||
hash_name,
|
|
||||||
MerkleNode::Chunk(crate::ChunkNode { data: value_slice }),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
DIRECTORY => {
|
|
||||||
let nb_entries = value_slice[1];
|
|
||||||
let mut dir_entries = Vec::new();
|
|
||||||
let mut offset = 1 as usize;
|
|
||||||
for i in 0..nb_entries {
|
|
||||||
offset = (offset as u8 + 64 * i) as usize;
|
|
||||||
let name = &recevied_datum[offset..offset + 32];
|
|
||||||
let mut hash = [0u8; 32];
|
|
||||||
hash.copy_from_slice(&recevied_datum[offset + 32..offset + 64]);
|
|
||||||
// envoyer un datum request
|
|
||||||
dir_entries.push(DirectoryEntry {
|
|
||||||
filename: name.to_vec(),
|
|
||||||
content_hash: hash,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
let current = DirectoryNode::new(dir_entries);
|
|
||||||
match current {
|
|
||||||
Ok(current_node) => {
|
|
||||||
tree.data
|
|
||||||
.insert(hash_name, MerkleNode::Directory(current_node));
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
println!("{}", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
BIG => {
|
|
||||||
let chlidren: Vec<NodeHash> = Vec::new();
|
|
||||||
tree.data.insert(
|
|
||||||
hash_name,
|
|
||||||
MerkleNode::Big(crate::BigNode {
|
|
||||||
children_hashes: chlidren,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
BIGDIRECTORY => {
|
|
||||||
let nb_entries = value_slice[1];
|
|
||||||
let mut dir_entries = Vec::new();
|
|
||||||
let mut offset = 1 as usize;
|
|
||||||
for i in 0..nb_entries {
|
|
||||||
offset = (offset as u8 + 64 * i) as usize;
|
|
||||||
let name = &recevied_datum[offset..offset + 32];
|
|
||||||
let mut hash = [0u8; 32];
|
|
||||||
hash.copy_from_slice(&recevied_datum[offset + 32..offset + 64]);
|
|
||||||
// envoyer un datum request
|
|
||||||
dir_entries.push(DirectoryEntry {
|
|
||||||
filename: name.to_vec(),
|
|
||||||
content_hash: hash,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
let current = BigDirectoryNode::new(dir_entries);
|
|
||||||
match current {
|
|
||||||
Ok(current_node) => {
|
|
||||||
tree.data
|
|
||||||
.insert(hash_name, MerkleNode::BigDirectory(current_node));
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
println!("{}", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -12,16 +12,13 @@ use crate::{
|
|||||||
cryptographic_signature::CryptographicSignature,
|
cryptographic_signature::CryptographicSignature,
|
||||||
message_handling::EventType,
|
message_handling::EventType,
|
||||||
messages_channels::{MultipleSenders, start_receving_thread},
|
messages_channels::{MultipleSenders, start_receving_thread},
|
||||||
messages_structure::{
|
messages_structure::{NATTRAVERSALREQUEST, NATTRAVERSALREQUEST2, construct_message},
|
||||||
NATTRAVERSALREQUEST, NATTRAVERSALREQUEST2, ROOTREQUEST, construct_message,
|
registration::{parse_addresses, register_ip_addresses, register_with_the_server},
|
||||||
},
|
|
||||||
peers_refresh::HandshakeHistory,
|
|
||||||
registration::{parse_addresses, perform_handshake, register_with_the_server},
|
|
||||||
server_communication::{generate_id, get_peer_list},
|
server_communication::{generate_id, get_peer_list},
|
||||||
};
|
};
|
||||||
use std::{
|
use std::{
|
||||||
io::Error,
|
io::Error,
|
||||||
net::{IpAddr, Ipv4Addr, UdpSocket},
|
net::{Ipv4Addr, UdpSocket},
|
||||||
};
|
};
|
||||||
use std::{
|
use std::{
|
||||||
net::SocketAddr,
|
net::SocketAddr,
|
||||||
@@ -34,7 +31,6 @@ pub struct P2PSharedData {
|
|||||||
shared_messageslist: Arc<Mutex<HashMap<i32, EventType>>>,
|
shared_messageslist: Arc<Mutex<HashMap<i32, EventType>>>,
|
||||||
shared_senders: Arc<MultipleSenders>,
|
shared_senders: Arc<MultipleSenders>,
|
||||||
server_name: Arc<Mutex<String>>,
|
server_name: Arc<Mutex<String>>,
|
||||||
handshake_peers: Arc<HandshakeHistory>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
@@ -56,14 +52,12 @@ impl P2PSharedData {
|
|||||||
let senders = MultipleSenders::new(1, &shared_socket, cmd_tx);
|
let senders = MultipleSenders::new(1, &shared_socket, cmd_tx);
|
||||||
let shared_senders = Arc::new(senders);
|
let shared_senders = Arc::new(senders);
|
||||||
let server_name = Arc::new(Mutex::new("".to_string()));
|
let server_name = Arc::new(Mutex::new("".to_string()));
|
||||||
let handhsake_peers = Arc::new(HandshakeHistory::new());
|
|
||||||
Ok(P2PSharedData {
|
Ok(P2PSharedData {
|
||||||
shared_socket: shared_socket,
|
shared_socket: shared_socket,
|
||||||
shared_cryptopair: shared_cryptopair,
|
shared_cryptopair: shared_cryptopair,
|
||||||
shared_messageslist: shared_messageslist,
|
shared_messageslist: shared_messageslist,
|
||||||
shared_senders: shared_senders,
|
shared_senders: shared_senders,
|
||||||
server_name: server_name,
|
server_name: server_name,
|
||||||
handshake_peers: handhsake_peers,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
pub fn socket(&self) -> Arc<UdpSocket> {
|
pub fn socket(&self) -> Arc<UdpSocket> {
|
||||||
@@ -94,9 +88,6 @@ impl P2PSharedData {
|
|||||||
pub fn cryptopair_ref(&self) -> &CryptographicSignature {
|
pub fn cryptopair_ref(&self) -> &CryptographicSignature {
|
||||||
&*self.shared_cryptopair
|
&*self.shared_cryptopair
|
||||||
}
|
}
|
||||||
pub fn handshake_ref(&self) -> &HandshakeHistory {
|
|
||||||
&*self.handshake_peers
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn messages_list_ref(&self) -> &Mutex<HashMap<i32, EventType>> {
|
pub fn messages_list_ref(&self) -> &Mutex<HashMap<i32, EventType>> {
|
||||||
&*self.shared_messageslist
|
&*self.shared_messageslist
|
||||||
@@ -126,8 +117,6 @@ pub enum NetworkCommand {
|
|||||||
RequestChunk(String, String),
|
RequestChunk(String, String),
|
||||||
Disconnect(),
|
Disconnect(),
|
||||||
ResetServerPeer(),
|
ResetServerPeer(),
|
||||||
Discover(String, String, String),
|
|
||||||
GetChildren(String, String),
|
|
||||||
// ...
|
// ...
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,7 +130,7 @@ pub enum NetworkEvent {
|
|||||||
PeerListUpdated(Vec<(String, bool)>),
|
PeerListUpdated(Vec<(String, bool)>),
|
||||||
FileTreeReceived(String, Vec<MerkleNode>), // peer_id, content
|
FileTreeReceived(String, Vec<MerkleNode>), // peer_id, content
|
||||||
DataReceived(String, MerkleNode),
|
DataReceived(String, MerkleNode),
|
||||||
FileTreeRootReceived(String, NodeHash),
|
FileTreeRootReceived(String, String),
|
||||||
HandshakeFailed(),
|
HandshakeFailed(),
|
||||||
ServerHandshakeFailed(String),
|
ServerHandshakeFailed(String),
|
||||||
// ...
|
// ...
|
||||||
@@ -176,8 +165,6 @@ pub fn start_p2p_executor(
|
|||||||
// Use tokio to spawn the asynchronous networking logic
|
// Use tokio to spawn the asynchronous networking logic
|
||||||
tokio::task::spawn(async move {
|
tokio::task::spawn(async move {
|
||||||
// P2P/Networking Setup goes here
|
// P2P/Networking Setup goes here
|
||||||
let handshake_history = Arc::new(Mutex::new(HandshakeHistory::new()));
|
|
||||||
let handshake_clone = handshake_history.clone();
|
|
||||||
|
|
||||||
println!("Network executor started.");
|
println!("Network executor started.");
|
||||||
|
|
||||||
@@ -187,13 +174,33 @@ pub fn start_p2p_executor(
|
|||||||
if let Ok(cmd) = cmd_rx.try_recv() {
|
if let Ok(cmd) = cmd_rx.try_recv() {
|
||||||
match cmd {
|
match cmd {
|
||||||
NetworkCommand::ServerHandshake(username, ip) => {
|
NetworkCommand::ServerHandshake(username, ip) => {
|
||||||
println!("server handshake called");
|
|
||||||
if let Some(sd) = shared_data.as_ref() {
|
if let Some(sd) = shared_data.as_ref() {
|
||||||
start_receving_thread(sd, event_tx.clone(), &handshake_clone);
|
println!("username:{}, ip:{}", username, ip);
|
||||||
let res =
|
let server_addr_query = get_socket_address(username.clone(), ip);
|
||||||
perform_handshake(&sd, username, ip, event_tx.clone(), true).await;
|
|
||||||
} else {
|
match server_addr_query.await {
|
||||||
println!("no shared data");
|
Some(server_address) => {
|
||||||
|
sd.set_servername(username);
|
||||||
|
// first: &SocketAddr
|
||||||
|
start_receving_thread(
|
||||||
|
sd,
|
||||||
|
server_address, // copie le SocketAddr (implémente Copy pour SocketAddr)
|
||||||
|
event_tx.clone(), //
|
||||||
|
);
|
||||||
|
register_ip_addresses(
|
||||||
|
sd.cryptopair_ref(),
|
||||||
|
server_address.to_string(),
|
||||||
|
sd.senders_ref(),
|
||||||
|
sd.messages_list_ref(),
|
||||||
|
generate_id(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
let err_msg =
|
||||||
|
format!("failed to retreive socket address").to_string();
|
||||||
|
let res = event_tx.send(NetworkEvent::Error(err_msg));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
NetworkCommand::ConnectPeer((username, connected)) => {
|
NetworkCommand::ConnectPeer((username, connected)) => {
|
||||||
@@ -206,56 +213,6 @@ pub fn start_p2p_executor(
|
|||||||
NetworkCommand::RequestFileTree(_) => {
|
NetworkCommand::RequestFileTree(_) => {
|
||||||
println!("[Network] RequestFileTree() called");
|
println!("[Network] RequestFileTree() called");
|
||||||
}
|
}
|
||||||
NetworkCommand::Discover(username, hash, ip) => {
|
|
||||||
// envoie un handshake au peer, puis un root request
|
|
||||||
if let Some(sd) = shared_data.as_ref() {
|
|
||||||
let res = {
|
|
||||||
let m = handshake_clone.lock().unwrap();
|
|
||||||
m.get_peer_info_username(username.clone()).cloned()
|
|
||||||
};
|
|
||||||
match res {
|
|
||||||
Some(peerinfo) => {
|
|
||||||
// envoyer un root request
|
|
||||||
let rootrequest = construct_message(
|
|
||||||
ROOTREQUEST,
|
|
||||||
Vec::new(),
|
|
||||||
generate_id(),
|
|
||||||
sd.cryptopair_ref(),
|
|
||||||
);
|
|
||||||
|
|
||||||
match rootrequest {
|
|
||||||
None => {}
|
|
||||||
Some(resp_msg) => {
|
|
||||||
println!("msg_sent:{:?}", resp_msg);
|
|
||||||
sd.senders_ref().send_via(
|
|
||||||
0,
|
|
||||||
resp_msg,
|
|
||||||
peerinfo.ip.to_string(),
|
|
||||||
false,
|
|
||||||
sd.messages_list_ref(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
// envoyer un handshake
|
|
||||||
let res = perform_handshake(
|
|
||||||
&sd,
|
|
||||||
username,
|
|
||||||
ip,
|
|
||||||
event_tx.clone(),
|
|
||||||
false,
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
println!("no shared data");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
NetworkCommand::GetChildren(username, hash) => {
|
|
||||||
// envoie un datum request au peer
|
|
||||||
}
|
|
||||||
NetworkCommand::RequestDirectoryContent(_, _) => {
|
NetworkCommand::RequestDirectoryContent(_, _) => {
|
||||||
println!("[Network] RequestDirectoryContent() called");
|
println!("[Network] RequestDirectoryContent() called");
|
||||||
}
|
}
|
||||||
@@ -366,13 +323,15 @@ pub fn start_p2p_executor(
|
|||||||
match server_addr_query.await {
|
match server_addr_query.await {
|
||||||
Some(server_addr) => match peer_addr_query.await {
|
Some(server_addr) => match peer_addr_query.await {
|
||||||
Some(peer_addr) => {
|
Some(peer_addr) => {
|
||||||
let payload = socket_addr_to_vec(server_addr);
|
let payload =
|
||||||
|
parse_pack(peer_addr.clone().to_string().as_str())
|
||||||
|
.expect("couldnt create payload");
|
||||||
|
|
||||||
print!("{:?}", payload.clone());
|
print!("{:?}", payload.clone());
|
||||||
|
|
||||||
let natreq = construct_message(
|
let natreq = construct_message(
|
||||||
NATTRAVERSALREQUEST,
|
NATTRAVERSALREQUEST,
|
||||||
server_addr.to_string().into_bytes(),
|
payload.clone().to_vec(),
|
||||||
generate_id(),
|
generate_id(),
|
||||||
&sd.cryptopair(),
|
&sd.cryptopair(),
|
||||||
);
|
);
|
||||||
@@ -384,7 +343,6 @@ pub fn start_p2p_executor(
|
|||||||
),
|
),
|
||||||
server_addr.to_string(),
|
server_addr.to_string(),
|
||||||
false,
|
false,
|
||||||
sd.messages_list_ref(),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
@@ -415,15 +373,6 @@ pub fn start_p2p_executor(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn socket_addr_to_vec(addr: SocketAddr) -> Vec<u8> {
|
|
||||||
let mut v = match addr.ip() {
|
|
||||||
IpAddr::V4(v4) => v4.octets().to_vec(),
|
|
||||||
IpAddr::V6(v6) => v6.octets().to_vec(),
|
|
||||||
};
|
|
||||||
v.extend(&addr.port().to_be_bytes());
|
|
||||||
v
|
|
||||||
}
|
|
||||||
|
|
||||||
fn parse_pack(s: &str) -> Option<[u8; 6]> {
|
fn parse_pack(s: &str) -> Option<[u8; 6]> {
|
||||||
// split into "ip" and "port"
|
// split into "ip" and "port"
|
||||||
let mut parts = s.rsplitn(2, ':');
|
let mut parts = s.rsplitn(2, ':');
|
||||||
@@ -461,31 +410,12 @@ pub async fn get_socket_address(username: String, ip: String) -> Option<SocketAd
|
|||||||
match String::from_utf8(body.to_vec()) {
|
match String::from_utf8(body.to_vec()) {
|
||||||
Ok(s) => {
|
Ok(s) => {
|
||||||
let addresses = parse_addresses(&s);
|
let addresses = parse_addresses(&s);
|
||||||
addresses.iter().copied().find(|a| a.is_ipv4())
|
if let Some(first) = addresses.first() {
|
||||||
|
Some(first.clone())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Err(_) => None,
|
Err(_) => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_possible_socket_address(username: String, ip: String) -> Vec<SocketAddr> {
|
|
||||||
let client = reqwest::Client::new();
|
|
||||||
let uri = format!("{}/peers/{}/addresses", ip, username);
|
|
||||||
let res = client.get(uri).send().await.expect("couldnt get response");
|
|
||||||
if res.status().is_success() {
|
|
||||||
println!("Successfully retreived the addresses.");
|
|
||||||
} else {
|
|
||||||
eprintln!(
|
|
||||||
"Failed to get the peers addresses from the server. Status: {}",
|
|
||||||
res.status()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
let body: Bytes = res.bytes().await.expect("couldnt get bytes");
|
|
||||||
|
|
||||||
match String::from_utf8(body.to_vec()) {
|
|
||||||
Ok(s) => {
|
|
||||||
let addresses = parse_addresses(&s);
|
|
||||||
addresses.iter().copied().filter(|a| a.is_ipv4()).collect()
|
|
||||||
}
|
|
||||||
Err(_) => Vec::new(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
NetworkEvent, NodeHash,
|
NetworkEvent,
|
||||||
cryptographic_signature::{
|
cryptographic_signature::{
|
||||||
CryptographicSignature, get_peer_key, sign_message, verify_signature,
|
CryptographicSignature, get_peer_key, sign_message, verify_signature,
|
||||||
},
|
},
|
||||||
messages_channels::MultipleSenders,
|
messages_channels::MultipleSenders,
|
||||||
messages_structure::construct_message,
|
messages_structure::construct_message,
|
||||||
peers_refresh::HandshakeHistory,
|
|
||||||
registration,
|
registration,
|
||||||
server_communication::generate_id,
|
|
||||||
};
|
};
|
||||||
use std::{collections::HashMap, net::SocketAddr};
|
use std::{collections::HashMap, net::SocketAddr};
|
||||||
use std::{
|
use std::{
|
||||||
@@ -16,7 +14,9 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub enum EventType {
|
pub enum EventType {
|
||||||
SendRootRequest,
|
ServerHelloReply,
|
||||||
|
PeerHelloReply,
|
||||||
|
PeerHello,
|
||||||
}
|
}
|
||||||
|
|
||||||
const ID: usize = 4;
|
const ID: usize = 4;
|
||||||
@@ -42,12 +42,11 @@ pub fn handle_recevied_message(
|
|||||||
messages_list: &Arc<Mutex<HashMap<i32, EventType>>>,
|
messages_list: &Arc<Mutex<HashMap<i32, EventType>>>,
|
||||||
recevied_message: &Vec<u8>,
|
recevied_message: &Vec<u8>,
|
||||||
crypto_pair: &CryptographicSignature,
|
crypto_pair: &CryptographicSignature,
|
||||||
//socket_addr: &SocketAddr,
|
socket_addr: &SocketAddr,
|
||||||
senders: &MultipleSenders,
|
senders: &MultipleSenders,
|
||||||
server_name: &String,
|
server_name: &String,
|
||||||
cmd_tx: crossbeam_channel::Sender<NetworkEvent>,
|
cmd_tx: crossbeam_channel::Sender<NetworkEvent>,
|
||||||
ip: SocketAddr,
|
ip: SocketAddr,
|
||||||
handhsake_history: &Arc<Mutex<HandshakeHistory>>,
|
|
||||||
) {
|
) {
|
||||||
if recevied_message.len() < 4 {
|
if recevied_message.len() < 4 {
|
||||||
return;
|
return;
|
||||||
@@ -77,8 +76,6 @@ pub fn handle_recevied_message(
|
|||||||
crypto_pair,
|
crypto_pair,
|
||||||
cmd_tx,
|
cmd_tx,
|
||||||
ip,
|
ip,
|
||||||
messages_list,
|
|
||||||
handhsake_history,
|
|
||||||
senders,
|
senders,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -86,13 +83,7 @@ pub fn handle_recevied_message(
|
|||||||
None => {}
|
None => {}
|
||||||
Some(resp_msg) => {
|
Some(resp_msg) => {
|
||||||
println!("msg_sent:{:?}", resp_msg);
|
println!("msg_sent:{:?}", resp_msg);
|
||||||
senders.send_via(
|
senders.send_via(0, resp_msg, ip.to_string(), is_resp_to_server_handshake);
|
||||||
0,
|
|
||||||
resp_msg,
|
|
||||||
ip.to_string(),
|
|
||||||
is_resp_to_server_handshake,
|
|
||||||
messages_list,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,11 +159,8 @@ pub fn parse_message(
|
|||||||
crypto_pair: &CryptographicSignature,
|
crypto_pair: &CryptographicSignature,
|
||||||
cmd_tx: crossbeam_channel::Sender<NetworkEvent>,
|
cmd_tx: crossbeam_channel::Sender<NetworkEvent>,
|
||||||
ip: SocketAddr,
|
ip: SocketAddr,
|
||||||
messages_list: &Arc<Mutex<HashMap<i32, EventType>>>,
|
|
||||||
handhsake_history_mutex: &Arc<Mutex<HandshakeHistory>>,
|
|
||||||
senders: &MultipleSenders,
|
senders: &MultipleSenders,
|
||||||
) -> Option<Vec<u8>> {
|
) -> Option<Vec<u8>> {
|
||||||
let mut handhsake_history = handhsake_history_mutex.lock().unwrap();
|
|
||||||
let cmd_tx_clone = cmd_tx.clone();
|
let cmd_tx_clone = cmd_tx.clone();
|
||||||
|
|
||||||
let id_bytes: [u8; 4] = received_message[0..ID]
|
let id_bytes: [u8; 4] = received_message[0..ID]
|
||||||
@@ -186,29 +174,20 @@ pub fn parse_message(
|
|||||||
.expect("Taille incorrecte");
|
.expect("Taille incorrecte");
|
||||||
|
|
||||||
let msg_length = u16::from_be_bytes(length_bytes) as usize;
|
let msg_length = u16::from_be_bytes(length_bytes) as usize;
|
||||||
|
|
||||||
// verify signature
|
// verify signature
|
||||||
match msgtype {
|
match msgtype {
|
||||||
HELLO | HELLOREPLY | NODATUM | NATTRAVERSALREQUEST | NATTRAVERSALREQUEST2 => {
|
HELLO | HELLOREPLY | ROOTREPLY | NODATUM | NATTRAVERSALREQUEST | NATTRAVERSALREQUEST2 => {
|
||||||
let ilength = u16::from_be_bytes(length_bytes);
|
let ilength = u16::from_be_bytes(length_bytes);
|
||||||
println!("name received length: {}", ilength);
|
println!("name received length: {}", ilength);
|
||||||
let received_name = &received_message[LENGTH + EXTENSIONS..LENGTH + ilength as usize];
|
let received_name = &received_message[LENGTH + EXTENSIONS..LENGTH + ilength as usize];
|
||||||
let received_username = String::from_utf8(received_name.to_vec());
|
let received_username = String::from_utf8(received_name.to_vec());
|
||||||
match received_username {
|
match received_username {
|
||||||
Ok(username) => {
|
Ok(username) => {
|
||||||
let peer_pubkey =
|
let peer_pubkey = tokio::runtime::Runtime::new()
|
||||||
match handhsake_history.get_peer_info_username(username.clone()) {
|
.unwrap()
|
||||||
Some(peerinfo) => peerinfo.pubkey,
|
.block_on(get_peer_key(&username))
|
||||||
_ => tokio::runtime::Runtime::new()
|
.expect("failed to retrieve public key");
|
||||||
.unwrap()
|
|
||||||
.block_on(get_peer_key(&username))
|
|
||||||
.expect("failed to retrieve public key"),
|
|
||||||
};
|
|
||||||
match msgtype {
|
|
||||||
HELLOREPLY => {
|
|
||||||
handhsake_history.add_new_handshake(peer_pubkey, "".to_string(), ip);
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
let signature: [u8; SIGNATURE] = received_message
|
let signature: [u8; SIGNATURE] = received_message
|
||||||
[LENGTH + msg_length..LENGTH + msg_length + SIGNATURE]
|
[LENGTH + msg_length..LENGTH + msg_length + SIGNATURE]
|
||||||
.try_into()
|
.try_into()
|
||||||
@@ -227,22 +206,6 @@ pub fn parse_message(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ROOTREPLY => {
|
|
||||||
let ilength = u16::from_be_bytes(length_bytes);
|
|
||||||
println!("name received length: {}", ilength);
|
|
||||||
if let Some(peerinfo) = handhsake_history.get_peer_info_ip(ip.to_string()) {
|
|
||||||
if !verify_signature(peerinfo.pubkey, &received_message) {
|
|
||||||
println!(
|
|
||||||
"incorrect signature from given peer: {}, ignoring message of type {} with id {}",
|
|
||||||
&peerinfo.username, received_message[ID], id
|
|
||||||
);
|
|
||||||
return None;
|
|
||||||
} else {
|
|
||||||
println!("signature verified");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -281,7 +244,6 @@ pub fn parse_message(
|
|||||||
natreq2.expect("couldnt construct message nattraversalrequest2"),
|
natreq2.expect("couldnt construct message nattraversalrequest2"),
|
||||||
address,
|
address,
|
||||||
false,
|
false,
|
||||||
&messages_list,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -290,7 +252,8 @@ pub fn parse_message(
|
|||||||
constructed_message = construct_message(OK, Vec::new(), id, crypto_pair);
|
constructed_message = construct_message(OK, Vec::new(), id, crypto_pair);
|
||||||
|
|
||||||
let ilength = u16::from_be_bytes(length_bytes);
|
let ilength = u16::from_be_bytes(length_bytes);
|
||||||
let received_address = &received_message[LENGTH..LENGTH + ilength as usize];
|
let received_address =
|
||||||
|
&received_message[LENGTH + EXTENSIONS..LENGTH + ilength as usize];
|
||||||
let address = String::from_utf8(received_address.to_vec()).expect("wrong name");
|
let address = String::from_utf8(received_address.to_vec()).expect("wrong name");
|
||||||
|
|
||||||
let pingreq = construct_message(PING, Vec::new(), id, crypto_pair);
|
let pingreq = construct_message(PING, Vec::new(), id, crypto_pair);
|
||||||
@@ -300,7 +263,6 @@ pub fn parse_message(
|
|||||||
pingreq.expect("couldnt construct message ping request"),
|
pingreq.expect("couldnt construct message ping request"),
|
||||||
address,
|
address,
|
||||||
false,
|
false,
|
||||||
&messages_list,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
@@ -336,40 +298,7 @@ pub fn parse_message(
|
|||||||
//
|
//
|
||||||
//
|
//
|
||||||
// ajoute a la liste des peers handshake
|
// ajoute a la liste des peers handshake
|
||||||
HELLOREPLY => {
|
HELLOREPLY => {}
|
||||||
// ajoute l'username a la liste des peers handshake
|
|
||||||
let received_length = u16::from_be_bytes(
|
|
||||||
received_message[TYPE..LENGTH]
|
|
||||||
.try_into()
|
|
||||||
.expect("incorrect size"),
|
|
||||||
);
|
|
||||||
let received_username =
|
|
||||||
&received_message[LENGTH + EXTENSIONS..LENGTH + received_length as usize];
|
|
||||||
handhsake_history.update_peer_info(
|
|
||||||
ip.to_string(),
|
|
||||||
String::from_utf8(received_username.to_vec()).expect("invalid conversion"),
|
|
||||||
);
|
|
||||||
// verifie s'il faut renvoyer un root request
|
|
||||||
let guard = messages_list.lock().expect("Échec du verrouillage");
|
|
||||||
let res = guard.get(&id);
|
|
||||||
match res {
|
|
||||||
Some(ev) => {
|
|
||||||
match ev {
|
|
||||||
EventType::SendRootRequest => {
|
|
||||||
// envoyer la root request
|
|
||||||
let rootrequest = construct_message(
|
|
||||||
ROOTREQUEST,
|
|
||||||
Vec::new(),
|
|
||||||
generate_id(),
|
|
||||||
crypto_pair,
|
|
||||||
);
|
|
||||||
return rootrequest;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//
|
//
|
||||||
// ROOTREQUEST
|
// ROOTREQUEST
|
||||||
//
|
//
|
||||||
@@ -377,26 +306,7 @@ pub fn parse_message(
|
|||||||
//
|
//
|
||||||
// ROOTREPLY
|
// ROOTREPLY
|
||||||
//
|
//
|
||||||
ROOTREPLY => {
|
// envoie un datum request
|
||||||
// recuperer le pseudo du peers ayant repondu
|
|
||||||
let peers_exist = handhsake_history.get_peer_info_ip(ip.to_string());
|
|
||||||
match peers_exist {
|
|
||||||
Some(peerinfo) => {
|
|
||||||
// envoyer le hash a la gui
|
|
||||||
let received_hash: NodeHash = received_message[LENGTH..(32 + LENGTH)]
|
|
||||||
.try_into()
|
|
||||||
.expect("incorrect size");
|
|
||||||
let res = cmd_tx_clone.send(NetworkEvent::FileTreeRootReceived(
|
|
||||||
peerinfo.username.clone(),
|
|
||||||
received_hash,
|
|
||||||
));
|
|
||||||
println!("file tree sent")
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
eprintln!("no peers found");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//
|
//
|
||||||
// DATUMREQUEST
|
// DATUMREQUEST
|
||||||
//
|
//
|
||||||
@@ -468,6 +378,6 @@ pub fn parse_message(
|
|||||||
//
|
//
|
||||||
// envoie OK à S puis envoie un ping à S
|
// envoie OK à S puis envoie un ping à S
|
||||||
_ => return None,
|
_ => return None,
|
||||||
};
|
}
|
||||||
constructed_message
|
constructed_message
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ use crate::P2PSharedData;
|
|||||||
use crate::cryptographic_signature::CryptographicSignature;
|
use crate::cryptographic_signature::CryptographicSignature;
|
||||||
use crate::message_handling::EventType;
|
use crate::message_handling::EventType;
|
||||||
use crate::message_handling::handle_recevied_message;
|
use crate::message_handling::handle_recevied_message;
|
||||||
use crate::peers_refresh::HandshakeHistory;
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use std::net::UdpSocket;
|
use std::net::UdpSocket;
|
||||||
@@ -22,9 +21,9 @@ pub struct MultipleSenders {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct Message {
|
pub struct Message {
|
||||||
pub payload: Vec<u8>,
|
payload: Vec<u8>,
|
||||||
pub address: String,
|
address: String,
|
||||||
pub is_resp_to_server_handshake: bool,
|
is_resp_to_server_handshake: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct RetryMessage {
|
struct RetryMessage {
|
||||||
@@ -206,74 +205,64 @@ impl MultipleSenders {
|
|||||||
data: Vec<u8>,
|
data: Vec<u8>,
|
||||||
remote_addr: String,
|
remote_addr: String,
|
||||||
is_resp_to_server_handshake: bool,
|
is_resp_to_server_handshake: bool,
|
||||||
messages_list: &Mutex<HashMap<i32, EventType>>,
|
|
||||||
) {
|
) {
|
||||||
println!(
|
println!(
|
||||||
"is_resp_to_server_handshake {}",
|
"is_resp_to_server_handshake {}",
|
||||||
is_resp_to_server_handshake
|
is_resp_to_server_handshake
|
||||||
);
|
);
|
||||||
let msg_to_send = Message {
|
|
||||||
payload: data.clone(),
|
|
||||||
address: remote_addr,
|
|
||||||
is_resp_to_server_handshake,
|
|
||||||
};
|
|
||||||
if let Some(sender) = self.senders.get(channel_idx) {
|
if let Some(sender) = self.senders.get(channel_idx) {
|
||||||
let _ = sender.send(msg_to_send);
|
let _ = sender.send(Message {
|
||||||
}
|
payload: data,
|
||||||
if !is_resp_to_server_handshake {
|
address: remote_addr,
|
||||||
let mut guard = messages_list.lock().unwrap();
|
is_resp_to_server_handshake,
|
||||||
let message_id: [u8; 4] = data[0..4].try_into().expect("size error");
|
});
|
||||||
let id = i32::from_be_bytes(message_id);
|
|
||||||
guard.insert(id, EventType::SendRootRequest);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*pub fn start_receving_thread(
|
|
||||||
socket: &Arc<UdpSocket>,
|
|
||||||
messages_list: &Arc<HashMap<i32, EventType>>,
|
|
||||||
crypto_pair: &Arc<CryptographicSignature>,
|
|
||||||
socket_addr: SocketAddr,
|
|
||||||
senders: &Arc<MultipleSenders>,
|
|
||||||
) {
|
|
||||||
let sock_clone = Arc::clone(socket);
|
|
||||||
let cryptopair_clone = Arc::clone(crypto_pair);
|
|
||||||
let senders_clone = Arc::clone(senders);
|
|
||||||
|
|
||||||
let messages_clone = Arc::clone(messages_list);
|
|
||||||
thread::spawn(move || {
|
|
||||||
let mut buf = [0u8; 1024];
|
|
||||||
|
|
||||||
loop {
|
|
||||||
match sock_clone.recv_from(&mut buf) {
|
|
||||||
Ok((amt, src)) => {
|
|
||||||
handle_recevied_message(
|
|
||||||
&messages_clone,
|
|
||||||
&buf.to_vec(),
|
|
||||||
&cryptopair_clone,
|
|
||||||
&socket_addr,
|
|
||||||
&senders_clone,
|
|
||||||
);
|
|
||||||
println!("Reçu {} octets de {}: {:?}", amt, src, &buf[..amt]);
|
|
||||||
}
|
|
||||||
Err(e) => eprintln!("Erreur de réception: {}", e),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*pub fn start_receving_thread(
|
||||||
|
socket: &Arc<UdpSocket>,
|
||||||
|
messages_list: &Arc<HashMap<i32, EventType>>,
|
||||||
|
crypto_pair: &Arc<CryptographicSignature>,
|
||||||
|
socket_addr: SocketAddr,
|
||||||
|
senders: &Arc<MultipleSenders>,
|
||||||
|
) {
|
||||||
|
let sock_clone = Arc::clone(socket);
|
||||||
|
let cryptopair_clone = Arc::clone(crypto_pair);
|
||||||
|
let senders_clone = Arc::clone(senders);
|
||||||
|
|
||||||
|
let messages_clone = Arc::clone(messages_list);
|
||||||
|
thread::spawn(move || {
|
||||||
|
let mut buf = [0u8; 1024];
|
||||||
|
|
||||||
|
loop {
|
||||||
|
match sock_clone.recv_from(&mut buf) {
|
||||||
|
Ok((amt, src)) => {
|
||||||
|
handle_recevied_message(
|
||||||
|
&messages_clone,
|
||||||
|
&buf.to_vec(),
|
||||||
|
&cryptopair_clone,
|
||||||
|
&socket_addr,
|
||||||
|
&senders_clone,
|
||||||
|
);
|
||||||
|
println!("Reçu {} octets de {}: {:?}", amt, src, &buf[..amt]);
|
||||||
|
}
|
||||||
|
Err(e) => eprintln!("Erreur de réception: {}", e),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}*/
|
||||||
|
|
||||||
pub fn start_receving_thread(
|
pub fn start_receving_thread(
|
||||||
shared_data: &P2PSharedData,
|
shared_data: &P2PSharedData,
|
||||||
|
socket_addr: SocketAddr,
|
||||||
cmd_tx: crossbeam_channel::Sender<NetworkEvent>,
|
cmd_tx: crossbeam_channel::Sender<NetworkEvent>,
|
||||||
handshake_history: &Arc<Mutex<HandshakeHistory>>,
|
|
||||||
) {
|
) {
|
||||||
let sock_clone = shared_data.socket();
|
let sock_clone = shared_data.socket();
|
||||||
let cryptopair_clone = shared_data.cryptopair();
|
let cryptopair_clone = shared_data.cryptopair();
|
||||||
let senders_clone = shared_data.senders();
|
let senders_clone = shared_data.senders();
|
||||||
let messages_clone = shared_data.messages_list();
|
let messages_clone = shared_data.messages_list();
|
||||||
let servername_clone = shared_data.servername();
|
let servername_clone = shared_data.servername();
|
||||||
|
|
||||||
let handshake_clone = handshake_history.clone();
|
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
let mut buf = [0u8; 1024];
|
let mut buf = [0u8; 1024];
|
||||||
loop {
|
loop {
|
||||||
@@ -286,11 +275,11 @@ pub fn start_receving_thread(
|
|||||||
&messages_clone,
|
&messages_clone,
|
||||||
&received_data,
|
&received_data,
|
||||||
&cryptopair_clone,
|
&cryptopair_clone,
|
||||||
|
&socket_addr,
|
||||||
&senders_clone,
|
&senders_clone,
|
||||||
&servername_clone,
|
&servername_clone,
|
||||||
cmd_tx.clone(),
|
cmd_tx.clone(),
|
||||||
src,
|
src,
|
||||||
&handshake_clone,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Err(e) => eprintln!("Erreur de réception: {}", e),
|
Err(e) => eprintln!("Erreur de réception: {}", e),
|
||||||
|
|||||||
@@ -43,22 +43,20 @@ pub fn construct_message(
|
|||||||
let signature = sign_message(crypto_pair, &message);
|
let signature = sign_message(crypto_pair, &message);
|
||||||
return Some(signature);
|
return Some(signature);
|
||||||
}
|
}
|
||||||
PING | OK | ROOTREQUEST => {
|
PING | OK => {
|
||||||
message.extend_from_slice(&0u16.to_be_bytes());
|
message.extend_from_slice(&0u16.to_be_bytes());
|
||||||
return Some(message);
|
return Some(message);
|
||||||
}
|
}
|
||||||
ERROR | DATUMREQUEST => {
|
ERROR | ROOTREQUEST | DATUMREQUEST => {
|
||||||
message.extend_from_slice(&payload.len().to_be_bytes());
|
message.extend_from_slice(&payload.len().to_be_bytes());
|
||||||
message.extend_from_slice(&payload);
|
message.extend_from_slice(&payload);
|
||||||
return Some(message);
|
return Some(message);
|
||||||
}
|
}
|
||||||
ROOTREPLY | NODATUM | DATUM | NATTRAVERSALREQUEST => {
|
ROOTREPLY | NODATUM | DATUM | NATTRAVERSALREQUEST => {
|
||||||
println!("payload:{:?}", &payload);
|
message.extend_from_slice(&payload.len().to_be_bytes());
|
||||||
message.extend_from_slice(&(payload.len() as u16).to_be_bytes());
|
|
||||||
message.extend_from_slice(&payload);
|
message.extend_from_slice(&payload);
|
||||||
println!("payload:{:?}", &message);
|
//let signature = sign_message(crypto_pair, &message);
|
||||||
let signature = sign_message(crypto_pair, &message);
|
//message.extend_from_slice(&signature);
|
||||||
message.extend_from_slice(&signature);
|
|
||||||
return Some(message);
|
return Some(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
collections::{HashMap, VecDeque},
|
collections::{HashMap, VecDeque},
|
||||||
net::{AddrParseError, Ipv4Addr, SocketAddr},
|
net::{AddrParseError, SocketAddr},
|
||||||
ops::Add,
|
ops::Add,
|
||||||
process::Command,
|
process::Command,
|
||||||
sync::{Arc, Mutex},
|
sync::{Arc, Mutex},
|
||||||
@@ -11,134 +11,54 @@ use std::{
|
|||||||
time::{self, Duration, SystemTime},
|
time::{self, Duration, SystemTime},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::NetworkEvent;
|
|
||||||
use crate::{
|
|
||||||
P2PSharedData, construct_message, generate_id, messages_structure,
|
|
||||||
registration::perform_handshake,
|
|
||||||
};
|
|
||||||
use crossbeam_channel::{Receiver, Sender};
|
|
||||||
use p256::ecdsa::VerifyingKey;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct PeerInfo {
|
pub struct PeerInfo {
|
||||||
pub username: String,
|
username: String,
|
||||||
pub pubkey: VerifyingKey,
|
ip: SocketAddr,
|
||||||
pub ip: SocketAddr,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct HandshakeHistory {
|
pub struct HandshakeHistory {
|
||||||
//time_k_ip_v: HashMap<u64, u64>,
|
time_k_ip_v: HashMap<u64, u64>,
|
||||||
username_k_peerinfo_v: HashMap<String, PeerInfo>,
|
ip_k_peerinfo_v: HashMap<u64, PeerInfo>,
|
||||||
ip_k_peerinfo_v: HashMap<String, PeerInfo>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HandshakeHistory {
|
impl HandshakeHistory {
|
||||||
pub fn new() -> HandshakeHistory {
|
pub fn new() -> HandshakeHistory {
|
||||||
HandshakeHistory {
|
HandshakeHistory {
|
||||||
//time_k_ip_v: HashMap::new(),
|
time_k_ip_v: HashMap::new(),
|
||||||
//ip_k_peerinfo_v: HashMap::new(),
|
|
||||||
username_k_peerinfo_v: HashMap::new(),
|
|
||||||
ip_k_peerinfo_v: HashMap::new(),
|
ip_k_peerinfo_v: HashMap::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*pub fn update_handshake(&self) {
|
pub fn update_handshake(&mut self) {
|
||||||
let hashmap_shared = Arc::new(self.username_k_peerinfo_v);
|
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
let selfhashmap = hashmap_shared.clone();
|
let mut times_to_check = VecDeque::new();
|
||||||
|
let current_time: u64 = SystemTime::now()
|
||||||
|
.duration_since(time::UNIX_EPOCH)
|
||||||
|
.expect("system time before UNIX EPOCH")
|
||||||
|
.add(Duration::from_secs(10))
|
||||||
|
.as_secs();
|
||||||
|
// adds 10 seconds in the queue every 10 seconds
|
||||||
loop {
|
loop {
|
||||||
for peer in selfhashmap.keys() {
|
let mut child = Command::new("sleep").arg("9").spawn().unwrap();
|
||||||
let peer_ip = selfhashmap.get(peer);
|
|
||||||
// send ping
|
|
||||||
}
|
|
||||||
let mut child = Command::new("sleep").arg("10").spawn().unwrap();
|
|
||||||
let _result = child.wait().unwrap();
|
let _result = child.wait().unwrap();
|
||||||
}
|
for n in 0..9 {
|
||||||
});
|
// push 9 successive seconds
|
||||||
}*/
|
times_to_check.push_back(current_time + n);
|
||||||
|
// gestion d'erreur si verrou mort
|
||||||
pub fn get_peer_info_username(&self, username: String) -> Option<&PeerInfo> {
|
|
||||||
self.username_k_peerinfo_v.get(&username).clone()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_peer_info_ip(&self, ip: String) -> Option<&PeerInfo> {
|
|
||||||
self.ip_k_peerinfo_v.get(&ip).clone()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn update_handshake(&self) {
|
|
||||||
// clone the map so we own it (cheap if PeerInfo is Clone)
|
|
||||||
let map_clone: Arc<HashMap<String, PeerInfo>> =
|
|
||||||
Arc::new(self.username_k_peerinfo_v.clone());
|
|
||||||
//let map_ip_clone: Arc<HashMap<String, PeerInfo>> = Arc::new(self.ip_k_peerinfo_v.clone());
|
|
||||||
let map_for_thread = Arc::clone(&map_clone);
|
|
||||||
thread::spawn(move || {
|
|
||||||
loop {
|
|
||||||
// Arc<HashMap<..>> derefs to &HashMap so these reads work
|
|
||||||
for (peer, peerinfo) in map_for_thread.iter() {
|
|
||||||
// send ping to peerinfo
|
|
||||||
}
|
}
|
||||||
thread::sleep(Duration::from_secs(10));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_peer_info(&mut self, ip: String, username: String) {
|
pub fn add_new_handshake(&mut self, hash: u64, username: String, ip: SocketAddr) {
|
||||||
let peerinfo = self.get_peer_info_ip(ip.clone());
|
let current_time: u64 = SystemTime::now()
|
||||||
match peerinfo {
|
.duration_since(time::UNIX_EPOCH)
|
||||||
Some(peer_info) => match ip.parse::<SocketAddr>() {
|
.expect("system time before UNIX EPOCH")
|
||||||
Ok(addr) => {
|
.as_secs();
|
||||||
let new_peer_info = PeerInfo {
|
println!("time:{}", current_time);
|
||||||
username: username.clone(),
|
/*self.time_k_hash_v.insert(current_time, hash);
|
||||||
pubkey: peer_info.pubkey,
|
self.hash_k_peerinfo_v
|
||||||
ip: addr,
|
.insert(hash, PeerInfo { username, ip });*/
|
||||||
};
|
|
||||||
self.ip_k_peerinfo_v.insert(ip, new_peer_info.clone());
|
|
||||||
self.username_k_peerinfo_v.insert(username, new_peer_info);
|
|
||||||
}
|
|
||||||
Err(e) => eprintln!("parse error: {}", e),
|
|
||||||
},
|
|
||||||
None => {
|
|
||||||
eprintln!("no peer info found in hashmap")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn add_new_handshake(&mut self, hash: VerifyingKey, username: String, ip: SocketAddr) {
|
|
||||||
let peerinfo = PeerInfo {
|
|
||||||
username: username.clone(),
|
|
||||||
pubkey: hash,
|
|
||||||
ip,
|
|
||||||
};
|
|
||||||
self.username_k_peerinfo_v
|
|
||||||
.insert(username, peerinfo.clone());
|
|
||||||
self.ip_k_peerinfo_v
|
|
||||||
.insert(ip.to_string(), peerinfo.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn perform_discover(
|
|
||||||
username: String,
|
|
||||||
hash: String,
|
|
||||||
sd: &P2PSharedData,
|
|
||||||
server_ip: String,
|
|
||||||
event_tx: Sender<NetworkEvent>,
|
|
||||||
) {
|
|
||||||
// first, sends handshake
|
|
||||||
if hash == "root" {
|
|
||||||
perform_handshake(sd, username, server_ip, event_tx, false);
|
|
||||||
/*if let Some(data) = construct_message(
|
|
||||||
messages_structure::ROOTREQUEST,
|
|
||||||
Vec::new(),
|
|
||||||
generate_id(),
|
|
||||||
sd.cryptopair_ref(),
|
|
||||||
) {
|
|
||||||
if let Some(peerinfo) = sd.handshake_ref() {
|
|
||||||
sd.senders_ref()
|
|
||||||
.send_via(0, data, peerinfo.ip.to_string(), false);
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
} else {
|
|
||||||
// envoyer un datum request
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,7 +68,10 @@ mod tests {
|
|||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
/*#[test]
|
///
|
||||||
|
/// creates a cryptographic signature
|
||||||
|
///
|
||||||
|
#[test]
|
||||||
fn creating_cryptographic_signature() {
|
fn creating_cryptographic_signature() {
|
||||||
let mut hh = HandshakeHistory::new();
|
let mut hh = HandshakeHistory::new();
|
||||||
hh.add_new_handshake(
|
hh.add_new_handshake(
|
||||||
@@ -156,5 +79,5 @@ mod tests {
|
|||||||
"putain".to_string(),
|
"putain".to_string(),
|
||||||
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 1),
|
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 1),
|
||||||
);
|
);
|
||||||
}*/
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,9 @@
|
|||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
|
|
||||||
use crate::NetworkEvent;
|
|
||||||
use crate::P2PSharedData;
|
|
||||||
use crate::cryptographic_signature::{CryptographicSignature, formatPubKey, sign_message};
|
use crate::cryptographic_signature::{CryptographicSignature, formatPubKey, sign_message};
|
||||||
use crate::get_socket_address;
|
|
||||||
use crate::message_handling::EventType;
|
use crate::message_handling::EventType;
|
||||||
use crate::messages_channels::MultipleSenders;
|
use crate::messages_channels::MultipleSenders;
|
||||||
use crate::messages_structure::construct_message;
|
use crate::messages_structure::construct_message;
|
||||||
use crate::server_communication::generate_id;
|
|
||||||
use crossbeam_channel::{Receiver, Sender};
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use std::net::UdpSocket;
|
use std::net::UdpSocket;
|
||||||
@@ -50,46 +45,23 @@ pub fn parse_addresses(input: &String) -> Vec<SocketAddr> {
|
|||||||
///
|
///
|
||||||
/// registers the IP addresses by sending a Hello request to the server.
|
/// registers the IP addresses by sending a Hello request to the server.
|
||||||
///
|
///
|
||||||
pub async fn perform_handshake(
|
pub fn register_ip_addresses(
|
||||||
sd: &P2PSharedData,
|
crypto_pair: &CryptographicSignature,
|
||||||
username: String,
|
server_uri: String,
|
||||||
ip: String,
|
senders: &MultipleSenders,
|
||||||
event_tx: Sender<NetworkEvent>,
|
messages_list: &Mutex<HashMap<i32, EventType>>,
|
||||||
is_server_handshake: bool,
|
id: i32,
|
||||||
) {
|
) {
|
||||||
println!("username: {}, ip: {}", username.clone(), ip.clone());
|
let mut payload = Vec::new();
|
||||||
let crypto_pair = sd.cryptopair_ref();
|
payload.extend_from_slice(&0u32.to_be_bytes());
|
||||||
let senders = sd.senders_ref();
|
payload.extend_from_slice(&crypto_pair.username.clone().as_bytes());
|
||||||
let messages_list = sd.messages_list_ref();
|
let hello_handshake = construct_message(1, payload, id, crypto_pair);
|
||||||
let id = generate_id();
|
match hello_handshake {
|
||||||
let server_addr_query = get_socket_address(username.clone(), ip.clone());
|
Some(handshake_message) => {
|
||||||
match server_addr_query.await {
|
senders.send_via(0, handshake_message, server_uri, false);
|
||||||
Some(sockaddr_bytes) => {
|
|
||||||
sd.set_servername(username);
|
|
||||||
// first: &SocketAddr
|
|
||||||
let mut payload = Vec::new();
|
|
||||||
payload.extend_from_slice(&0u32.to_be_bytes());
|
|
||||||
payload.extend_from_slice(&crypto_pair.username.clone().as_bytes());
|
|
||||||
let hello_handshake = construct_message(1, payload, id, crypto_pair);
|
|
||||||
match hello_handshake {
|
|
||||||
Some(handshake_message) => {
|
|
||||||
senders.send_via(
|
|
||||||
0,
|
|
||||||
handshake_message,
|
|
||||||
sockaddr_bytes.to_string(),
|
|
||||||
is_server_handshake,
|
|
||||||
messages_list,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
None => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
let err_msg = format!("failed to retreive socket address:").to_string();
|
|
||||||
let res = event_tx.send(NetworkEvent::Error(err_msg));
|
|
||||||
}
|
}
|
||||||
|
None => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*let mut list = messages_list.lock().expect("Failed to lock messages_list");
|
/*let mut list = messages_list.lock().expect("Failed to lock messages_list");
|
||||||
match list.get(&id) {
|
match list.get(&id) {
|
||||||
Some(_) => {
|
Some(_) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user