make sure hosts with successful attempts can be advertised

pull/53/head
Zlatin Balevsky 2020-10-21 06:10:14 +01:00
parent 38bf4f2ea2
commit efae38a400
No known key found for this signature in database
GPG Key ID: A72832072D525E41
2 changed files with 13 additions and 9 deletions

View File

@ -43,11 +43,11 @@ class H2HostCache extends HostCache {
// overwrite MC with optimistic values // overwrite MC with optimistic values
if (fromHostcache) { if (fromHostcache) {
sql.execute("delete from HOST_ATTEMPTS where DESTINATION=${d.toBase64()}") 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)) { if (uniqueHosts.add(d)) {
allHosts.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") log.fine("onConnection ${d.toBase32()} status $status")
if (status == ConnectionAttemptStatus.SUCCESSFUL && uniqueHosts.add(d)) { if (status == ConnectionAttemptStatus.SUCCESSFUL) {
if (uniqueHosts.add(d)) {
allHosts.add(d) allHosts.add(d)
profiles.put(d, new HostMCProfile()) profiles.put(d, new HostMCProfile(true))
} else
profiles.get(d).successfulAttempt = true
} }
// record into db // record into db
@ -285,7 +288,7 @@ class H2HostCache extends HostCache {
Destination dest = new Destination(it.DESTINATION) Destination dest = new Destination(it.DESTINATION)
if (uniqueHosts.add(dest)) { if (uniqueHosts.add(dest)) {
def fromDB = sql.firstRow("select * from HOST_PROFILES where DESTINATION=${dest.toBase64()}") def fromDB = sql.firstRow("select * from HOST_PROFILES where DESTINATION=${dest.toBase64()}")
def profile = new HostMCProfile() def profile = new HostMCProfile(true)
if (fromDB != null) if (fromDB != null)
profile = new HostMCProfile(fromDB) profile = new HostMCProfile(fromDB)
profiles.put(dest, profile) profiles.put(dest, profile)

View File

@ -38,12 +38,13 @@ class HostMCProfile {
ConnectionAttemptStatus state = ConnectionAttemptStatus.SUCCESSFUL ConnectionAttemptStatus state = ConnectionAttemptStatus.SUCCESSFUL
final boolean hasHistory final boolean hasHistory
boolean successfulAttempt
/** /**
* constructs an "optimistic" predictor for newly discovered hosts. * constructs an "optimistic" predictor for newly discovered hosts.
*/ */
HostMCProfile() { HostMCProfile(boolean hasHistory) {
hasHistory = false this.hasHistory = hasHistory
S = new Probability[3] S = new Probability[3]
R = new Probability[3] R = new Probability[3]
F = new Probability[3] F = new Probability[3]
@ -159,7 +160,7 @@ class HostMCProfile {
* @return if the host should be advertised in pongs * @return if the host should be advertised in pongs
*/ */
boolean shouldAdvertise() { boolean shouldAdvertise() {
hasHistory && nextState() != ConnectionAttemptStatus.FAILED (hasHistory || successfulAttempt) && nextState() != ConnectionAttemptStatus.FAILED
} }
/** /**