skeleton of host cache querying functionality

pull/4/head
Zlatin Balevsky 2018-07-22 04:42:12 +01:00
parent 6ddce7d276
commit cbe359deca
6 changed files with 85 additions and 0 deletions

View File

@ -0,0 +1,12 @@
package com.muwire.core.connection
import com.muwire.core.Event
import net.i2p.data.Destination
class ConnectionEvent extends Event {
Destination destination
ConnectionAttemptStatus status
}

View File

@ -0,0 +1,19 @@
package com.muwire.core.hostcache
import net.i2p.data.Destination
class CacheServers {
private static final int TO_GIVE = 3
private static List<Destination> CACHES = [
new Destination("KvwWPKMSAtzf7Yruj8TQaHi2jaQpSNsXJskbpmSBTxkcYlDB2GllH~QBu-cs4FSYdaRmKDUUx7793jjnYJgTMbrjqeIL5-BTORZ09n6PUfhSejDpJjdkUxaV1OHRatfYs70RNBv7rvdj1-nXUow5tMfOJtoWVocUoKefUGFQFbJLDDkBqjm1kFyKFZv6m6S6YqXxBgVB1qYicooy67cNQF5HLUFtP15pk5fMDNGz5eNCjPfC~2Gp8FF~OpSy92HT0XN7uAMJykPcbdnWfcvVwqD7eS0K4XEnsqnMPLEiMAhqsugEFiFqtB3Wmm7UHVc03lcAfRhr1e2uZBNFTtM2Uol4MD5sCCKRZVHGcH-WGPSEz0BM5YO~Xi~dQ~N3NVud32PVzhh8xoGcAlhTqMqAbRJndCv-H6NflX90pYmbirCTIDOaR9758mThrqX0d4CwCn4jFXer52l8Qe8CErGoLuB-4LL~Gwrn7R1k7ZQc2PthkqeW8MfigyiN7hZVkul9AAAA")
]
static List<Destination> getCacheServers() {
List<Destination> allCaches = new ArrayList<>(CACHES)
Collections.shuffle(allCaches)
if (allCaches.size() <= TO_GIVE)
return allCaches
allCaches[0..TO_GIVE-1]
}
}

View File

@ -0,0 +1,27 @@
package com.muwire.core.hostcache
import net.i2p.data.Destination
class Host {
private static final int MAX_FAILURES = 3
final Destination destination
int failures
public Host(Destination destination) {
this.destination = destination
}
synchronized void onConnect() {
failures = 0
}
synchronized void onFailure() {
failures++
}
synchronized boolean isFailed() {
failures >= MAX_FAILURES
}
}

View File

@ -0,0 +1,12 @@
package com.muwire.core.hostcache
import com.muwire.core.trust.TrustService
class HostCache {
final TrustService trustService
public HostCache(TrustService trustService) {
this.trustService = trustService
}
}

View File

@ -0,0 +1,10 @@
package com.muwire.core.hostcache
import com.muwire.core.Event
import net.i2p.data.Destination
class HostDiscoveredEvent extends Event {
Destination destination
}

View File

@ -0,0 +1,5 @@
package com.muwire.core.connection;
public enum ConnectionAttemptStatus {
SUCCESSFUL, REJECTED, FAILED
}