Skip to content

Commit

Permalink
Republish after each resolve in IpnsPublisher
Browse files Browse the repository at this point in the history
  • Loading branch information
ianopolous committed Dec 27, 2023
1 parent aa53118 commit b6a16b7
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/main/java/org/peergos/IpnsPublisher.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,17 @@ public static void main(String[] a) throws Exception {
EmbeddedIpfs ipfs = startIpfs();
if (publishFile.toFile().exists()) {
List<String> lines = Files.readAllLines(publishFile);
keys = lines.stream()
.map(line -> KeyKt.unmarshalPrivateKey(ArrayOps.hexToBytes(line.split(" ")[0])))
.collect(Collectors.toList());
List<PublishResult> records = lines.stream()
.map(line -> new PublishResult(KeyKt.unmarshalPrivateKey(ArrayOps.hexToBytes(line.split(" ")[0])),
Multihash.fromBase58(line.split(" ")[1]),
ArrayOps.hexToBytes(line.split(" ")[2]),
0))
.collect(Collectors.toList());

System.out.println("Resolving " + keys.size() + " keys");
System.out.println("Resolving " + records.size() + " keys");
for (int c=0; c < 100; c++) {
long t0 = System.currentTimeMillis();
List<Integer> recordCounts = resolve(keys, ipfs);
List<Integer> recordCounts = resolveAndRepublish(records, ipfs);
Path resultsFile = Paths.get("publish-resolve-counts-" + LocalDateTime.now().withNano(0) + ".txt");
Files.write(resultsFile,
recordCounts.stream()
Expand All @@ -58,7 +55,6 @@ public static void main(String[] a) throws Exception {
.collect(Collectors.toList());
System.out.println(fails);
Files.write(resultsFile, fails.getBytes(), StandardOpenOption.APPEND);
publish(records, ipfs);
}
} else {
keys = IntStream.range(0, keycount)
Expand Down Expand Up @@ -128,15 +124,16 @@ public static CompletableFuture<PublishResult> publish(PublishResult signed, Emb
}, ioExec);
}

public static List<Integer> resolve(List<PrivKey> publishers, EmbeddedIpfs ipfs) {
public static List<Integer> resolveAndRepublish(List<PublishResult> publishers, EmbeddedIpfs ipfs) {
List<Integer> res = new ArrayList<>();
int done = 0;
for (PrivKey publisher : publishers) {
List<IpnsRecord> records = ipfs.resolveRecords(publisher.publicKey(), 30);
for (PublishResult pub : publishers) {
List<IpnsRecord> records = ipfs.resolveRecords(pub.priv.publicKey(), 30);
res.add(records.size());
done++;
if (done % 10 == 0)
System.out.println("resolved " + done);
CompletableFuture.supplyAsync(() -> ipfs.publishPresignedRecord(pub.pub, pub.record));
}
return res;
}
Expand Down

0 comments on commit b6a16b7

Please sign in to comment.