diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..5ace460 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,6 @@ +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" diff --git a/.github/workflows/ant.yml b/.github/workflows/ant.yml index 12ca6ed..6abe970 100644 --- a/.github/workflows/ant.yml +++ b/.github/workflows/ant.yml @@ -1,6 +1,10 @@ name: Java CI -on: [push, pull_request] +on: + schedule: + - cron: '42 0 * * 4' + push: + pull_request: jobs: build: @@ -8,10 +12,11 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v5 - name: Set up JDK 11 - uses: actions/setup-java@v1 + uses: actions/setup-java@v5 with: + distribution: temurin java-version: 11 - name: Install and run ipfs run: ./install-run-ipfs.sh diff --git a/.github/workflows/generated-pr.yml b/.github/workflows/generated-pr.yml new file mode 100644 index 0000000..b8c5cc6 --- /dev/null +++ b/.github/workflows/generated-pr.yml @@ -0,0 +1,14 @@ +name: Close Generated PRs + +on: + schedule: + - cron: '0 0 * * *' + workflow_dispatch: + +permissions: + issues: write + pull-requests: write + +jobs: + stale: + uses: ipdxco/unified-github-workflows/.github/workflows/reusable-generated-pr.yml@v1 diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml new file mode 100644 index 0000000..7c955c4 --- /dev/null +++ b/.github/workflows/stale.yml @@ -0,0 +1,14 @@ +name: Close Stale Issues + +on: + schedule: + - cron: '0 0 * * *' + workflow_dispatch: + +permissions: + issues: write + pull-requests: write + +jobs: + stale: + uses: ipdxco/unified-github-workflows/.github/workflows/reusable-stale-issue.yml@v1 diff --git a/src/main/java/io/ipfs/api/IPFS.java b/src/main/java/io/ipfs/api/IPFS.java index ccc3b0e..9f93d5c 100644 --- a/src/main/java/io/ipfs/api/IPFS.java +++ b/src/main/java/io/ipfs/api/IPFS.java @@ -397,8 +397,8 @@ public Multihash ls() throws IOException { /*public String migrate(boolean allowDowngrade) throws IOException { return retrieveString("repo/migrate?allow-downgrade=" + allowDowngrade); }*/ - public Map stat(boolean sizeOnly, boolean humanReadable) throws IOException { - return retrieveMap("repo/stat?size-only=" + sizeOnly + "&human=" + humanReadable); + public RepoStat stat(boolean sizeOnly) throws IOException { + return RepoStat.fromJson(retrieveAndParse("repo/stat?size-only=" + sizeOnly)); } public Map verify() throws IOException { return retrieveMap("repo/verify"); @@ -812,8 +812,8 @@ public String reprovide() throws IOException { public Map stat() throws IOException { return retrieveMap("bitswap/stat"); } - public Map stat(boolean verbose, boolean humanReadable) throws IOException { - return retrieveMap("bitswap/stat?verbose=" + verbose + "&human=" + humanReadable); + public Map stat(boolean verbose) throws IOException { + return retrieveMap("bitswap/stat?verbose=" + verbose); } public Map wantlist(Multihash peerId) throws IOException { return retrieveMap("bitswap/wantlist?peer=" + peerId); @@ -856,6 +856,9 @@ public List rmAll() throws IOException { public class Swarm { public List peers() throws IOException { Map m = retrieveMap("swarm/peers?stream-channels=true"); + if (m.get("Peers") == null) { + return Collections.emptyList(); + } return ((List)m.get("Peers")).stream() .flatMap(json -> { try { @@ -981,8 +984,8 @@ public Map id() throws IOException { } public class Stats { - public Map bitswap(boolean verbose, boolean humanReadable) throws IOException { - return retrieveMap("stats/bitswap?verbose=" + verbose + "&human=" + humanReadable); + public Map bitswap(boolean verbose) throws IOException { + return retrieveMap("stats/bitswap?verbose=" + verbose); } public Map bw() throws IOException { return retrieveMap("stats/bw"); @@ -993,8 +996,8 @@ public Map dht() throws IOException { public Map provide() throws IOException { return retrieveMap("stats/provide"); } - public Map repo(boolean sizeOnly, boolean humanReadable) throws IOException { - return retrieveMap("stats/repo?size-only=" + sizeOnly + "&human=" + humanReadable); + public RepoStat repo(boolean sizeOnly) throws IOException { + return RepoStat.fromJson(retrieveAndParse("stats/repo?size-only=" + sizeOnly)); } } diff --git a/src/main/java/io/ipfs/api/RepoStat.java b/src/main/java/io/ipfs/api/RepoStat.java new file mode 100644 index 0000000..7dcf3ae --- /dev/null +++ b/src/main/java/io/ipfs/api/RepoStat.java @@ -0,0 +1,30 @@ +package io.ipfs.api; + +import java.util.Map; + +public class RepoStat { + + public final long RepoSize; + public final long StorageMax; + public final long NumObjects; + public final String RepoPath; + public final String Version; + + public RepoStat(long repoSize, long storageMax, long numObjects, String repoPath, String version ) { + this.RepoSize = repoSize; + this.StorageMax = storageMax; + this.NumObjects = numObjects; + this.RepoPath = repoPath; + this.Version = version; + } + public static RepoStat fromJson(Object rawjson) { + Map json = (Map)rawjson; + long repoSize = Long.parseLong(json.get("RepoSize").toString()); + long storageMax = Long.parseLong(json.get("StorageMax").toString()); + long numObjects = Long.parseLong(json.get("NumObjects").toString()); + String repoPath = (String)json.get("RepoPath"); + String version = (String)json.get("Version"); + + return new RepoStat(repoSize, storageMax, numObjects, repoPath, version); + } +} diff --git a/src/test/java/io/ipfs/api/APITest.java b/src/test/java/io/ipfs/api/APITest.java index 11ef6ec..adf5393 100644 --- a/src/test/java/io/ipfs/api/APITest.java +++ b/src/test/java/io/ipfs/api/APITest.java @@ -719,7 +719,8 @@ public void repoTest() throws IOException { ipfs.repo.gc(); Multihash res = ipfs.repo.ls(); //String migration = ipfs.repo.migrate(false); - Map stat = ipfs.repo.stat(false, true); + RepoStat stat = ipfs.repo.stat(false); + RepoStat stat2 = ipfs.repo.stat(true); Map verify = ipfs.repo.verify(); Map version = ipfs.repo.version(); } @@ -765,11 +766,11 @@ public void localId() throws Exception { @Test public void statsTest() throws IOException { Map stats = ipfs.stats.bw(); - Map bitswap = ipfs.stats.bitswap(true, true); + Map bitswap = ipfs.stats.bitswap(true); Map dht = ipfs.stats.dht(); //{"Message":"can only return stats if Experimental.AcceleratedDHTClient is enabled","Code":0,"Type":"error"} //requires Map provide = ipfs.stats.provide(); - Map repo = ipfs.stats.repo(false, true); + RepoStat repo = ipfs.stats.repo(false); } public void resolveTest() throws IOException { @@ -859,7 +860,7 @@ public void bitswapTest() throws IOException { Map want = ipfs.bitswap.wantlist(peers.get(0).id); //String reprovide = ipfs.bitswap.reprovide(); Map stat = ipfs.bitswap.stat(); - Map stat2 = ipfs.bitswap.stat(true, false); + Map stat2 = ipfs.bitswap.stat(true); } @Test public void bootstrapTest() throws IOException {