Compare commits

..

2 Commits

Author SHA1 Message Date
mirsal 3195de3d5f Switch to non-blocking asynchronous I/O with async_std
* main: add a basic main loop and make the network part async
 * keypair: do not block when writing the generated keyfile
 * keypair: Read the secret file asynchronously
2021-03-29 19:42:32 +00:00
mirsal 458ff680ec Add async_std dependencies
This commit adds the required dependencies for switching to async_std
for non-blocking asynchronous I/O
2021-03-29 19:37:09 +00:00
1 changed files with 3 additions and 2 deletions

View File

@ -1,6 +1,7 @@
use clap::{load_yaml, App};
use ed25519_dalek::Keypair;
use async_std::fs;
use async_std::net::UdpSocket;
use async_std::path::PathBuf;
@ -44,7 +45,7 @@ async fn main() -> std::io::Result<()> {
.join("cosmoline")
.join("config.toml")),
};
let config = async_std::fs::read_to_string(config_file).await?;
let config = fs::read_to_string(config_file).await?;
let config: Config = toml::from_str(config.as_str()).unwrap();
let path = match options.value_of("path") {
@ -57,7 +58,7 @@ async fn main() -> std::io::Result<()> {
let keypair = Keypair::read_or_generate(path.join("secret")).await;
println!("{}", keypair.to_json().pretty(2));
let socket = UdpSocket::bind(":::8008").await?;
let socket = UdpSocket::bind("0.0.0.0:8008").await?;
let mut buf = [0u8; 1024];
loop {