tidy
This commit is contained in:
@@ -218,17 +218,12 @@ use crossbeam_channel::{Receiver, Sender};
|
||||
use sha2::{Digest, Sha256};
|
||||
|
||||
pub fn calculate_chunk_id(data: &[u8]) -> String {
|
||||
// 1. Create a new Sha256 hasher instance
|
||||
let mut hasher = Sha256::new();
|
||||
|
||||
// 2. Write the input data into the hasher
|
||||
hasher.update(data);
|
||||
|
||||
// 3. Finalize the hash computation and get the resulting bytes
|
||||
let hash_bytes = hasher.finalize();
|
||||
|
||||
// 4. Convert the hash bytes (array of u8) into a hexadecimal string
|
||||
// This is the common, human-readable format for cryptographic IDs.
|
||||
hex::encode(hash_bytes)
|
||||
}
|
||||
|
||||
@@ -237,15 +232,11 @@ pub fn start_p2p_executor(
|
||||
event_tx: Sender<NetworkEvent>,
|
||||
mut shared_data: Option<P2PSharedData>,
|
||||
) -> tokio::task::JoinHandle<()> {
|
||||
// Use tokio to spawn the asynchronous networking logic
|
||||
tokio::task::spawn(async move {
|
||||
// P2P/Networking Setup goes here
|
||||
|
||||
println!("Network executor started.");
|
||||
|
||||
// Main network loop
|
||||
loop {
|
||||
// Check for commands from the GUI
|
||||
if let Ok(cmd) = cmd_rx.try_recv() {
|
||||
match cmd {
|
||||
NetworkCommand::InitDownload(hash, ip, name) => {
|
||||
@@ -384,9 +375,6 @@ pub fn start_p2p_executor(
|
||||
NetworkCommand::ConnectPeer((username, _)) => {
|
||||
println!("[Network] ConnectPeer() called");
|
||||
println!("[Network] Attempting to connect to: {}", username);
|
||||
// Network logic to connect...
|
||||
// If successful, send an event back:
|
||||
// event_tx.send(NetworkEvent::PeerConnected(addr)).unwrap();
|
||||
}
|
||||
NetworkCommand::RequestFileTree(_) => {
|
||||
println!("[Network] RequestFileTree() called");
|
||||
@@ -549,18 +537,7 @@ pub fn start_p2p_executor(
|
||||
};
|
||||
println!("username created: {}", sd.cryptopair().username);
|
||||
}
|
||||
//println!("ip: {}", ip);
|
||||
}
|
||||
|
||||
//tokio::time::sleep(std::time::Duration::from_millis(5000)).await;
|
||||
|
||||
/*let res = event_tx.send(NetworkEvent::Connected());
|
||||
if let Some(error) = res.err() {
|
||||
println!(
|
||||
"[Network] Couldn't send crossbeam message to GUI: {}",
|
||||
error.to_string()
|
||||
);
|
||||
}*/
|
||||
}
|
||||
NetworkCommand::FetchPeerList(ip) => {
|
||||
println!("[Network] FetchPeerList() called");
|
||||
@@ -716,12 +693,6 @@ pub fn start_p2p_executor(
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Poll network for new events (e.g., an incoming connection)
|
||||
// ...
|
||||
// When a new peer is found:
|
||||
// event_tx.send(NetworkEvent::PeerConnected("NewPeerID".to_string())).unwrap();
|
||||
|
||||
// Avoid spinning too fast
|
||||
sleep(std::time::Duration::from_millis(50)).await;
|
||||
}
|
||||
})
|
||||
@@ -762,7 +733,6 @@ async fn quick_ping(addr: &SocketAddr, timeout_ms: u64, sd: &P2PSharedData) -> b
|
||||
///
|
||||
/// 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,
|
||||
|
||||
Reference in New Issue
Block a user