changed handling of async tasks
This commit is contained in:
parent
719a0b5455
commit
32fcfcb385
29
Cargo.lock
generated
29
Cargo.lock
generated
@ -518,6 +518,21 @@ dependencies = [
|
|||||||
"percent-encoding",
|
"percent-encoding",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures"
|
||||||
|
version = "0.3.30"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0"
|
||||||
|
dependencies = [
|
||||||
|
"futures-channel",
|
||||||
|
"futures-core",
|
||||||
|
"futures-executor",
|
||||||
|
"futures-io",
|
||||||
|
"futures-sink",
|
||||||
|
"futures-task",
|
||||||
|
"futures-util",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "futures-channel"
|
name = "futures-channel"
|
||||||
version = "0.3.30"
|
version = "0.3.30"
|
||||||
@ -525,6 +540,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78"
|
checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"futures-core",
|
"futures-core",
|
||||||
|
"futures-sink",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -533,6 +549,17 @@ version = "0.3.30"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d"
|
checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-executor"
|
||||||
|
version = "0.3.30"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d"
|
||||||
|
dependencies = [
|
||||||
|
"futures-core",
|
||||||
|
"futures-task",
|
||||||
|
"futures-util",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "futures-io"
|
name = "futures-io"
|
||||||
version = "0.3.30"
|
version = "0.3.30"
|
||||||
@ -568,6 +595,7 @@ version = "0.3.30"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48"
|
checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"futures-channel",
|
||||||
"futures-core",
|
"futures-core",
|
||||||
"futures-io",
|
"futures-io",
|
||||||
"futures-macro",
|
"futures-macro",
|
||||||
@ -642,6 +670,7 @@ name = "hacker-challenge"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ed25519-dalek",
|
"ed25519-dalek",
|
||||||
|
"futures",
|
||||||
"hex",
|
"hex",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"prost",
|
"prost",
|
||||||
|
@ -5,6 +5,7 @@ edition = "2021"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
ed25519-dalek = { version = "2.1.1", features = ["rand_core", "serde"] }
|
ed25519-dalek = { version = "2.1.1", features = ["rand_core", "serde"] }
|
||||||
|
futures = "0.3.30"
|
||||||
hex = "0.4.3"
|
hex = "0.4.3"
|
||||||
once_cell = "1.19.0"
|
once_cell = "1.19.0"
|
||||||
prost = "0.13.1"
|
prost = "0.13.1"
|
||||||
|
@ -73,7 +73,7 @@ pub fn sign_message_with_key(pubkey: &str, message: &str) -> Result<String, Sign
|
|||||||
let key_bytes = hex::decode(pubkey)?;
|
let key_bytes = hex::decode(pubkey)?;
|
||||||
let pubkey = VerifyingKey::from_bytes(&key_bytes.as_slice().try_into()?)?;
|
let pubkey = VerifyingKey::from_bytes(&key_bytes.as_slice().try_into()?)?;
|
||||||
|
|
||||||
// Lock the hashmap and try to get the SigningKey
|
// Lock the hashmap and try to get the SigningKey
|
||||||
let key_store = KEYS.lock().unwrap();
|
let key_store = KEYS.lock().unwrap();
|
||||||
let signing_key = match key_store.get(&pubkey) {
|
let signing_key = match key_store.get(&pubkey) {
|
||||||
Some(k) => k,
|
Some(k) => k,
|
||||||
|
20
src/grpc.rs
20
src/grpc.rs
@ -54,16 +54,26 @@ impl KeyDistribution for MyKeyDistribution {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn start() -> Result<(), Box<dyn std::error::Error>> {
|
async fn start_client() {
|
||||||
let addr = "[::1]:31373".parse().unwrap();
|
loop {
|
||||||
let key_distribution = MyKeyDistribution::default();
|
tokio::time::sleep(Duration::from_secs(10)).await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn start_server() {
|
||||||
|
let addr = "0.0.0.0:31373".parse().unwrap();
|
||||||
|
let key_distribution = MyKeyDistribution::default();
|
||||||
Server::builder()
|
Server::builder()
|
||||||
.add_service(KeyDistributionServer::new(key_distribution))
|
.add_service(KeyDistributionServer::new(key_distribution))
|
||||||
.serve(addr)
|
.serve(addr)
|
||||||
.await?;
|
.await
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
pub async fn start() {
|
||||||
|
let start_client = tokio::task::spawn(start_server());
|
||||||
|
let start_server = tokio::task::spawn(start_server());
|
||||||
|
futures::future::select(start_client, start_server).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_node(ip: String) {
|
pub fn add_node(ip: String) {
|
||||||
|
@ -25,7 +25,7 @@ async fn sign(req: &mut Request) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn start() {
|
pub async fn start() {
|
||||||
let acceptor = TcpListener::new("0.0.0.0:5800").bind().await;
|
let acceptor = TcpListener::new("0.0.0.0:31372").bind().await;
|
||||||
let router = Router::new()
|
let router = Router::new()
|
||||||
.get(homepage)
|
.get(homepage)
|
||||||
.push(Router::with_path("sign").get(sign));
|
.push(Router::with_path("sign").get(sign));
|
||||||
|
Loading…
Reference in New Issue
Block a user