Skip to content

Commit

Permalink
Make the hours TTL of an IPNS record part of the API
Browse files Browse the repository at this point in the history
  • Loading branch information
ianopolous committed Dec 13, 2023
1 parent 8b86b55 commit 4bba117
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
7 changes: 3 additions & 4 deletions src/main/java/org/peergos/EmbeddedIpfs.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,10 @@ public List<HashedBlock> getBlocks(List<Want> wants, Set<PeerId> peers, boolean
.collect(Collectors.toList());
}

public CompletableFuture<Void> publishValue(PrivKey priv, byte[] value, long sequence) {
public CompletableFuture<Void> publishValue(PrivKey priv, byte[] value, long sequence, int hoursTtl) {
Multihash pub = Multihash.deserialize(PeerId.fromPubKey(priv.publicKey()).getBytes());
int hours = 1;
LocalDateTime expiry = LocalDateTime.now().plusHours(hours);
long ttlNanos = hours * 3600_000_000_000L;
LocalDateTime expiry = LocalDateTime.now().plusHours(hoursTtl);
long ttlNanos = hoursTtl * 3600_000_000_000L;
return dht.publishValue(priv, pub, value, sequence, expiry, ttlNanos, node);
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/peergos/EmbeddedIpfsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void publishValue() throws Exception {

PrivKey publisher = Ed25519Kt.generateEd25519KeyPair().getFirst();
byte[] value = "This is a test".getBytes();
node1.publishValue(publisher, value, 1).join();
node1.publishValue(publisher, value, 1, 24).join();
byte[] res = node1.resolveValue(publisher.publicKey()).join();
Assert.assertTrue(Arrays.equals(res, value));

Expand Down

0 comments on commit 4bba117

Please sign in to comment.