diff --git a/core/src/main/groovy/com/muwire/core/connection/ConnectionEvent.groovy b/core/src/main/groovy/com/muwire/core/connection/ConnectionEvent.groovy new file mode 100644 index 00000000..8711657b --- /dev/null +++ b/core/src/main/groovy/com/muwire/core/connection/ConnectionEvent.groovy @@ -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 + +} diff --git a/core/src/main/groovy/com/muwire/core/hostcache/CacheServers.groovy b/core/src/main/groovy/com/muwire/core/hostcache/CacheServers.groovy new file mode 100644 index 00000000..3ddcc897 --- /dev/null +++ b/core/src/main/groovy/com/muwire/core/hostcache/CacheServers.groovy @@ -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 CACHES = [ + new Destination("KvwWPKMSAtzf7Yruj8TQaHi2jaQpSNsXJskbpmSBTxkcYlDB2GllH~QBu-cs4FSYdaRmKDUUx7793jjnYJgTMbrjqeIL5-BTORZ09n6PUfhSejDpJjdkUxaV1OHRatfYs70RNBv7rvdj1-nXUow5tMfOJtoWVocUoKefUGFQFbJLDDkBqjm1kFyKFZv6m6S6YqXxBgVB1qYicooy67cNQF5HLUFtP15pk5fMDNGz5eNCjPfC~2Gp8FF~OpSy92HT0XN7uAMJykPcbdnWfcvVwqD7eS0K4XEnsqnMPLEiMAhqsugEFiFqtB3Wmm7UHVc03lcAfRhr1e2uZBNFTtM2Uol4MD5sCCKRZVHGcH-WGPSEz0BM5YO~Xi~dQ~N3NVud32PVzhh8xoGcAlhTqMqAbRJndCv-H6NflX90pYmbirCTIDOaR9758mThrqX0d4CwCn4jFXer52l8Qe8CErGoLuB-4LL~Gwrn7R1k7ZQc2PthkqeW8MfigyiN7hZVkul9AAAA") + ] + + static List getCacheServers() { + List allCaches = new ArrayList<>(CACHES) + Collections.shuffle(allCaches) + if (allCaches.size() <= TO_GIVE) + return allCaches + allCaches[0..TO_GIVE-1] + } +} diff --git a/core/src/main/groovy/com/muwire/core/hostcache/Host.groovy b/core/src/main/groovy/com/muwire/core/hostcache/Host.groovy new file mode 100644 index 00000000..bb1c50f4 --- /dev/null +++ b/core/src/main/groovy/com/muwire/core/hostcache/Host.groovy @@ -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 + } +} diff --git a/core/src/main/groovy/com/muwire/core/hostcache/HostCache.groovy b/core/src/main/groovy/com/muwire/core/hostcache/HostCache.groovy new file mode 100644 index 00000000..d66a0962 --- /dev/null +++ b/core/src/main/groovy/com/muwire/core/hostcache/HostCache.groovy @@ -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 + } + +} diff --git a/core/src/main/groovy/com/muwire/core/hostcache/HostDiscoveredEvent.groovy b/core/src/main/groovy/com/muwire/core/hostcache/HostDiscoveredEvent.groovy new file mode 100644 index 00000000..4f3348ca --- /dev/null +++ b/core/src/main/groovy/com/muwire/core/hostcache/HostDiscoveredEvent.groovy @@ -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 +} diff --git a/core/src/main/java/com/muwire/core/connection/ConnectionAttemptStatus.java b/core/src/main/java/com/muwire/core/connection/ConnectionAttemptStatus.java new file mode 100644 index 00000000..0f2508ae --- /dev/null +++ b/core/src/main/java/com/muwire/core/connection/ConnectionAttemptStatus.java @@ -0,0 +1,5 @@ +package com.muwire.core.connection; + +public enum ConnectionAttemptStatus { + SUCCESSFUL, REJECTED, FAILED +}