forked from ryzokuken/cosmoline
src: add simple broadcast listening logic
This commit is contained in:
parent
4111aed599
commit
1f2635d845
30
src/main.rs
30
src/main.rs
|
@ -1,6 +1,7 @@
|
||||||
use clap::{load_yaml, App};
|
use clap::{load_yaml, App};
|
||||||
use ed25519_dalek::Keypair;
|
use ed25519_dalek::Keypair;
|
||||||
|
|
||||||
|
use std::net::UdpSocket;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
mod keypair;
|
mod keypair;
|
||||||
|
@ -9,6 +10,28 @@ use keypair::SSBKeypair;
|
||||||
|
|
||||||
type Config = toml::map::Map<String, toml::Value>;
|
type Config = toml::map::Map<String, toml::Value>;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct Host {
|
||||||
|
protocol: String,
|
||||||
|
host: String,
|
||||||
|
port: String,
|
||||||
|
pubkey: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_packet(packet: String) -> Host {
|
||||||
|
let mut packet = packet.splitn(4, ':');
|
||||||
|
let protocol = packet.next().unwrap();
|
||||||
|
let host = packet.next().unwrap();
|
||||||
|
let port = packet.next().unwrap().splitn(2, '~').next().unwrap();
|
||||||
|
let pubkey = packet.next().unwrap();
|
||||||
|
Host {
|
||||||
|
protocol: protocol.to_string(),
|
||||||
|
host: host.to_string(),
|
||||||
|
port: port.to_string(),
|
||||||
|
pubkey: pubkey.to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let options = load_yaml!("options.yaml");
|
let options = load_yaml!("options.yaml");
|
||||||
let options = App::from(options).get_matches();
|
let options = App::from(options).get_matches();
|
||||||
|
@ -32,4 +55,11 @@ fn main() {
|
||||||
};
|
};
|
||||||
let keypair = Keypair::read_or_generate(path.join("secret"));
|
let keypair = Keypair::read_or_generate(path.join("secret"));
|
||||||
println!("{}", keypair.to_json().pretty(2));
|
println!("{}", keypair.to_json().pretty(2));
|
||||||
|
|
||||||
|
let socket = UdpSocket::bind("0.0.0.0:8008").unwrap();
|
||||||
|
let mut buf = [0; 1024];
|
||||||
|
let (amt, _) = socket.recv_from(&mut buf).unwrap();
|
||||||
|
let buf = &mut buf[..amt];
|
||||||
|
let packet = String::from_utf8(buf.to_vec()).unwrap();
|
||||||
|
println!("{:?}", parse_packet(packet));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue