Skip to content

Commit

Permalink
Use a different peer to publish and reoslve in IpnsPublisher
Browse files Browse the repository at this point in the history
  • Loading branch information
ianopolous committed Dec 27, 2023
1 parent b6a16b7 commit e6f3b45
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/main/java/org/peergos/IpnsPublisher.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public class IpnsPublisher {
private static final ExecutorService ioExec = Executors.newFixedThreadPool(10);
public static void main(String[] a) throws Exception {
Path publishFile = Paths.get("publishers.txt");
List<PrivKey> keys;
int keycount = 1000;
EmbeddedIpfs ipfs = startIpfs();
EmbeddedIpfs publisher = startIpfs();
EmbeddedIpfs resolver = startIpfs();
if (publishFile.toFile().exists()) {
List<String> lines = Files.readAllLines(publishFile);
List<PublishResult> records = lines.stream()
Expand All @@ -38,7 +38,7 @@ public static void main(String[] a) throws Exception {
System.out.println("Resolving " + records.size() + " keys");
for (int c=0; c < 100; c++) {
long t0 = System.currentTimeMillis();
List<Integer> recordCounts = resolveAndRepublish(records, ipfs);
List<Integer> recordCounts = resolveAndRepublish(records, resolver, publisher);
Path resultsFile = Paths.get("publish-resolve-counts-" + LocalDateTime.now().withNano(0) + ".txt");
Files.write(resultsFile,
recordCounts.stream()
Expand All @@ -57,11 +57,11 @@ public static void main(String[] a) throws Exception {
Files.write(resultsFile, fails.getBytes(), StandardOpenOption.APPEND);
}
} else {
keys = IntStream.range(0, keycount)
List<PrivKey> keys = IntStream.range(0, keycount)
.mapToObj(i -> Ed25519Kt.generateEd25519KeyPair().getFirst())
.collect(Collectors.toList());
long t0 = System.currentTimeMillis();
List<CompletableFuture<PublishResult>> futs = publish(keys, "The result".getBytes(), ipfs)
List<CompletableFuture<PublishResult>> futs = publish(keys, "The result".getBytes(), publisher)
.collect(Collectors.toList());
futs.forEach(res -> {
try {
Expand All @@ -76,7 +76,7 @@ public static void main(String[] a) throws Exception {
long t1 = System.currentTimeMillis();
System.out.println("Published all in " + (t1-t0)/1000 + "s");
}
ipfs.stop().join();
publisher.stop().join();
System.exit(0);
}

Expand Down Expand Up @@ -124,16 +124,18 @@ public static CompletableFuture<PublishResult> publish(PublishResult signed, Emb
}, ioExec);
}

public static List<Integer> resolveAndRepublish(List<PublishResult> publishers, EmbeddedIpfs ipfs) {
public static List<Integer> resolveAndRepublish(List<PublishResult> publishers,
EmbeddedIpfs resolver,
EmbeddedIpfs publisher) {
List<Integer> res = new ArrayList<>();
int done = 0;
for (PublishResult pub : publishers) {
List<IpnsRecord> records = ipfs.resolveRecords(pub.priv.publicKey(), 30);
List<IpnsRecord> records = resolver.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));
CompletableFuture.supplyAsync(() -> publisher.publishPresignedRecord(pub.pub, pub.record));
}
return res;
}
Expand Down

0 comments on commit e6f3b45

Please sign in to comment.