From 8ef7757267a3befb932facde5c5af503d4d902fd Mon Sep 17 00:00:00 2001 From: ghe0 Date: Thu, 22 Aug 2024 01:58:36 +0300 Subject: [PATCH] possible fixes --- scripts/run_tests.sh | 12 +++++++++++- src/datastore.rs | 13 ++++++++++++- src/grpc/client.rs | 5 ++--- src/main.rs | 5 ++--- 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/scripts/run_tests.sh b/scripts/run_tests.sh index 1f0c2b5..eae4b29 100644 --- a/scripts/run_tests.sh +++ b/scripts/run_tests.sh @@ -25,16 +25,26 @@ do ip="172.17.0.${i}" random_key=$(curl -s "${ip}:31372" | grep true | tail -1 | awk '{ print $4 }') message="ValyDoesNotLikeMyCodeSoHeIsSilentAboutIt" + mkdir -p .tmp status=$(curl -sG \ - -o /dev/null -w "%{http_code}\n" \ + -o .tmp/output -w "%{http_code}\n" \ --data-urlencode "pubkey=${random_key}" \ --data-urlencode "something=${message}" \ "172.17.0.${i}:31372/sign") if (( "$status" != "200" )); then echo Container at ip ${ip} could not sign string with key ${random_key} + echo The status was $status + echo The error was $(cat .tmp/output) + echo Output of keys on 172.17.0.${i}: + curl 172.17.0.${i}:31372 + father_of_key=$(curl 172.17.0.${i}:31372 | grep ${random_key} | awk '{ print $2 }') + echo Output of keys on ${father_of_key}: + curl ${father_of_key}:31372 + rm -rf .tmp exit 1 fi done echo OK! +rm -rf .tmp diff --git a/src/datastore.rs b/src/datastore.rs index dfbad71..b94bc92 100644 --- a/src/datastore.rs +++ b/src/datastore.rs @@ -117,7 +117,8 @@ impl Store { None => return Err(SigningError::KeyNotFound), }; - let signature = format!("{:?}", signing_key.sign(message.as_bytes())); + // let signature = format!("{:?}", signing_key.sign(message.as_bytes())); + let signature = hex::encode(signing_key.sign(message.as_bytes()).to_bytes()); Ok(signature) } @@ -189,6 +190,16 @@ impl Store { /// returns old pubkey if node got updated async fn update_node(&self, ip: String, info: NodeInfo) -> Option { + // if let Some(old_node) = self.nodes.get(&ip) { + // if SystemTime::now() + // .duration_since(old_node.updated_at) + // .unwrap_or(Duration::ZERO) + // .as_secs() + // < 50 + // { + // return None; + // } + // } self.nodes.insert(ip, info.clone()) } diff --git a/src/grpc/client.rs b/src/grpc/client.rs index 1e4bf64..879e9af 100644 --- a/src/grpc/client.rs +++ b/src/grpc/client.rs @@ -3,7 +3,7 @@ use crate::datastore::Store; use crate::grpc::challenge::update_client::UpdateClient; use std::sync::Arc; use tokio::sync::broadcast::Sender; -use tokio::time::Duration; +use tokio::time::{sleep, Duration}; use tokio_stream::wrappers::BroadcastStream; use tokio_stream::StreamExt; @@ -23,14 +23,13 @@ impl ConnManager { } pub async fn start(self) { - let mut interval = tokio::time::interval(Duration::from_secs(3)); loop { if let Some(node) = self.ds.get_random_node().await { if node != "localhost" { self.connect_wrapper(node.clone()).await; } } - interval.tick().await; + sleep(Duration::from_secs(3)).await; } } diff --git a/src/main.rs b/src/main.rs index 7808e22..df4fe58 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,13 +9,12 @@ use std::fs::File; use std::io::{BufRead, BufReader}; use std::sync::Arc; use tokio::sync::broadcast; -use tokio::time::Duration; +use tokio::time::{sleep, Duration}; async fn cycle_keys(ds: Arc, tx: Sender) { - let mut interval = tokio::time::interval(Duration::from_secs(60)); loop { let _ = tx.send(ds.reset_localhost_keys().await); - interval.tick().await; + sleep(Duration::from_secs(60)).await; } }