/** * Does the client support this message? * * @param clientVersion may be null * @return version != null and version >= 0.9.7 */ public static boolean isSupported(String clientVersion) { return clientVersion != null && VersionComparator.comp(clientVersion, MIN_VERSION) >= 0; }
/** * Parses a long, ignoring any non-digit characters. * @param s string to parse from * @param start index in the string to start * @param end index in the string to stop at * @return the parsed value, or -1 if nothing was parsed or there was a problem. */ private static long parseLong(String s, int start, int end) { long rv = 0; boolean parsedAny = false; for (int i = start; i < end && rv >= 0; i++) { final char c = s.charAt(i); if (!isDigit(c)) continue; parsedAny = true; rv = rv * 10 + getDigit(c); } if (!parsedAny) return -1; return rv; } }
/** * @param s string to process * @param start starting index in the string to process * @return the index of the next separator character, or end of string. */ private static int nextSeparator(String s, int start) { while( start < s.length()) { if (isSeparator(s.charAt(start))) return start; start++; } return start; }
nl = nextSeparator(l, il); lv = parseLong(l,il,nl); il = nl + 1; nr = nextSeparator(r, ir); rv = parseLong(r,ir,nr); ir = nr + 1;
/** * Checks if the given version is newer than the given current version. * * @param currentVersion The current version. * @param newVersion The version to test. * * @return <code>true</code> if the given version is newer than the current * version, otherwise <code>false</code>. */ public static final boolean needsUpdate(String currentVersion, String newVersion) { return VersionComparator.comp(currentVersion, newVersion) < 0; }
public int compare(String l, String r) { return comp(l, r); }
private static String chooseBestVersion(String minVer, String maxVer) { if (VersionComparator.comp(VERSION, minVer) >= 0 && VersionComparator.comp(VERSION, maxVer) <= 0) return VERSION; if (VersionComparator.comp("3.2", minVer) >= 0 && VersionComparator.comp("3.2", maxVer) <= 0) return "3.2"; if (VersionComparator.comp("3.1", minVer) >= 0 && VersionComparator.comp("3.1", maxVer) <= 0) return "3.1"; // in VersionComparator, "3" < "3.0" so // use comparisons carefully if (VersionComparator.comp("3.0", minVer) >= 0 && VersionComparator.comp("3", maxVer) <= 0) return "3.0"; if (VersionComparator.comp("2.0", minVer) >= 0 && VersionComparator.comp("2", maxVer) <= 0) return "2.0"; if (VersionComparator.comp("1.0", minVer) >= 0 && VersionComparator.comp("1", maxVer) <= 0) return "1.0"; return null; }
/** * Is it too old? * @since 0.9.33 */ static boolean shouldStoreTo(RouterInfo ri) { String v = ri.getVersion(); return VersionComparator.comp(v, MIN_STORE_VERSION) >= 0; }
/** * Is it too old? * @since 0.9.38 */ static boolean shouldStoreLS2To(RouterInfo ri) { String v = ri.getVersion(); return VersionComparator.comp(v, MIN_STORE_LS2_VERSION) >= 0; }
/** * Does this router support encrypted replies? * * @param to null OK * @since 0.9.7 */ public static boolean supportsEncryptedReplies(RouterInfo to) { if (to == null) return false; String v = to.getVersion(); return VersionComparator.comp(v, MIN_ENCRYPTION_VERSION) >= 0; }
/** @param routerVersion as rcvd in the SetDateMessage, may be null for very old routers */ void dateUpdated(String routerVersion) { boolean isrc = _context.isRouterContext(); _routerSupportsFastReceive = isrc || (routerVersion != null && routerVersion.length() > 0 && VersionComparator.comp(routerVersion, MIN_FAST_VERSION) >= 0); _routerSupportsHostLookup = isrc || TEST_LOOKUP || (routerVersion != null && routerVersion.length() > 0 && VersionComparator.comp(routerVersion, MIN_HOST_LOOKUP_VERSION) >= 0); _routerSupportsSubsessions = isrc || (routerVersion != null && routerVersion.length() > 0 && VersionComparator.comp(routerVersion, MIN_SUBSESSION_VERSION) >= 0); _routerSupportsLS2 = isrc || (routerVersion != null && routerVersion.length() > 0 && VersionComparator.comp(routerVersion, MIN_LS2_VERSION) >= 0); synchronized (_stateLock) { if (_state == State.OPENING) { changeState(State.GOTDATE); } } }
/** * @return true if needs an upgrade * @throws IOE on bad version * @since 0.8.9 */ private boolean needsUpgrade(BlockFile bf) throws IOException { if (VersionComparator.comp(_version, VERSION) >= 0) return false; if (!bf.file.canWrite()) { _log.logAlways(Log.WARN, "Not upgrading read-only database version " + _version); return false; } return true; }
if (version == null) throw new IOException("No version"); if (VersionComparator.comp(version, VERSION) > 0) throw new IOException("Database version is " + version + " but this implementation only supports versions 1-" + VERSION + " Did you downgrade I2P??"); _version = version; if (VersionComparator.comp(version, "4") >= 0) { _destSerializer = _destSerializerV4; _isVersion4 = true;
return; String installed = ctx.getProperty("router.firstVersion"); if (installed != null && VersionComparator.comp(installed, "0.9.30") >= 0) { ctx.router().saveConfig(PROP_JETTY9_MIGRATED, "true"); return;
if (isIPv6) { String v = peerInfo.getVersion(); if (VersionComparator.comp(v, MIN_V6_PEER_TEST_VERSION) < 0) continue;
return; if (user != null && password != null && VersionComparator.comp(version, "3.2") < 0) { System.err.println("user/password require 3.2"); return;
if (VersionComparator.comp(_version, "2") < 0) { SkipList<Integer, Properties> rev = _bf.getIndex(REVERSE_SKIPLIST, _hashIndexSerializer, _infoSerializer); if (rev == null) { if (VersionComparator.comp(_version, "3") < 0) { Map<String, Destination> entries = getEntries(); int i = 0; if (VersionComparator.comp(_version, "4") < 0) { if (listVersion == null || VersionComparator.comp(listVersion, "4") < 0) { if (_log.shouldWarn()) _log.warn("Upgrading " + list + " from database version 3 to 4");