wip structures and message signature

This commit is contained in:
2025-12-17 14:09:51 +01:00
parent 3664d55678
commit e902070c82
4 changed files with 174 additions and 39 deletions

View File

@@ -1,4 +1,5 @@
use crate::cryptographic_signature::{CryptographicSignature, formatPubKey};
use crate::cryptographic_signature::{CryptographicSignature, formatPubKey, sign_message};
use crate::messages_structure::HandshakeMessage;
use std::net::UdpSocket;
///
/// Registration with the server happens in two steps: first, the client
@@ -30,8 +31,16 @@ async fn register_with_the_server(crypto_pair: CryptographicSignature) -> Result
/// to receive requests by sending a Hello request to the client. If the client doesnt reply to the Hello
/// request with a properly signed message, its address will not be published by the server.
fn register_ip_addresses(crypto_pair: CryptographicSignature) {
let socket = UdpSocket::bind("127.0.0.1:4242");
//TODO
let socket = UdpSocket::bind("127.0.0.1:4242").expect("bind failed");
let username_size = crypto_pair.username.len();
let hello_handshake = HandshakeMessage::hello(0, username_size as u16, crypto_pair.username.clone());
let hello_handshake_serialized = hello_handshake.serialize();
let message_signed = sign_message(crypto_pair, hello_handshake_serialized);
socket.send_to(&message_signed, "jch.irif.fr:8443").expect("send failed");
let mut buf = [0u8; 1024];
socket.recv_from(&mut buf).expect("receive failed");
let hello_handshake_received = HandshakeMessage::parse(buf);
hello_handshake_received.display();
}
#[cfg(test)]
@@ -39,12 +48,12 @@ mod tests {
// Note this useful idiom: importing names from outer (for mod tests) scope.
use super::*;
#[tokio::test]
/*#[tokio::test]
async fn creating_cryptographic_signature() {
let username = String::from("charlie_kirk");
let crypto_pair = CryptographicSignature::new(username);
if let Err(e) = register_with_the_server(crypto_pair).await {
eprintln!("Error during registration: {}", e);
}
}
}*/
}