src: add minimal logging

This commit is contained in:
Ujjwal Sharma 2021-04-05 17:20:27 +05:30
parent 59c4b4d37b
commit ad7db7481d
Signed by: ryzokuken
GPG Key ID: 460B292812C67D9F
4 changed files with 27 additions and 1 deletions

21
Cargo.lock generated
View File

@ -314,7 +314,9 @@ dependencies = [
"clap",
"dirs",
"ed25519-dalek",
"env_logger",
"json",
"log",
"rand",
"regex",
"toml",
@ -412,6 +414,19 @@ dependencies = [
"zeroize",
]
[[package]]
name = "env_logger"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17392a012ea30ef05a610aa97dfb49496e71c9f676b27879922ea5bdf60d9d3f"
dependencies = [
"atty",
"humantime",
"log",
"regex",
"termcolor",
]
[[package]]
name = "event-listener"
version = "2.5.1"
@ -521,6 +536,12 @@ dependencies = [
"libc",
]
[[package]]
name = "humantime"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
[[package]]
name = "indexmap"
version = "1.6.2"

View File

@ -16,6 +16,8 @@ json = "0.12.4"
base64 = "0.13.0"
regex = "1.4.5"
async-trait = "0.1.7"
log = "0.4.14"
env_logger = "0.8.3"
[dependencies.async-std]
version = "1.6.2"

View File

@ -17,6 +17,7 @@ pub async fn recv(sender: async_std::channel::Sender<Peer>) {
let (amt, _) = socket.recv_from(&mut buf).await.unwrap();
let buf = &mut buf[..amt];
let packet = String::from_utf8(buf.to_vec()).unwrap();
log::debug!("Recieved discovery beacon: {}", packet);
let peer = Peer::from_discovery_packet(packet.as_str());
if !old.contains(&peer) {
old.insert(peer.clone());
@ -42,6 +43,7 @@ pub async fn send(pubkey: Arc<String>) {
socket.set_broadcast(true).unwrap();
loop {
log::debug!("Sending discovery beacon");
socket.send_to(&buf, "255.255.255.255:8008").await.unwrap();
socket.send_to(&buf, "[FF02::1]:8008").await.unwrap();
task::sleep(std::time::Duration::from_secs(1)).await;

View File

@ -12,6 +12,7 @@ use keypair::{SSBKeypair, SSBPublicKey};
#[async_std::main]
async fn main() {
env_logger::init();
let options = load_yaml!("options.yaml");
let options = App::from(options).get_matches();
@ -41,6 +42,6 @@ async fn main() {
task::spawn(discovery::send(Arc::new(keypair.public.to_base64())));
while let Ok(peer) = precv.recv().await {
println!("{}", peer.to_discovery_packet());
log::info!("New peer found: {}", peer.to_discovery_packet());
};
}