mirror of https://github.com/zlatinb/muwire
change state on observation even if there is not enough history yet. Initialize MC with last state from DB
parent
e1b2582ca6
commit
f5f84899ec
|
@ -73,6 +73,7 @@ class H2HostCache extends HostCache {
|
||||||
def count = sql.firstRow("select count(*) as COUNT from HOST_ATTEMPTS where DESTINATION=${d.toBase64()}")
|
def count = sql.firstRow("select count(*) as COUNT from HOST_ATTEMPTS where DESTINATION=${d.toBase64()}")
|
||||||
if (count.COUNT < settings.minHostProfileHistory) {
|
if (count.COUNT < settings.minHostProfileHistory) {
|
||||||
log.fine("not enough history for Markov")
|
log.fine("not enough history for Markov")
|
||||||
|
profiles.put(d, new HostMCProfile(state))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -316,8 +317,11 @@ class H2HostCache extends HostCache {
|
||||||
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()
|
||||||
if (fromDB != null)
|
if (fromDB != null) {
|
||||||
profile = new HostMCProfile(fromDB, ConnectionAttemptStatus.SUCCESSFUL)
|
def lastObservation = sql.firstRow("select STATUS from HOST_ATTEMPTS where DESTINATION=${dest.toBase64()} order by TSTAMP desc limit 1")
|
||||||
|
if (lastObservation != null)
|
||||||
|
profile = new HostMCProfile(fromDB, ConnectionAttemptStatus.valueOf(lastObservation.STATUS))
|
||||||
|
}
|
||||||
profiles.put(dest, profile)
|
profiles.put(dest, profile)
|
||||||
allHosts.add(dest)
|
allHosts.add(dest)
|
||||||
log.fine("Loaded profile for ${dest.toBase32()} $profile")
|
log.fine("Loaded profile for ${dest.toBase32()} $profile")
|
||||||
|
|
|
@ -40,11 +40,18 @@ class HostMCProfile {
|
||||||
boolean successfulAttempt
|
boolean successfulAttempt
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* constructs an "optimistic" predictor for newly discovered hosts.
|
* Constructs an optimistic predictor for newly discovered hosts
|
||||||
*/
|
*/
|
||||||
HostMCProfile() {
|
HostMCProfile() {
|
||||||
|
this(ConnectionAttemptStatus.SUCCESSFUL)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* constructs a predictor with default values and the specified state
|
||||||
|
*/
|
||||||
|
HostMCProfile(ConnectionAttemptStatus state) {
|
||||||
this.hasHistory = false
|
this.hasHistory = false
|
||||||
this.state = ConnectionAttemptStatus.SUCCESSFUL
|
this.state = state
|
||||||
S = new Probability[3]
|
S = new Probability[3]
|
||||||
R = new Probability[3]
|
R = new Probability[3]
|
||||||
F = new Probability[3]
|
F = new Probability[3]
|
||||||
|
@ -67,7 +74,7 @@ class HostMCProfile {
|
||||||
"RF:${R[2].probability},"+
|
"RF:${R[2].probability},"+
|
||||||
"FS:${F[0].probability},"+
|
"FS:${F[0].probability},"+
|
||||||
"FR:${F[1].probability},"+
|
"FR:${F[1].probability},"+
|
||||||
"FF:${F[2].probability}"
|
"FF:${F[2].probability} " + state
|
||||||
|
|
||||||
Arrays.sort(S)
|
Arrays.sort(S)
|
||||||
S[1].probability += S[0].probability
|
S[1].probability += S[0].probability
|
||||||
|
@ -134,7 +141,7 @@ class HostMCProfile {
|
||||||
"RF:${R[2].probability},"+
|
"RF:${R[2].probability},"+
|
||||||
"FS:${F[0].probability},"+
|
"FS:${F[0].probability},"+
|
||||||
"FR:${F[1].probability},"+
|
"FR:${F[1].probability},"+
|
||||||
"FF:${F[2].probability}"
|
"FF:${F[2].probability} " + state
|
||||||
|
|
||||||
Arrays.sort(S)
|
Arrays.sort(S)
|
||||||
S[1].probability += S[0].probability
|
S[1].probability += S[0].probability
|
||||||
|
@ -193,7 +200,7 @@ class HostMCProfile {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
toString + " state " + state
|
toString
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Probability implements Comparable<Probability> {
|
private static class Probability implements Comparable<Probability> {
|
||||||
|
|
Loading…
Reference in New Issue