Skip to content

Commit

Permalink
Merge pull request #219 from ipfs-shipyard/fix/override-version-check
Browse files Browse the repository at this point in the history
Allow client to override minimum ipfs version check
  • Loading branch information
kevodwyer authored Mar 2, 2023
2 parents 07395a0 + c09a0c0 commit 2a8edec
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/main/java/io/ipfs/api/IPFS.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,18 @@ public IPFS(MultiAddress addr) {
}

public IPFS(String host, int port, String version, boolean ssl) {
this(host, port, version, DEFAULT_CONNECT_TIMEOUT_MILLIS, DEFAULT_READ_TIMEOUT_MILLIS, ssl);
this(host, port, version, true, DEFAULT_CONNECT_TIMEOUT_MILLIS, DEFAULT_READ_TIMEOUT_MILLIS, ssl);
}

public IPFS(String host, int port, String version, boolean enforceMinVersion, boolean ssl) {
this(host, port, version, enforceMinVersion, DEFAULT_CONNECT_TIMEOUT_MILLIS, DEFAULT_READ_TIMEOUT_MILLIS, ssl);
}

public IPFS(String host, int port, String version, int connectTimeoutMillis, int readTimeoutMillis, boolean ssl) {
this(host, port, version, true, connectTimeoutMillis, readTimeoutMillis, ssl);
}

public IPFS(String host, int port, String version, boolean enforceMinVersion, int connectTimeoutMillis, int readTimeoutMillis, boolean ssl) {
if (connectTimeoutMillis < 0) throw new IllegalArgumentException("connect timeout must be zero or positive");
if (readTimeoutMillis < 0) throw new IllegalArgumentException("read timeout must be zero or positive");
this.host = host;
Expand All @@ -86,12 +94,14 @@ public IPFS(String host, int port, String version, int connectTimeoutMillis, int

this.apiVersion = version;
// Check IPFS is sufficiently recent
try {
Version detected = Version.parse(version());
if (detected.isBefore(MIN_VERSION))
throw new IllegalStateException("You need to use a more recent version of IPFS! >= " + MIN_VERSION);
} catch (IOException e) {
throw new RuntimeException(e);
if (enforceMinVersion) {
try {
Version detected = Version.parse(version());
if (detected.isBefore(MIN_VERSION))
throw new IllegalStateException("You need to use a more recent version of IPFS! >= " + MIN_VERSION);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

Expand Down

0 comments on commit 2a8edec

Please sign in to comment.