Skip to content

Commit 6f42d95

Browse files
committed
Put in explicit check for minimum IPFS version.
1 parent 25e118a commit 6f42d95

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/main/java/org/ipfs/api/IPFS.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import java.util.stream.*;
77

88
public class IPFS {
9+
10+
public static final String MIN_VERSION = "0.4.2";
911
public enum PinType {all, direct, indirect, recursive}
1012
public List<String> ObjectTemplates = Arrays.asList("unixfs-dir");
1113
public List<String> ObjectPatchTypes = Arrays.asList("add-link", "rm-link", "set-data", "append-data");
@@ -44,6 +46,16 @@ public IPFS(String host, int port, String version) {
4446
this.host = host;
4547
this.port = port;
4648
this.version = version;
49+
// Check IPFS is sufficiently recent
50+
try {
51+
String ipfsVersion = version();
52+
int[] parts = Stream.of(ipfsVersion.split("\\.")).mapToInt(Integer::parseInt).toArray();
53+
int[] minParts = Stream.of(MIN_VERSION.split("\\.")).mapToInt(Integer::parseInt).toArray();
54+
if (parts[0] < minParts[0] || parts[1] < minParts[1] || parts[2] < minParts[2])
55+
throw new IllegalStateException("You need to use a more recent version of IPFS! >= " + MIN_VERSION);
56+
} catch (IOException e) {
57+
throw new RuntimeException(e);
58+
}
4759
}
4860

4961
public MerkleNode add(NamedStreamable file) throws IOException {

0 commit comments

Comments
 (0)