Files
p2p/client-network/src/server_communication.rs
2026-01-02 23:21:50 +01:00

23 lines
635 B
Rust

use bytes::Bytes;
use rand::Rng;
pub async fn get_peer_list(server_address: String) -> Result<Bytes, reqwest::Error> {
let client = reqwest::Client::new();
let uri = format!("{}/peers/", server_address);
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 generate_id() -> i32 {
rand::rng().random_range(0..i32::MAX)
}