Compare commits
3 Commits
341f8f123d
...
tmp
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c852c5bb4a | ||
| 98fcc1a0b2 | |||
| 8e279d9e24 |
@@ -1,5 +1,5 @@
|
||||
use client_network::{
|
||||
MerkleNode, MerkleTree, NetworkCommand, NetworkEvent, NodeHash, filename_to_string,
|
||||
ChunkNode, MerkleNode, MerkleTree, NetworkCommand, NetworkEvent, NodeHash, filename_to_string,
|
||||
node_hash_to_hex_string,
|
||||
};
|
||||
use crossbeam_channel::{Receiver, Sender};
|
||||
@@ -27,7 +27,7 @@ pub struct P2PClientApp {
|
||||
|
||||
// GUI State
|
||||
status_message: String,
|
||||
known_peers: Vec<(String, bool)>,
|
||||
known_peers: Vec<String>,
|
||||
connect_address_input: String,
|
||||
connected_address: String,
|
||||
connect_name_input: String,
|
||||
@@ -49,11 +49,11 @@ pub struct P2PClientApp {
|
||||
|
||||
impl P2PClientApp {
|
||||
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 tree = MerkleTree::new(tree_content, root_hash);
|
||||
loaded_fs.insert("bob".to_string(), tree);
|
||||
//let tree = MerkleTree::new(tree_content, root_hash);
|
||||
//loaded_fs.insert("bob".to_string(), tree);
|
||||
|
||||
Self {
|
||||
remaining: std::time::Duration::from_secs(0),
|
||||
@@ -62,7 +62,7 @@ impl P2PClientApp {
|
||||
network_cmd_tx: cmd_tx,
|
||||
network_event_rx: event_rx,
|
||||
status_message: "Client Initialized. Awaiting network status...".to_string(),
|
||||
known_peers: vec![("bob".to_string(), true)],
|
||||
known_peers: vec!["bob".to_string()],
|
||||
connect_address_input: "https://jch.irif.fr:8443".to_string(),
|
||||
connected_address: "".to_string(),
|
||||
loaded_fs,
|
||||
@@ -111,8 +111,8 @@ impl eframe::App for P2PClientApp {
|
||||
todo!();
|
||||
|
||||
self.status_message = format!("✅ Peer connected: {}", addr);
|
||||
if !self.known_peers.contains(&(addr, true)) {
|
||||
self.known_peers.push((addr, true));
|
||||
if !self.known_peers.contains(&addr) {
|
||||
self.known_peers.push(addr);
|
||||
}
|
||||
}
|
||||
NetworkEvent::PeerListUpdated(peers) => {
|
||||
@@ -123,23 +123,41 @@ impl eframe::App for P2PClientApp {
|
||||
NetworkEvent::FileTreeReceived(_peer_id, _) => {
|
||||
todo!();
|
||||
|
||||
// self.loaded_tree_nodes.insert(_peer_id, tree);
|
||||
self.status_message = "🔄 File tree updated successfully.".to_string();
|
||||
//self.loaded_tree_nodes.insert(_peer_id, tree);
|
||||
//self.status_message = "🔄 File tree updated successfully.".to_string();
|
||||
}
|
||||
NetworkEvent::FileTreeRootReceived(peer_id, root_hash) => {
|
||||
todo!();
|
||||
// todo!();
|
||||
|
||||
// self.status_message = format!("🔄 Received Merkle Root from {}: {}", peer_id, &root_hash[..8]);
|
||||
//
|
||||
//
|
||||
// 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,
|
||||
// ));
|
||||
/*self.status_message = format!(
|
||||
"🔄 Received Merkle Root from {}: {}",
|
||||
peer_id,
|
||||
&root_hash[..8]
|
||||
);*/
|
||||
|
||||
if let Ok(chunknode) = ChunkNode::new(Vec::new()) {
|
||||
let mut data_map: HashMap<NodeHash, MerkleNode> = HashMap::new();
|
||||
data_map.insert(root_hash, MerkleNode::Chunk(chunknode));
|
||||
let tree = MerkleTree {
|
||||
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) => {
|
||||
self.server_status = ServerStatus::Connected;
|
||||
@@ -343,26 +361,29 @@ impl eframe::App for P2PClientApp {
|
||||
} else {
|
||||
for peer in &self.known_peers {
|
||||
let is_active =
|
||||
self.active_peer.as_ref().map_or(false, |id| id == &peer.0); // if peer.id == self.active_peer_id
|
||||
self.active_peer.as_ref().map_or(false, |id| id == peer); // if peer.id == self.active_peer_id
|
||||
|
||||
let selectable;
|
||||
if &self.active_server == &peer.0 {
|
||||
if &self.active_server == peer {
|
||||
selectable =
|
||||
ui.selectable_label(is_active, format!("{} 📡 🌀", peer.0))
|
||||
ui.selectable_label(is_active, format!("{} 📡 🌀", peer))
|
||||
} else {
|
||||
selectable = ui.selectable_label(is_active, format!("{}", peer.0));
|
||||
selectable = ui.selectable_label(is_active, format!("{}", peer));
|
||||
}
|
||||
if selectable.clicked() {
|
||||
// switch to displaying this peer's tree
|
||||
self.active_peer = Some(peer.0.clone());
|
||||
self.active_peer = Some(peer.clone());
|
||||
// Request root content if not loaded
|
||||
if !self
|
||||
.loaded_fs
|
||||
.contains_key(self.active_peer.as_ref().unwrap())
|
||||
{
|
||||
let _ = self
|
||||
.network_cmd_tx
|
||||
.send(NetworkCommand::ConnectPeer(peer.clone()));
|
||||
//todo!();
|
||||
let _ = self.network_cmd_tx.send(NetworkCommand::Discover(
|
||||
peer.clone(),
|
||||
"root".to_string(),
|
||||
self.connected_address.clone(),
|
||||
));
|
||||
}
|
||||
}
|
||||
selectable.context_menu(|ui| {
|
||||
@@ -373,10 +394,10 @@ impl eframe::App for P2PClientApp {
|
||||
.button("Utiliser le peer en tant que serveur")
|
||||
.clicked()
|
||||
{
|
||||
self.active_server = peer.0.to_string();
|
||||
self.active_server = peer.to_string();
|
||||
let res = self.network_cmd_tx.send(
|
||||
NetworkCommand::ServerHandshake(
|
||||
peer.0.to_string(),
|
||||
peer.to_string(),
|
||||
self.connected_address.clone(),
|
||||
),
|
||||
);
|
||||
@@ -384,29 +405,10 @@ impl eframe::App for P2PClientApp {
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
if ui.button("Send Ping").clicked() {
|
||||
let res = self
|
||||
.network_cmd_tx
|
||||
.send(NetworkCommand::Ping(peer.0.to_string()));
|
||||
}
|
||||
if ui.button("Send Nat Traversal Request").clicked() {
|
||||
match self.network_cmd_tx.send(NetworkCommand::NatTraversal(
|
||||
peer.0.to_string(),
|
||||
self.connected_address.clone(),
|
||||
)) {
|
||||
Ok(_) => {
|
||||
print!("[+] successfully sent nat traversal request")
|
||||
}
|
||||
Err(_) => {
|
||||
print!("[-] failed to send nat traversal request")
|
||||
}
|
||||
}
|
||||
}
|
||||
if ui.button("Infos").clicked() {
|
||||
// action 3
|
||||
ui.close();
|
||||
}
|
||||
|
||||
// ... autres boutons
|
||||
});
|
||||
}
|
||||
@@ -525,7 +527,13 @@ impl P2PClientApp {
|
||||
entry.content_hash,
|
||||
tree,
|
||||
depth + 1,
|
||||
Some(entry.filename),
|
||||
Some(
|
||||
entry
|
||||
.filename
|
||||
.as_slice()
|
||||
.try_into()
|
||||
.expect("incorrect size"),
|
||||
),
|
||||
);
|
||||
}
|
||||
});
|
||||
@@ -546,7 +554,7 @@ impl P2PClientApp {
|
||||
.enabled(true)
|
||||
.show(ui, |ui| {
|
||||
for child in &node.children_hashes {
|
||||
self.draw_file_node(ui, child.clone(), tree, depth + 1, None);
|
||||
self.draw_file_node(ui, child.content_hash, tree, depth + 1, None);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ impl MerkleTree {
|
||||
}
|
||||
}
|
||||
|
||||
fn generate_random_file_node(
|
||||
/*fn generate_random_file_node(
|
||||
storage: &mut HashMap<NodeHash, MerkleNode>,
|
||||
) -> Result<NodeHash, String> {
|
||||
let mut rng = rng();
|
||||
@@ -110,9 +110,9 @@ fn generate_random_file_node(
|
||||
storage.insert(hash, node);
|
||||
Ok(hash)
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
fn generate_random_directory_node(
|
||||
/*fn generate_random_directory_node(
|
||||
depth: u32,
|
||||
max_depth: u32,
|
||||
storage: &mut HashMap<NodeHash, MerkleNode>,
|
||||
@@ -172,7 +172,7 @@ fn generate_random_directory_node(
|
||||
storage.insert(hash, node);
|
||||
Ok(hash)
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ChunkNode {
|
||||
@@ -208,7 +208,7 @@ impl ChunkNode {
|
||||
// Helper struct
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct DirectoryEntry {
|
||||
pub filename: [u8; FILENAME_HASH_SIZE],
|
||||
pub filename: Vec<u8>,
|
||||
pub content_hash: NodeHash,
|
||||
}
|
||||
|
||||
@@ -240,7 +240,7 @@ pub struct 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();
|
||||
if n < MIN_BIG_CHILDREN || n > MAX_BIG_CHILDREN {
|
||||
return Err(format!(
|
||||
@@ -249,16 +249,17 @@ impl BigNode {
|
||||
));
|
||||
}
|
||||
Ok(BigNode { children_hashes })
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct BigDirectoryNode {
|
||||
pub children_hashes: Vec<NodeHash>,
|
||||
//pub children_hashes: Vec<NodeHash>,
|
||||
pub children_hashes: Vec<DirectoryEntry>,
|
||||
}
|
||||
|
||||
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();
|
||||
if n < MIN_BIG_CHILDREN || n > MAX_BIG_CHILDREN {
|
||||
return Err(format!(
|
||||
@@ -267,6 +268,14 @@ impl BigDirectoryNode {
|
||||
));
|
||||
}
|
||||
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,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -301,14 +310,14 @@ impl MerkleNode {
|
||||
}
|
||||
MerkleNode::BigDirectory(node) => {
|
||||
for hash in &node.children_hashes {
|
||||
bytes.extend_from_slice(hash);
|
||||
bytes.extend_from_slice(&hash.content_hash);
|
||||
}
|
||||
}
|
||||
}
|
||||
bytes
|
||||
}
|
||||
|
||||
pub fn generate_random_tree(
|
||||
/*pub fn generate_random_tree(
|
||||
max_depth: u32,
|
||||
) -> Result<(NodeHash, HashMap<NodeHash, MerkleNode>), String> {
|
||||
let mut storage = HashMap::new();
|
||||
@@ -317,9 +326,9 @@ impl MerkleNode {
|
||||
let root_hash = generate_random_directory_node(0, max_depth, &mut 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 node1 = MerkleNode::Chunk(ChunkNode::new_random());
|
||||
@@ -369,5 +378,5 @@ impl MerkleNode {
|
||||
res.insert(root_hash, root);
|
||||
|
||||
(root_hash, res)
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
@@ -1 +1,96 @@
|
||||
fn parse_received_datum(recevied_datum: Vec<u8>) {}
|
||||
use crate::{BigDirectoryNode, DirectoryEntry, DirectoryNode, MerkleNode, MerkleTree, NodeHash};
|
||||
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,17 +12,21 @@ use crate::{
|
||||
cryptographic_signature::CryptographicSignature,
|
||||
message_handling::EventType,
|
||||
messages_channels::{MultipleSenders, start_receving_thread},
|
||||
messages_structure::{NATTRAVERSALREQUEST, NATTRAVERSALREQUEST2, construct_message},
|
||||
registration::{parse_addresses, register_ip_addresses, register_with_the_server},
|
||||
messages_structure::{ROOTREQUEST, construct_message},
|
||||
peers_refresh::HandshakeHistory,
|
||||
registration::{
|
||||
get_socket_address, parse_addresses, perform_handshake, register_with_the_server,
|
||||
},
|
||||
server_communication::{generate_id, get_peer_list},
|
||||
};
|
||||
use std::{
|
||||
io::Error,
|
||||
net::{Ipv4Addr, UdpSocket},
|
||||
fmt,
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
use std::{
|
||||
net::SocketAddr,
|
||||
sync::{Arc, Mutex},
|
||||
io::Error,
|
||||
net::{SocketAddr, UdpSocket},
|
||||
str::FromStr,
|
||||
};
|
||||
|
||||
pub struct P2PSharedData {
|
||||
@@ -31,11 +35,9 @@ pub struct P2PSharedData {
|
||||
shared_messageslist: Arc<Mutex<HashMap<i32, EventType>>>,
|
||||
shared_senders: Arc<MultipleSenders>,
|
||||
server_name: Arc<Mutex<String>>,
|
||||
handshake_peers: Arc<HandshakeHistory>,
|
||||
}
|
||||
|
||||
use bytes::Bytes;
|
||||
use p256::pkcs8::der::pem::Base64Encoder;
|
||||
|
||||
impl P2PSharedData {
|
||||
pub fn new(
|
||||
username: String,
|
||||
@@ -52,12 +54,14 @@ impl P2PSharedData {
|
||||
let senders = MultipleSenders::new(1, &shared_socket, cmd_tx);
|
||||
let shared_senders = Arc::new(senders);
|
||||
let server_name = Arc::new(Mutex::new("".to_string()));
|
||||
let handhsake_peers = Arc::new(HandshakeHistory::new());
|
||||
Ok(P2PSharedData {
|
||||
shared_socket: shared_socket,
|
||||
shared_cryptopair: shared_cryptopair,
|
||||
shared_messageslist: shared_messageslist,
|
||||
shared_senders: shared_senders,
|
||||
server_name: server_name,
|
||||
handshake_peers: handhsake_peers,
|
||||
})
|
||||
}
|
||||
pub fn socket(&self) -> Arc<UdpSocket> {
|
||||
@@ -88,6 +92,9 @@ impl P2PSharedData {
|
||||
pub fn cryptopair_ref(&self) -> &CryptographicSignature {
|
||||
&*self.shared_cryptopair
|
||||
}
|
||||
pub fn handshake_ref(&self) -> &HandshakeHistory {
|
||||
&*self.handshake_peers
|
||||
}
|
||||
|
||||
pub fn messages_list_ref(&self) -> &Mutex<HashMap<i32, EventType>> {
|
||||
&*self.shared_messageslist
|
||||
@@ -109,14 +116,15 @@ pub enum NetworkCommand {
|
||||
ServerHandshake(String, String), // ServerName
|
||||
FetchPeerList(String), // ServerIP
|
||||
RegisterAsPeer(String),
|
||||
Ping(String),
|
||||
NatTraversal(String, String),
|
||||
ConnectPeer((String, bool)), // IP:PORT
|
||||
RequestFileTree(String), // peer_id
|
||||
Ping(),
|
||||
ConnectPeer(String), // IP:PORT
|
||||
RequestFileTree(String), // peer_id
|
||||
RequestDirectoryContent(String, String),
|
||||
RequestChunk(String, String),
|
||||
Disconnect(),
|
||||
ResetServerPeer(),
|
||||
Discover(String, String, String),
|
||||
GetChildren(String, String),
|
||||
// ...
|
||||
}
|
||||
|
||||
@@ -127,10 +135,10 @@ pub enum NetworkEvent {
|
||||
Disconnected(),
|
||||
Error(String),
|
||||
PeerConnected(String),
|
||||
PeerListUpdated(Vec<(String, bool)>),
|
||||
PeerListUpdated(Vec<String>),
|
||||
FileTreeReceived(String, Vec<MerkleNode>), // peer_id, content
|
||||
DataReceived(String, MerkleNode),
|
||||
FileTreeRootReceived(String, String),
|
||||
FileTreeRootReceived(String, NodeHash),
|
||||
HandshakeFailed(),
|
||||
ServerHandshakeFailed(String),
|
||||
// ...
|
||||
@@ -165,6 +173,8 @@ pub fn start_p2p_executor(
|
||||
// Use tokio to spawn the asynchronous networking logic
|
||||
tokio::task::spawn(async move {
|
||||
// P2P/Networking Setup goes here
|
||||
let handshake_history = Arc::new(Mutex::new(HandshakeHistory::new()));
|
||||
let handshake_clone = handshake_history.clone();
|
||||
|
||||
println!("Network executor started.");
|
||||
|
||||
@@ -174,38 +184,18 @@ pub fn start_p2p_executor(
|
||||
if let Ok(cmd) = cmd_rx.try_recv() {
|
||||
match cmd {
|
||||
NetworkCommand::ServerHandshake(username, ip) => {
|
||||
println!("server handshake called");
|
||||
if let Some(sd) = shared_data.as_ref() {
|
||||
println!("username:{}, ip:{}", username, ip);
|
||||
let server_addr_query = get_socket_address(username.clone(), ip);
|
||||
|
||||
match server_addr_query.await {
|
||||
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));
|
||||
}
|
||||
}
|
||||
start_receving_thread(sd, event_tx.clone(), &handshake_clone);
|
||||
let res =
|
||||
perform_handshake(&sd, username, ip, event_tx.clone(), true).await;
|
||||
} else {
|
||||
println!("no shared data");
|
||||
}
|
||||
}
|
||||
NetworkCommand::ConnectPeer((username, connected)) => {
|
||||
NetworkCommand::ConnectPeer(addr) => {
|
||||
println!("[Network] ConnectPeer() called");
|
||||
println!("[Network] Attempting to connect to: {}", username);
|
||||
println!("[Network] Attempting to connect to: {}", addr);
|
||||
// Network logic to connect...
|
||||
// If successful, send an event back:
|
||||
// event_tx.send(NetworkEvent::PeerConnected(addr)).unwrap();
|
||||
@@ -213,6 +203,56 @@ pub fn start_p2p_executor(
|
||||
NetworkCommand::RequestFileTree(_) => {
|
||||
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(_, _) => {
|
||||
println!("[Network] RequestDirectoryContent() called");
|
||||
}
|
||||
@@ -268,11 +308,11 @@ pub fn start_p2p_executor(
|
||||
match get_peer_list(ip).await {
|
||||
Ok(body) => match String::from_utf8(body.to_vec()) {
|
||||
Ok(peers_list) => {
|
||||
let mut peers: Vec<(String, bool)> = Vec::new();
|
||||
let mut peers: Vec<String> = Vec::new();
|
||||
let mut current = String::new();
|
||||
for i in peers_list.chars() {
|
||||
if i == '\n' {
|
||||
peers.push((current.clone(), false));
|
||||
peers.push(current.clone());
|
||||
current.clear();
|
||||
} else {
|
||||
current.push(i);
|
||||
@@ -293,7 +333,7 @@ pub fn start_p2p_executor(
|
||||
NetworkCommand::RegisterAsPeer(_) => {
|
||||
println!("[Network] RegisterAsPeer() called");
|
||||
}
|
||||
NetworkCommand::Ping(String) => {
|
||||
NetworkCommand::Ping() => {
|
||||
println!("[Network] Ping() called");
|
||||
}
|
||||
NetworkCommand::Disconnect() => {
|
||||
@@ -312,53 +352,6 @@ pub fn start_p2p_executor(
|
||||
println!("no p2p data");
|
||||
}
|
||||
}
|
||||
NetworkCommand::NatTraversal(username, ip) => {
|
||||
if let Some(sd) = shared_data.as_ref() {
|
||||
println!("username:{}, ip:{}", username, ip);
|
||||
// user server to send nattraversal request
|
||||
let server_addr_query =
|
||||
get_socket_address(sd.servername().clone(), ip.clone());
|
||||
let peer_addr_query = get_socket_address(username.clone(), ip.clone());
|
||||
|
||||
match server_addr_query.await {
|
||||
Some(server_addr) => match peer_addr_query.await {
|
||||
Some(peer_addr) => {
|
||||
let payload =
|
||||
parse_pack(peer_addr.clone().to_string().as_str())
|
||||
.expect("couldnt create payload");
|
||||
|
||||
print!("{:?}", payload.clone());
|
||||
|
||||
let natreq = construct_message(
|
||||
NATTRAVERSALREQUEST,
|
||||
payload.clone().to_vec(),
|
||||
generate_id(),
|
||||
&sd.cryptopair(),
|
||||
);
|
||||
|
||||
sd.senders_ref().send_via(
|
||||
0,
|
||||
natreq.expect(
|
||||
"couldnt construct message nattraversalrequest2",
|
||||
),
|
||||
server_addr.to_string(),
|
||||
false,
|
||||
);
|
||||
}
|
||||
None => {
|
||||
let err_msg = format!("failed to retreive socket address")
|
||||
.to_string();
|
||||
let res = event_tx.send(NetworkEvent::Error(err_msg));
|
||||
}
|
||||
},
|
||||
None => {
|
||||
let err_msg =
|
||||
format!("failed to retreive socket address").to_string();
|
||||
let res = event_tx.send(NetworkEvent::Error(err_msg));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -372,50 +365,3 @@ pub fn start_p2p_executor(
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn parse_pack(s: &str) -> Option<[u8; 6]> {
|
||||
// split into "ip" and "port"
|
||||
let mut parts = s.rsplitn(2, ':');
|
||||
let port_str = parts.next()?;
|
||||
let ip_str = parts.next()?; // if missing, invalid
|
||||
|
||||
let ip: Ipv4Addr = ip_str.parse().ok()?;
|
||||
let port: u16 = port_str.parse().ok()?;
|
||||
|
||||
let octets = ip.octets();
|
||||
let port_be = port.to_be_bytes();
|
||||
Some([
|
||||
octets[0], octets[1], octets[2], octets[3], port_be[0], port_be[1],
|
||||
])
|
||||
}
|
||||
|
||||
///
|
||||
/// sends a get request to the server to get the socket address of the given peer
|
||||
///
|
||||
|
||||
pub async fn get_socket_address(username: String, ip: String) -> Option<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);
|
||||
if let Some(first) = addresses.first() {
|
||||
Some(first.clone())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
Err(_) => None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
use crate::{
|
||||
NetworkEvent,
|
||||
NetworkEvent, NodeHash,
|
||||
cryptographic_signature::{
|
||||
CryptographicSignature, get_peer_key, sign_message, verify_signature,
|
||||
},
|
||||
messages_channels::MultipleSenders,
|
||||
messages_structure::construct_message,
|
||||
peers_refresh::HandshakeHistory,
|
||||
registration,
|
||||
server_communication::generate_id,
|
||||
};
|
||||
use std::{collections::HashMap, net::SocketAddr};
|
||||
use std::{
|
||||
@@ -14,9 +16,7 @@ use std::{
|
||||
};
|
||||
|
||||
pub enum EventType {
|
||||
ServerHelloReply,
|
||||
PeerHelloReply,
|
||||
PeerHello,
|
||||
SendRootRequest,
|
||||
}
|
||||
|
||||
const ID: usize = 4;
|
||||
@@ -42,11 +42,12 @@ pub fn handle_recevied_message(
|
||||
messages_list: &Arc<Mutex<HashMap<i32, EventType>>>,
|
||||
recevied_message: &Vec<u8>,
|
||||
crypto_pair: &CryptographicSignature,
|
||||
socket_addr: &SocketAddr,
|
||||
//socket_addr: &SocketAddr,
|
||||
senders: &MultipleSenders,
|
||||
server_name: &String,
|
||||
cmd_tx: crossbeam_channel::Sender<NetworkEvent>,
|
||||
ip: SocketAddr,
|
||||
handhsake_history: &Arc<Mutex<HandshakeHistory>>,
|
||||
) {
|
||||
if recevied_message.len() < 4 {
|
||||
return;
|
||||
@@ -76,14 +77,21 @@ pub fn handle_recevied_message(
|
||||
crypto_pair,
|
||||
cmd_tx,
|
||||
ip,
|
||||
senders,
|
||||
messages_list,
|
||||
handhsake_history,
|
||||
);
|
||||
|
||||
match resp {
|
||||
None => {}
|
||||
Some(resp_msg) => {
|
||||
println!("msg_sent:{:?}", resp_msg);
|
||||
senders.send_via(0, resp_msg, ip.to_string(), is_resp_to_server_handshake);
|
||||
senders.send_via(
|
||||
0,
|
||||
resp_msg,
|
||||
ip.to_string(),
|
||||
is_resp_to_server_handshake,
|
||||
messages_list,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,8 +167,10 @@ pub fn parse_message(
|
||||
crypto_pair: &CryptographicSignature,
|
||||
cmd_tx: crossbeam_channel::Sender<NetworkEvent>,
|
||||
ip: SocketAddr,
|
||||
senders: &MultipleSenders,
|
||||
messages_list: &Arc<Mutex<HashMap<i32, EventType>>>,
|
||||
handhsake_history_mutex: &Arc<Mutex<HandshakeHistory>>,
|
||||
) -> Option<Vec<u8>> {
|
||||
let mut handhsake_history = handhsake_history_mutex.lock().unwrap();
|
||||
let cmd_tx_clone = cmd_tx.clone();
|
||||
|
||||
let id_bytes: [u8; 4] = received_message[0..ID]
|
||||
@@ -174,20 +184,29 @@ pub fn parse_message(
|
||||
.expect("Taille incorrecte");
|
||||
|
||||
let msg_length = u16::from_be_bytes(length_bytes) as usize;
|
||||
|
||||
// verify signature
|
||||
match msgtype {
|
||||
HELLO | HELLOREPLY | ROOTREPLY | NODATUM | NATTRAVERSALREQUEST | NATTRAVERSALREQUEST2 => {
|
||||
HELLO | HELLOREPLY | NODATUM | NATTRAVERSALREQUEST | NATTRAVERSALREQUEST2 => {
|
||||
let ilength = u16::from_be_bytes(length_bytes);
|
||||
println!("name received length: {}", ilength);
|
||||
let received_name = &received_message[LENGTH + EXTENSIONS..LENGTH + ilength as usize];
|
||||
let received_username = String::from_utf8(received_name.to_vec());
|
||||
match received_username {
|
||||
Ok(username) => {
|
||||
let peer_pubkey = tokio::runtime::Runtime::new()
|
||||
.unwrap()
|
||||
.block_on(get_peer_key(&username))
|
||||
.expect("failed to retrieve public key");
|
||||
let peer_pubkey =
|
||||
match handhsake_history.get_peer_info_username(username.clone()) {
|
||||
Some(peerinfo) => peerinfo.pubkey,
|
||||
_ => tokio::runtime::Runtime::new()
|
||||
.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
|
||||
[LENGTH + msg_length..LENGTH + msg_length + SIGNATURE]
|
||||
.try_into()
|
||||
@@ -206,6 +225,22 @@ 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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_ => {}
|
||||
}
|
||||
|
||||
@@ -223,48 +258,6 @@ pub fn parse_message(
|
||||
//
|
||||
// rien ?
|
||||
// si NATTRAVERSALREQUEST alors
|
||||
NATTRAVERSALREQUEST => {
|
||||
// send ok & send nattraversalrequest2 to peer
|
||||
constructed_message = construct_message(OK, Vec::new(), id, crypto_pair);
|
||||
|
||||
let ilength = u16::from_be_bytes(length_bytes);
|
||||
let received_address =
|
||||
&received_message[LENGTH + EXTENSIONS..LENGTH + ilength as usize];
|
||||
let address = String::from_utf8(received_address.to_vec()).expect("wrong name");
|
||||
|
||||
let natreq2 = construct_message(
|
||||
NATTRAVERSALREQUEST2,
|
||||
ip.to_string().into_bytes(),
|
||||
id,
|
||||
crypto_pair,
|
||||
);
|
||||
|
||||
senders.send_via(
|
||||
0,
|
||||
natreq2.expect("couldnt construct message nattraversalrequest2"),
|
||||
address,
|
||||
false,
|
||||
);
|
||||
}
|
||||
|
||||
NATTRAVERSALREQUEST2 => {
|
||||
// send ok & send ping to peer
|
||||
constructed_message = construct_message(OK, Vec::new(), id, crypto_pair);
|
||||
|
||||
let ilength = u16::from_be_bytes(length_bytes);
|
||||
let received_address =
|
||||
&received_message[LENGTH + EXTENSIONS..LENGTH + ilength as usize];
|
||||
let address = String::from_utf8(received_address.to_vec()).expect("wrong name");
|
||||
|
||||
let pingreq = construct_message(PING, Vec::new(), id, crypto_pair);
|
||||
|
||||
senders.send_via(
|
||||
0,
|
||||
pingreq.expect("couldnt construct message ping request"),
|
||||
address,
|
||||
false,
|
||||
);
|
||||
}
|
||||
//
|
||||
// ERROR
|
||||
//
|
||||
@@ -298,7 +291,40 @@ pub fn parse_message(
|
||||
//
|
||||
//
|
||||
// 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
|
||||
//
|
||||
@@ -306,7 +332,26 @@ pub fn parse_message(
|
||||
//
|
||||
// ROOTREPLY
|
||||
//
|
||||
// envoie un datum request
|
||||
ROOTREPLY => {
|
||||
// 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
|
||||
//
|
||||
@@ -378,6 +423,6 @@ pub fn parse_message(
|
||||
//
|
||||
// envoie OK à S puis envoie un ping à S
|
||||
_ => return None,
|
||||
}
|
||||
};
|
||||
constructed_message
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ use crate::P2PSharedData;
|
||||
use crate::cryptographic_signature::CryptographicSignature;
|
||||
use crate::message_handling::EventType;
|
||||
use crate::message_handling::handle_recevied_message;
|
||||
use crate::peers_refresh::HandshakeHistory;
|
||||
use std::collections::HashMap;
|
||||
use std::net::SocketAddr;
|
||||
use std::net::UdpSocket;
|
||||
@@ -21,9 +22,9 @@ pub struct MultipleSenders {
|
||||
}
|
||||
|
||||
pub struct Message {
|
||||
payload: Vec<u8>,
|
||||
address: String,
|
||||
is_resp_to_server_handshake: bool,
|
||||
pub payload: Vec<u8>,
|
||||
pub address: String,
|
||||
pub is_resp_to_server_handshake: bool,
|
||||
}
|
||||
|
||||
struct RetryMessage {
|
||||
@@ -205,64 +206,74 @@ impl MultipleSenders {
|
||||
data: Vec<u8>,
|
||||
remote_addr: String,
|
||||
is_resp_to_server_handshake: bool,
|
||||
messages_list: &Mutex<HashMap<i32, EventType>>,
|
||||
) {
|
||||
println!(
|
||||
"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) {
|
||||
let _ = sender.send(Message {
|
||||
payload: data,
|
||||
address: remote_addr,
|
||||
is_resp_to_server_handshake,
|
||||
});
|
||||
let _ = sender.send(msg_to_send);
|
||||
}
|
||||
if !is_resp_to_server_handshake {
|
||||
let mut guard = messages_list.lock().unwrap();
|
||||
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);
|
||||
/*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];
|
||||
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]);
|
||||
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),
|
||||
}
|
||||
Err(e) => eprintln!("Erreur de réception: {}", e),
|
||||
}
|
||||
}
|
||||
});
|
||||
}*/
|
||||
});
|
||||
}*/
|
||||
}
|
||||
|
||||
pub fn start_receving_thread(
|
||||
shared_data: &P2PSharedData,
|
||||
socket_addr: SocketAddr,
|
||||
cmd_tx: crossbeam_channel::Sender<NetworkEvent>,
|
||||
handshake_history: &Arc<Mutex<HandshakeHistory>>,
|
||||
) {
|
||||
let sock_clone = shared_data.socket();
|
||||
let cryptopair_clone = shared_data.cryptopair();
|
||||
let senders_clone = shared_data.senders();
|
||||
let messages_clone = shared_data.messages_list();
|
||||
let servername_clone = shared_data.servername();
|
||||
|
||||
let handshake_clone = handshake_history.clone();
|
||||
thread::spawn(move || {
|
||||
let mut buf = [0u8; 1024];
|
||||
loop {
|
||||
@@ -275,11 +286,11 @@ pub fn start_receving_thread(
|
||||
&messages_clone,
|
||||
&received_data,
|
||||
&cryptopair_clone,
|
||||
&socket_addr,
|
||||
&senders_clone,
|
||||
&servername_clone,
|
||||
cmd_tx.clone(),
|
||||
src,
|
||||
&handshake_clone,
|
||||
);
|
||||
}
|
||||
Err(e) => eprintln!("Erreur de réception: {}", e),
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
use crate::cryptographic_signature::{CryptographicSignature, sign_message};
|
||||
use crate::{
|
||||
cryptographic_signature::{CryptographicSignature, sign_message},
|
||||
server_communication::generate_id,
|
||||
};
|
||||
|
||||
const ID: usize = 4;
|
||||
const TYPE: usize = 5;
|
||||
@@ -6,18 +9,18 @@ const LENGTH: usize = 7;
|
||||
const EXTENSIONS: usize = 4;
|
||||
const SIGNATURE: usize = 64;
|
||||
|
||||
pub(crate) const PING: u8 = 0;
|
||||
pub(crate) const OK: u8 = 128;
|
||||
pub(crate) const ERROR: u8 = 129;
|
||||
pub(crate) const HELLO: u8 = 1;
|
||||
pub(crate) const HELLOREPLY: u8 = 130;
|
||||
pub(crate) const ROOTREQUEST: u8 = 2;
|
||||
pub(crate) const ROOTREPLY: u8 = 131;
|
||||
pub(crate) const DATUMREQUEST: u8 = 3;
|
||||
pub(crate) const NODATUM: u8 = 133;
|
||||
pub(crate) const DATUM: u8 = 132;
|
||||
pub(crate) const NATTRAVERSALREQUEST: u8 = 4;
|
||||
pub(crate) const NATTRAVERSALREQUEST2: u8 = 5;
|
||||
const PING: u8 = 0;
|
||||
const OK: u8 = 128;
|
||||
const ERROR: u8 = 129;
|
||||
const HELLO: u8 = 1;
|
||||
const HELLOREPLY: u8 = 130;
|
||||
pub const ROOTREQUEST: u8 = 2;
|
||||
const ROOTREPLY: u8 = 131;
|
||||
const DATUMREQUEST: u8 = 3;
|
||||
const NODATUM: u8 = 133;
|
||||
const DATUM: u8 = 132;
|
||||
const NATTRAVERSALREQUEST: u8 = 4;
|
||||
const NATTRAVERSALREQUEST2: u8 = 5;
|
||||
|
||||
pub fn construct_message(
|
||||
msgtype: u8,
|
||||
@@ -43,11 +46,11 @@ pub fn construct_message(
|
||||
let signature = sign_message(crypto_pair, &message);
|
||||
return Some(signature);
|
||||
}
|
||||
PING | OK => {
|
||||
PING | OK | ROOTREQUEST => {
|
||||
message.extend_from_slice(&0u16.to_be_bytes());
|
||||
return Some(message);
|
||||
}
|
||||
ERROR | ROOTREQUEST | DATUMREQUEST => {
|
||||
ERROR | DATUMREQUEST => {
|
||||
message.extend_from_slice(&payload.len().to_be_bytes());
|
||||
message.extend_from_slice(&payload);
|
||||
return Some(message);
|
||||
@@ -55,8 +58,8 @@ pub fn construct_message(
|
||||
ROOTREPLY | NODATUM | DATUM | NATTRAVERSALREQUEST => {
|
||||
message.extend_from_slice(&payload.len().to_be_bytes());
|
||||
message.extend_from_slice(&payload);
|
||||
//let signature = sign_message(crypto_pair, &message);
|
||||
//message.extend_from_slice(&signature);
|
||||
let signature = sign_message(crypto_pair, &message);
|
||||
message.extend_from_slice(&signature);
|
||||
return Some(message);
|
||||
}
|
||||
|
||||
@@ -64,176 +67,3 @@ pub fn construct_message(
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
pub struct UDPMessage {
|
||||
id: u32,
|
||||
msg_type: u8,
|
||||
length: u16,
|
||||
body: Vec<u8>,
|
||||
signature: Vec<u8>,
|
||||
}
|
||||
|
||||
pub struct HandshakeMessage {
|
||||
pub id: u32,
|
||||
msg_type: u8,
|
||||
length: u16,
|
||||
extensions: u32,
|
||||
pub name: Vec<u8>,
|
||||
pub signature: Vec<u8>,
|
||||
}
|
||||
|
||||
pub struct NatTraversal {}
|
||||
|
||||
impl UDPMessage {
|
||||
pub fn ping(id: u32) -> UDPMessage {
|
||||
UDPMessage {
|
||||
id: id,
|
||||
msg_type: 0,
|
||||
length: 0,
|
||||
body: vec![0; 985],
|
||||
signature: vec![0; 32],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn error(id: u32) -> UDPMessage {
|
||||
UDPMessage {
|
||||
id: id,
|
||||
msg_type: 129,
|
||||
length: 0,
|
||||
body: vec![0; 985],
|
||||
signature: vec![0; 32],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse(received_message: Vec<u8>) -> UDPMessage {
|
||||
let id_bytes: [u8; 4] = received_message[0..4]
|
||||
.try_into()
|
||||
.expect("Taille incorrecte");
|
||||
let length_bytes: [u8; 2] = received_message[5..7]
|
||||
.try_into()
|
||||
.expect("Taille incorrecte");
|
||||
let msg_length = u16::from_be_bytes(length_bytes);
|
||||
let name_bytes = &received_message[7..msg_length as usize + 8];
|
||||
let signature_bytes =
|
||||
&received_message[msg_length as usize + 8..msg_length as usize + 9 + 32];
|
||||
UDPMessage {
|
||||
id: u32::from_be_bytes(id_bytes),
|
||||
msg_type: received_message[4],
|
||||
length: u16::from_be_bytes(length_bytes),
|
||||
body: name_bytes.to_vec(),
|
||||
signature: signature_bytes.to_vec(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn display(&self) {
|
||||
println!("ID: {:?}", self.id);
|
||||
println!("Message Type: {}", self.msg_type);
|
||||
println!("Length: {:?}", self.length);
|
||||
let good_length = usize::min(self.length as usize, 985);
|
||||
println!("name: {:?}", &self.body[..good_length]);
|
||||
println!("Signature: {:?}", self.signature);
|
||||
}
|
||||
}
|
||||
|
||||
impl HandshakeMessage {
|
||||
pub fn display(&self) {
|
||||
println!("ID: {:?}", self.id);
|
||||
println!("Message Type: {}", self.msg_type);
|
||||
println!("Length: {:?}", self.length);
|
||||
println!("extensions: {:?}", self.extensions);
|
||||
println!("name: {:?}", &self.name[..(self.length - 4) as usize]);
|
||||
println!("Signature: {:?}", self.signature);
|
||||
}
|
||||
pub fn hello(id: u32, length: u16, username: String) -> HandshakeMessage {
|
||||
let name_vec = username.trim_end_matches(char::from(0)).as_bytes().to_vec();
|
||||
HandshakeMessage {
|
||||
id: id,
|
||||
msg_type: 1,
|
||||
length: length,
|
||||
extensions: 0,
|
||||
name: name_vec,
|
||||
signature: vec![0; 64],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn helloReply(id: u32, length: u16, username: String) -> HandshakeMessage {
|
||||
let name_vec = username.trim_end_matches(char::from(0)).as_bytes().to_vec();
|
||||
HandshakeMessage {
|
||||
id: id,
|
||||
msg_type: 130,
|
||||
length: length,
|
||||
extensions: 0,
|
||||
name: name_vec,
|
||||
signature: vec![0; 64],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn serialize(&self) -> Vec<u8> {
|
||||
let mut out = Vec::with_capacity(4 + 1 + 2 + 4 + self.name.len() + self.signature.len());
|
||||
|
||||
// id: u32 little-endian
|
||||
out.extend_from_slice(&self.id.to_be_bytes());
|
||||
|
||||
// msg_type: u8
|
||||
out.push(self.msg_type);
|
||||
|
||||
out.extend_from_slice(&self.length.to_be_bytes());
|
||||
|
||||
out.extend_from_slice(&self.extensions.to_be_bytes());
|
||||
|
||||
out.extend_from_slice(&self.name);
|
||||
|
||||
out.extend_from_slice(&self.signature);
|
||||
|
||||
out
|
||||
}
|
||||
|
||||
pub fn parse(received_message: Vec<u8>) -> HandshakeMessage {
|
||||
let id_bytes: [u8; 4] = received_message[0..4]
|
||||
.try_into()
|
||||
.expect("Taille incorrecte");
|
||||
let length_bytes: [u8; 2] = received_message[5..7]
|
||||
.try_into()
|
||||
.expect("Taille incorrecte");
|
||||
let msg_length = u16::from_be_bytes(length_bytes);
|
||||
let extensions_bytes: [u8; 4] = received_message[7..11]
|
||||
.try_into()
|
||||
.expect("Taille incorrecte");
|
||||
let name_bytes = &received_message[11..(11 + msg_length - 4) as usize];
|
||||
let signature_bytes =
|
||||
&received_message[(11 + msg_length - 4) as usize..(11 + msg_length - 4 + 64) as usize];
|
||||
HandshakeMessage {
|
||||
id: u32::from_be_bytes(id_bytes),
|
||||
msg_type: received_message[4],
|
||||
length: u16::from_be_bytes(length_bytes),
|
||||
extensions: u32::from_be_bytes(extensions_bytes),
|
||||
name: name_bytes.to_vec(),
|
||||
signature: signature_bytes.to_vec(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
// Note this useful idiom: importing names from outer (for mod tests) scope.
|
||||
use super::*;
|
||||
|
||||
/// creates an handshake message
|
||||
#[tokio::test]
|
||||
async fn creating_handshake_msg() {
|
||||
let username = String::from("charlie_kirk");
|
||||
let handshake = HandshakeMessage::hello(0, 12, username);
|
||||
handshake.display();
|
||||
}
|
||||
|
||||
/// parses an handshake message
|
||||
#[tokio::test]
|
||||
async fn parse_handshakemessage() {
|
||||
let username = String::from("charlie_kirk");
|
||||
let handshake = HandshakeMessage::hello(0, 12, username);
|
||||
let ser = handshake.serialize();
|
||||
let parsed = HandshakeMessage::parse(ser);
|
||||
handshake.display();
|
||||
parsed.display();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
use std::{
|
||||
collections::{HashMap, VecDeque},
|
||||
net::{AddrParseError, SocketAddr},
|
||||
net::{AddrParseError, Ipv4Addr, SocketAddr},
|
||||
ops::Add,
|
||||
process::Command,
|
||||
sync::{Arc, Mutex},
|
||||
@@ -11,54 +11,134 @@ use std::{
|
||||
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 {
|
||||
username: String,
|
||||
ip: SocketAddr,
|
||||
pub username: String,
|
||||
pub pubkey: VerifyingKey,
|
||||
pub ip: SocketAddr,
|
||||
}
|
||||
|
||||
pub struct HandshakeHistory {
|
||||
time_k_ip_v: HashMap<u64, u64>,
|
||||
ip_k_peerinfo_v: HashMap<u64, PeerInfo>,
|
||||
//time_k_ip_v: HashMap<u64, u64>,
|
||||
username_k_peerinfo_v: HashMap<String, PeerInfo>,
|
||||
ip_k_peerinfo_v: HashMap<String, PeerInfo>,
|
||||
}
|
||||
|
||||
impl HandshakeHistory {
|
||||
pub fn new() -> 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(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update_handshake(&mut self) {
|
||||
/*pub fn update_handshake(&self) {
|
||||
let hashmap_shared = Arc::new(self.username_k_peerinfo_v);
|
||||
thread::spawn(move || {
|
||||
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
|
||||
let selfhashmap = hashmap_shared.clone();
|
||||
loop {
|
||||
let mut child = Command::new("sleep").arg("9").spawn().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
|
||||
for peer in selfhashmap.keys() {
|
||||
let peer_ip = selfhashmap.get(peer);
|
||||
// send ping
|
||||
}
|
||||
let mut child = Command::new("sleep").arg("10").spawn().unwrap();
|
||||
let _result = child.wait().unwrap();
|
||||
}
|
||||
});
|
||||
}*/
|
||||
|
||||
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 add_new_handshake(&mut self, hash: u64, username: String, ip: SocketAddr) {
|
||||
let current_time: u64 = SystemTime::now()
|
||||
.duration_since(time::UNIX_EPOCH)
|
||||
.expect("system time before UNIX EPOCH")
|
||||
.as_secs();
|
||||
println!("time:{}", current_time);
|
||||
/*self.time_k_hash_v.insert(current_time, hash);
|
||||
self.hash_k_peerinfo_v
|
||||
.insert(hash, PeerInfo { username, ip });*/
|
||||
pub fn update_peer_info(&mut self, ip: String, username: String) {
|
||||
let peerinfo = self.get_peer_info_ip(ip.clone());
|
||||
match peerinfo {
|
||||
Some(peer_info) => match ip.parse::<SocketAddr>() {
|
||||
Ok(addr) => {
|
||||
let new_peer_info = PeerInfo {
|
||||
username: username.clone(),
|
||||
pubkey: peer_info.pubkey,
|
||||
ip: addr,
|
||||
};
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,10 +148,7 @@ mod tests {
|
||||
|
||||
use super::*;
|
||||
|
||||
///
|
||||
/// creates a cryptographic signature
|
||||
///
|
||||
#[test]
|
||||
/*#[test]
|
||||
fn creating_cryptographic_signature() {
|
||||
let mut hh = HandshakeHistory::new();
|
||||
hh.add_new_handshake(
|
||||
@@ -79,5 +156,5 @@ mod tests {
|
||||
"putain".to_string(),
|
||||
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 1),
|
||||
);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
use bytes::Bytes;
|
||||
use getrandom::Error;
|
||||
|
||||
use crate::NetworkEvent;
|
||||
use crate::P2PSharedData;
|
||||
use crate::cryptographic_signature::{CryptographicSignature, formatPubKey, sign_message};
|
||||
use crate::message_handling::EventType;
|
||||
use crate::messages_channels::MultipleSenders;
|
||||
use crate::messages_channels::{Message, MultipleSenders};
|
||||
use crate::messages_structure::construct_message;
|
||||
use crate::server_communication::generate_id;
|
||||
use crossbeam_channel::{Receiver, Sender};
|
||||
use std::collections::HashMap;
|
||||
use std::net::SocketAddr;
|
||||
use std::net::UdpSocket;
|
||||
@@ -28,6 +33,26 @@ pub async fn register_with_the_server(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
///
|
||||
/// sends a get request to the server to get the socket address of the given peer
|
||||
///
|
||||
|
||||
pub async fn get_socket_address(username: String, ip: String) -> Result<Bytes, reqwest::Error> {
|
||||
let client = reqwest::Client::new();
|
||||
let uri = format!("{}/peers/{}/addresses", ip, username);
|
||||
let res = client.get(uri).send().await?;
|
||||
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?;
|
||||
Ok(body)
|
||||
}
|
||||
|
||||
pub fn parse_addresses(input: &String) -> Vec<SocketAddr> {
|
||||
let mut addrs = Vec::new();
|
||||
for line in input.lines() {
|
||||
@@ -45,23 +70,67 @@ pub fn parse_addresses(input: &String) -> Vec<SocketAddr> {
|
||||
///
|
||||
/// registers the IP addresses by sending a Hello request to the server.
|
||||
///
|
||||
pub fn register_ip_addresses(
|
||||
crypto_pair: &CryptographicSignature,
|
||||
server_uri: String,
|
||||
senders: &MultipleSenders,
|
||||
messages_list: &Mutex<HashMap<i32, EventType>>,
|
||||
id: i32,
|
||||
pub async fn perform_handshake(
|
||||
sd: &P2PSharedData,
|
||||
username: String,
|
||||
ip: String,
|
||||
event_tx: Sender<NetworkEvent>,
|
||||
is_server_handshake: bool,
|
||||
) {
|
||||
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, server_uri, false);
|
||||
println!("username: {}, ip: {}", username.clone(), ip.clone());
|
||||
let crypto_pair = sd.cryptopair_ref();
|
||||
let senders = sd.senders_ref();
|
||||
let messages_list = sd.messages_list_ref();
|
||||
let id = generate_id();
|
||||
let server_addr_query = get_socket_address(username.clone(), ip.clone());
|
||||
match server_addr_query.await {
|
||||
Ok(sockaddr_bytes) => {
|
||||
match String::from_utf8(sockaddr_bytes.to_vec()) {
|
||||
Ok(s) => {
|
||||
let addresses = parse_addresses(&s);
|
||||
if let Some(first) = addresses.first() {
|
||||
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,
|
||||
first.to_string(),
|
||||
is_server_handshake,
|
||||
messages_list,
|
||||
);
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
|
||||
//let res = event_tx
|
||||
// .send(NetworkEvent::());
|
||||
} else {
|
||||
//let res = event_tx.send(NetworkEvent::Error());
|
||||
let err_msg =
|
||||
format!("no valid socket addresses found in: {}", s).to_string();
|
||||
let res = event_tx.send(NetworkEvent::Error(err_msg));
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
//let res = event_tx.send(NetworkEvent::Error());
|
||||
let err_msg =
|
||||
format!("invalid UTF-8 in socket address bytes: {}", e).to_string();
|
||||
let res = event_tx.send(NetworkEvent::Error(err_msg));
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
let err_msg = format!("failed to retreive socket address: {}", e).to_string();
|
||||
let res = event_tx.send(NetworkEvent::Error(err_msg));
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
|
||||
/*let mut list = messages_list.lock().expect("Failed to lock messages_list");
|
||||
match list.get(&id) {
|
||||
Some(_) => {
|
||||
|
||||
41
todo.md
41
todo.md
@@ -1,32 +1,13 @@
|
||||
# Todo
|
||||
# Todo :
|
||||
|
||||
|
||||
## peer discovery
|
||||
|
||||
## handshake
|
||||
|
||||
# Todo
|
||||
|
||||
## peer discovery
|
||||
|
||||
- get rsquest to the uri /peers/
|
||||
|
||||
## registration with the server
|
||||
|
||||
- generation of the cryptographic key OK
|
||||
- put request to the uri (check if the peer is already connected) OK
|
||||
- udp handshakes OK
|
||||
- get request to the uri /peers/key to get the public key of a peer OK
|
||||
- get request to the uri /peers/key/addresses OK
|
||||
|
||||
## handshake
|
||||
|
||||
- handshake structure OK
|
||||
|
||||
- 5min timeout after handshake
|
||||
- matain connection every 4 min
|
||||
|
||||
## data transfer
|
||||
|
||||
- request structure
|
||||
- root/root reply structure
|
||||
- datum/nodatum and datum structures
|
||||
@@ -34,16 +15,7 @@
|
||||
- setting in gui to act as a relay
|
||||
- chunk, directory, big, bigdirectory structures
|
||||
|
||||
## fonctionnalités application
|
||||
|
||||
## nat traversal
|
||||
|
||||
- make hello and helloreply messages set the first extension bit to announce that peer is available for nat traversal
|
||||
- implement actual nat traversal requests
|
||||
- implement nat traversal :
|
||||
- if hello/helloreply doesnt work with a peer, find a peer that supports nat traversal (server in priority) then begin protocol
|
||||
|
||||
fonctionnalités :
|
||||
## fonctionnalités application :
|
||||
|
||||
rechercher les fichiers d'un pair
|
||||
telechargement des fichiers
|
||||
@@ -53,11 +25,13 @@ choisir le nombre de canaux
|
||||
handshake server DOING
|
||||
se deconnecter du réseau DOING
|
||||
|
||||
## autre
|
||||
|
||||
## autre :
|
||||
|
||||
socket ipv6
|
||||
|
||||
# FAIT
|
||||
|
||||
# FAIT :
|
||||
|
||||
- choisir un pseudo OK
|
||||
- get rsquest to the uri /peers/ OK
|
||||
@@ -71,3 +45,4 @@ socket ipv6
|
||||
- generer une clé publique OK
|
||||
- verifier signature OK
|
||||
- 2 channels -> un pour envoyer et un pour recevoir OK
|
||||
|
||||
|
||||
Reference in New Issue
Block a user