Skip to content

Commit 2a8edec

Browse files
authored
Merge pull request #219 from ipfs-shipyard/fix/override-version-check
Allow client to override minimum ipfs version check
2 parents 07395a0 + c09a0c0 commit 2a8edec

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

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

+17-7
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,18 @@ public IPFS(MultiAddress addr) {
6767
}
6868

6969
public IPFS(String host, int port, String version, boolean ssl) {
70-
this(host, port, version, DEFAULT_CONNECT_TIMEOUT_MILLIS, DEFAULT_READ_TIMEOUT_MILLIS, ssl);
70+
this(host, port, version, true, DEFAULT_CONNECT_TIMEOUT_MILLIS, DEFAULT_READ_TIMEOUT_MILLIS, ssl);
71+
}
72+
73+
public IPFS(String host, int port, String version, boolean enforceMinVersion, boolean ssl) {
74+
this(host, port, version, enforceMinVersion, DEFAULT_CONNECT_TIMEOUT_MILLIS, DEFAULT_READ_TIMEOUT_MILLIS, ssl);
7175
}
7276

7377
public IPFS(String host, int port, String version, int connectTimeoutMillis, int readTimeoutMillis, boolean ssl) {
78+
this(host, port, version, true, connectTimeoutMillis, readTimeoutMillis, ssl);
79+
}
80+
81+
public IPFS(String host, int port, String version, boolean enforceMinVersion, int connectTimeoutMillis, int readTimeoutMillis, boolean ssl) {
7482
if (connectTimeoutMillis < 0) throw new IllegalArgumentException("connect timeout must be zero or positive");
7583
if (readTimeoutMillis < 0) throw new IllegalArgumentException("read timeout must be zero or positive");
7684
this.host = host;
@@ -86,12 +94,14 @@ public IPFS(String host, int port, String version, int connectTimeoutMillis, int
8694

8795
this.apiVersion = version;
8896
// Check IPFS is sufficiently recent
89-
try {
90-
Version detected = Version.parse(version());
91-
if (detected.isBefore(MIN_VERSION))
92-
throw new IllegalStateException("You need to use a more recent version of IPFS! >= " + MIN_VERSION);
93-
} catch (IOException e) {
94-
throw new RuntimeException(e);
97+
if (enforceMinVersion) {
98+
try {
99+
Version detected = Version.parse(version());
100+
if (detected.isBefore(MIN_VERSION))
101+
throw new IllegalStateException("You need to use a more recent version of IPFS! >= " + MIN_VERSION);
102+
} catch (IOException e) {
103+
throw new RuntimeException(e);
104+
}
95105
}
96106
}
97107

0 commit comments

Comments
 (0)