This commit is contained in:
TIBERGHIEN corentin
2026-01-08 19:12:07 +01:00
parent dc1767abe4
commit cd2f87cb81
4 changed files with 34 additions and 21 deletions

BIN
README.md

Binary file not shown.

View File

@@ -301,7 +301,7 @@ impl eframe::App for P2PClientApp {
ui.label("No connection.."); ui.label("No connection..");
} }
ServerStatus::ConnectedHandshake => { ServerStatus::ConnectedHandshake => {
let str = format!("📡 {}", self.active_server); let str = format!("📡");
ui.label(str); ui.label(str);
} }
} }
@@ -344,7 +344,14 @@ impl eframe::App for P2PClientApp {
for peer in &self.known_peers { for peer in &self.known_peers {
let is_active = let is_active =
self.active_peer.as_ref().map_or(false, |id| id == peer); // 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 = ui.selectable_label(is_active, format!("{}", peer));
let selectable;
if &self.active_server == peer {
selectable =
ui.selectable_label(is_active, format!("{} 📡 🌀", peer))
} else {
selectable = ui.selectable_label(is_active, format!("{}", peer));
}
if selectable.clicked() { if selectable.clicked() {
// switch to displaying this peer's tree // switch to displaying this peer's tree
self.active_peer = Some(peer.clone()); self.active_peer = Some(peer.clone());

View File

@@ -4,7 +4,7 @@ use crate::{
CryptographicSignature, get_peer_key, sign_message, verify_signature, CryptographicSignature, get_peer_key, sign_message, verify_signature,
}, },
messages_channels::MultipleSenders, messages_channels::MultipleSenders,
messages_structure::HandshakeMessage, messages_structure::{HandshakeMessage, constructMessage},
registration, registration,
}; };
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
@@ -141,6 +141,7 @@ pub fn parse_message(
received_name: String, received_name: String,
id: i32, id: i32,
username: String, username: String,
crypto_pair: &CryptographicSignature
) -> Option<Vec<u8>> { ) -> Option<Vec<u8>> {
let id_bytes: [u8; 4] = received_message[0..ID] let id_bytes: [u8; 4] = received_message[0..ID]
.try_into() .try_into()
@@ -161,7 +162,6 @@ pub fn parse_message(
.unwrap() .unwrap()
.block_on(get_peer_key(&received_name)) .block_on(get_peer_key(&received_name))
.expect("failed to retrieve public key"); .expect("failed to retrieve public key");
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()
@@ -195,6 +195,7 @@ pub fn parse_message(
// //
HELLO => { HELLO => {
let username_size = username.len(); let username_size = username.len();
let helloreply = constructMessage(msgtype, payload, &id, crypto_pair)
let hello_handshake = let hello_handshake =
HandshakeMessage::helloReply(id as u32, username_size as u16 + 4, username.clone()); HandshakeMessage::helloReply(id as u32, username_size as u16 + 4, username.clone());
//HandshakeMessage::display(&hello_handshake); //HandshakeMessage::display(&hello_handshake);

View File

@@ -1,4 +1,7 @@
use crate::server_communication::generate_id; use crate::{
cryptographic_signature::{CryptographicSignature, sign_message},
server_communication::generate_id,
};
const ID: usize = 4; const ID: usize = 4;
const TYPE: usize = 5; const TYPE: usize = 5;
@@ -19,25 +22,27 @@ const DATUM: u8 = 132;
const NATTRAVERSALREQUEST: u8 = 4; const NATTRAVERSALREQUEST: u8 = 4;
const NATTRAVERSALREQUEST2: u8 = 5; const NATTRAVERSALREQUEST2: u8 = 5;
pub fn constructMessage(msgtype: u8, payload: Vec<u8>, id: &[u8]) { pub fn constructMessage(
msgtype: u8,
payload: Vec<u8>,
id: i32,
crypto_pair: &CryptographicSignature,
) -> Option<Vec<u8>> {
let mut message = Vec::new();
message.extend_from_slice(&id);
message.push(msgtype);
match msgtype { match msgtype {
HELLO => { HELLO | HELLOREPLY => {
let message: Vec<u8> = vec![0u8; LENGTH + EXTENSIONS + payload.len() + SIGNATURE]; message.extend_from_slice(&payload);
let signature = sign_message(crypto_pair, &message);
message.extend_from_slice(id); message.extend_from_slice(&signature);
message.extend_from_slice(0); return Some(message);
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],
}
} }
_ => {}
} }
None
} }
pub struct UDPMessage { pub struct UDPMessage {