tmp #1

Merged
wikano merged 5 commits from tmp into master 2026-01-11 20:58:32 +00:00
4 changed files with 34 additions and 21 deletions
Showing only changes of commit cd2f87cb81 - Show all commits

BIN
README.md

Binary file not shown.

View File

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

View File

@@ -4,7 +4,7 @@ use crate::{
CryptographicSignature, get_peer_key, sign_message, verify_signature,
},
messages_channels::MultipleSenders,
messages_structure::HandshakeMessage,
messages_structure::{HandshakeMessage, constructMessage},
registration,
};
use std::sync::{Arc, Mutex};
@@ -141,6 +141,7 @@ pub fn parse_message(
received_name: String,
id: i32,
username: String,
crypto_pair: &CryptographicSignature
) -> Option<Vec<u8>> {
let id_bytes: [u8; 4] = received_message[0..ID]
.try_into()
@@ -161,7 +162,6 @@ pub fn parse_message(
.unwrap()
.block_on(get_peer_key(&received_name))
.expect("failed to retrieve public key");
let signature: [u8; SIGNATURE] = received_message
[LENGTH + msg_length..LENGTH + msg_length + SIGNATURE]
.try_into()
@@ -195,6 +195,7 @@ pub fn parse_message(
//
HELLO => {
let username_size = username.len();
let helloreply = constructMessage(msgtype, payload, &id, crypto_pair)
let hello_handshake =
HandshakeMessage::helloReply(id as u32, username_size as u16 + 4, username.clone());
//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 TYPE: usize = 5;
@@ -19,25 +22,27 @@ const DATUM: u8 = 132;
const NATTRAVERSALREQUEST: u8 = 4;
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 {
HELLO => {
let message: Vec<u8> = vec![0u8; LENGTH + EXTENSIONS + payload.len() + SIGNATURE];
message.extend_from_slice(id);
message.extend_from_slice(0);
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],
}
HELLO | HELLOREPLY => {
message.extend_from_slice(&payload);
let signature = sign_message(crypto_pair, &message);
message.extend_from_slice(&signature);
return Some(message);
}
_ => {}
}
None
}
pub struct UDPMessage {