mirror of https://github.com/zlatinb/muwire
make sure hosts with successful attempts can be advertised
parent
38bf4f2ea2
commit
efae38a400
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue