Skip to content

Commit 569cec3

Browse files
committed
edit time feature
1 parent 00a169a commit 569cec3

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

compute/src/reqres/heartbeat.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct HeartbeatRequester;
1515
#[derive(Serialize, Deserialize, Debug, Clone)]
1616
pub struct HeartbeatRequest {
1717
/// A unique ID for the heartbeat request.
18-
pub(crate) uuid: Uuid,
18+
pub(crate) heartbeat_id: Uuid,
1919
/// Deadline for the heartbeat request, in nanoseconds.
2020
pub(crate) deadline: chrono::DateTime<chrono::Utc>,
2121
/// Models available in the node.
@@ -31,7 +31,7 @@ pub struct HeartbeatRequest {
3131
#[derive(Serialize, Deserialize, Debug, Clone)]
3232
pub struct HeartbeatResponse {
3333
/// UUID as given in the request.
34-
pub(crate) uuid: Uuid,
34+
pub(crate) heartbeat_id: Uuid,
3535
/// Acknowledgement of the heartbeat.
3636
pub(crate) ack: bool,
3737
}
@@ -53,7 +53,7 @@ impl HeartbeatRequester {
5353
let deadline = chrono::Utc::now() + HEARTBEAT_DEADLINE_SECS;
5454

5555
let heartbeat_request = HeartbeatRequest {
56-
uuid,
56+
heartbeat_id: uuid,
5757
deadline,
5858
models: node.config.workflows.models.clone(),
5959
pending_tasks: node.get_pending_task_count(),
@@ -79,7 +79,7 @@ impl HeartbeatRequester {
7979
node: &mut DriaComputeNode,
8080
res: HeartbeatResponse,
8181
) -> Result<()> {
82-
if let Some(deadline) = node.heartbeats.remove(&res.uuid) {
82+
if let Some(deadline) = node.heartbeats.remove(&res.heartbeat_id) {
8383
if !res.ack {
8484
Err(eyre!("Heartbeat was not acknowledged."))
8585
} else if chrono::Utc::now() > deadline {
@@ -93,7 +93,7 @@ impl HeartbeatRequester {
9393
} else {
9494
Err(eyre!(
9595
"Received an unknown heartbeat response with UUID {}.",
96-
res.uuid
96+
res.heartbeat_id
9797
))
9898
}
9999
}

compute/src/reqres/specs.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@ use crate::utils::Specs;
22

33
use super::IsResponder;
44
use serde::{Deserialize, Serialize};
5+
use uuid::Uuid;
56

67
#[derive(Serialize, Deserialize)]
78
pub struct SpecRequest {
8-
/// UUID of the specs request, prevents replay attacks.
9-
pub request_id: String,
9+
/// UUID of the specs request, prevents replays.
10+
pub request_id: Uuid,
1011
}
1112

1213
#[derive(Serialize, Deserialize)]
1314
pub struct SpecResponse {
14-
/// UUID of the specs request, prevents replay attacks.
15-
pub request_id: String,
15+
/// UUID of the specs request, prevents replays.
16+
pub request_id: Uuid,
1617
/// Node specs, will be flattened during serialization.
1718
#[serde(flatten)]
1819
specs: Specs,

p2p/tests/request_test.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
use std::str::FromStr;
2+
use std::thread::sleep;
3+
use std::time::Duration;
24

35
use dkn_p2p::DriaNetworkType::Community;
46
use dkn_p2p::{DriaNodes, DriaP2PClient, DriaP2PProtocol};
@@ -23,15 +25,13 @@ async fn test_request_message() -> Result<()> {
2325
.is_test(true)
2426
.try_init();
2527

26-
let listen_addr = "/ip4/0.0.0.0/tcp/4001".parse()?;
27-
2828
// prepare nodes
2929
let nodes = DriaNodes::new(Community).with_statics();
3030

3131
// spawn P2P client in another task
3232
let (client, mut commander, mut req_rx) = DriaP2PClient::new(
3333
Keypair::generate_secp256k1(),
34-
listen_addr,
34+
"/ip4/127.0.0.1/tcp/0".parse().unwrap(),
3535
&nodes,
3636
DriaP2PProtocol::default(),
3737
)
@@ -41,7 +41,7 @@ async fn test_request_message() -> Result<()> {
4141
let task_handle = tokio::spawn(async move { client.run().await });
4242

4343
log::info!("Waiting a bit until we have enough peers");
44-
tokio::time::sleep(tokio::time::Duration::from_secs(10)).await;
44+
sleep(Duration::from_secs(10));
4545

4646
let peer_id =
4747
PeerId::from_str("16Uiu2HAmB5HGdwLNHX81u7ey1fvDx5Mr4ofa2PdSSVxFKrrcErAN").unwrap();

0 commit comments

Comments
 (0)