diff --git a/core/src/main/groovy/com/muwire/core/hostcache/H2HostCache.groovy b/core/src/main/groovy/com/muwire/core/hostcache/H2HostCache.groovy index 503c9236..76596dab 100644 --- a/core/src/main/groovy/com/muwire/core/hostcache/H2HostCache.groovy +++ b/core/src/main/groovy/com/muwire/core/hostcache/H2HostCache.groovy @@ -43,11 +43,11 @@ class H2HostCache extends HostCache { // overwrite MC with optimistic values if (fromHostcache) { sql.execute("delete from HOST_ATTEMPTS where DESTINATION=${d.toBase64()}") - profiles.put(d, new HostMCProfile()) + profiles.put(d, new HostMCProfile(false)) } if (uniqueHosts.add(d)) { allHosts.add(d) - profiles.put(d, new HostMCProfile()) + profiles.put(d, new HostMCProfile(false)) } } @@ -56,9 +56,12 @@ class H2HostCache extends HostCache { log.fine("onConnection ${d.toBase32()} status $status") - if (status == ConnectionAttemptStatus.SUCCESSFUL && uniqueHosts.add(d)) { - allHosts.add(d) - profiles.put(d, new HostMCProfile()) + if (status == ConnectionAttemptStatus.SUCCESSFUL) { + if (uniqueHosts.add(d)) { + allHosts.add(d) + profiles.put(d, new HostMCProfile(true)) + } else + profiles.get(d).successfulAttempt = true } // record into db @@ -285,7 +288,7 @@ class H2HostCache extends HostCache { Destination dest = new Destination(it.DESTINATION) if (uniqueHosts.add(dest)) { def fromDB = sql.firstRow("select * from HOST_PROFILES where DESTINATION=${dest.toBase64()}") - def profile = new HostMCProfile() + def profile = new HostMCProfile(true) if (fromDB != null) profile = new HostMCProfile(fromDB) profiles.put(dest, profile) diff --git a/core/src/main/groovy/com/muwire/core/hostcache/HostMCProfile.groovy b/core/src/main/groovy/com/muwire/core/hostcache/HostMCProfile.groovy index d4e051d0..c4ceb665 100644 --- a/core/src/main/groovy/com/muwire/core/hostcache/HostMCProfile.groovy +++ b/core/src/main/groovy/com/muwire/core/hostcache/HostMCProfile.groovy @@ -38,12 +38,13 @@ class HostMCProfile { ConnectionAttemptStatus state = ConnectionAttemptStatus.SUCCESSFUL final boolean hasHistory + boolean successfulAttempt /** * constructs an "optimistic" predictor for newly discovered hosts. */ - HostMCProfile() { - hasHistory = false + HostMCProfile(boolean hasHistory) { + this.hasHistory = hasHistory S = new Probability[3] R = new Probability[3] F = new Probability[3] @@ -159,7 +160,7 @@ class HostMCProfile { * @return if the host should be advertised in pongs */ boolean shouldAdvertise() { - hasHistory && nextState() != ConnectionAttemptStatus.FAILED + (hasHistory || successfulAttempt) && nextState() != ConnectionAttemptStatus.FAILED } /**