mirror of https://github.com/zlatinb/muwire
respond to discovery of new hosts and connection attempts
parent
2e95831a24
commit
db98d63caf
|
@ -3,6 +3,8 @@ package com.muwire.core.hostcache
|
|||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
import com.muwire.core.MuWireSettings
|
||||
import com.muwire.core.connection.ConnectionAttemptStatus
|
||||
import com.muwire.core.connection.ConnectionEvent
|
||||
import com.muwire.core.trust.TrustLevel
|
||||
import com.muwire.core.trust.TrustService
|
||||
|
||||
|
@ -35,6 +37,33 @@ class HostCache {
|
|||
timer.cancel()
|
||||
}
|
||||
|
||||
void onHostDiscoveredEvent(HostDiscoveredEvent e) {
|
||||
if (hosts.containsKey(e.destination))
|
||||
return
|
||||
Host host = new Host(e.destination)
|
||||
if (allowHost(host)) {
|
||||
hosts.put(e.destination, host)
|
||||
}
|
||||
}
|
||||
|
||||
void onConnectionEvent(ConnectionEvent e) {
|
||||
Host host = hosts.get(e.destination)
|
||||
if (host == null) {
|
||||
host = new Host(e.destination)
|
||||
hosts.put(e.destination, host)
|
||||
}
|
||||
|
||||
switch(e.status) {
|
||||
case ConnectionAttemptStatus.SUCCESSFUL:
|
||||
case ConnectionAttemptStatus.REJECTED:
|
||||
host.onConnect()
|
||||
break
|
||||
case ConnectionAttemptStatus.FAILED:
|
||||
host.onFailure()
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
List<Destination> getHosts(int n) {
|
||||
List<Destination> rv = new ArrayList<>(hosts.keySet())
|
||||
rv.retainAll {allowHost(it)}
|
||||
|
|
Loading…
Reference in New Issue