Skip to content

Commit 72bd14c

Browse files
committed
chore: fix timestamp
1 parent aa68c2a commit 72bd14c

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

interop/kad/nim-peer/src/nim_peer.nim

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,12 @@ proc main() {.async.} =
3535
.build()
3636

3737
let
38-
goPeerId = PeerId.init(readFile("../go-peer/peer.id")).get()
39-
goMa = MultiAddress.init("/ip4/127.0.0.1/tcp/4040").get()
38+
peerId = PeerId.init(readFile("../rust-peer/peer.id")).get()
39+
peerMa = MultiAddress.init("/ip4/127.0.0.1/tcp/4141").get()
4040
kad = KadDHT.new(
4141
switch,
42-
bootstrapNodes = @[(goPeerId, @[goMa])],
42+
bootstrapNodes = @[(peerId, @[peerMa])],
4343
config = KadDHTConfig.new(quorum = 1),
44-
codec = "/test/kad/1.0.0",
4544
)
4645

4746
switch.mount(kad)
@@ -67,7 +66,7 @@ proc main() {.async.} =
6766
quit(1)
6867

6968
when isMainModule:
70-
if waitFor(waitForService("127.0.0.1", Port(4040))):
69+
if waitFor(waitForService("127.0.0.1", Port(4141))):
7170
waitFor(main())
7271
else:
7372
quit("timeout waiting for service", 1)

interop/kad/rust-peer/src/main.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::error::Error;
1+
use std::{error::Error, fs};
22

33
use futures::stream::StreamExt;
44
use libp2p::{
@@ -14,7 +14,10 @@ use tracing_subscriber::EnvFilter;
1414
#[tokio::main]
1515
async fn main() -> Result<(), Box<dyn Error>> {
1616
let _ = tracing_subscriber::fmt()
17-
.with_env_filter(EnvFilter::from_default_env())
17+
.with_env_filter(
18+
EnvFilter::try_from_default_env()
19+
.unwrap_or_else(|_| EnvFilter::new("debug,libp2p=debug")),
20+
)
1821
.try_init();
1922

2023
// We create a custom network behaviour that combines Kademlia and mDNS.
@@ -45,6 +48,10 @@ async fn main() -> Result<(), Box<dyn Error>> {
4548
})?
4649
.build();
4750

51+
let peer_id = *swarm.local_peer_id();
52+
fs::write("peer.id", peer_id.to_string())?;
53+
println!("Local PeerId: {peer_id}");
54+
4855
swarm.behaviour_mut().kademlia.set_mode(Some(Mode::Server));
4956

5057
swarm.listen_on("/ip4/0.0.0.0/tcp/4141".parse()?)?;

libp2p/protocols/kademlia/get.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ proc dispatchGetVal(
4848
return
4949

5050
let time = record.timeReceived.valueOr:
51-
debug "GetValue returned record with no timeReceived",
51+
debug "GetValue returned record with no timeReceived, using current time instead",
5252
msg = msg, reply = reply, conn = conn
53-
return
53+
TimeStamp($times.now().utc)
5454

5555
received[peer] = Opt.some(EntryRecord(value: value, time: time))
5656

0 commit comments

Comments
 (0)