Skip to content

Commit 87d27eb

Browse files
committed
rm autonat, add re-dial, increase timeout
1 parent 000ccf3 commit 87d27eb

File tree

11 files changed

+75
-110
lines changed

11 files changed

+75
-110
lines changed

Cargo.lock

Lines changed: 0 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compute/src/node/diagnostic.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ impl DriaComputeNode {
2020
}
2121

2222
/// Peer refresh simply reports the peer count to the user.
23-
pub(crate) async fn handle_diagnostic_refresh(&self) {
23+
pub(crate) async fn handle_diagnostic_refresh(&mut self) {
2424
let mut diagnostics = vec![format!("Diagnostics (v{}):", DRIA_COMPUTE_NODE_VERSION)];
2525

2626
// print steps
@@ -38,6 +38,21 @@ impl DriaComputeNode {
3838
"Completed Tasks (single/batch): {} / {}",
3939
self.completed_tasks_single, self.completed_tasks_batch
4040
));
41+
42+
diagnostics.push(format!(
43+
"RPC {}: {}",
44+
self.dria_rpc.peer_id,
45+
if self
46+
.p2p
47+
.is_connected(self.dria_rpc.peer_id)
48+
.await
49+
.unwrap_or(false)
50+
{
51+
"Connected".green()
52+
} else {
53+
"Disconnected".red()
54+
}
55+
));
4156
}
4257

4358
// print peer id and address

compute/src/node/reqres.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use colored::Colorize;
22
use dkn_p2p::libp2p::{
3-
request_response::{self, ResponseChannel},
3+
request_response::{self, OutboundRequestId, ResponseChannel},
44
PeerId,
55
};
66
use eyre::{eyre, Result};
@@ -43,7 +43,7 @@ impl DriaComputeNode {
4343
request_id,
4444
} => {
4545
log::debug!("Received a response ({}) from {}", request_id, peer_id);
46-
if let Err(e) = self.handle_response(peer_id, response).await {
46+
if let Err(e) = self.handle_response(peer_id, request_id, response).await {
4747
log::error!("Error handling response: {:?}", e);
4848
}
4949
}
@@ -55,12 +55,16 @@ impl DriaComputeNode {
5555
/// - Internally, the data is expected to be some JSON serialized data that is expected to be parsed and handled.
5656
/// - Can be inlined because it is only called by [`DriaComputeNode::handle_reqres`].
5757
#[inline]
58-
async fn handle_response(&mut self, peer_id: PeerId, data: Vec<u8>) -> Result<()> {
58+
async fn handle_response(
59+
&mut self,
60+
peer_id: PeerId,
61+
request_id: OutboundRequestId,
62+
data: Vec<u8>,
63+
) -> Result<()> {
5964
if let Ok(heartbeat_response) = HeartbeatRequester::try_parse_response(&data) {
6065
log::info!(
61-
"Received a {} response from {}",
66+
"Received a {} response ({request_id}) from {peer_id}",
6267
"heartbeat".blue(),
63-
peer_id
6468
);
6569
HeartbeatRequester::handle_ack(self, heartbeat_response).await
6670
} else {
@@ -97,19 +101,17 @@ impl DriaComputeNode {
97101
channel: ResponseChannel<Vec<u8>>,
98102
) -> Result<()> {
99103
log::info!(
100-
"Got a {} request from peer {} with id {}",
104+
"Got a {} request from peer {peer_id} with id {}",
101105
"spec".green(),
102-
peer_id,
103106
spec_request.request_id
104107
);
105108

106109
let response = SpecResponder::respond(spec_request, self.spec_collector.collect().await);
107110
let response_data = serde_json::to_vec(&response)?;
108111

109112
log::info!(
110-
"Responding to {} request from peer {} with id {}",
113+
"Responding to {} request from peer {peer_id} with id {}",
111114
"spec".green(),
112-
peer_id,
113115
response.request_id
114116
);
115117
self.p2p.respond(response_data, channel).await?;

compute/src/payloads/stats.rs

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,27 +52,14 @@ mod tests {
5252
#[test]
5353
fn test_stats() {
5454
let mut stats = TaskStats::default();
55+
let unix_epoch = chrono::DateTime::<chrono::Utc>::default();
5556

56-
assert_eq!(
57-
stats.received_at,
58-
chrono::DateTime::<chrono::Utc>::default()
59-
);
57+
assert_eq!(stats.received_at, unix_epoch);
6058
stats = stats.record_received_at();
61-
assert_ne!(
62-
stats.received_at,
63-
chrono::DateTime::<chrono::Utc>::default()
64-
);
59+
assert_ne!(stats.received_at, unix_epoch);
6560

66-
assert_eq!(
67-
stats.published_at,
68-
chrono::DateTime::<chrono::Utc>::default()
69-
);
61+
assert_eq!(stats.published_at, unix_epoch);
7062
stats = stats.record_published_at();
71-
assert_ne!(
72-
stats.published_at,
73-
chrono::DateTime::<chrono::Utc>::default()
74-
);
75-
76-
println!("{:?}", stats);
63+
assert_ne!(stats.published_at, unix_epoch);
7764
}
7865
}

compute/src/utils/points.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,6 @@ mod tests {
5656
let steps = get_points("0xa43536a6032a3907ccf60e8109429ee1047b207c")
5757
.await
5858
.unwrap();
59-
println!("{:?}", steps);
59+
assert!(steps.score != 0);
6060
}
6161
}

compute/src/utils/rpc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,6 @@ mod tests {
6767
#[tokio::test]
6868
async fn test_dria_nodes() {
6969
let node = DriaRPC::new(DriaNetworkType::Community).await;
70-
println!("{:?}", node);
70+
assert!(node.is_ok());
7171
}
7272
}

compute/src/utils/specs.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,5 @@ mod tests {
9494
assert!(!specs.os.is_empty());
9595
assert!(!specs.arch.is_empty());
9696
assert!(specs.lookup.is_some());
97-
98-
// print optionally:
99-
// println!("{}", serde_json::to_string_pretty(&specs).unwrap());
10097
}
10198
}

compute/src/workers/task.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ mod tests {
324324
let result = publish_rx.recv().await.unwrap();
325325
log::info!("Got result {}", i + 1,);
326326
if result.result.is_err() {
327-
println!("Error: {:?}", result.result);
327+
log::error!("Error: {:?}", result.result);
328328
}
329329
results.push(result);
330330
}

p2p/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ libp2p = { git = "https://github.com/anilaltuner/rust-libp2p.git", rev = "7ce9f9
1515
"identify",
1616
"tokio",
1717
"noise",
18-
"autonat",
1918
"macros",
2019
"request-response",
2120
"cbor",

p2p/src/behaviour.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
use eyre::Result;
22
use libp2p::identity::{Keypair, PublicKey};
3-
use libp2p::{autonat, identify, request_response, PeerId, StreamProtocol};
3+
use libp2p::{identify, request_response, PeerId, StreamProtocol};
44
use std::time::Duration;
55

66
#[derive(libp2p::swarm::NetworkBehaviour)]
77
pub struct DriaBehaviour {
88
pub identify: identify::Behaviour,
9-
pub autonat: autonat::Behaviour,
109
pub request_response: request_response::cbor::Behaviour<Vec<u8>, Vec<u8>>,
1110
}
1211

1312
impl DriaBehaviour {
1413
pub fn new(key: &Keypair, identity_protocol: String, reqres_protocol: StreamProtocol) -> Self {
1514
let public_key = key.public();
16-
let peer_id = public_key.to_peer_id();
1715

1816
Self {
1917
identify: create_identify_behaviour(public_key, identity_protocol),
2018
request_response: create_request_response_behaviour(reqres_protocol),
21-
autonat: create_autonat_behaviour(peer_id),
2219
}
2320
}
2421
}
@@ -50,17 +47,3 @@ fn create_identify_behaviour(
5047

5148
Behaviour::new(Config::new(protocol_version, local_public_key))
5249
}
53-
54-
/// Configures the Autonat behavior to assist in network address translation detection.
55-
#[inline]
56-
fn create_autonat_behaviour(local_peer_id: PeerId) -> autonat::Behaviour {
57-
use autonat::{Behaviour, Config};
58-
59-
Behaviour::new(
60-
local_peer_id,
61-
Config {
62-
// only_global_ips: false,
63-
..Default::default()
64-
},
65-
)
66-
}

0 commit comments

Comments
 (0)