Skip to content

Commit 67871e3

Browse files
authored
simplify sleep logic in publishers (#49)
1 parent 15ce816 commit 67871e3

File tree

2 files changed

+6
-6
lines changed
  • iroh-pkarr-naming-system/src
  • iroh-pkarr-node-discovery/src

2 files changed

+6
-6
lines changed

iroh-pkarr-naming-system/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ impl IPNS {
6464
let pkarr = self.0.pkarr.clone();
6565
let signed_packet: SignedPacket = Self::to_signed_packet(&secret_key, &record, 0)?;
6666
let publish_task = tokio::spawn(async move {
67+
tokio::time::sleep(INITIAL_PUBLISH_DELAY).await;
6768
loop {
68-
tokio::time::sleep(INITIAL_PUBLISH_DELAY).await;
6969
let res = pkarr.publish(&signed_packet).await;
7070
match res {
7171
Ok(sqm) => {
@@ -75,7 +75,7 @@ impl IPNS {
7575
tracing::warn!("Failed to publish record: {}", e);
7676
}
7777
}
78-
tokio::time::sleep(REPUBLISH_DELAY - INITIAL_PUBLISH_DELAY).await;
78+
tokio::time::sleep(REPUBLISH_DELAY).await;
7979
}
8080
});
8181
let mut packets = self.0.packets.lock().unwrap();

iroh-pkarr-node-discovery/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,10 @@ impl PkarrNodeDiscovery {
175175
let z32 = pkarr::PublicKey::try_from(*keypair.public().as_bytes())
176176
.expect("valid public key")
177177
.to_z32();
178+
// initial delay. If the task gets aborted before this delay is over,
179+
// we have not published anything to the DHT yet.
180+
tokio::time::sleep(INITIAL_PUBLISH_DELAY).await;
178181
loop {
179-
// initial delay. If the task gets aborted before this delay is over,
180-
// we have not published anything to the DHT yet.
181-
tokio::time::sleep(INITIAL_PUBLISH_DELAY).await;
182182
// publish to the DHT if enabled
183183
let dht_publish = async {
184184
if this.0.dht {
@@ -224,7 +224,7 @@ impl PkarrNodeDiscovery {
224224
};
225225
// do both at the same time
226226
tokio::join!(relay_publish, dht_publish);
227-
tokio::time::sleep(REPUBLISH_DELAY - INITIAL_PUBLISH_DELAY).await;
227+
tokio::time::sleep(REPUBLISH_DELAY).await;
228228
}
229229
}
230230

0 commit comments

Comments
 (0)