forked from ryzokuken/cosmoline
Compare commits
3 Commits
9c0bc7c5c1
...
0405ec3b16
Author | SHA1 | Date |
---|---|---|
mirsal | 0405ec3b16 | |
mirsal | 749cf151bf | |
mirsal | 60cf753b7f |
|
@ -1,9 +1,7 @@
|
||||||
|
|
||||||
use ed25519_dalek::{Keypair, PublicKey, SecretKey};
|
use ed25519_dalek::{Keypair, PublicKey, SecretKey};
|
||||||
use json::{object, JsonValue};
|
use json::{object, JsonValue};
|
||||||
use rand::rngs::OsRng;
|
use rand::rngs::OsRng;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
|
||||||
use async_std::fs;
|
use async_std::fs;
|
||||||
use async_std::path::PathBuf;
|
use async_std::path::PathBuf;
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
|
|
11
src/main.rs
11
src/main.rs
|
@ -1,6 +1,5 @@
|
||||||
use clap::{load_yaml, App};
|
use clap::{load_yaml, App};
|
||||||
use ed25519_dalek::Keypair;
|
use ed25519_dalek::Keypair;
|
||||||
|
|
||||||
use async_std::fs;
|
use async_std::fs;
|
||||||
use async_std::net::UdpSocket;
|
use async_std::net::UdpSocket;
|
||||||
use async_std::path::PathBuf;
|
use async_std::path::PathBuf;
|
||||||
|
@ -34,7 +33,7 @@ fn parse_packet(packet: String) -> Host {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_std::main]
|
#[async_std::main]
|
||||||
async fn main() -> std::io::Result<()> {
|
async 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();
|
||||||
|
|
||||||
|
@ -45,7 +44,7 @@ async fn main() -> std::io::Result<()> {
|
||||||
.join("cosmoline")
|
.join("cosmoline")
|
||||||
.join("config.toml")),
|
.join("config.toml")),
|
||||||
};
|
};
|
||||||
let config = fs::read_to_string(config_file).await?;
|
let config = fs::read_to_string(config_file).await.unwrap();
|
||||||
let config: Config = toml::from_str(config.as_str()).unwrap();
|
let config: Config = toml::from_str(config.as_str()).unwrap();
|
||||||
|
|
||||||
let path = match options.value_of("path") {
|
let path = match options.value_of("path") {
|
||||||
|
@ -58,14 +57,14 @@ async fn main() -> std::io::Result<()> {
|
||||||
let keypair = Keypair::read_or_generate(path.join("secret")).await;
|
let keypair = Keypair::read_or_generate(path.join("secret")).await;
|
||||||
println!("{}", keypair.to_json().pretty(2));
|
println!("{}", keypair.to_json().pretty(2));
|
||||||
|
|
||||||
let socket = UdpSocket::bind("0.0.0.0:8008").await?;
|
let socket = UdpSocket::bind(":::8008").await.unwrap();
|
||||||
let mut buf = [0u8; 1024];
|
let mut buf = [0u8; 1024];
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let (amt, peer) = socket.recv_from(&mut buf).await?;
|
let (amt, peer) = socket.recv_from(&mut buf).await.unwrap();
|
||||||
let buf = &mut buf[..amt];
|
let buf = &mut buf[..amt];
|
||||||
let packet = String::from_utf8(buf.to_vec()).unwrap();
|
let packet = String::from_utf8(buf.to_vec()).unwrap();
|
||||||
println!("{:?}", (peer, parse_packet(packet)));
|
println!("{:?}", (peer, parse_packet(packet)));
|
||||||
}
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue