diff --git a/router/java/src/net/i2p/data/i2np/DatabaseLookupMessage.java b/router/java/src/net/i2p/data/i2np/DatabaseLookupMessage.java index 6a331748536afc2ab4d3ffd187fc2ddd9a2b659e..06d996857493992e12d34ec3b1feadabd99d73eb 100644 --- a/router/java/src/net/i2p/data/i2np/DatabaseLookupMessage.java +++ b/router/java/src/net/i2p/data/i2np/DatabaseLookupMessage.java @@ -212,7 +212,7 @@ public class DatabaseLookupMessage extends FastI2NPMessageImpl { public Set<Hash> getDontIncludePeers() { if (_dontIncludePeers == null) return null; - return new HashSet(_dontIncludePeers); + return new HashSet<Hash>(_dontIncludePeers); } /** @@ -225,7 +225,7 @@ public class DatabaseLookupMessage extends FastI2NPMessageImpl { public void setDontIncludePeers(Collection<Hash> peers) { _hasChecksum = false; if (peers != null) - _dontIncludePeers = new ArrayList(peers); + _dontIncludePeers = new ArrayList<Hash>(peers); else _dontIncludePeers = null; } @@ -239,7 +239,7 @@ public class DatabaseLookupMessage extends FastI2NPMessageImpl { */ public void addDontIncludePeer(Hash peer) { if (_dontIncludePeers == null) - _dontIncludePeers = new ArrayList(); + _dontIncludePeers = new ArrayList<Hash>(); else if (_dontIncludePeers.contains(peer)) return; _hasChecksum = false; @@ -256,7 +256,7 @@ public class DatabaseLookupMessage extends FastI2NPMessageImpl { public void addDontIncludePeers(Collection<Hash> peers) { _hasChecksum = false; if (_dontIncludePeers == null) { - _dontIncludePeers = new ArrayList(peers); + _dontIncludePeers = new ArrayList<Hash>(peers); } else { for (Hash peer : peers) { if (!_dontIncludePeers.contains(peer)) @@ -297,7 +297,7 @@ public class DatabaseLookupMessage extends FastI2NPMessageImpl { if ( (numPeers < 0) || (numPeers > MAX_NUM_PEERS) ) throw new I2NPMessageException("Invalid number of peers - " + numPeers); - List<Hash> peers = new ArrayList(numPeers); + List<Hash> peers = new ArrayList<Hash>(numPeers); for (int i = 0; i < numPeers; i++) { //byte peer[] = new byte[Hash.HASH_LENGTH]; //System.arraycopy(data, curIndex, peer, 0, Hash.HASH_LENGTH); diff --git a/router/java/src/net/i2p/data/i2np/DatabaseSearchReplyMessage.java b/router/java/src/net/i2p/data/i2np/DatabaseSearchReplyMessage.java index 1c4838000c34740d4f2f2f07b1402ad2831b6c21..b2da84295a55b09cafd1a6cb9786586cf890dd5f 100644 --- a/router/java/src/net/i2p/data/i2np/DatabaseSearchReplyMessage.java +++ b/router/java/src/net/i2p/data/i2np/DatabaseSearchReplyMessage.java @@ -33,7 +33,7 @@ public class DatabaseSearchReplyMessage extends FastI2NPMessageImpl { // do this in netdb if we need it //_context.statManager().createRateStat("netDb.searchReplyMessageSend", "How many search reply messages we send", "NetworkDatabase", new long[] { 60*1000, 5*60*1000, 10*60*1000, 60*60*1000 }); //_context.statManager().createRateStat("netDb.searchReplyMessageReceive", "How many search reply messages we receive", "NetworkDatabase", new long[] { 60*1000, 5*60*1000, 10*60*1000, 60*60*1000 }); - _peerHashes = new ArrayList(3); + _peerHashes = new ArrayList<Hash>(3); } /** diff --git a/router/java/src/net/i2p/data/i2np/I2NPMessageException.java b/router/java/src/net/i2p/data/i2np/I2NPMessageException.java index 4b64a7370d7fbe1c0f21a55a8189dda6d1cbaaa6..6ecba8ce6023de20b35ce3cc11b151c13057d497 100644 --- a/router/java/src/net/i2p/data/i2np/I2NPMessageException.java +++ b/router/java/src/net/i2p/data/i2np/I2NPMessageException.java @@ -9,7 +9,6 @@ package net.i2p.data.i2np; */ import net.i2p.I2PException; -import net.i2p.util.Log; /** * Represent an error serializing or deserializing an APIMessage diff --git a/router/java/src/net/i2p/data/i2np/I2NPMessageImpl.java b/router/java/src/net/i2p/data/i2np/I2NPMessageImpl.java index 97635e0a90eac1071c52030adaed86d2408e17a6..f3add3c2a1b4d9930fe2a4002f5dc03cc2080dbb 100644 --- a/router/java/src/net/i2p/data/i2np/I2NPMessageImpl.java +++ b/router/java/src/net/i2p/data/i2np/I2NPMessageImpl.java @@ -48,7 +48,7 @@ public abstract class I2NPMessageImpl extends DataStructureImpl implements I2NPM //private static final boolean RAW_FULL_SIZE = false; /** unused */ - private static final Map<Integer, Builder> _builders = new ConcurrentHashMap(1); + private static final Map<Integer, Builder> _builders = new ConcurrentHashMap<Integer, Builder>(1); /** @deprecated unused */ public static final void registerBuilder(Builder builder, int type) { _builders.put(Integer.valueOf(type), builder); } diff --git a/router/java/src/net/i2p/router/Banlist.java b/router/java/src/net/i2p/router/Banlist.java index c167108e011e488eba371556a17007d83fe50230..d10186d5d1b687b4a3fd037515fe121eceaff4ad 100644 --- a/router/java/src/net/i2p/router/Banlist.java +++ b/router/java/src/net/i2p/router/Banlist.java @@ -58,7 +58,7 @@ public class Banlist { public Banlist(RouterContext context) { _context = context; _log = context.logManager().getLog(Banlist.class); - _entries = new ConcurrentHashMap(16); + _entries = new ConcurrentHashMap<Hash, Entry>(16); _context.jobQueue().addJob(new Cleanup(_context)); } @@ -66,7 +66,7 @@ public class Banlist { private List<Hash> _toUnbanlist; public Cleanup(RouterContext ctx) { super(ctx); - _toUnbanlist = new ArrayList(4); + _toUnbanlist = new ArrayList<Hash>(4); getTiming().setStartAfter(ctx.clock().now() + BANLIST_CLEANER_START_DELAY); } public String getName() { return "Expire banned peers"; } @@ -74,8 +74,8 @@ public class Banlist { _toUnbanlist.clear(); long now = getContext().clock().now(); try { - for (Iterator iter = _entries.entrySet().iterator(); iter.hasNext(); ) { - Map.Entry<Hash, Entry> e = (Map.Entry) iter.next(); + for (Iterator<Map.Entry<Hash, Entry>> iter = _entries.entrySet().iterator(); iter.hasNext(); ) { + Map.Entry<Hash, Entry> e = iter.next(); if (e.getValue().expireOn <= now) { iter.remove(); _toUnbanlist.add(e.getKey()); @@ -169,7 +169,7 @@ public class Banlist { e.causeCode = reasonCode; e.transports = null; if (transport != null) { - e.transports = new ConcurrentHashSet(2); + e.transports = new ConcurrentHashSet<String>(2); e.transports.add(transport); } diff --git a/router/java/src/net/i2p/router/Blocklist.java b/router/java/src/net/i2p/router/Blocklist.java index 11a4cc5c42086ab99839f27aec088803944a362e..4c3b8407b48188984d2bc0f714f19ae71e4c203e 100644 --- a/router/java/src/net/i2p/router/Blocklist.java +++ b/router/java/src/net/i2p/router/Blocklist.java @@ -75,8 +75,8 @@ public class Blocklist { private int _blocklistSize; private final Object _lock = new Object(); private Entry _wrapSave; - private final Set<Hash> _inProcess = new HashSet(4); - private Map<Hash, String> _peerBlocklist = new HashMap(4); + private final Set<Hash> _inProcess = new HashSet<Hash>(4); + private Map<Hash, String> _peerBlocklist = new HashMap<Hash, String>(4); /** * Limits of transient (in-memory) blocklists. @@ -86,8 +86,8 @@ public class Blocklist { private static final int MAX_IPV4_SINGLES = 256; private static final int MAX_IPV6_SINGLES = 512; - private final Set<Integer> _singleIPBlocklist = new ConcurrentHashSet(4); - private final Map<BigInteger, Object> _singleIPv6Blocklist = new LHMCache(MAX_IPV6_SINGLES); + private final Set<Integer> _singleIPBlocklist = new ConcurrentHashSet<Integer>(4); + private final Map<BigInteger, Object> _singleIPv6Blocklist = new LHMCache<BigInteger, Object>(MAX_IPV6_SINGLES); private static final Object DUMMY = Integer.valueOf(0); @@ -518,8 +518,8 @@ public class Blocklist { private List<byte[]> getAddresses(Hash peer) { RouterInfo pinfo = _context.netDb().lookupRouterInfoLocally(peer); if (pinfo == null) - return Collections.EMPTY_LIST; - List<byte[]> rv = new ArrayList(4); + return Collections.emptyList(); + List<byte[]> rv = new ArrayList<byte[]>(4); // for each peer address for (RouterAddress pa : pinfo.getAddresses()) { byte[] pib = pa.getIP(); @@ -753,7 +753,7 @@ public class Blocklist { * Additional jobs can wait. * Although could this clog up the job queue runners? Yes. * So we also stagger these jobs. - * + *(Map.Entry) */ private synchronized void banlistForever(Hash peer, List<byte[]> ips) { String file = _context.getProperty(PROP_BLOCKLIST_FILE, BLOCKLIST_FILE_DEFAULT); @@ -818,7 +818,7 @@ public class Blocklist { public void renderStatusHTML(Writer out) throws IOException { // move to the jsp //out.write("<h2>Banned IPs</h2>"); - Set<Integer> singles = new TreeSet(); + Set<Integer> singles = new TreeSet<Integer>(); singles.addAll(_singleIPBlocklist); if (!(singles.isEmpty() && _singleIPv6Blocklist.isEmpty())) { out.write("<table><tr><th align=\"center\" colspan=\"2\"><b>"); @@ -846,7 +846,7 @@ public class Blocklist { if (!_singleIPv6Blocklist.isEmpty()) { List<BigInteger> s6; synchronized(_singleIPv6Blocklist) { - s6 = new ArrayList(_singleIPv6Blocklist.keySet()); + s6 = new ArrayList<BigInteger>(_singleIPv6Blocklist.keySet()); } Collections.sort(s6); for (BigInteger bi : s6) { diff --git a/router/java/src/net/i2p/router/ClientManagerFacade.java b/router/java/src/net/i2p/router/ClientManagerFacade.java index 204a3f591d13ae7e3c714b67e9286129eb2a8792..a5e403973f4847080779ea326a425fd5383241f3 100644 --- a/router/java/src/net/i2p/router/ClientManagerFacade.java +++ b/router/java/src/net/i2p/router/ClientManagerFacade.java @@ -89,7 +89,7 @@ public abstract class ClientManagerFacade implements Service { * * @return set of Destination objects */ - public Set<Destination> listClients() { return Collections.EMPTY_SET; } + public Set<Destination> listClients() { return Collections.emptySet(); } /** * Return the client's current config, or null if not connected diff --git a/router/java/src/net/i2p/router/CommSystemFacade.java b/router/java/src/net/i2p/router/CommSystemFacade.java index 1386b87277d9b909292b4cec560fce935d05878c..591fd817937ca92b07970169adac56cfbc7753c4 100644 --- a/router/java/src/net/i2p/router/CommSystemFacade.java +++ b/router/java/src/net/i2p/router/CommSystemFacade.java @@ -12,8 +12,6 @@ import java.io.IOException; import java.io.Writer; import java.util.Collections; import java.util.List; -import java.util.Set; - import net.i2p.data.Hash; import net.i2p.data.RouterAddress; @@ -29,14 +27,14 @@ public abstract class CommSystemFacade implements Service { public void renderStatusHTML(Writer out) throws IOException { renderStatusHTML(out, null, 0); } /** Create the list of RouterAddress structures based on the router's config */ - public List<RouterAddress> createAddresses() { return Collections.EMPTY_LIST; } + public List<RouterAddress> createAddresses() { return Collections.emptyList(); } public int countActivePeers() { return 0; } public int countActiveSendPeers() { return 0; } public boolean haveInboundCapacity(int pct) { return true; } public boolean haveOutboundCapacity(int pct) { return true; } public boolean haveHighOutboundCapacity() { return true; } - public List getMostRecentErrorMessages() { return Collections.EMPTY_LIST; } + public List getMostRecentErrorMessages() { return Collections.emptyList(); } /** * Median clock skew of connected peers in seconds, or null if we cannot answer. diff --git a/router/java/src/net/i2p/router/InNetMessagePool.java b/router/java/src/net/i2p/router/InNetMessagePool.java index a4396dc8dc7fec3c0228f2635ac50dc8619f2d84..8f185ef1dad182c73f3147c4dc834815e6bd56cd 100644 --- a/router/java/src/net/i2p/router/InNetMessagePool.java +++ b/router/java/src/net/i2p/router/InNetMessagePool.java @@ -36,9 +36,9 @@ public class InNetMessagePool implements Service { private final HandlerJobBuilder _handlerJobBuilders[]; /** following 5 unused unless DISPATCH_DIRECT == false */ - private final List _pendingDataMessages; - private final List _pendingDataMessagesFrom; - private final List _pendingGatewayMessages; + private final List<I2NPMessage> _pendingDataMessages; + private final List<Hash> _pendingDataMessagesFrom; + private final List<I2NPMessage> _pendingGatewayMessages; private SharedShortCircuitDataJob _shortCircuitDataJob; private SharedShortCircuitGatewayJob _shortCircuitGatewayJob; @@ -56,7 +56,7 @@ public class InNetMessagePool implements Service { * using the jobQueue's single thread. * */ - public static final String PROP_DISPATCH_THREADED = "router.dispatchThreaded"; + public static final String PROP_DISPATCH_THREADED = "router.dispatchTemptyList()hreaded"; public static final boolean DEFAULT_DISPATCH_THREADED = false; /** * If we aren't doing threaded dispatch for tunnel messages, should we @@ -75,9 +75,9 @@ public class InNetMessagePool implements Service { _pendingDataMessagesFrom = null; _pendingGatewayMessages = null; } else { - _pendingDataMessages = new ArrayList(16); - _pendingDataMessagesFrom = new ArrayList(16); - _pendingGatewayMessages = new ArrayList(16); + _pendingDataMessages = new ArrayList<I2NPMessage>(16); + _pendingDataMessagesFrom = new ArrayList<Hash>(16); + _pendingGatewayMessages = new ArrayList<I2NPMessage>(16); _shortCircuitDataJob = new SharedShortCircuitDataJob(context); _shortCircuitGatewayJob = new SharedShortCircuitGatewayJob(context); } diff --git a/router/java/src/net/i2p/router/KeyManager.java b/router/java/src/net/i2p/router/KeyManager.java index a0eddf9d31a9964e44e9b6be520fb0abb1daa409..5486beac717be47fb66ce1b32c098f5356ef2f60 100644 --- a/router/java/src/net/i2p/router/KeyManager.java +++ b/router/java/src/net/i2p/router/KeyManager.java @@ -12,7 +12,6 @@ import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.InputStream; import java.io.IOException; import java.io.OutputStream; @@ -27,7 +26,6 @@ import net.i2p.data.PrivateKey; import net.i2p.data.PublicKey; import net.i2p.data.SigningPrivateKey; import net.i2p.data.SigningPublicKey; -import net.i2p.util.Clock; import net.i2p.util.Log; import net.i2p.util.SecureDirectory; import net.i2p.util.SecureFileOutputStream; @@ -57,7 +55,7 @@ public class KeyManager { public KeyManager(RouterContext context) { _context = context; _log = _context.logManager().getLog(KeyManager.class); - _leaseSetKeys = new ConcurrentHashMap(); + _leaseSetKeys = new ConcurrentHashMap<Hash, LeaseSetKeys>(); } public void startup() { diff --git a/router/java/src/net/i2p/router/MessageHistory.java b/router/java/src/net/i2p/router/MessageHistory.java index 1eec0fa30f10a38e3efc6886be374bf359f5bed2..5622580e61cdd95cc1f1e84329d761ff36cd82ef 100644 --- a/router/java/src/net/i2p/router/MessageHistory.java +++ b/router/java/src/net/i2p/router/MessageHistory.java @@ -56,7 +56,7 @@ public class MessageHistory { _log = context.logManager().getLog(getClass()); _fmt = new SimpleDateFormat("yy/MM/dd.HH:mm:ss.SSS"); _fmt.setTimeZone(TimeZone.getTimeZone("GMT")); - _unwrittenEntries = new LinkedBlockingQueue(); + _unwrittenEntries = new LinkedBlockingQueue<String>(); _reinitializeJob = new ReinitializeJob(); _writeJob = new WriteJob(); _firstPass = true; diff --git a/router/java/src/net/i2p/router/MultiRouter.java b/router/java/src/net/i2p/router/MultiRouter.java index 0790f48be599e0db6784d2f0ead64599e379d64e..8d5f381eac7081ab926b014bd41d23c11821dbd3 100644 --- a/router/java/src/net/i2p/router/MultiRouter.java +++ b/router/java/src/net/i2p/router/MultiRouter.java @@ -1,7 +1,6 @@ package net.i2p.router; import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.PrintStream; import java.util.ArrayList; @@ -13,7 +12,6 @@ import net.i2p.I2PAppContext; import net.i2p.data.DataHelper; import net.i2p.data.RouterInfo; import net.i2p.router.Router; -import net.i2p.util.Log; /** * Fire up multiple routers in the same VM, all with their own RouterContext diff --git a/router/java/src/net/i2p/router/NetworkDatabaseFacade.java b/router/java/src/net/i2p/router/NetworkDatabaseFacade.java index 4cd201b146370aef9da968e33f63879d1608630e..be0ce340e93add63a84a8a6a151bf805ee40fd2d 100644 --- a/router/java/src/net/i2p/router/NetworkDatabaseFacade.java +++ b/router/java/src/net/i2p/router/NetworkDatabaseFacade.java @@ -77,9 +77,9 @@ public abstract class NetworkDatabaseFacade implements Service { /** @deprecated moved to router console */ public void renderStatusHTML(Writer out) throws IOException {} /** public for NetDbRenderer in routerconsole */ - public Set<LeaseSet> getLeases() { return Collections.EMPTY_SET; } + public Set<LeaseSet> getLeases() { return Collections.emptySet(); } /** public for NetDbRenderer in routerconsole */ - public Set<RouterInfo> getRouters() { return Collections.EMPTY_SET; } + public Set<RouterInfo> getRouters() { return Collections.emptySet(); } /** @since 0.9 */ public ReseedChecker reseedChecker() { return null; }; diff --git a/router/java/src/net/i2p/router/OutNetMessage.java b/router/java/src/net/i2p/router/OutNetMessage.java index 043b6cfae89e4015cc86c394c12ef5ebf0492a4d..7b1e17d3b4e267450ad601204a8bd56a32657588 100644 --- a/router/java/src/net/i2p/router/OutNetMessage.java +++ b/router/java/src/net/i2p/router/OutNetMessage.java @@ -154,7 +154,7 @@ public class OutNetMessage implements CDPQEntry { return (Map<String, Long>)_timestamps.clone(); } } - return Collections.EMPTY_MAP; + return Collections.emptyMap(); } /** @deprecated unused */ @@ -170,8 +170,8 @@ public class OutNetMessage implements CDPQEntry { private void locked_initTimestamps() { if (_timestamps == null) { - _timestamps = new HashMap(8); - _timestampOrder = new ArrayList(8); + _timestamps = new HashMap<String, Long>(8); + _timestampOrder = new ArrayList<String>(8); } } @@ -279,7 +279,7 @@ public class OutNetMessage implements CDPQEntry { public synchronized void transportFailed(String transportStyle) { if (_failedTransports == null) - _failedTransports = new HashSet(2); + _failedTransports = new HashSet<String>(2); _failedTransports.add(transportStyle); } diff --git a/router/java/src/net/i2p/router/Router.java b/router/java/src/net/i2p/router/Router.java index 174898818923af6495e387fb7c9741e90bc90ec5..26daf7514919c0fce19eea1e38095ad2cb8d5cf6 100644 --- a/router/java/src/net/i2p/router/Router.java +++ b/router/java/src/net/i2p/router/Router.java @@ -11,20 +11,16 @@ package net.i2p.router; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.InputStreamReader; import java.io.IOException; import java.util.Collection; import java.util.Collections; -import java.util.Date; -import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Properties; import java.util.Set; import java.util.TimeZone; -import java.util.TreeSet; import java.util.concurrent.ConcurrentHashMap; import net.i2p.data.Certificate; @@ -53,7 +49,6 @@ import net.i2p.util.Log; import net.i2p.util.OrderedProperties; import net.i2p.util.SecureFileOutputStream; import net.i2p.util.SimpleByteCache; -import net.i2p.util.SimpleScheduler; import net.i2p.util.SystemVersion; import net.i2p.util.Translate; @@ -147,7 +142,7 @@ public class Router implements RouterClock.ClockShiftListener { public Router(String configFilename, Properties envProps) { _gracefulExitCode = -1; - _config = new ConcurrentHashMap(); + _config = new ConcurrentHashMap<String, String>(); if (configFilename == null) { if (envProps != null) { @@ -1028,7 +1023,7 @@ public class Router implements RouterClock.ClockShiftListener { * @return success * @since 0.8.13 */ - public boolean saveConfig(Map toAdd, Collection<String> toRemove) { + public boolean saveConfig(Map<String, String> toAdd, Collection<String> toRemove) { synchronized(_configFileLock) { if (toAdd != null) _config.putAll(toAdd); diff --git a/router/java/src/net/i2p/router/RouterClock.java b/router/java/src/net/i2p/router/RouterClock.java index 8ec8db80efebb9a26d3b58bca70dd39b7606b027..3e743c67108f46f961348ff1d6c8cd93ac099973 100644 --- a/router/java/src/net/i2p/router/RouterClock.java +++ b/router/java/src/net/i2p/router/RouterClock.java @@ -57,7 +57,7 @@ public class RouterClock extends Clock { super(context); _lastStratum = WORST_STRATUM; _lastSlewed = System.currentTimeMillis(); - _shiftListeners = new CopyOnWriteArraySet(); + _shiftListeners = new CopyOnWriteArraySet<ClockShiftListener>(); _lastShiftNanos = System.nanoTime(); _timeStamper = new RouterTimestamper(context, this); } diff --git a/router/java/src/net/i2p/router/RouterContext.java b/router/java/src/net/i2p/router/RouterContext.java index 0fbb2a6f602343f2e7b6bdeab95394fdb2d8057d..6af37e54fa0dba00051d43e6669014016ce37498 100644 --- a/router/java/src/net/i2p/router/RouterContext.java +++ b/router/java/src/net/i2p/router/RouterContext.java @@ -1,6 +1,5 @@ package net.i2p.router; -import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Properties; @@ -69,7 +68,7 @@ public class RouterContext extends I2PAppContext { private volatile boolean _initialized; private final Object _lock1 = new Object(), _lock2 = new Object(), _lock3 = new Object(); - private static final List<RouterContext> _contexts = new CopyOnWriteArrayList(); + private static final List<RouterContext> _contexts = new CopyOnWriteArrayList<RouterContext>(); /** * Caller MUST call initAll() after instantiation. @@ -89,7 +88,7 @@ public class RouterContext extends I2PAppContext { //initAll(); if (!_contexts.isEmpty()) System.err.println("Warning - More than one router in this JVM"); - _finalShutdownTasks = new CopyOnWriteArraySet(); + _finalShutdownTasks = new CopyOnWriteArraySet<Runnable>(); _contexts.add(this); } diff --git a/router/java/src/net/i2p/router/client/ClientConnectionRunner.java b/router/java/src/net/i2p/router/client/ClientConnectionRunner.java index 94d26378f3a5a3f9e75026284796511113fe4282..e73041deaadddc1f4c4a4bd575aaa939f58d2b50 100644 --- a/router/java/src/net/i2p/router/client/ClientConnectionRunner.java +++ b/router/java/src/net/i2p/router/client/ClientConnectionRunner.java @@ -46,8 +46,6 @@ import net.i2p.router.RouterContext; import net.i2p.util.ConcurrentHashSet; import net.i2p.util.I2PThread; import net.i2p.util.Log; -import net.i2p.util.RandomSource; -import net.i2p.util.SimpleScheduler; import net.i2p.util.SimpleTimer; /** @@ -119,9 +117,9 @@ class ClientConnectionRunner { _manager = manager; _socket = socket; // unused for fastReceive - _messages = new ConcurrentHashMap(); - _alreadyProcessed = new ArrayList(); - _acceptedPending = new ConcurrentHashSet(); + _messages = new ConcurrentHashMap<MessageId, Payload>(); + _alreadyProcessed = new ArrayList<MessageId>(); + _acceptedPending = new ConcurrentHashSet<MessageId>(); _messageId = new AtomicInteger(_context.random().nextInt()); } diff --git a/router/java/src/net/i2p/router/client/ClientManager.java b/router/java/src/net/i2p/router/client/ClientManager.java index e259c91aba647add67a4936438b3168795962869..5ad45279568389151f0906458b900f4a04459014 100644 --- a/router/java/src/net/i2p/router/client/ClientManager.java +++ b/router/java/src/net/i2p/router/client/ClientManager.java @@ -11,7 +11,6 @@ package net.i2p.router.client; import java.io.IOException; import java.io.Writer; import java.util.Collections; -import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.Map; @@ -78,9 +77,9 @@ class ClientManager { // "How large are messages received by the client?", // "ClientMessages", // new long[] { 60*1000l, 60*60*1000l, 24*60*60*1000l }); - _runners = new ConcurrentHashMap(); - _runnersByHash = new ConcurrentHashMap(); - _pendingRunners = new HashSet(); + _runners = new ConcurrentHashMap<Destination, ClientConnectionRunner>(); + _runnersByHash = new ConcurrentHashMap<Hash, ClientConnectionRunner>(); + _pendingRunners = new HashSet<ClientConnectionRunner>(); _port = port; // following are for RequestLeaseSetJob _ctx.statManager().createRateStat("client.requestLeaseSetSuccess", "How frequently the router requests successfully a new leaseSet?", "ClientMessages", new long[] { 60*60*1000 }); @@ -124,7 +123,7 @@ class ClientManager { _log.info("Shutting down the ClientManager"); if (_listener != null) _listener.stopListening(); - Set<ClientConnectionRunner> runners = new HashSet(); + Set<ClientConnectionRunner> runners = new HashSet<ClientConnectionRunner>(); synchronized (_runners) { for (Iterator<ClientConnectionRunner> iter = _runners.values().iterator(); iter.hasNext();) { ClientConnectionRunner runner = iter.next(); @@ -153,8 +152,8 @@ class ClientManager { public I2CPMessageQueue internalConnect() throws I2PSessionException { if (!_isStarted) throw new I2PSessionException("Router client manager is shut down"); - LinkedBlockingQueue<I2CPMessage> in = new LinkedBlockingQueue(INTERNAL_QUEUE_SIZE); - LinkedBlockingQueue<I2CPMessage> out = new LinkedBlockingQueue(INTERNAL_QUEUE_SIZE); + LinkedBlockingQueue<I2CPMessage> in = new LinkedBlockingQueue<I2CPMessage>(INTERNAL_QUEUE_SIZE); + LinkedBlockingQueue<I2CPMessage> out = new LinkedBlockingQueue<I2CPMessage>(INTERNAL_QUEUE_SIZE); I2CPMessageQueue myQueue = new I2CPMessageQueueImpl(in, out); I2CPMessageQueue hisQueue = new I2CPMessageQueueImpl(out, in); ClientConnectionRunner runner = new QueuedClientConnectionRunner(_ctx, this, myQueue); @@ -344,7 +343,7 @@ class ClientManager { * Unsynchronized */ public Set<Destination> listClients() { - Set<Destination> rv = new HashSet(); + Set<Destination> rv = new HashSet<Destination>(); rv.addAll(_runners.keySet()); return rv; } diff --git a/router/java/src/net/i2p/router/client/ClientManagerFacadeImpl.java b/router/java/src/net/i2p/router/client/ClientManagerFacadeImpl.java index edb92147a96324be0c0e93c71861791c564da817..94dbe6d36144942382845523d82fe09fcf3c9b60 100644 --- a/router/java/src/net/i2p/router/client/ClientManagerFacadeImpl.java +++ b/router/java/src/net/i2p/router/client/ClientManagerFacadeImpl.java @@ -11,7 +11,6 @@ package net.i2p.router.client; import java.io.IOException; import java.io.Writer; import java.util.Collections; -import java.util.Iterator; import java.util.Set; import net.i2p.client.I2PSessionException; @@ -239,7 +238,7 @@ public class ClientManagerFacadeImpl extends ClientManagerFacade implements Inte if (_manager != null) return _manager.listClients(); else - return Collections.EMPTY_SET; + return Collections.emptySet(); } /** diff --git a/router/java/src/net/i2p/router/client/ClientWriterRunner.java b/router/java/src/net/i2p/router/client/ClientWriterRunner.java index 8bdeeded45abbaa8285bb3a221b2448016f80486..581b2a5edf6fa11b02fccde4d93cfacdb9e924cd 100644 --- a/router/java/src/net/i2p/router/client/ClientWriterRunner.java +++ b/router/java/src/net/i2p/router/client/ClientWriterRunner.java @@ -28,7 +28,7 @@ class ClientWriterRunner implements Runnable { public ClientWriterRunner(RouterContext context, ClientConnectionRunner runner) { //_log = context.logManager().getLog(ClientWriterRunner.class); - _messagesToWrite = new LinkedBlockingQueue(QUEUE_SIZE); + _messagesToWrite = new LinkedBlockingQueue<I2CPMessage>(QUEUE_SIZE); _runner = runner; //_id = ++__id; } diff --git a/router/java/src/net/i2p/router/client/QueuedClientConnectionRunner.java b/router/java/src/net/i2p/router/client/QueuedClientConnectionRunner.java index 3ad1958053623bc5626a0f224d2c25efc111b982..147440a927f524503da3a0553ae76f505db6dd75 100644 --- a/router/java/src/net/i2p/router/client/QueuedClientConnectionRunner.java +++ b/router/java/src/net/i2p/router/client/QueuedClientConnectionRunner.java @@ -6,7 +6,6 @@ import net.i2p.data.i2cp.I2CPMessageException; import net.i2p.internal.I2CPMessageQueue; import net.i2p.internal.QueuedI2CPMessageReader; import net.i2p.router.RouterContext; -import net.i2p.util.Log; /** * Zero-copy in-JVM. diff --git a/router/java/src/net/i2p/router/client/RequestLeaseSetJob.java b/router/java/src/net/i2p/router/client/RequestLeaseSetJob.java index bd153fbddafc10f60df4ebe24d0e51ea3ed07426..d2de37098caa1c2f9c21983794e747aa93844070 100644 --- a/router/java/src/net/i2p/router/client/RequestLeaseSetJob.java +++ b/router/java/src/net/i2p/router/client/RequestLeaseSetJob.java @@ -16,7 +16,6 @@ import net.i2p.data.i2cp.I2CPMessage; import net.i2p.data.i2cp.I2CPMessageException; import net.i2p.data.i2cp.RequestLeaseSetMessage; import net.i2p.data.i2cp.RequestVariableLeaseSetMessage; -import net.i2p.router.Job; import net.i2p.router.JobImpl; import net.i2p.router.RouterContext; import net.i2p.util.Log; diff --git a/router/java/src/net/i2p/router/client/SSLClientListenerRunner.java b/router/java/src/net/i2p/router/client/SSLClientListenerRunner.java index d65f75bce6449d441b937b19f3ab63386bdba8a8..fcd008ad68a540ab37a4231bb91123f53bf93fa5 100644 --- a/router/java/src/net/i2p/router/client/SSLClientListenerRunner.java +++ b/router/java/src/net/i2p/router/client/SSLClientListenerRunner.java @@ -4,15 +4,11 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; -import java.io.OutputStream; -import java.io.PrintWriter; import java.net.InetAddress; import java.net.Socket; import java.net.ServerSocket; import java.security.KeyStore; import java.security.GeneralSecurityException; -import java.security.cert.Certificate; -import java.security.cert.CertificateEncodingException; import java.util.HashMap; import java.util.Map; @@ -21,9 +17,7 @@ import javax.net.ssl.SSLServerSocketFactory; import javax.net.ssl.SSLContext; import net.i2p.client.I2PClient; -import net.i2p.crypto.CertUtil; import net.i2p.crypto.KeyStoreUtil; -import net.i2p.data.Base32; import net.i2p.router.RouterContext; import net.i2p.util.Log; import net.i2p.util.SecureDirectory; @@ -94,7 +88,7 @@ class SSLClientListenerRunner extends ClientListenerRunner { if (success) { success = ks.exists(); if (success) { - Map<String, String> changes = new HashMap(); + Map<String, String> changes = new HashMap<String, String>(); changes.put(PROP_KEYSTORE_PASSWORD, DEFAULT_KEYSTORE_PASSWORD); changes.put(PROP_KEY_PASSWORD, keyPassword); _context.router().saveConfig(changes, null); diff --git a/router/java/src/net/i2p/router/dummy/DummyNetworkDatabaseFacade.java b/router/java/src/net/i2p/router/dummy/DummyNetworkDatabaseFacade.java index eeb0e1384ada63f2d246dcf319ae7a48aa312bdc..77d79f12f25ee3d1a1d7deaed87e8f3cad590a5b 100644 --- a/router/java/src/net/i2p/router/dummy/DummyNetworkDatabaseFacade.java +++ b/router/java/src/net/i2p/router/dummy/DummyNetworkDatabaseFacade.java @@ -23,11 +23,11 @@ import net.i2p.router.NetworkDatabaseFacade; import net.i2p.router.RouterContext; public class DummyNetworkDatabaseFacade extends NetworkDatabaseFacade { - private Map _routers; + private Map<Hash, RouterInfo> _routers; private RouterContext _context; public DummyNetworkDatabaseFacade(RouterContext ctx) { - _routers = Collections.synchronizedMap(new HashMap()); + _routers = Collections.synchronizedMap(new HashMap<Hash, RouterInfo>()); _context = ctx; } @@ -61,6 +61,6 @@ public class DummyNetworkDatabaseFacade extends NetworkDatabaseFacade { _routers.remove(dbEntry); } - public Set<Hash> getAllRouters() { return new HashSet(_routers.keySet()); } + public Set<Hash> getAllRouters() { return new HashSet<Hash>(_routers.keySet()); } public Set<Hash> findNearestRouters(Hash key, int maxNumRouters, Set<Hash> peersToIgnore) { return new HashSet(_routers.values()); } } diff --git a/router/java/src/net/i2p/router/dummy/VMCommSystem.java b/router/java/src/net/i2p/router/dummy/VMCommSystem.java index cb700011ad9d30bddba688e511e281f87eaa4fa1..1d02d07b25eadabe6b47c3bd0ad9611064715757 100644 --- a/router/java/src/net/i2p/router/dummy/VMCommSystem.java +++ b/router/java/src/net/i2p/router/dummy/VMCommSystem.java @@ -29,7 +29,7 @@ public class VMCommSystem extends CommSystemFacade { /** * Mapping from Hash to VMCommSystem for all routers hooked together */ - private static Map _commSystemFacades = Collections.synchronizedMap(new HashMap(16)); + private static Map<Hash, VMCommSystem> _commSystemFacades = Collections.synchronizedMap(new HashMap<Hash, VMCommSystem>(16)); public VMCommSystem(RouterContext context) { _context = context; diff --git a/router/java/src/net/i2p/router/message/CloveSet.java b/router/java/src/net/i2p/router/message/CloveSet.java index ac4aaf1eb686bb084dbe376bb1e76d3b8c3968cf..caa5e1bff3bfb76b5e7a535afa2b5261915c700d 100644 --- a/router/java/src/net/i2p/router/message/CloveSet.java +++ b/router/java/src/net/i2p/router/message/CloveSet.java @@ -25,7 +25,7 @@ class CloveSet { private long _expiration; public CloveSet() { - _cloves = new ArrayList(4); + _cloves = new ArrayList<GarlicClove>(4); _msgId = -1; _expiration = -1; } diff --git a/router/java/src/net/i2p/router/message/GarlicConfig.java b/router/java/src/net/i2p/router/message/GarlicConfig.java index 9dcfc1e6bff6f51dcbebe185edb6f335aab82a1f..101c8c3289331b7f77995fa3ad5541396d140a59 100644 --- a/router/java/src/net/i2p/router/message/GarlicConfig.java +++ b/router/java/src/net/i2p/router/message/GarlicConfig.java @@ -41,7 +41,7 @@ class GarlicConfig { public GarlicConfig() { _id = -1; _expiration = -1; - _cloveConfigs = new ArrayList(4); + _cloveConfigs = new ArrayList<GarlicConfig>(4); //_replyBlockMessageId = -1; //_replyBlockExpiration = -1; } diff --git a/router/java/src/net/i2p/router/message/GarlicMessageBuilder.java b/router/java/src/net/i2p/router/message/GarlicMessageBuilder.java index cdbbd543f88f0d8a664f0c2b022df1ba3b5426e9..ae2f792a57ccff47677151ce2cf8aab56ae75ee3 100644 --- a/router/java/src/net/i2p/router/message/GarlicMessageBuilder.java +++ b/router/java/src/net/i2p/router/message/GarlicMessageBuilder.java @@ -65,7 +65,7 @@ public class GarlicMessageBuilder { private static GarlicMessage buildMessage(RouterContext ctx, GarlicConfig config) { Log log = ctx.logManager().getLog(GarlicMessageBuilder.class); log.error("buildMessage 2 args, using router SKM", new Exception("who did it")); - return buildMessage(ctx, config, new SessionKey(), new HashSet(), ctx.sessionKeyManager()); + return buildMessage(ctx, config, new SessionKey(), new HashSet<SessionTag>(), ctx.sessionKeyManager()); } /** diff --git a/router/java/src/net/i2p/router/message/OutboundCache.java b/router/java/src/net/i2p/router/message/OutboundCache.java index 64518d4740cccec9a7cb3d5776ddf0e1d1f54f48..bc3dcd653940161c4650dfb4b24af7309604aed0 100644 --- a/router/java/src/net/i2p/router/message/OutboundCache.java +++ b/router/java/src/net/i2p/router/message/OutboundCache.java @@ -11,7 +11,6 @@ import net.i2p.data.LeaseSet; import net.i2p.router.Router; import net.i2p.router.RouterContext; import net.i2p.router.TunnelInfo; -import net.i2p.util.SimpleScheduler; import net.i2p.util.SimpleTimer; /** @@ -43,12 +42,12 @@ public class OutboundCache { * * NOT concurrent. */ - final Map<HashPair, TunnelInfo> tunnelCache = new HashMap(64); + final Map<HashPair, TunnelInfo> tunnelCache = new HashMap<HashPair, TunnelInfo>(64); /* * NOT concurrent. */ - final Map<HashPair, TunnelInfo> backloggedTunnelCache = new HashMap(64); + final Map<HashPair, TunnelInfo> backloggedTunnelCache = new HashMap<HashPair, TunnelInfo>(64); /** * Returns the reply lease set if forced to do so, @@ -68,7 +67,7 @@ public class OutboundCache { * * Concurrent. */ - final Map<HashPair, LeaseSet> leaseSetCache = new ConcurrentHashMap(64); + final Map<HashPair, LeaseSet> leaseSetCache = new ConcurrentHashMap<HashPair, LeaseSet>(64); /** * Use the same inbound tunnel (i.e. lease) as we did for the same destination previously, @@ -84,7 +83,7 @@ public class OutboundCache { * * Concurrent. */ - final ConcurrentHashMap<HashPair, Lease> leaseCache = new ConcurrentHashMap(64); + final ConcurrentHashMap<HashPair, Lease> leaseCache = new ConcurrentHashMap<HashPair, Lease>(64); /** * This cache is used to ensure that we request a reply every so often. @@ -94,7 +93,7 @@ public class OutboundCache { * * Concurrent. */ - final Map<HashPair, Long> lastReplyRequestCache = new ConcurrentHashMap(64); + final Map<HashPair, Long> lastReplyRequestCache = new ConcurrentHashMap<HashPair, Long>(64); private final RouterContext _context; diff --git a/router/java/src/net/i2p/router/message/OutboundClientMessageOneShotJob.java b/router/java/src/net/i2p/router/message/OutboundClientMessageOneShotJob.java index 072bfde8304f8a792560272899353ce9eb94016c..78ef6faa72fa1c02cc2b80f67361f1b43351d03b 100644 --- a/router/java/src/net/i2p/router/message/OutboundClientMessageOneShotJob.java +++ b/router/java/src/net/i2p/router/message/OutboundClientMessageOneShotJob.java @@ -4,7 +4,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; import java.util.List; -import java.util.Properties; import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; @@ -322,7 +321,7 @@ public class OutboundClientMessageOneShotJob extends JobImpl { } // get the possible leases - List<Lease> leases = new ArrayList(_leaseSet.getLeaseCount()); + List<Lease> leases = new ArrayList<Lease>(_leaseSet.getLeaseCount()); for (int i = 0; i < _leaseSet.getLeaseCount(); i++) { Lease lease = _leaseSet.getLease(i); if (lease.isExpired(Router.CLOCK_FUDGE_FACTOR)) { @@ -454,7 +453,7 @@ public class OutboundClientMessageOneShotJob extends JobImpl { PublicKey key = _leaseSet.getEncryptionKey(); SessionKey sessKey = new SessionKey(); - Set<SessionTag> tags = new HashSet(); + Set<SessionTag> tags = new HashSet<SessionTag>(); LeaseSet replyLeaseSet; // Per-message flag == false overrides session option which is default true diff --git a/router/java/src/net/i2p/router/networkdb/HandleDatabaseLookupMessageJob.java b/router/java/src/net/i2p/router/networkdb/HandleDatabaseLookupMessageJob.java index 20257bc6e2b38989c608187a51052bc0fb205374..22879b56377b5baafa4823da78f066eaa5a650fc 100644 --- a/router/java/src/net/i2p/router/networkdb/HandleDatabaseLookupMessageJob.java +++ b/router/java/src/net/i2p/router/networkdb/HandleDatabaseLookupMessageJob.java @@ -9,7 +9,6 @@ package net.i2p.router.networkdb; */ import java.util.Collections; -import java.util.HashSet; import java.util.Set; import net.i2p.data.DatabaseEntry; diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/ExpireLeasesJob.java b/router/java/src/net/i2p/router/networkdb/kademlia/ExpireLeasesJob.java index 6ea401d6671b145288eecadc20dba0e3288c72e3..8aab12dfe4d9cd7f79ceca15c7f3f30baf2568c9 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/ExpireLeasesJob.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/ExpireLeasesJob.java @@ -58,7 +58,7 @@ class ExpireLeasesJob extends JobImpl { * */ private Set<Hash> selectKeysToExpire() { - Set<Hash> toExpire = new HashSet(128); + Set<Hash> toExpire = new HashSet<Hash>(128); for (Map.Entry<Hash, DatabaseEntry> entry : _facade.getDataStore().getMapEntries()) { DatabaseEntry obj = entry.getValue(); if (obj.getType() == DatabaseEntry.KEY_TYPE_LEASESET) { diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/ExpireRoutersJob.java b/router/java/src/net/i2p/router/networkdb/kademlia/ExpireRoutersJob.java index 7afc4006bbc73f93837189448ab4b5ce40fa639b..d84914ea708e9fad246b06df81bfcaa70e863f50 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/ExpireRoutersJob.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/ExpireRoutersJob.java @@ -8,7 +8,6 @@ package net.i2p.router.networkdb.kademlia; * */ -import java.util.Collections; import java.util.Set; import net.i2p.data.DatabaseEntry; diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/ExploreJob.java b/router/java/src/net/i2p/router/networkdb/kademlia/ExploreJob.java index b6259aab676ebf471784fc8266484895626bf286..05154420ba1457bb715e2fe0e4942d954c7ade1f 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/ExploreJob.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/ExploreJob.java @@ -117,7 +117,7 @@ class ExploreJob extends SearchJob { // We don't want our hash in the message's don't-include list though. // We're just exploring, but this could give things away, and tie our exploratory tunnels to our router, // so let's not put our hash in there. - Set<Hash> dontInclude = new HashSet(dontIncludePeers); + Set<Hash> dontInclude = new HashSet<Hash>(dontIncludePeers); List<Hash> peers = _peerSelector.selectNearestExplicit(rkey, available, dontInclude, ks); dontIncludePeers.addAll(peers); } diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/ExploreKeySelectorJob.java b/router/java/src/net/i2p/router/networkdb/kademlia/ExploreKeySelectorJob.java index f11937571aaf62e631c7c24bf3cdc4a00aa12d2c..cb4f111f608e1ccd5804d2c6b7c9710e879429b7 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/ExploreKeySelectorJob.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/ExploreKeySelectorJob.java @@ -42,7 +42,7 @@ class ExploreKeySelectorJob extends JobImpl { requeue(30*RERUN_DELAY_MS); return; } - Set toExplore = selectKeysToExplore(); + Set<Hash> toExplore = selectKeysToExplore(); _log.info("Filling the explorer pool with: " + toExplore); if (toExplore != null) _facade.queueForExploration(toExplore); @@ -54,16 +54,16 @@ class ExploreKeySelectorJob extends JobImpl { * for it, with a maximum number of keys limited by the exploration pool size * */ - private Set selectKeysToExplore() { - Set alreadyQueued = _facade.getExploreKeys(); + private Set<Hash> selectKeysToExplore() { + Set<Hash> alreadyQueued = _facade.getExploreKeys(); if (alreadyQueued.size() > KBucketSet.NUM_BUCKETS) return null; - Set toExplore = new HashSet(KBucketSet.NUM_BUCKETS - alreadyQueued.size()); + Set<Hash> toExplore = new HashSet<Hash>(KBucketSet.NUM_BUCKETS - alreadyQueued.size()); for (int i = 0; i < KBucketSet.NUM_BUCKETS; i++) { KBucket bucket = _facade.getKBuckets().getBucket(i); if (bucket.getKeyCount() < KBucketSet.BUCKET_SIZE) { boolean already = false; - for (Iterator iter = alreadyQueued.iterator(); iter.hasNext(); ) { - Hash key = (Hash)iter.next(); + for (Iterator<Hash> iter = alreadyQueued.iterator(); iter.hasNext(); ) { + Hash key = iter.next(); if (bucket.shouldContain(key)) { already = true; _log.debug("Bucket " + i + " is already queued for exploration \t" + key); diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/FloodOnlySearchJob.java b/router/java/src/net/i2p/router/networkdb/kademlia/FloodOnlySearchJob.java index 555b16f78f876d81d16109e61e75c829b39d7db5..c07f3de9be505e84a0cb4c307b1767f49ad8cdf3 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/FloodOnlySearchJob.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/FloodOnlySearchJob.java @@ -55,7 +55,7 @@ class FloodOnlySearchJob extends FloodSearchJob { // these override the settings in super _timeoutMs = Math.min(timeoutMs, SearchJob.PER_FLOODFILL_PEER_TIMEOUT); _expiration = _timeoutMs + ctx.clock().now(); - _unheardFrom = new HashSet(CONCURRENT_SEARCHES); + _unheardFrom = new HashSet<Hash>(CONCURRENT_SEARCHES); _replySelector = new FloodOnlyLookupSelector(getContext(), this); _onReply = new FloodOnlyLookupMatchJob(getContext(), this); _onTimeout = new FloodOnlyLookupTimeoutJob(getContext(), this); @@ -77,7 +77,7 @@ class FloodOnlySearchJob extends FloodSearchJob { // but we're passing the rkey not the key, so we do it below instead in certain cases. floodfillPeers = ((FloodfillPeerSelector)_facade.getPeerSelector()).selectFloodfillParticipants(rkey, MIN_FOR_NO_DSRM, ks); } else { - floodfillPeers = Collections.EMPTY_LIST; + floodfillPeers = Collections.emptyList(); } // If we dont know enough floodfills, @@ -91,7 +91,7 @@ class FloodOnlySearchJob extends FloodSearchJob { // so this situation should be temporary if (_log.shouldLog(Log.WARN)) _log.warn("Running netDb searches against the floodfill peers, but we don't know any"); - floodfillPeers = new ArrayList(_facade.getAllRouters()); + floodfillPeers = new ArrayList<Hash>(_facade.getAllRouters()); if (floodfillPeers.isEmpty()) { if (_log.shouldLog(Log.ERROR)) _log.error("We don't know any peers at all"); diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/FloodSearchJob.java b/router/java/src/net/i2p/router/networkdb/kademlia/FloodSearchJob.java index 46815fb5d78d74437de8a288ef5d803ea27a854d..316cf3ff6ba0006a2fbcbe1c71a0e795f2e92c5a 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/FloodSearchJob.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/FloodSearchJob.java @@ -43,10 +43,10 @@ public class FloodSearchJob extends JobImpl { _log = ctx.logManager().getLog(getClass()); _facade = facade; _key = key; - _onFind = new CopyOnWriteArrayList(); + _onFind = new CopyOnWriteArrayList<Job>(); if (onFind != null) _onFind.add(onFind); - _onFailed = new CopyOnWriteArrayList(); + _onFailed = new CopyOnWriteArrayList<Job>(); if (onFailed != null) _onFailed.add(onFailed); int timeout = timeoutMs / FLOOD_SEARCH_TIME_FACTOR; diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/FloodThrottler.java b/router/java/src/net/i2p/router/networkdb/kademlia/FloodThrottler.java index 2fced02c6b3b8d324444b121a2b1ddc5f2def291..75a56bc4020642f9b03236af1146c650fd5f719b 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/FloodThrottler.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/FloodThrottler.java @@ -17,7 +17,7 @@ class FloodThrottler { private static final long CLEAN_TIME = 60*1000; FloodThrottler() { - this.counter = new ObjectCounter(); + this.counter = new ObjectCounter<Hash>(); SimpleScheduler.getInstance().addPeriodicEvent(new Cleaner(), CLEAN_TIME); } diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/FloodfillNetworkDatabaseFacade.java b/router/java/src/net/i2p/router/networkdb/kademlia/FloodfillNetworkDatabaseFacade.java index 2f716760e745fa5f139ed7c3a5ece867bd1990ee..e8cae585a6963ccae96d4fdf91d65f7406cbf1f5 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/FloodfillNetworkDatabaseFacade.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/FloodfillNetworkDatabaseFacade.java @@ -7,7 +7,6 @@ import java.util.Map; import java.util.Set; import net.i2p.data.DatabaseEntry; -import net.i2p.data.DataFormatException; import net.i2p.data.Hash; import net.i2p.data.RouterInfo; import net.i2p.data.TunnelId; @@ -47,8 +46,8 @@ public class FloodfillNetworkDatabaseFacade extends KademliaNetworkDatabaseFacad public FloodfillNetworkDatabaseFacade(RouterContext context) { super(context); - _activeFloodQueries = new HashMap(); - _verifiesInProgress = new ConcurrentHashSet(8); + _activeFloodQueries = new HashMap<Hash, FloodSearchJob>(); + _verifiesInProgress = new ConcurrentHashSet<Hash>(8); _context.statManager().createRequiredRateStat("netDb.successTime", "Time for successful lookup (ms)", "NetworkDatabase", new long[] { 60*60*1000l, 24*60*60*1000l }); _context.statManager().createRateStat("netDb.failedTime", "How long a failed search takes", "NetworkDatabase", new long[] { 60*60*1000l, 24*60*60*1000l }); @@ -140,7 +139,7 @@ public class FloodfillNetworkDatabaseFacade extends KademliaNetworkDatabaseFacad } @Override - public void sendStore(Hash key, DatabaseEntry ds, Job onSuccess, Job onFailure, long sendTimeout, Set toIgnore) { + public void sendStore(Hash key, DatabaseEntry ds, Job onSuccess, Job onFailure, long sendTimeout, Set<Hash> toIgnore) { // if we are a part of the floodfill netDb, don't send out our own leaseSets as part // of the flooding - instead, send them to a random floodfill peer so *they* can flood 'em out. // perhaps statistically adjust this so we are the source every 1/N times... or something. @@ -268,7 +267,7 @@ public class FloodfillNetworkDatabaseFacade extends KademliaNetworkDatabaseFacad } public List<RouterInfo> getKnownRouterData() { - List<RouterInfo> rv = new ArrayList(); + List<RouterInfo> rv = new ArrayList<RouterInfo>(); DataStore ds = getDataStore(); if (ds != null) { for (DatabaseEntry o : ds.getEntries()) { diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/FloodfillPeerSelector.java b/router/java/src/net/i2p/router/networkdb/kademlia/FloodfillPeerSelector.java index 98da4c1187f3695bc968a2b34241d4fc12cf72d0..3e054ed0c4709af4c36c4d5b2df7fa043881e2c2 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/FloodfillPeerSelector.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/FloodfillPeerSelector.java @@ -88,7 +88,7 @@ class FloodfillPeerSelector extends PeerSelector { peersToIgnore.add(_context.routerHash()); // TODO this is very slow FloodfillSelectionCollector matches = new FloodfillSelectionCollector(key, peersToIgnore, maxNumRouters); - if (kbuckets == null) return new ArrayList(); + if (kbuckets == null) return new ArrayList<Hash>(); kbuckets.getAll(matches); List<Hash> rv = matches.get(maxNumRouters, preferConnected); if (_log.shouldLog(Log.DEBUG)) @@ -126,7 +126,7 @@ class FloodfillPeerSelector extends PeerSelector { return matches.getFloodfillParticipants(); *****/ Set<Hash> set = _context.peerManager().getPeersByCapability(FloodfillNetworkDatabaseFacade.CAPABILITY_FLOODFILL); - List<Hash> rv = new ArrayList(set.size()); + List<Hash> rv = new ArrayList<Hash>(set.size()); for (Hash h : set) { if ((toIgnore != null && toIgnore.contains(h)) || _context.banlist().isBanlistedForever(h)) @@ -180,7 +180,7 @@ class FloodfillPeerSelector extends PeerSelector { toIgnore = Collections.singleton(_context.routerHash()); } else if (!toIgnore.contains(_context.routerHash())) { // copy the Set so we don't confuse StoreJob - toIgnore = new HashSet(toIgnore); + toIgnore = new HashSet<Hash>(toIgnore); toIgnore.add(_context.routerHash()); } return selectFloodfillParticipantsIncludingUs(key, howMany, toIgnore, kbuckets); @@ -195,12 +195,12 @@ class FloodfillPeerSelector extends PeerSelector { */ private List<Hash> selectFloodfillParticipantsIncludingUs(Hash key, int howMany, Set<Hash> toIgnore, KBucketSet kbuckets) { List<Hash> ffs = selectFloodfillParticipants(toIgnore, kbuckets); - TreeSet<Hash> sorted = new TreeSet(new XORComparator(key)); + TreeSet<Hash> sorted = new TreeSet<Hash>(new XORComparator(key)); sorted.addAll(ffs); - List<Hash> rv = new ArrayList(howMany); - List<Hash> okff = new ArrayList(ffs.size()); - List<Hash> badff = new ArrayList(ffs.size()); + List<Hash> rv = new ArrayList<Hash>(howMany); + List<Hash> okff = new ArrayList<Hash>(ffs.size()); + List<Hash> badff = new ArrayList<Hash>(ffs.size()); int found = 0; long now = _context.clock().now(); @@ -219,7 +219,7 @@ class FloodfillPeerSelector extends PeerSelector { // 5 == FNDF.MAX_TO_FLOOD + 1 int limit = Math.max(5, howMany); limit = Math.min(limit, ffs.size()); - Set<Integer> maskedIPs = new HashSet(limit + 4); + Set<Integer> maskedIPs = new HashSet<Integer>(limit + 4); // split sorted list into 3 sorted lists for (int i = 0; found < howMany && i < limit; i++) { Hash entry = sorted.first(); @@ -303,7 +303,7 @@ class FloodfillPeerSelector extends PeerSelector { * @since 0.9.5 modified from ProfileOrganizer */ private Set<Integer> maskedIPSet(Hash peer, RouterInfo pinfo, int mask) { - Set<Integer> rv = new HashSet(4); + Set<Integer> rv = new HashSet<Integer>(4); byte[] commIP = _context.commSystem().getIP(peer); if (commIP != null) rv.add(maskedIP(commIP, mask)); @@ -354,8 +354,8 @@ class FloodfillPeerSelector extends PeerSelector { */ public FloodfillSelectionCollector(Hash key, Set<Hash> toIgnore, int wanted) { _key = key; - _sorted = new TreeSet(new XORComparator(key)); - _floodfillMatches = new ArrayList(8); + _sorted = new TreeSet<Hash>(new XORComparator(key)); + _floodfillMatches = new ArrayList<Hash>(8); _toIgnore = toIgnore; _wanted = wanted; } @@ -410,15 +410,15 @@ class FloodfillPeerSelector extends PeerSelector { * Group 4: Non-floodfills, sorted by closest-to-the-key */ public List<Hash> get(int howMany, boolean preferConnected) { - List<Hash> rv = new ArrayList(howMany); - List<Hash> badff = new ArrayList(howMany); - List<Hash> unconnectedff = new ArrayList(howMany); + List<Hash> rv = new ArrayList<Hash>(howMany); + List<Hash> badff = new ArrayList<Hash>(howMany); + List<Hash> unconnectedff = new ArrayList<Hash>(howMany); int found = 0; long now = _context.clock().now(); // Only add in "good" floodfills here... // Let's say published in last 3h and no failed sends in last 30m // (Forever banlisted ones are excluded in add() above) - for (Iterator<Hash> iter = new RandomIterator(_floodfillMatches); (found < howMany) && iter.hasNext(); ) { + for (Iterator<Hash> iter = new RandomIterator<Hash>(_floodfillMatches); (found < howMany) && iter.hasNext(); ) { Hash entry = iter.next(); RouterInfo info = _context.netDb().lookupRouterInfoLocally(entry); if (info != null && now - info.getPublished() > 3*60*60*1000) { diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/FloodfillVerifyStoreJob.java b/router/java/src/net/i2p/router/networkdb/kademlia/FloodfillVerifyStoreJob.java index eb6d3ee9d05eebb286ef4a8abad5ed0100eb8151..e98b86e8edf258e1ba1476e85e933ab2d12daa85 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/FloodfillVerifyStoreJob.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/FloodfillVerifyStoreJob.java @@ -55,7 +55,7 @@ class FloodfillVerifyStoreJob extends JobImpl { _log = ctx.logManager().getLog(getClass()); _sentTo = sentTo; _facade = facade; - _ignore = new HashSet(MAX_PEERS_TO_TRY); + _ignore = new HashSet<Hash>(MAX_PEERS_TO_TRY); if (sentTo != null) { _ignore.add(_sentTo); } @@ -277,7 +277,7 @@ class FloodfillVerifyStoreJob extends JobImpl { private void resend() { DatabaseEntry ds = _facade.lookupLocally(_key); if (ds != null) { - Set<Hash> toSkip = new HashSet(2); + Set<Hash> toSkip = new HashSet<Hash>(2); if (_sentTo != null) toSkip.add(_sentTo); if (_target != null) diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/HarvesterJob.java b/router/java/src/net/i2p/router/networkdb/kademlia/HarvesterJob.java index 80f48623fbce0e02bf6ef4da2ef87d03f9d67271..fb2c1546bd02933f82526908c5f7d51475fa44e4 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/HarvesterJob.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/HarvesterJob.java @@ -57,9 +57,9 @@ class HarvesterJob extends JobImpl { public String getName() { return "Harvest the netDb"; } public void runJob() { if (shouldHarvest()) { - List peers = selectPeersToUpdate(); + List<Hash> peers = selectPeersToUpdate(); for (int i = 0; i < peers.size(); i++) { - Hash peer= (Hash)peers.get(i); + Hash peer= peers.get(i); harvest(peer); } } @@ -75,12 +75,12 @@ class HarvesterJob extends JobImpl { * Retrieve a list of hashes for peers we want to update * */ - private List selectPeersToUpdate() { - Map routersByAge = new TreeMap(); - Set peers = _facade.getAllRouters(); + private List<Hash> selectPeersToUpdate() { + Map<Long, Hash> routersByAge = new TreeMap<Long, Hash>(); + Set<Hash> peers = _facade.getAllRouters(); long now = getContext().clock().now(); - for (Iterator iter = peers.iterator(); iter.hasNext(); ) { - Hash peer = (Hash)iter.next(); + for (Iterator<Hash> iter = peers.iterator(); iter.hasNext(); ) { + Hash peer = iter.next(); RouterInfo info = _facade.lookupRouterInfoLocally(peer); if (info != null) { long when = info.getPublished(); @@ -95,9 +95,9 @@ class HarvesterJob extends JobImpl { // ok now we have the known peers sorted by date (oldest first), // ignoring peers that are new, so lets grab the oldest MAX_PER_RUN // entries - List rv = new ArrayList(); - for (Iterator iter = routersByAge.values().iterator(); iter.hasNext(); ) { - Hash peer = (Hash)iter.next(); + List<Hash> rv = new ArrayList<Hash>(); + for (Iterator<Hash> iter = routersByAge.values().iterator(); iter.hasNext(); ) { + Hash peer = iter.next(); rv.add(peer); if (rv.size() >= MAX_PER_RUN) break; diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/IterativeSearchJob.java b/router/java/src/net/i2p/router/networkdb/kademlia/IterativeSearchJob.java index 5afb88857a60cd35fc5bfa5ee913eb8d8ef5dd18..edc186954c76fe78c98f13fde83127319a708324 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/IterativeSearchJob.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/IterativeSearchJob.java @@ -25,7 +25,6 @@ import net.i2p.router.RouterContext; import net.i2p.router.TunnelInfo; import net.i2p.router.util.RandomIterator; import net.i2p.util.Log; -import net.i2p.util.VersionComparator; /** * A traditional Kademlia search that continues to search @@ -94,10 +93,10 @@ class IterativeSearchJob extends FloodSearchJob { _timeoutMs = Math.min(timeoutMs, MAX_SEARCH_TIME); _expiration = _timeoutMs + ctx.clock().now(); _rkey = ctx.routingKeyGenerator().getRoutingKey(key); - _toTry = new TreeSet(new XORComparator(_rkey)); - _unheardFrom = new HashSet(CONCURRENT_SEARCHES); - _failedPeers = new HashSet(TOTAL_SEARCH_LIMIT); - _sentTime = new ConcurrentHashMap(TOTAL_SEARCH_LIMIT); + _toTry = new TreeSet<Hash>(new XORComparator(_rkey)); + _unheardFrom = new HashSet<Hash>(CONCURRENT_SEARCHES); + _failedPeers = new HashSet<Hash>(TOTAL_SEARCH_LIMIT); + _sentTime = new ConcurrentHashMap<Hash, Long>(TOTAL_SEARCH_LIMIT); } @Override @@ -116,7 +115,7 @@ class IterativeSearchJob extends FloodSearchJob { // but we're passing the rkey not the key, so we do it below instead in certain cases. floodfillPeers = ((FloodfillPeerSelector)_facade.getPeerSelector()).selectFloodfillParticipants(_rkey, TOTAL_SEARCH_LIMIT, ks); } else { - floodfillPeers = new ArrayList(TOTAL_SEARCH_LIMIT); + floodfillPeers = new ArrayList<Hash>(TOTAL_SEARCH_LIMIT); } // For testing or local networks... we will @@ -137,14 +136,14 @@ class IterativeSearchJob extends FloodSearchJob { // so this situation should be temporary if (_log.shouldLog(Log.WARN)) _log.warn("Running netDb searches against the floodfill peers, but we don't know any"); - List<Hash> all = new ArrayList(_facade.getAllRouters()); + List<Hash> all = new ArrayList<Hash>(_facade.getAllRouters()); if (all.isEmpty()) { if (_log.shouldLog(Log.ERROR)) _log.error("We don't know any peers at all"); failed(); return; } - Iterator<Hash> iter = new RandomIterator(all); + Iterator<Hash> iter = new RandomIterator<Hash>(all); // Limit non-FF to 3, because we don't sort the FFs ahead of the non-FFS, // so once we get some FFs we want to be sure to query them for (int i = 0; iter.hasNext() && i < MAX_NON_FF; i++) { diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/KBucketImpl.java b/router/java/src/net/i2p/router/networkdb/kademlia/KBucketImpl.java index 59b72927bd4567c366ad5d30404db575e688401f..5b618991887db773ba2bbf5d43bfe268f646b07c 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/KBucketImpl.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/KBucketImpl.java @@ -49,7 +49,7 @@ class KBucketImpl implements KBucket { public KBucketImpl(I2PAppContext context, LocalHash local) { _context = context; _log = context.logManager().getLog(KBucketImpl.class); - _entries = new ConcurrentHashSet(2); //all but the last 1 or 2 buckets will be empty + _entries = new ConcurrentHashSet<Hash>(2); //all but the last 1 or 2 buckets will be empty _lastShuffle = context.clock().now(); setLocal(local); } @@ -219,8 +219,8 @@ class KBucketImpl implements KBucket { /** * @deprecated makes a copy, remove toIgnore in KBS instead */ - public Set<Hash> getEntries(Set toIgnoreHashes) { - Set<Hash> entries = new HashSet(_entries); + public Set<Hash> getEntries(Set<Hash> toIgnoreHashes) { + Set<Hash> entries = new HashSet<Hash>(_entries); entries.removeAll(toIgnoreHashes); return entries; } diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/KBucketSet.java b/router/java/src/net/i2p/router/networkdb/kademlia/KBucketSet.java index 2a0910ff83634713a8e5f73ea3ab4b63d0a19a9e..9b14bd9834e7739e4ee61ad1a246ad44fad557ec 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/KBucketSet.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/KBucketSet.java @@ -94,16 +94,16 @@ class KBucketSet { /** @since 0.8.8 */ public void clear() { for (int i = 0; i < _buckets.length; i++) { - _buckets[i].setEntries(Collections.EMPTY_SET); + _buckets[i].setEntries(Collections.<Hash> emptySet()); } _size.set(0); _us.clearXorCache(); } - public Set<Hash> getAll() { return getAll(Collections.EMPTY_SET); }; + public Set<Hash> getAll() { return getAll(Collections.<Hash> emptySet()); }; public Set<Hash> getAll(Set<Hash> toIgnore) { - Set<Hash> all = new HashSet(1024); + Set<Hash> all = new HashSet<Hash>(1024); for (int i = 0; i < _buckets.length; i++) { all.addAll(_buckets[i].getEntries()); } diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/KademliaNetworkDatabaseFacade.java b/router/java/src/net/i2p/router/networkdb/kademlia/KademliaNetworkDatabaseFacade.java index 1a6b3139c69f589239b258a64151ffe92bf7f562..851e7897ce853d8e01cd93c1fb9932779e933487 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/KademliaNetworkDatabaseFacade.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/KademliaNetworkDatabaseFacade.java @@ -46,7 +46,7 @@ public class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacade { /** where the data store is pushing the data */ private String _dbDir; // set of Hash objects that we should search on (to fill up a bucket, not to get data) - private final Set<Hash> _exploreKeys = new ConcurrentHashSet(64); + private final Set<Hash> _exploreKeys = new ConcurrentHashSet<Hash>(64); private boolean _initialized; /** Clock independent time of when we started up */ private long _started; @@ -138,8 +138,8 @@ public class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacade { _context = context; _log = _context.logManager().getLog(getClass()); _peerSelector = createPeerSelector(); - _publishingLeaseSets = new HashMap(8); - _activeRequests = new HashMap(8); + _publishingLeaseSets = new HashMap<Hash, RepublishLeaseSetJob>(8); + _activeRequests = new HashMap<Hash, SearchJob>(8); _reseedChecker = new ReseedChecker(context); context.statManager().createRateStat("netDb.lookupDeferred", "how many lookups are deferred?", "NetworkDatabase", new long[] { 60*60*1000 }); context.statManager().createRateStat("netDb.exploreKeySet", "how many keys are queued for exploration?", "NetworkDatabase", new long[] { 60*60*1000 }); @@ -181,7 +181,7 @@ public class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacade { /** @return unmodifiable set */ public Set<Hash> getExploreKeys() { if (!_initialized) - return Collections.EMPTY_SET; + return Collections.emptySet(); return Collections.unmodifiableSet(_exploreKeys); } @@ -323,8 +323,8 @@ public class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacade { * @param peersToIgnore can be null */ public Set<Hash> findNearestRouters(Hash key, int maxNumRouters, Set<Hash> peersToIgnore) { - if (!_initialized) return Collections.EMPTY_SET; - return new HashSet(_peerSelector.selectNearest(key, maxNumRouters, peersToIgnore, _kb)); + if (!_initialized) return Collections.emptySet(); + return new HashSet<Hash>(_peerSelector.selectNearest(key, maxNumRouters, peersToIgnore, _kb)); } /***** @@ -349,9 +349,9 @@ public class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacade { /** get the hashes for all known routers */ public Set<Hash> getAllRouters() { - if (!_initialized) return Collections.EMPTY_SET; + if (!_initialized) return Collections.emptySet(); Set<Map.Entry<Hash, DatabaseEntry>> entries = _ds.getMapEntries(); - Set<Hash> rv = new HashSet(entries.size()); + Set<Hash> rv = new HashSet<Hash>(entries.size()); for (Map.Entry<Hash, DatabaseEntry> entry : entries) { if (entry.getValue().getType() == DatabaseEntry.KEY_TYPE_ROUTERINFO) { rv.add(entry.getKey()); @@ -988,10 +988,10 @@ public class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacade { @Override public Set<LeaseSet> getLeases() { if (!_initialized) return null; - Set leases = new HashSet(); + Set<LeaseSet> leases = new HashSet<LeaseSet>(); for (DatabaseEntry o : getDataStore().getEntries()) { if (o.getType() == DatabaseEntry.KEY_TYPE_LEASESET) - leases.add(o); + leases.add((LeaseSet)o); } return leases; } @@ -1000,10 +1000,10 @@ public class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacade { @Override public Set<RouterInfo> getRouters() { if (!_initialized) return null; - Set routers = new HashSet(); + Set<RouterInfo> routers = new HashSet<RouterInfo>(); for (DatabaseEntry o : getDataStore().getEntries()) { if (o.getType() == DatabaseEntry.KEY_TYPE_ROUTERINFO) - routers.add(o); + routers.add((RouterInfo)o); } return routers; } @@ -1034,7 +1034,7 @@ public class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacade { } /** unused (overridden in FNDF) */ - public void sendStore(Hash key, DatabaseEntry ds, Job onSuccess, Job onFailure, long sendTimeout, Set toIgnore) { + public void sendStore(Hash key, DatabaseEntry ds, Job onSuccess, Job onFailure, long sendTimeout, Set<Hash> toIgnore) { if ( (ds == null) || (key == null) ) { if (onFailure != null) _context.jobQueue().addJob(onFailure); diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/LocalHash.java b/router/java/src/net/i2p/router/networkdb/kademlia/LocalHash.java index d2b10e79d77b9735d738282a2fb92e5cb0cde520..2b3a23d356accdf931ca4ec7326241d7d161ba8f 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/LocalHash.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/LocalHash.java @@ -48,7 +48,7 @@ class LocalHash extends Hash { public void prepareCache() { synchronized (this) { if (_xorCache == null) - _xorCache = new HashMap(MAX_CACHED_XOR); + _xorCache = new HashMap<Hash, byte[]>(MAX_CACHED_XOR); } } @@ -70,13 +70,13 @@ class LocalHash extends Hash { synchronized (_xorCache) { int toRemove = _xorCache.size() + 1 - MAX_CACHED_XOR; if (toRemove > 0) { - Set keys = new HashSet(toRemove); + Set<Hash> keys = new HashSet<Hash>(toRemove); // this removes essentially random keys - we dont maintain any sort // of LRU or age. perhaps we should? int removed = 0; - for (Iterator iter = _xorCache.keySet().iterator(); iter.hasNext() && removed < toRemove; removed++) + for (Iterator<Hash> iter = _xorCache.keySet().iterator(); iter.hasNext() && removed < toRemove; removed++) keys.add(iter.next()); - for (Iterator iter = keys.iterator(); iter.hasNext(); ) + for (Iterator<Hash> iter = keys.iterator(); iter.hasNext(); ) _xorCache.remove(iter.next()); } distance = DataHelper.xor(key.getData(), getData()); diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/LookupThrottler.java b/router/java/src/net/i2p/router/networkdb/kademlia/LookupThrottler.java index 12feea376ae299c4c2114d6a4d27f49d74f86256..4156ac152901c5a8145074557697d4ec0ed0476c 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/LookupThrottler.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/LookupThrottler.java @@ -24,7 +24,7 @@ class LookupThrottler { private static final long CLEAN_TIME = 60*1000; LookupThrottler() { - this.counter = new ObjectCounter(); + this.counter = new ObjectCounter<ReplyTunnel>(); SimpleScheduler.getInstance().addPeriodicEvent(new Cleaner(), CLEAN_TIME); } diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/MessageWrapper.java b/router/java/src/net/i2p/router/networkdb/kademlia/MessageWrapper.java index 672f862885a2ea2183ed00783b4905dfb498f9ee..ba4615bf792bcf45d12337bcd790e6709a58ac7c 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/MessageWrapper.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/MessageWrapper.java @@ -59,7 +59,7 @@ public class MessageWrapper { if (skm == null) return null; SessionKey sentKey = new SessionKey(); - Set<SessionTag> sentTags = new HashSet(); + Set<SessionTag> sentTags = new HashSet<SessionTag>(); GarlicMessage msg = GarlicMessageBuilder.buildMessage(ctx, payload, sentKey, sentTags, NETDB_TAGS_TO_DELIVER, NETDB_LOW_THRESHOLD, skm); if (msg == null) @@ -192,7 +192,7 @@ public class MessageWrapper { private static OneTimeSession generateSession(RouterContext ctx, SessionKeyManager skm) { SessionKey key = ctx.keyGenerator().generateSessionKey(); SessionTag tag = new SessionTag(true); - Set<SessionTag> tags = new RemovableSingletonSet(tag); + Set<SessionTag> tags = new RemovableSingletonSet<SessionTag>(tag); skm.tagsReceived(key, tags, 2*60*1000); return new OneTimeSession(key, tag); } diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/NegativeLookupCache.java b/router/java/src/net/i2p/router/networkdb/kademlia/NegativeLookupCache.java index c967503085d3ff1b4a8519f01cf021da891f9a1f..6612ea9dc4dd10efbec490bf99990d0a9d4ce494 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/NegativeLookupCache.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/NegativeLookupCache.java @@ -16,7 +16,7 @@ class NegativeLookupCache { private static final long CLEAN_TIME = 4*60*1000; public NegativeLookupCache() { - this.counter = new ObjectCounter(); + this.counter = new ObjectCounter<Hash>(); SimpleScheduler.getInstance().addPeriodicEvent(new Cleaner(), CLEAN_TIME); } diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/PeerSelector.java b/router/java/src/net/i2p/router/networkdb/kademlia/PeerSelector.java index f6b48216bc8a1c444424840bcbb61090919936c2..1dc2de75ec76588a352e900a18bd0f229e1f60a5 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/PeerSelector.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/PeerSelector.java @@ -96,11 +96,11 @@ class PeerSelector { */ List<Hash> selectNearestExplicitThin(Hash key, int maxNumRouters, Set<Hash> peersToIgnore, KBucketSet kbuckets) { if (peersToIgnore == null) - peersToIgnore = new HashSet(1); + peersToIgnore = new HashSet<Hash>(1); peersToIgnore.add(_context.routerHash()); MatchSelectionCollector matches = new MatchSelectionCollector(key, peersToIgnore); kbuckets.getAll(matches); - List rv = matches.get(maxNumRouters); + List<Hash> rv = matches.get(maxNumRouters); if (_log.shouldLog(Log.DEBUG)) _log.debug("Searching for " + maxNumRouters + " peers close to " + key + ": " + rv + " (not including " + peersToIgnore + ") [allHashes.size = " @@ -116,7 +116,7 @@ class PeerSelector { private int _matches; public MatchSelectionCollector(Hash key, Set<Hash> toIgnore) { _key = key; - _sorted = new TreeMap(); + _sorted = new TreeMap<BigInteger, Hash>(); _toIgnore = toIgnore; _matches = 0; } @@ -138,7 +138,7 @@ class PeerSelector { } /** get the first $howMany entries matching */ public List<Hash> get(int howMany) { - List<Hash> rv = new ArrayList(howMany); + List<Hash> rv = new ArrayList<Hash>(howMany); for (int i = 0; i < howMany; i++) { if (_sorted.isEmpty()) break; diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/PersistentDataStore.java b/router/java/src/net/i2p/router/networkdb/kademlia/PersistentDataStore.java index 8e559336a1a93917feedcfb00ad6506ca0c15051..3074bfa164fa6290e1847774431a3f89dd39aaea 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/PersistentDataStore.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/PersistentDataStore.java @@ -196,7 +196,7 @@ class PersistentDataStore extends TransientDataStore { private volatile boolean _quit; public Writer() { - _keys = new ConcurrentHashMap(64); + _keys = new ConcurrentHashMap<Hash, DatabaseEntry>(64); _waitLock = new Object(); } diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/SearchJob.java b/router/java/src/net/i2p/router/networkdb/kademlia/SearchJob.java index 80815ea820d375a9557cbc7a5176b61a4f32eb95..a8c84df33e238a7a1eb021a8c03cb9f679c3927a 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/SearchJob.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/SearchJob.java @@ -49,7 +49,7 @@ class SearchJob extends JobImpl { private final boolean _keepStats; private Job _pendingRequeueJob; private final PeerSelector _peerSelector; - private final List _deferredSearches; + private final List<Search> _deferredSearches; private boolean _deferredCleared; private long _startedOn; private boolean _floodfillPeersExhausted; @@ -99,7 +99,7 @@ class SearchJob extends JobImpl { _onFailure = onFailure; _timeoutMs = timeoutMs; _keepStats = keepStats; - _deferredSearches = new ArrayList(0); + _deferredSearches = new ArrayList<Search>(0); _peerSelector = facade.getPeerSelector(); _startedOn = -1; _expiration = getContext().clock().now() + timeoutMs; @@ -260,7 +260,7 @@ class SearchJob extends JobImpl { return; } int sent = 0; - Set attempted = _state.getAttempted(); + Set<Hash> attempted = _state.getAttempted(); while (sent <= 0) { //boolean onlyFloodfill = onlyQueryFloodfillPeers(getContext()); boolean onlyFloodfill = true; @@ -271,7 +271,7 @@ class SearchJob extends JobImpl { fail(); return; } - List closestHashes = getClosestRouters(_state.getTarget(), toCheck, attempted); + List<Hash> closestHashes = getClosestRouters(_state.getTarget(), toCheck, attempted); if ( (closestHashes == null) || (closestHashes.isEmpty()) ) { if (_state.getPending().isEmpty()) { // we tried to find some peers, but there weren't any and no one else is going to answer @@ -290,8 +290,8 @@ class SearchJob extends JobImpl { return; } else { attempted.addAll(closestHashes); - for (Iterator iter = closestHashes.iterator(); iter.hasNext(); ) { - Hash peer = (Hash)iter.next(); + for (Iterator<Hash> iter = closestHashes.iterator(); iter.hasNext(); ) { + Hash peer = iter.next(); DatabaseEntry ds = _facade.getDataStore().get(peer); if (ds == null) { if (_log.shouldLog(Log.INFO)) @@ -365,7 +365,7 @@ class SearchJob extends JobImpl { * * @return ordered list of Hash objects */ - private List getClosestRouters(Hash key, int numClosest, Set alreadyChecked) { + private List<Hash> getClosestRouters(Hash key, int numClosest, Set<Hash> alreadyChecked) { Hash rkey = getContext().routingKeyGenerator().getRoutingKey(key); if (_log.shouldLog(Log.DEBUG)) _log.debug(getJobId() + ": Current routing key for " + key + ": " + rkey); @@ -627,11 +627,11 @@ class SearchJob extends JobImpl { _facade.sendStore(_state.getTarget(), ds, null, null, RESEND_TIMEOUT, _state.getSuccessful()); } } else { - Set sendTo = _state.getRepliedPeers(); // _state.getFailed(); + Set<Hash> sendTo = _state.getRepliedPeers(); // _state.getFailed(); sendTo.addAll(_state.getPending()); int numSent = 0; - for (Iterator iter = sendTo.iterator(); iter.hasNext(); ) { - Hash peer = (Hash)iter.next(); + for (Iterator<Hash> iter = sendTo.iterator(); iter.hasNext(); ) { + Hash peer = iter.next(); RouterInfo peerInfo = _facade.lookupRouterInfoLocally(peer); if (peerInfo == null) continue; if (resend(peerInfo, (LeaseSet)ds)) @@ -726,10 +726,10 @@ class SearchJob extends JobImpl { } private void handleDeferred(boolean success) { - List deferred = null; + List<Search> deferred = null; synchronized (_deferredSearches) { if (!_deferredSearches.isEmpty()) { - deferred = new ArrayList(_deferredSearches); + deferred = new ArrayList<Search>(_deferredSearches); _deferredSearches.clear(); } _deferredCleared = true; @@ -737,7 +737,7 @@ class SearchJob extends JobImpl { if (deferred != null) { long now = getContext().clock().now(); for (int i = 0; i < deferred.size(); i++) { - Search cur = (Search)deferred.get(i); + Search cur = deferred.get(i); if (cur.getExpiration() < now) getContext().jobQueue().addJob(cur.getOnFail()); else if (success) diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/SearchState.java b/router/java/src/net/i2p/router/networkdb/kademlia/SearchState.java index bb04fb4617fe5aff78b3bdf92bcffa083d86c9cd..9a4f99c43b725819b3a8bd696e16af029216ebb8 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/SearchState.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/SearchState.java @@ -31,12 +31,12 @@ class SearchState { public SearchState(RouterContext context, Hash key) { _context = context; _searchKey = key; - _pendingPeers = new HashSet(16); - _attemptedPeers = new HashSet(16); - _failedPeers = new HashSet(16); - _successfulPeers = new HashSet(16); - _pendingPeerTimes = new HashMap(16); - _repliedPeers = new HashSet(16); + _pendingPeers = new HashSet<Hash>(16); + _attemptedPeers = new HashSet<Hash>(16); + _failedPeers = new HashSet<Hash>(16); + _successfulPeers = new HashSet<Hash>(16); + _pendingPeerTimes = new HashMap<Hash, Long>(16); + _repliedPeers = new HashSet<Hash>(16); _completed = -1; _started = _context.clock().now(); } @@ -44,12 +44,12 @@ class SearchState { public Hash getTarget() { return _searchKey; } public Set<Hash> getPending() { synchronized (_pendingPeers) { - return (Set)_pendingPeers.clone(); + return (Set<Hash>)_pendingPeers.clone(); } } public Set<Hash> getAttempted() { synchronized (_attemptedPeers) { - return (Set)_attemptedPeers.clone(); + return (Set<Hash>)_attemptedPeers.clone(); } } public Set<Hash> getClosestAttempted(int max) { @@ -60,10 +60,10 @@ class SearchState { private Set<Hash> locked_getClosest(Set<Hash> peers, int max, Hash target) { if (_attemptedPeers.size() <= max) - return new HashSet(_attemptedPeers); - TreeSet closest = new TreeSet(new XORComparator(target)); + return new HashSet<Hash>(_attemptedPeers); + TreeSet<Hash> closest = new TreeSet<Hash>(new XORComparator(target)); closest.addAll(_attemptedPeers); - Set<Hash> rv = new HashSet(max); + Set<Hash> rv = new HashSet<Hash>(max); int i = 0; for (Iterator<Hash> iter = closest.iterator(); iter.hasNext() && i < max; i++) { rv.add(iter.next()); @@ -78,12 +78,12 @@ class SearchState { } public Set<Hash> getSuccessful() { synchronized (_successfulPeers) { - return (Set)_successfulPeers.clone(); + return (Set<Hash>)_successfulPeers.clone(); } } public Set<Hash> getFailed() { synchronized (_failedPeers) { - return (Set)_failedPeers.clone(); + return (Set<Hash>)_failedPeers.clone(); } } public boolean completed() { return _completed != -1; } @@ -155,7 +155,7 @@ class SearchState { } } - public Set getRepliedPeers() { synchronized (_repliedPeers) { return (Set)_repliedPeers.clone(); } } + public Set<Hash> getRepliedPeers() { synchronized (_repliedPeers) { return (Set<Hash>)_repliedPeers.clone(); } } public void replyTimeout(Hash peer) { synchronized (_pendingPeers) { diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/StartExplorersJob.java b/router/java/src/net/i2p/router/networkdb/kademlia/StartExplorersJob.java index 8b4e05b4f7f2273a60f3268edef561d766fc40c3..cced2f5466511db1b0efac7acf1a4116faeb58bf 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/StartExplorersJob.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/StartExplorersJob.java @@ -133,7 +133,7 @@ class StartExplorersJob extends JobImpl { Set<Hash> queued = _facade.getExploreKeys(); if (_log.shouldLog(Log.DEBUG)) _log.debug("Keys waiting for exploration: " + queued.size()); - Set<Hash> rv = new HashSet(num); + Set<Hash> rv = new HashSet<Hash>(num); for (Hash key : queued) { if (rv.size() >= num) break; rv.add(key); diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/StoreJob.java b/router/java/src/net/i2p/router/networkdb/kademlia/StoreJob.java index e70c3b6dc0942bbac6a896705772ad180dfe3ce9..72f6315aef4f5d5856048505ca64003a23753fa4 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/StoreJob.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/StoreJob.java @@ -234,7 +234,7 @@ class StoreJob extends JobImpl { private List<Hash> getClosestFloodfillRouters(Hash key, int numClosest, Set<Hash> alreadyChecked) { Hash rkey = getContext().routingKeyGenerator().getRoutingKey(key); KBucketSet ks = _facade.getKBuckets(); - if (ks == null) return new ArrayList(); + if (ks == null) return new ArrayList<Hash>(); return ((FloodfillPeerSelector)_peerSelector).selectFloodfillParticipants(rkey, numClosest, alreadyChecked, ks); } diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/StoreState.java b/router/java/src/net/i2p/router/networkdb/kademlia/StoreState.java index 876e2f4af8eaddeb7c64894bd1f4534e8f963f3d..b599186127e5bc50a69c58203c15de22fa7e62bd 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/StoreState.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/StoreState.java @@ -12,6 +12,7 @@ import java.util.concurrent.ConcurrentHashMap; import net.i2p.data.DatabaseEntry; import net.i2p.data.Hash; import net.i2p.router.RouterContext; +import net.i2p.router.networkdb.kademlia.MessageWrapper.WrappedMessage; /** * Tracks the state of a StoreJob @@ -38,16 +39,16 @@ class StoreState { _context = ctx; _key = key; _data = data; - _pendingPeers = new HashSet(4); - _pendingPeerTimes = new HashMap(4); - _pendingMessages = new ConcurrentHashMap(4); - _attemptedPeers = new HashSet(8); + _pendingPeers = new HashSet<Hash>(4); + _pendingPeerTimes = new HashMap<Hash, Long>(4); + _pendingMessages = new ConcurrentHashMap<Hash, WrappedMessage>(4); + _attemptedPeers = new HashSet<Hash>(8); if (toSkip != null) { _attemptedPeers.addAll(toSkip); _completeCount = toSkip.size(); } - _failedPeers = new HashSet(8); - _successfulPeers = new HashSet(4); + _failedPeers = new HashSet<Hash>(8); + _successfulPeers = new HashSet<Hash>(4); //_successfulExploratoryPeers = new HashSet(16); _completed = -1; _started = _context.clock().now(); diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/TransientDataStore.java b/router/java/src/net/i2p/router/networkdb/kademlia/TransientDataStore.java index 9f6ff888cf77b4317df11cfbfff559f33a95cb05..2a7318d25f08e64da79cb6fb119e0677a4bc7f93 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/TransientDataStore.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/TransientDataStore.java @@ -33,7 +33,7 @@ class TransientDataStore implements DataStore { public TransientDataStore(RouterContext ctx) { _context = ctx; _log = ctx.logManager().getLog(getClass()); - _data = new ConcurrentHashMap(1024); + _data = new ConcurrentHashMap<Hash, DatabaseEntry>(1024); if (_log.shouldLog(Log.INFO)) _log.info("Data Store initialized"); } diff --git a/router/java/src/net/i2p/router/networkdb/reseed/Reseeder.java b/router/java/src/net/i2p/router/networkdb/reseed/Reseeder.java index 9c8bb8eeb897d871cc1777eca045738cd07092e7..17554a159982421863918e0e7991bf4367bfd888 100644 --- a/router/java/src/net/i2p/router/networkdb/reseed/Reseeder.java +++ b/router/java/src/net/i2p/router/networkdb/reseed/Reseeder.java @@ -251,7 +251,7 @@ public class Reseeder { * @return count of routerinfos successfully fetched */ private int reseed(boolean echoStatus) { - List<String> URLList = new ArrayList(); + List<String> URLList = new ArrayList<String>(); String URLs = _context.getProperty(PROP_RESEED_URL); boolean defaulted = URLs == null; boolean SSLDisable = _context.getBooleanProperty(PROP_SSL_DISABLE); @@ -267,7 +267,7 @@ public class Reseeder { Collections.shuffle(URLList, _context.random()); if (defaulted && !SSLDisable) { // put the non-SSL at the end of the SSL - List<String> URLList2 = new ArrayList(); + List<String> URLList2 = new ArrayList<String>(); tok = new StringTokenizer(DEFAULT_SEED_URL, " ,"); while (tok.hasMoreTokens()) URLList2.add(tok.nextToken().trim()); @@ -334,7 +334,7 @@ public class Reseeder { String content = new String(contentRaw); // This isn't really URLs, but Base64 hashes // but they may include % encoding - Set<String> urls = new HashSet(1024); + Set<String> urls = new HashSet<String>(1024); Hash ourHash = _context.routerHash(); String ourB64 = ourHash != null ? ourHash.toBase64() : null; int cur = 0; @@ -370,7 +370,7 @@ public class Reseeder { return 0; } - List<String> urlList = new ArrayList(urls); + List<String> urlList = new ArrayList<String>(urls); Collections.shuffle(urlList, _context.random()); int fetched = 0; int errors = 0; diff --git a/router/java/src/net/i2p/router/peermanager/PeerManager.java b/router/java/src/net/i2p/router/peermanager/PeerManager.java index bf3564298aac90d497023ba0c62a9cd35879e7a6..904ca8bdb339c4611cda232d115558e53136b59b 100644 --- a/router/java/src/net/i2p/router/peermanager/PeerManager.java +++ b/router/java/src/net/i2p/router/peermanager/PeerManager.java @@ -73,10 +73,10 @@ class PeerManager { _persistenceHelper = new ProfilePersistenceHelper(context); _organizer = context.profileOrganizer(); _organizer.setUs(context.routerHash()); - _capabilitiesByPeer = new ConcurrentHashMap(256); - _peersByCapability = new HashMap(TRACKED_CAPS.length()); + _capabilitiesByPeer = new ConcurrentHashMap<Hash, String>(256); + _peersByCapability = new HashMap<Character, Set<Hash>>(TRACKED_CAPS.length()); for (int i = 0; i < TRACKED_CAPS.length(); i++) - _peersByCapability.put(Character.valueOf(Character.toLowerCase(TRACKED_CAPS.charAt(i))), new ConcurrentHashSet()); + _peersByCapability.put(Character.valueOf(Character.toLowerCase(TRACKED_CAPS.charAt(i))), new ConcurrentHashSet<Hash>()); loadProfilesInBackground(); ////_context.jobQueue().addJob(new EvaluateProfilesJob(_context)); //SimpleScheduler.getInstance().addPeriodicEvent(new Reorg(), 0, REORGANIZE_TIME); @@ -119,7 +119,7 @@ class PeerManager { void clearProfiles() { _organizer.clearProfiles(); _capabilitiesByPeer.clear(); - for (Set p : _peersByCapability.values()) + for (Set<Hash> p : _peersByCapability.values()) p.clear(); } @@ -177,9 +177,9 @@ class PeerManager { * Only used by PeerTestJob (PURPOSE_TEST) */ List<Hash> selectPeers(PeerSelectionCriteria criteria) { - Set<Hash> peers = new HashSet(criteria.getMinimumRequired()); + Set<Hash> peers = new HashSet<Hash>(criteria.getMinimumRequired()); // not a singleton, SANFP adds to it - Set<Hash> exclude = new HashSet(1); + Set<Hash> exclude = new HashSet<Hash>(1); exclude.add(_context.routerHash()); switch (criteria.getPurpose()) { case PeerSelectionCriteria.PURPOSE_TEST: @@ -221,7 +221,7 @@ class PeerManager { } if (_log.shouldLog(Log.INFO)) _log.info("Peers selected: " + peers); - return new ArrayList(peers); + return new ArrayList<Hash>(peers); } /** @@ -300,6 +300,6 @@ class PeerManager { Set<Hash> peers = locked_getPeers(capability); if (peers != null) return Collections.unmodifiableSet(peers); - return Collections.EMPTY_SET; + return Collections.emptySet(); } } diff --git a/router/java/src/net/i2p/router/peermanager/PeerManagerFacadeImpl.java b/router/java/src/net/i2p/router/peermanager/PeerManagerFacadeImpl.java index 433067e83879adbb96ea3fa5840839e10230730e..74e96cd01a22c02812916d7f274d0bbde1e25013 100644 --- a/router/java/src/net/i2p/router/peermanager/PeerManagerFacadeImpl.java +++ b/router/java/src/net/i2p/router/peermanager/PeerManagerFacadeImpl.java @@ -89,7 +89,7 @@ public class PeerManagerFacadeImpl implements PeerManagerFacade { * @return non-null unmodifiable set */ public Set<Hash> getPeersByCapability(char capability) { - if (_manager == null) return Collections.EMPTY_SET; + if (_manager == null) return Collections.emptySet(); return _manager.getPeersByCapability(capability); } diff --git a/router/java/src/net/i2p/router/peermanager/PeerProfile.java b/router/java/src/net/i2p/router/peermanager/PeerProfile.java index a84f4acded6b65386135678173a7d519ca62ed92..ec2e094d354b906869aeff35fac4bb922fc23a1b 100644 --- a/router/java/src/net/i2p/router/peermanager/PeerProfile.java +++ b/router/java/src/net/i2p/router/peermanager/PeerProfile.java @@ -73,7 +73,7 @@ public class PeerProfile { * Only routers in these countries will use a same-country metric. * Yes this is an arbitrary cutoff. */ - private static final Set<String> _bigCountries = new HashSet(); + private static final Set<String> _bigCountries = new HashSet<String>(); static { String[] big = new String[] { "fr", "de", "ru", "ua", "us" }; diff --git a/router/java/src/net/i2p/router/peermanager/PeerTestJob.java b/router/java/src/net/i2p/router/peermanager/PeerTestJob.java index bd2140091fa394278d9ec653df315e2c3408239f..d9a00d40a05e5aa64fa14e9939f7e5a999e7f1ab 100644 --- a/router/java/src/net/i2p/router/peermanager/PeerTestJob.java +++ b/router/java/src/net/i2p/router/peermanager/PeerTestJob.java @@ -69,12 +69,12 @@ public class PeerTestJob extends JobImpl { public void runJob() { if (!_keepTesting) return; - Set peers = selectPeersToTest(); + Set<RouterInfo> peers = selectPeersToTest(); if (_log.shouldLog(Log.DEBUG)) _log.debug("Testing " + peers.size() + " peers"); - for (Iterator iter = peers.iterator(); iter.hasNext(); ) { - RouterInfo peer = (RouterInfo)iter.next(); + for (Iterator<RouterInfo> iter = peers.iterator(); iter.hasNext(); ) { + RouterInfo peer = iter.next(); if (_log.shouldLog(Log.DEBUG)) _log.debug("Testing peer " + peer.getIdentity().getHash().toBase64()); testPeer(peer); @@ -87,19 +87,19 @@ public class PeerTestJob extends JobImpl { * * @return set of RouterInfo structures */ - private Set selectPeersToTest() { + private Set<RouterInfo> selectPeersToTest() { PeerSelectionCriteria criteria = new PeerSelectionCriteria(); criteria.setMinimumRequired(getTestConcurrency()); criteria.setMaximumRequired(getTestConcurrency()); criteria.setPurpose(PeerSelectionCriteria.PURPOSE_TEST); - List peerHashes = _manager.selectPeers(criteria); + List<Hash> peerHashes = _manager.selectPeers(criteria); if (_log.shouldLog(Log.DEBUG)) _log.debug("Peer selection found " + peerHashes.size() + " peers"); - Set peers = new HashSet(peerHashes.size()); - for (Iterator iter = peerHashes.iterator(); iter.hasNext(); ) { - Hash peer = (Hash)iter.next(); + Set<RouterInfo> peers = new HashSet<RouterInfo>(peerHashes.size()); + for (Iterator<Hash> iter = peerHashes.iterator(); iter.hasNext(); ) { + Hash peer = iter.next(); RouterInfo peerInfo = getContext().netDb().lookupRouterInfoLocally(peer); if (peerInfo != null) { peers.add(peerInfo); diff --git a/router/java/src/net/i2p/router/peermanager/ProfileOrganizer.java b/router/java/src/net/i2p/router/peermanager/ProfileOrganizer.java index 7096aa13974f6cc24c66eb3260374351bbf46024..30eb5c9dffbcc77d714a97ff9e6f6261ed5e59f8 100644 --- a/router/java/src/net/i2p/router/peermanager/ProfileOrganizer.java +++ b/router/java/src/net/i2p/router/peermanager/ProfileOrganizer.java @@ -2,13 +2,10 @@ package net.i2p.router.peermanager; import java.io.IOException; import java.io.OutputStream; -import java.net.InetAddress; -import java.net.UnknownHostException; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -97,13 +94,13 @@ public class ProfileOrganizer { _context = context; _log = context.logManager().getLog(ProfileOrganizer.class); _comp = new InverseCapacityComparator(); - _fastPeers = new HashMap(32); - _highCapacityPeers = new HashMap(64); - _wellIntegratedPeers = new HashMap(128); - _notFailingPeers = new HashMap(256); - _notFailingPeersList = new ArrayList(256); - _failingPeers = new HashMap(16); - _strictCapacityOrder = new TreeSet(_comp); + _fastPeers = new HashMap<Hash, PeerProfile>(32); + _highCapacityPeers = new HashMap<Hash, PeerProfile>(64); + _wellIntegratedPeers = new HashMap<Hash, PeerProfile>(128); + _notFailingPeers = new HashMap<Hash, PeerProfile>(256); + _notFailingPeersList = new ArrayList<Hash>(256); + _failingPeers = new HashMap<Hash, PeerProfile>(16); + _strictCapacityOrder = new TreeSet<PeerProfile>(_comp); _persistenceHelper = new ProfilePersistenceHelper(_context); _context.statManager().createRateStat("peer.profileSortTime", "How long the reorg takes sorting peers", "Peers", new long[] { 60*60*1000 }); @@ -219,7 +216,7 @@ public class ProfileOrganizer { return old; } - private int count(Map m) { + private int count(Map<? extends Object, ? extends Object> m) { getReadLock(); try { return m.size(); @@ -567,7 +564,7 @@ public class ProfileOrganizer { */ private void selectActiveNotFailingPeers2(int howMany, Set<Hash> exclude, Set<Hash> matches, int mask) { if (matches.size() < howMany) { - Map<Hash, PeerProfile> activePeers = new HashMap(); + Map<Hash, PeerProfile> activePeers = new HashMap<Hash, PeerProfile>(); getReadLock(); try { for (Iterator<Map.Entry<Hash, PeerProfile>> iter = _notFailingPeers.entrySet().iterator(); iter.hasNext(); ) { @@ -604,11 +601,11 @@ public class ProfileOrganizer { if (matches.size() < howMany) { int orig = matches.size(); int needed = howMany - orig; - List selected = new ArrayList(needed); + List<Hash> selected = new ArrayList<Hash>(needed); getReadLock(); try { // use RandomIterator to avoid shuffling the whole thing - for (Iterator<Hash> iter = new RandomIterator(_notFailingPeersList); (selected.size() < needed) && iter.hasNext(); ) { + for (Iterator<Hash> iter = new RandomIterator<Hash>(_notFailingPeersList); (selected.size() < needed) && iter.hasNext(); ) { Hash cur = iter.next(); if (matches.contains(cur) || (exclude != null && exclude.contains(cur))) { @@ -666,9 +663,9 @@ public class ProfileOrganizer { getReadLock(); try { count = _notFailingPeers.size(); - n = new ArrayList(_notFailingPeers.keySet()); + n = new ArrayList<Hash>(_notFailingPeers.keySet()); } finally { releaseReadLock(); } - List<Hash> l = new ArrayList(count / 4); + List<Hash> l = new ArrayList<Hash>(count / 4); for (Iterator<Hash> iter = n.iterator(); iter.hasNext(); ) { Hash peer = iter.next(); if (_context.commSystem().wasUnreachable(peer)) @@ -719,7 +716,7 @@ public class ProfileOrganizer { try { long cutoff = _context.clock().now() - (20*1000); int count = _notFailingPeers.size(); - List<Hash> l = new ArrayList(count / 128); + List<Hash> l = new ArrayList<Hash>(count / 128); for (Iterator<PeerProfile> iter = _notFailingPeers.values().iterator(); iter.hasNext(); ) { PeerProfile prof = iter.next(); if (prof.getTunnelHistory().getLastRejectedBandwidth() > cutoff) @@ -736,7 +733,7 @@ public class ProfileOrganizer { public Set<Hash> selectAllPeers() { getReadLock(); try { - Set<Hash> allPeers = new HashSet(_failingPeers.size() + _notFailingPeers.size() + _highCapacityPeers.size() + _fastPeers.size()); + Set<Hash> allPeers = new HashSet<Hash>(_failingPeers.size() + _notFailingPeers.size() + _highCapacityPeers.size() + _fastPeers.size()); allPeers.addAll(_failingPeers.keySet()); allPeers.addAll(_notFailingPeers.keySet()); allPeers.addAll(_highCapacityPeers.keySet()); @@ -806,7 +803,7 @@ public class ProfileOrganizer { //allPeers.addAll(_highCapacityPeers.values()); //allPeers.addAll(_fastPeers.values()); - Set<PeerProfile> reordered = new TreeSet(_comp); + Set<PeerProfile> reordered = new TreeSet<PeerProfile>(_comp); long sortStart = System.currentTimeMillis(); for (Iterator<PeerProfile> iter = _strictCapacityOrder.iterator(); iter.hasNext(); ) { PeerProfile prof = iter.next(); @@ -932,7 +929,7 @@ public class ProfileOrganizer { if (_log.shouldLog(Log.INFO)) _log.info("Need to explicitly demote " + numToDemote + " peers from the fast group"); // sort by speed, slowest-first - Set<PeerProfile> sorted = new TreeSet(new SpeedComparator()); + Set<PeerProfile> sorted = new TreeSet<PeerProfile>(new SpeedComparator()); sorted.addAll(_fastPeers.values()); Iterator<PeerProfile> iter = sorted.iterator(); for (int i = 0; i < numToDemote && iter.hasNext(); i++) { @@ -1024,7 +1021,7 @@ public class ProfileOrganizer { private void locked_calculateThresholds(Set<PeerProfile> allPeers) { double totalCapacity = 0; double totalIntegration = 0; - Set<PeerProfile> reordered = new TreeSet(_comp); + Set<PeerProfile> reordered = new TreeSet<PeerProfile>(_comp); for (Iterator<PeerProfile> iter = allPeers.iterator(); iter.hasNext(); ) { PeerProfile profile = iter.next(); @@ -1217,10 +1214,10 @@ public class ProfileOrganizer { * not be in the same tunnel. 0 = disable check; 1 = /8; 2 = /16; 3 = /24; 4 = exact IP match */ private void locked_selectPeers(Map<Hash, PeerProfile> peers, int howMany, Set<Hash> toExclude, Set<Hash> matches, int mask) { - List<Hash> all = new ArrayList(peers.keySet()); - Set<Integer> IPSet = new HashSet(8); + List<Hash> all = new ArrayList<Hash>(peers.keySet()); + Set<Integer> IPSet = new HashSet<Integer>(8); // use RandomIterator to avoid shuffling the whole thing - for (Iterator<Hash> iter = new RandomIterator(all); (matches.size() < howMany) && iter.hasNext(); ) { + for (Iterator<Hash> iter = new RandomIterator<Hash>(all); (matches.size() < howMany) && iter.hasNext(); ) { Hash peer = iter.next(); if (toExclude != null && toExclude.contains(peer)) continue; @@ -1262,7 +1259,7 @@ public class ProfileOrganizer { * @return an opaque set of masked IPs for this peer */ private Set<Integer> maskedIPSet(Hash peer, int mask) { - Set<Integer> rv = new HashSet(4); + Set<Integer> rv = new HashSet<Integer>(4); byte[] commIP = _context.commSystem().getIP(peer); if (commIP != null) rv.add(maskedIP(commIP, mask)); @@ -1299,7 +1296,7 @@ public class ProfileOrganizer { } /** does a contain any of the elements in b? */ - private static boolean containsAny(Set a, Set b) { + private static boolean containsAny(Set<? extends Object> a, Set<? extends Object> b) { for (Object o : b) { if (a.contains(o)) return true; @@ -1320,9 +1317,9 @@ public class ProfileOrganizer { *</pre> */ private void locked_selectPeers(Map<Hash, PeerProfile> peers, int howMany, Set<Hash> toExclude, Set<Hash> matches, Hash randomKey, int subTierMode) { - List<Hash> all = new ArrayList(peers.keySet()); + List<Hash> all = new ArrayList<Hash>(peers.keySet()); // use RandomIterator to avoid shuffling the whole thing - for (Iterator<Hash> iter = new RandomIterator(all); (matches.size() < howMany) && iter.hasNext(); ) { + for (Iterator<Hash> iter = new RandomIterator<Hash>(all); (matches.size() < howMany) && iter.hasNext(); ) { Hash peer = iter.next(); if (toExclude != null && toExclude.contains(peer)) continue; diff --git a/router/java/src/net/i2p/router/peermanager/ProfilePersistenceHelper.java b/router/java/src/net/i2p/router/peermanager/ProfilePersistenceHelper.java index 3336a443fa5f29bdb8a6fda88f733ab99798ed00..32c15038c0f25a7e470df1a45a20ac01de941922 100644 --- a/router/java/src/net/i2p/router/peermanager/ProfilePersistenceHelper.java +++ b/router/java/src/net/i2p/router/peermanager/ProfilePersistenceHelper.java @@ -178,7 +178,7 @@ class ProfilePersistenceHelper { public Set<PeerProfile> readProfiles() { long start = _context.clock().now(); List<File> files = selectFiles(); - Set<PeerProfile> profiles = new HashSet(files.size()); + Set<PeerProfile> profiles = new HashSet<PeerProfile>(files.size()); for (File f : files) { PeerProfile profile = readProfile(f); if (profile != null) @@ -202,7 +202,7 @@ class ProfilePersistenceHelper { File files[] = _profileDir.listFiles(filter); if (files != null && files.length > 0) migrate(files); - List rv = new ArrayList(1024); + List<File> rv = new ArrayList<File>(1024); for (int j = 0; j < B64.length(); j++) { File subdir = new File(_profileDir, DIR_PREFIX + B64.charAt(j)); files = subdir.listFiles(filter); diff --git a/router/java/src/net/i2p/router/startup/ClientAppConfig.java b/router/java/src/net/i2p/router/startup/ClientAppConfig.java index 7d81ebd06d44b40ad3e36333ec765d68987ff13b..9c3ff4cd6f4a911ca45168453ef19fcc04f7906c 100644 --- a/router/java/src/net/i2p/router/startup/ClientAppConfig.java +++ b/router/java/src/net/i2p/router/startup/ClientAppConfig.java @@ -151,7 +151,7 @@ public class ClientAppConfig { try { DataHelper.loadProps(clientApps, cfgFile); } catch (IOException ioe) { - return Collections.EMPTY_LIST; + return Collections.emptyList(); } return getClientApps(clientApps); } @@ -162,7 +162,7 @@ public class ClientAppConfig { * @since 0.7.12 */ private static List<ClientAppConfig> getClientApps(Properties clientApps) { - List<ClientAppConfig> rv = new ArrayList(8); + List<ClientAppConfig> rv = new ArrayList<ClientAppConfig>(8); int i = 0; while (true) { String className = clientApps.getProperty(PREFIX + i + ".main"); diff --git a/router/java/src/net/i2p/router/startup/CreateRouterInfoJob.java b/router/java/src/net/i2p/router/startup/CreateRouterInfoJob.java index 4308c0bf6a8c02dd26994fd8a43b96f0b6b9c7c4..498cbe6658be5ecd009ba3e120d075fbd7aba3be 100644 --- a/router/java/src/net/i2p/router/startup/CreateRouterInfoJob.java +++ b/router/java/src/net/i2p/router/startup/CreateRouterInfoJob.java @@ -10,7 +10,6 @@ package net.i2p.router.startup; import java.io.BufferedOutputStream; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.util.Properties; diff --git a/router/java/src/net/i2p/router/startup/LoadClientAppsJob.java b/router/java/src/net/i2p/router/startup/LoadClientAppsJob.java index e31176d840f32a7e2e8be0f9612dfc72984b073b..e34a71173ac06ac9095f9862ff6f3d866273fc3a 100644 --- a/router/java/src/net/i2p/router/startup/LoadClientAppsJob.java +++ b/router/java/src/net/i2p/router/startup/LoadClientAppsJob.java @@ -36,7 +36,7 @@ public class LoadClientAppsJob extends JobImpl { if (_loaded) return; _loaded = true; } - List apps = ClientAppConfig.getClientApps(getContext()); + List<ClientAppConfig> apps = ClientAppConfig.getClientApps(getContext()); if (apps.isEmpty()) { _log.error("Warning - No client apps or router console configured - we are just a router"); System.err.println("Warning - No client apps or router console configured - we are just a router"); @@ -106,7 +106,7 @@ public class LoadClientAppsJob extends JobImpl { * @return non-null, 0-length if args is null */ public static String[] parseArgs(String args) { - List<String> argList = new ArrayList(4); + List<String> argList = new ArrayList<String>(4); if (args != null) { char data[] = args.toCharArray(); StringBuilder buf = new StringBuilder(32); diff --git a/router/java/src/net/i2p/router/startup/LoadRouterInfoJob.java b/router/java/src/net/i2p/router/startup/LoadRouterInfoJob.java index f41e4d125fa2a6ad2aed5311e1cfdc0faacd8789..9a560da5f42ecebda2508d463e60b1b970985f7a 100644 --- a/router/java/src/net/i2p/router/startup/LoadRouterInfoJob.java +++ b/router/java/src/net/i2p/router/startup/LoadRouterInfoJob.java @@ -15,7 +15,6 @@ import java.io.InputStream; import java.io.IOException; import java.util.concurrent.atomic.AtomicBoolean; -import net.i2p.crypto.KeyGenerator; import net.i2p.data.DataFormatException; import net.i2p.data.PrivateKey; import net.i2p.data.PublicKey; diff --git a/router/java/src/net/i2p/router/startup/RouterAppManager.java b/router/java/src/net/i2p/router/startup/RouterAppManager.java index 1b4441fcbfbec3f99f49867fdceef98b6a15b066..8f7ca212a5cf5bd1dc57b91a8d6de2eed75165f5 100644 --- a/router/java/src/net/i2p/router/startup/RouterAppManager.java +++ b/router/java/src/net/i2p/router/startup/RouterAppManager.java @@ -35,8 +35,8 @@ public class RouterAppManager implements ClientAppManager { public RouterAppManager(RouterContext ctx) { _context = ctx; _log = ctx.logManager().getLog(RouterAppManager.class); - _clients = new ConcurrentHashMap(16); - _registered = new ConcurrentHashMap(8); + _clients = new ConcurrentHashMap<ClientApp, String[]>(16); + _registered = new ConcurrentHashMap<String, ClientApp>(8); ctx.addShutdownTask(new Shutdown()); } @@ -175,7 +175,7 @@ public class RouterAppManager implements ClientAppManager { * @since 0.9.6 */ public synchronized void shutdown() { - Set<ClientApp> apps = new HashSet(_clients.keySet()); + Set<ClientApp> apps = new HashSet<ClientApp>(_clients.keySet()); for (ClientApp app : apps) { ClientAppState state = app.getState(); if (state == RUNNING || state == STARTING) { @@ -214,7 +214,7 @@ public class RouterAppManager implements ClientAppManager { * @since 0.9.6 */ private void toString1(StringBuilder buf) { - List<String> list = new ArrayList(_clients.size()); + List<String> list = new ArrayList<String>(_clients.size()); for (Map.Entry<ClientApp, String[]> entry : _clients.entrySet()) { ClientApp key = entry.getKey(); String[] val = entry.getValue(); @@ -231,7 +231,7 @@ public class RouterAppManager implements ClientAppManager { * @since 0.9.6 */ private void toString2(StringBuilder buf) { - List<String> list = new ArrayList(_registered.size()); + List<String> list = new ArrayList<String>(_registered.size()); for (Map.Entry<String, ClientApp> entry : _registered.entrySet()) { String key = entry.getKey(); ClientApp val = entry.getValue(); diff --git a/router/java/src/net/i2p/router/tasks/RouterWatchdog.java b/router/java/src/net/i2p/router/tasks/RouterWatchdog.java index efe07edbda8aa97391aa3916e2ba289e8200f5f6..b55ad6497755f531422d7edc897e81e753d6e0f7 100644 --- a/router/java/src/net/i2p/router/tasks/RouterWatchdog.java +++ b/router/java/src/net/i2p/router/tasks/RouterWatchdog.java @@ -1,7 +1,5 @@ package net.i2p.router.tasks; -import java.io.File; - import net.i2p.data.DataHelper; import net.i2p.router.Job; import net.i2p.router.CommSystemFacade; @@ -10,7 +8,6 @@ import net.i2p.router.RouterContext; import net.i2p.router.util.EventLog; import net.i2p.stat.Rate; import net.i2p.stat.RateStat; -import net.i2p.util.ShellCommand; import net.i2p.util.Log; import net.i2p.util.SystemVersion; diff --git a/router/java/src/net/i2p/router/time/NtpClient.java b/router/java/src/net/i2p/router/time/NtpClient.java index 3a1d8ab06cd93887aea8869c9b5197ab65653d87..a30b92f70f1f96f53e08608c3eef2ec452bd214d 100644 --- a/router/java/src/net/i2p/router/time/NtpClient.java +++ b/router/java/src/net/i2p/router/time/NtpClient.java @@ -65,7 +65,7 @@ class NtpClient { public static long currentTime(String serverNames[]) { if (serverNames == null) throw new IllegalArgumentException("No NTP servers specified"); - ArrayList names = new ArrayList(serverNames.length); + ArrayList<String> names = new ArrayList<String>(serverNames.length); for (int i = 0; i < serverNames.length; i++) names.add(serverNames[i]); Collections.shuffle(names); @@ -87,7 +87,7 @@ class NtpClient { public static long[] currentTimeAndStratum(String serverNames[]) { if (serverNames == null) throw new IllegalArgumentException("No NTP servers specified"); - ArrayList names = new ArrayList(serverNames.length); + ArrayList<String> names = new ArrayList<String>(serverNames.length); for (int i = 0; i < serverNames.length; i++) names.add(serverNames[i]); Collections.shuffle(names); diff --git a/router/java/src/net/i2p/router/time/RouterTimestamper.java b/router/java/src/net/i2p/router/time/RouterTimestamper.java index d835b66f9c9bb939b114133f64cccf8934634ab2..33ba07b9cb9a09a15e4984be428453f023d1c0d7 100644 --- a/router/java/src/net/i2p/router/time/RouterTimestamper.java +++ b/router/java/src/net/i2p/router/time/RouterTimestamper.java @@ -61,8 +61,8 @@ public class RouterTimestamper extends Timestamper { public RouterTimestamper(I2PAppContext ctx, UpdateListener lsnr, boolean daemon) { super(); // moved here to prevent problems with synchronized statements. - _servers = new ArrayList(3); - _listeners = new CopyOnWriteArrayList(); + _servers = new ArrayList<String>(3); + _listeners = new CopyOnWriteArrayList<UpdateListener>(); _context = ctx; _daemon = daemon; // DO NOT initialize _log here, stack overflow via LogManager init loop @@ -178,7 +178,7 @@ public class RouterTimestamper extends Timestamper { lastFailed = !queryTime(_servers.toArray(new String[_servers.size()])); } catch (IllegalArgumentException iae) { if ( (!_initialized) && (_log.shouldLog(Log.ERROR)) ) { - List<String> all = new ArrayList(); + List<String> all = new ArrayList<String>(); if (_priorityServers != null) all.addAll(_priorityServers); all.addAll(_servers); @@ -299,7 +299,7 @@ public class RouterTimestamper extends Timestamper { country = country.toLowerCase(Locale.US); } if (country != null && country.length() > 0) { - _priorityServers = new ArrayList(3); + _priorityServers = new ArrayList<String>(3); for (int i = 0; i < 3; i++) _priorityServers.add(i + "." + country + ".pool.ntp.org"); } else { diff --git a/router/java/src/net/i2p/router/transport/BadCountries.java b/router/java/src/net/i2p/router/transport/BadCountries.java index f5d36b64ac551206994442dc589f664987947415..4a85f2644b941e6ead544170b4f43a0ff30a2cb7 100644 --- a/router/java/src/net/i2p/router/transport/BadCountries.java +++ b/router/java/src/net/i2p/router/transport/BadCountries.java @@ -56,7 +56,7 @@ abstract class BadCountries { /* Vietnam */ "VN", /* Yemen */ "YE" }; - _countries = new HashSet(Arrays.asList(c)); + _countries = new HashSet<String>(Arrays.asList(c)); } /** @param country non-null, two letter code, case-independent */ diff --git a/router/java/src/net/i2p/router/transport/CommSystemFacadeImpl.java b/router/java/src/net/i2p/router/transport/CommSystemFacadeImpl.java index d6401ae48219adf9ba519bb2243988afee840cb4..d216ba0e8a504ffe0d0a8160a1eef5a852012dcb 100644 --- a/router/java/src/net/i2p/router/transport/CommSystemFacadeImpl.java +++ b/router/java/src/net/i2p/router/transport/CommSystemFacadeImpl.java @@ -12,12 +12,9 @@ import java.io.IOException; import java.io.Writer; import java.util.ArrayList; import java.util.Collections; -import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Locale; -import java.util.Map; -import java.util.Properties; import java.util.Vector; import net.i2p.data.Hash; @@ -30,7 +27,6 @@ import net.i2p.router.transport.udp.UDPTransport; import net.i2p.router.util.EventLog; import net.i2p.util.Addresses; import net.i2p.util.Log; -import net.i2p.util.SimpleScheduler; import net.i2p.util.SimpleTimer; import net.i2p.util.SimpleTimer2; import net.i2p.util.Translate; @@ -191,7 +187,7 @@ public class CommSystemFacadeImpl extends CommSystemFacade { // No, don't do this, it makes it almost impossible to build inbound tunnels //if (_context.router().isHidden()) // return Collections.EMPTY_SET; - List<RouterAddress> addresses = new ArrayList(_manager.getAddresses()); + List<RouterAddress> addresses = new ArrayList<RouterAddress>(_manager.getAddresses()); if (_log.shouldLog(Log.INFO)) _log.info("Creating addresses: " + addresses, new Exception("creator")); return addresses; diff --git a/router/java/src/net/i2p/router/transport/FIFOBandwidthLimiter.java b/router/java/src/net/i2p/router/transport/FIFOBandwidthLimiter.java index 1b79fd740fb6d678f532b76617cdb5e96769d8de..231dadeec59e3463279e90012112c32cb7835cde 100644 --- a/router/java/src/net/i2p/router/transport/FIFOBandwidthLimiter.java +++ b/router/java/src/net/i2p/router/transport/FIFOBandwidthLimiter.java @@ -91,8 +91,8 @@ public class FIFOBandwidthLimiter { _context.statManager().createRateStat("bwLimiter.pendingInboundRequests", "How many inbound requests are ahead of the current one (ignoring ones with 0)?", "BandwidthLimiter", new long[] { 5*60*1000l, 60*60*1000l }); _context.statManager().createRateStat("bwLimiter.outboundDelayedTime", "How long it takes to honor an outbound request (ignoring ones with that go instantly)?", "BandwidthLimiter", new long[] { 5*60*1000l, 60*60*1000l }); _context.statManager().createRateStat("bwLimiter.inboundDelayedTime", "How long it takes to honor an inbound request (ignoring ones with that go instantly)?", "BandwidthLimiter", new long[] { 5*60*1000l, 60*60*1000l }); - _pendingInboundRequests = new ArrayList(16); - _pendingOutboundRequests = new ArrayList(16); + _pendingInboundRequests = new ArrayList<Request>(16); + _pendingOutboundRequests = new ArrayList<Request>(16); _lastTotalSent = _totalAllocatedOutboundBytes.get(); _lastTotalReceived = _totalAllocatedInboundBytes.get(); _lastStatsUpdated = now(); @@ -796,7 +796,7 @@ public class FIFOBandwidthLimiter { * @param priority 0 for now */ public SimpleRequest(int bytes, int priority) { - satisfiedBuffer = new ArrayList(1); + satisfiedBuffer = new ArrayList<Request>(1); _total = bytes; _priority = priority; // following two are temp until switch to PBQ diff --git a/router/java/src/net/i2p/router/transport/FIFOBandwidthRefiller.java b/router/java/src/net/i2p/router/transport/FIFOBandwidthRefiller.java index 48717ecb84407ef1c9f3a49e32fc4b2fd4dda151..4da99288ed97fe2eb7eef749bd14bac336cebe5c 100644 --- a/router/java/src/net/i2p/router/transport/FIFOBandwidthRefiller.java +++ b/router/java/src/net/i2p/router/transport/FIFOBandwidthRefiller.java @@ -7,6 +7,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock; import net.i2p.I2PAppContext; import net.i2p.data.DataHelper; +import net.i2p.router.transport.FIFOBandwidthLimiter.Request; import net.i2p.util.Log; /** @@ -92,7 +93,7 @@ public class FIFOBandwidthRefiller implements Runnable { public void run() { // bootstrap 'em with nothing _lastRefillTime = _limiter.now(); - List<FIFOBandwidthLimiter.Request> buffer = new ArrayList(2); + List<FIFOBandwidthLimiter.Request> buffer = new ArrayList<Request>(2); while (_isRunning) { long now = _limiter.now(); if (now >= _lastCheckConfigTime + _configCheckPeriodMs) { diff --git a/router/java/src/net/i2p/router/transport/GeoIP.java b/router/java/src/net/i2p/router/transport/GeoIP.java index bb4232f07e8b484aa825079f0565cc5ac81bc215..cad3654c0298dcd309502e26dee25a56f14c2799 100644 --- a/router/java/src/net/i2p/router/transport/GeoIP.java +++ b/router/java/src/net/i2p/router/transport/GeoIP.java @@ -8,9 +8,7 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.File; import java.io.FileInputStream; -import java.net.InetAddress; import java.io.InputStreamReader; -import java.net.UnknownHostException; import java.util.Arrays; import java.util.Locale; import java.util.Map; @@ -62,12 +60,12 @@ class GeoIP { public GeoIP(RouterContext context) { _context = context; _log = context.logManager().getLog(GeoIP.class); - _codeToName = new ConcurrentHashMap(512); - _codeCache = new ConcurrentHashMap(512); - _IPToCountry = new ConcurrentHashMap(); - _pendingSearch = new ConcurrentHashSet(); - _pendingIPv6Search = new ConcurrentHashSet(); - _notFound = new ConcurrentHashSet(); + _codeToName = new ConcurrentHashMap<String, String>(512); + _codeCache = new ConcurrentHashMap<String, String>(512); + _IPToCountry = new ConcurrentHashMap<Long, String>(); + _pendingSearch = new ConcurrentHashSet<Long>(); + _pendingIPv6Search = new ConcurrentHashSet<Long>(); + _notFound = new ConcurrentHashSet<Long>(); _lock = new AtomicBoolean(); readCountryFile(); } diff --git a/router/java/src/net/i2p/router/transport/GeoIPv6.java b/router/java/src/net/i2p/router/transport/GeoIPv6.java index ebf79e5d14018c22c43ff2767525850ff5ec0158..f26e33a7eb2042709c0e0c53991241b697b5fc27 100644 --- a/router/java/src/net/i2p/router/transport/GeoIPv6.java +++ b/router/java/src/net/i2p/router/transport/GeoIPv6.java @@ -154,7 +154,7 @@ class GeoIPv6 { */ private static boolean compressGeoIPv6CSVFiles(List<File> inFiles, File outFile) { boolean DEBUG = false; - List<V6Entry> entries = new ArrayList(20000); + List<V6Entry> entries = new ArrayList<V6Entry>(20000); for (File geoFile : inFiles) { int count = 0; InputStream in = null; @@ -342,7 +342,7 @@ class GeoIPv6 { System.err.println("Usage: GeoIPv6 infile1.csv [infile2.csv...] outfile.dat.gz"); System.exit(1); } - List<File> infiles = new ArrayList(); + List<File> infiles = new ArrayList<File>(); for (int i = 0; i < args.length - 1; i++) { infiles.add(new File(args[i])); } @@ -353,6 +353,6 @@ class GeoIPv6 { System.exit(1); } // readback for testing - readGeoIPFile(outfile, new Long[] { Long.MAX_VALUE }, Collections.EMPTY_MAP, new Log(GeoIPv6.class)); + readGeoIPFile(outfile, new Long[] { Long.MAX_VALUE }, Collections.<String, String> emptyMap(), new Log(GeoIPv6.class)); } } diff --git a/router/java/src/net/i2p/router/transport/OutboundMessageRegistry.java b/router/java/src/net/i2p/router/transport/OutboundMessageRegistry.java index 947127f1e926e60c21b25484bf1927f0d456db67..9eabbd7191aadac451a9f81894f5a5b9543a690a 100644 --- a/router/java/src/net/i2p/router/transport/OutboundMessageRegistry.java +++ b/router/java/src/net/i2p/router/transport/OutboundMessageRegistry.java @@ -51,9 +51,9 @@ public class OutboundMessageRegistry { public OutboundMessageRegistry(RouterContext context) { _context = context; _log = _context.logManager().getLog(OutboundMessageRegistry.class); - _selectors = new ArrayList(64); - _selectorToMessage = new HashMap(64); - _activeMessages = new ConcurrentHashSet(64); + _selectors = new ArrayList<MessageSelector>(64); + _selectorToMessage = new HashMap<MessageSelector, Object>(64); + _activeMessages = new ConcurrentHashSet<OutNetMessage>(64); _cleanupTask = new CleanupTask(); } @@ -108,10 +108,10 @@ public class OutboundMessageRegistry { MessageSelector sel = _selectors.get(i); boolean isMatch = sel.isMatch(message); if (isMatch) { - if (matchedSelectors == null) matchedSelectors = new ArrayList(1); + if (matchedSelectors == null) matchedSelectors = new ArrayList<MessageSelector>(1); matchedSelectors.add(sel); if (!sel.continueMatching()) { - if (removedSelectors == null) removedSelectors = new ArrayList(1); + if (removedSelectors == null) removedSelectors = new ArrayList<MessageSelector>(1); removedSelectors.add(sel); //iter.remove(); _selectors.remove(i); @@ -123,11 +123,11 @@ public class OutboundMessageRegistry { List<OutNetMessage> rv = null; if (matchedSelectors != null) { - rv = new ArrayList(matchedSelectors.size()); + rv = new ArrayList<OutNetMessage>(matchedSelectors.size()); for (MessageSelector sel : matchedSelectors) { boolean removed = false; OutNetMessage msg = null; - List msgs = null; + List<OutNetMessage> msgs = null; synchronized (_selectorToMessage) { Object o = null; if ( (removedSelectors != null) && (removedSelectors.contains(sel)) ) { @@ -154,7 +154,7 @@ public class OutboundMessageRegistry { } } } else { - rv = Collections.EMPTY_LIST; + rv = Collections.emptyList(); } return rv; @@ -202,11 +202,11 @@ public class OutboundMessageRegistry { synchronized (_selectorToMessage) { Object oldMsg = _selectorToMessage.put(sel, msg); if (oldMsg != null) { - List multi = null; + List<OutNetMessage> multi = null; if (oldMsg instanceof OutNetMessage) { //multi = Collections.synchronizedList(new ArrayList(4)); - multi = new ArrayList(4); - multi.add(oldMsg); + multi = new ArrayList<OutNetMessage>(4); + multi.add((OutNetMessage)oldMsg); multi.add(msg); _selectorToMessage.put(sel, multi); } else if (oldMsg instanceof List) { @@ -261,7 +261,7 @@ public class OutboundMessageRegistry { public void timeReached() { long now = _context.clock().now(); - List<MessageSelector> removing = new ArrayList(8); + List<MessageSelector> removing = new ArrayList<MessageSelector>(8); synchronized (_selectors) { // CME? //for (Iterator<MessageSelector> iter = _selectors.iterator(); iter.hasNext(); ) { diff --git a/router/java/src/net/i2p/router/transport/TransportImpl.java b/router/java/src/net/i2p/router/transport/TransportImpl.java index 89b6cbeda78ed89b8bf2c0808367db34d87bbbdc..ccdfaada587932144ca546e0c55b7e45bd06e7dd 100644 --- a/router/java/src/net/i2p/router/transport/TransportImpl.java +++ b/router/java/src/net/i2p/router/transport/TransportImpl.java @@ -23,7 +23,6 @@ import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.Vector; -import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingQueue; import java.util.concurrent.CopyOnWriteArrayList; @@ -43,7 +42,6 @@ import net.i2p.router.RouterContext; import net.i2p.util.ConcurrentHashSet; import net.i2p.util.LHMCache; import net.i2p.util.Log; -import net.i2p.util.SimpleScheduler; import net.i2p.util.SimpleTimer; import net.i2p.util.SystemVersion; import net.i2p.util.Translate; @@ -75,7 +73,7 @@ public abstract class TransportImpl implements Transport { long max = 4096; // 1024 nominal for 128 MB int size = (int) Math.max(min, Math.min(max, 1 + (maxMemory / (128*1024)))); - _IPMap = new LHMCache(size); + _IPMap = new LHMCache<Hash, byte[]>(size); } /** @@ -95,14 +93,14 @@ public abstract class TransportImpl implements Transport { //_context.statManager().createRateStat("transport.sendProcessingTime." + getStyle(), "Time to process and send a message (ms)", "Transport", new long[] { 60*1000l }); _context.statManager().createRateStat("transport.expiredOnQueueLifetime", "How long a message that expires on our outbound queue is processed", "Transport", new long[] { 60*1000l, 10*60*1000l, 60*60*1000l, 24*60*60*1000l } ); - _currentAddresses = new CopyOnWriteArrayList(); + _currentAddresses = new CopyOnWriteArrayList<RouterAddress>(); if (getStyle().equals("NTCP")) - _sendPool = new ArrayBlockingQueue(8); + _sendPool = new ArrayBlockingQueue<OutNetMessage>(8); else _sendPool = null; - _unreachableEntries = new HashMap(32); - _wasUnreachableEntries = new HashMap(32); - _localAddresses = new ConcurrentHashSet(4); + _unreachableEntries = new HashMap<Hash, Long>(32); + _wasUnreachableEntries = new HashMap<Hash, Long>(32); + _localAddresses = new ConcurrentHashSet<InetAddress>(4); _context.simpleScheduler().addPeriodicEvent(new CleanupUnreachable(), 2 * UNREACHABLE_PERIOD, UNREACHABLE_PERIOD / 2); } @@ -179,7 +177,7 @@ public abstract class TransportImpl implements Transport { */ public Vector getClockSkews() { return new Vector(); } - public List<String> getMostRecentErrorMessages() { return Collections.EMPTY_LIST; } + public List<String> getMostRecentErrorMessages() { return Collections.emptyList(); } /** * Nonblocking call to pull the next outbound message @@ -564,7 +562,7 @@ public abstract class TransportImpl implements Transport { * @since IPv6 */ protected Collection<InetAddress> getSavedLocalAddresses() { - List<InetAddress> rv = new ArrayList(_localAddresses); + List<InetAddress> rv = new ArrayList<InetAddress>(_localAddresses); _localAddresses.clear(); return rv; } diff --git a/router/java/src/net/i2p/router/transport/TransportManager.java b/router/java/src/net/i2p/router/transport/TransportManager.java index 52c79f941cd492668b44edfe2eb9ff34c699b8dd..af12b515b5d13295ce5ce39207c2babbcb62028a 100644 --- a/router/java/src/net/i2p/router/transport/TransportManager.java +++ b/router/java/src/net/i2p/router/transport/TransportManager.java @@ -13,9 +13,7 @@ import java.io.Writer; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.ArrayList; -import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -31,6 +29,7 @@ import net.i2p.router.CommSystemFacade; import net.i2p.router.OutNetMessage; import net.i2p.router.RouterContext; import static net.i2p.router.transport.Transport.AddressSource.*; +import net.i2p.router.transport.TransportManager.Port; import net.i2p.router.transport.crypto.DHSessionKeyBuilder; import net.i2p.router.transport.ntcp.NTCPTransport; import net.i2p.router.transport.udp.UDPTransport; @@ -66,7 +65,7 @@ public class TransportManager implements TransportEventListener { _context.statManager().createRateStat("transport.bidFailSelf", "Could not attempt to bid on message, as it targeted ourselves", "Transport", new long[] { 60*1000, 10*60*1000, 60*60*1000 }); _context.statManager().createRateStat("transport.bidFailNoTransports", "Could not attempt to bid on message, as none of the transports could attempt it", "Transport", new long[] { 60*1000, 10*60*1000, 60*60*1000 }); _context.statManager().createRateStat("transport.bidFailAllTransports", "Could not attempt to bid on message, as all of the transports had failed", "Transport", new long[] { 60*1000, 10*60*1000, 60*60*1000 }); - _transports = new ConcurrentHashMap(2); + _transports = new ConcurrentHashMap<String, Transport>(2); if (_context.getBooleanPropertyDefaultTrue(PROP_ENABLE_UPNP)) _upnpManager = new UPnPManager(context, this); else @@ -168,7 +167,7 @@ public class TransportManager implements TransportEventListener { _log.debug("Starting up the transport manager"); // Let's do this in a predictable order to make testing easier // Start NTCP first so it can get notified from SSU - List<Transport> tps = new ArrayList(); + List<Transport> tps = new ArrayList<Transport>(); Transport tp = getTransport(NTCPTransport.STYLE); if (tp != null) tps.add(tp); @@ -363,7 +362,7 @@ public class TransportManager implements TransportEventListener { * This forces a rebuild */ public List<RouterAddress> getAddresses() { - List<RouterAddress> rv = new ArrayList(4); + List<RouterAddress> rv = new ArrayList<RouterAddress>(4); // do this first since SSU may force a NTCP change for (Transport t : _transports.values()) t.updateAddress(); @@ -406,7 +405,7 @@ public class TransportManager implements TransportEventListener { * which we will pass along to UPnP */ private Set<Port> getPorts() { - Set<Port> rv = new HashSet(4); + Set<Port> rv = new HashSet<Port>(4); for (Transport t : _transports.values()) { int port = t.getRequestedPort(); // Use UDP port for NTCP too - see comment in NTCPTransport.getRequestedPort() for why this is here @@ -435,7 +434,7 @@ public class TransportManager implements TransportEventListener { if (_context.router().getRouterInfo().equals(msg.getTarget())) throw new IllegalArgumentException("WTF, bids for a message bound to ourselves?"); - List<TransportBid> rv = new ArrayList(_transports.size()); + List<TransportBid> rv = new ArrayList<TransportBid>(_transports.size()); Set failedTransports = msg.getFailedTransports(); for (Transport t : _transports.values()) { if (failedTransports.contains(t.getStyle())) { @@ -535,7 +534,7 @@ public class TransportManager implements TransportEventListener { } public List<String> getMostRecentErrorMessages() { - List<String> rv = new ArrayList(16); + List<String> rv = new ArrayList<String>(16); for (Transport t : _transports.values()) { rv.addAll(t.getMostRecentErrorMessages()); } @@ -543,7 +542,7 @@ public class TransportManager implements TransportEventListener { } public void renderStatusHTML(Writer out, String urlBase, int sortFlags) throws IOException { - TreeMap<String, Transport> transports = new TreeMap(); + TreeMap<String, Transport> transports = new TreeMap<String, Transport>(); for (Transport t : _transports.values()) { transports.put(t.getStyle(), t); } diff --git a/router/java/src/net/i2p/router/transport/UPnP.java b/router/java/src/net/i2p/router/transport/UPnP.java index 980de066f8c0bc64de9b32b8a54526cb16a54407..3c69e4d2a45ce6fca63cd001deaafcda9bbe4595 100644 --- a/router/java/src/net/i2p/router/transport/UPnP.java +++ b/router/java/src/net/i2p/router/transport/UPnP.java @@ -266,9 +266,9 @@ class UPnP extends ControlPoint implements DeviceChangeListener, EventListener { } private void registerPortMappings() { - Set ports; + Set<ForwardPort> ports; synchronized(lock) { - ports = new HashSet(portsForwarded); + ports = new HashSet<ForwardPort>(portsForwarded); } if (ports.isEmpty()) return; @@ -326,9 +326,9 @@ class UPnP extends ControlPoint implements DeviceChangeListener, EventListener { } public void unregisterPortMappings() { - Set ports; + Set<ForwardPort> ports; synchronized(lock) { - ports = new HashSet(portsForwarded); + ports = new HashSet<ForwardPort>(portsForwarded); } if (ports.isEmpty()) return; @@ -918,7 +918,7 @@ class UPnP extends ControlPoint implements DeviceChangeListener, EventListener { ForwardPortStatus fps = new ForwardPortStatus(ForwardPortStatus.DEFINITE_FAILURE, "UPnP device does not support port forwarding", port.portNumber); - Map map = Collections.singletonMap(port, fps); + Map<ForwardPort, ForwardPortStatus> map = Collections.singletonMap(port, fps); forwardCallback.portForwardStatus(map); } return; @@ -949,7 +949,7 @@ class UPnP extends ControlPoint implements DeviceChangeListener, EventListener { } else { fps = new ForwardPortStatus(ForwardPortStatus.PROBABLE_FAILURE, "UPnP port forwarding apparently failed", port.portNumber); } - Map map = Collections.singletonMap(port, fps); + Map<ForwardPort, ForwardPortStatus> map = Collections.singletonMap(port, fps); try { forwardCallback.portForwardStatus(map); } catch (Exception e) { diff --git a/router/java/src/net/i2p/router/transport/UPnPManager.java b/router/java/src/net/i2p/router/transport/UPnPManager.java index b3fb90cc2bdaee016d20c100d4c8bcf9339bac2d..d7e5544e0baedb3c375d7f439321373d769f0113 100644 --- a/router/java/src/net/i2p/router/transport/UPnPManager.java +++ b/router/java/src/net/i2p/router/transport/UPnPManager.java @@ -6,7 +6,6 @@ package net.i2p.router.transport; import java.net.InetAddress; import java.util.HashSet; -import java.util.Iterator; import java.util.Map; import java.util.Set; @@ -122,7 +121,7 @@ class UPnPManager { return; //} - Set<ForwardPort> forwards = new HashSet(ports.size()); + Set<ForwardPort> forwards = new HashSet<ForwardPort>(ports.size()); for (TransportManager.Port entry : ports) { String style = entry.style; int port = entry.port; diff --git a/router/java/src/net/i2p/router/transport/crypto/DHSessionKeyBuilder.java b/router/java/src/net/i2p/router/transport/crypto/DHSessionKeyBuilder.java index 592d0f90f831d2ed6ddc14b01c196f3918538111..68ade63967c3cc8dcd52e3ebc2c65bee09adf083 100644 --- a/router/java/src/net/i2p/router/transport/crypto/DHSessionKeyBuilder.java +++ b/router/java/src/net/i2p/router/transport/crypto/DHSessionKeyBuilder.java @@ -17,7 +17,6 @@ import java.util.concurrent.LinkedBlockingQueue; import net.i2p.I2PAppContext; import net.i2p.I2PException; import net.i2p.crypto.CryptoConstants; -import net.i2p.crypto.KeyGenerator; import net.i2p.crypto.SHA256Generator; import net.i2p.data.ByteArray; //import net.i2p.data.DataHelper; @@ -470,7 +469,7 @@ public class DHSessionKeyBuilder { if (_log.shouldLog(Log.DEBUG)) _log.debug("DH Precalc (minimum: " + _minSize + " max: " + _maxSize + ", delay: " + _calcDelay + ")"); - _builders = new LinkedBlockingQueue(_maxSize); + _builders = new LinkedBlockingQueue<DHSessionKeyBuilder>(_maxSize); setPriority(Thread.MIN_PRIORITY); } diff --git a/router/java/src/net/i2p/router/transport/ntcp/NTCPConnection.java b/router/java/src/net/i2p/router/transport/ntcp/NTCPConnection.java index fb1a3ff69c90a1197b854db849171dc67c432c0c..d637901f54e4a75e64d85cb55680cdc1c3fa6eb3 100644 --- a/router/java/src/net/i2p/router/transport/ntcp/NTCPConnection.java +++ b/router/java/src/net/i2p/router/transport/ntcp/NTCPConnection.java @@ -6,7 +6,6 @@ import java.nio.ByteBuffer; import java.nio.channels.SelectionKey; import java.nio.channels.SocketChannel; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import java.util.Queue; import java.util.Set; @@ -30,7 +29,7 @@ import net.i2p.router.OutNetMessage; import net.i2p.router.Router; import net.i2p.router.RouterContext; import net.i2p.router.transport.FIFOBandwidthLimiter; -import net.i2p.router.util.CoDelPriorityBlockingQueue; +import net.i2p.router.transport.FIFOBandwidthLimiter.Request; import net.i2p.router.util.PriBlockingQueue; import net.i2p.util.ByteCache; import net.i2p.util.ConcurrentHashSet; @@ -170,12 +169,12 @@ class NTCPConnection { _transport = transport; _remAddr = null; _chan = chan; - _readBufs = new ConcurrentLinkedQueue(); - _writeBufs = new ConcurrentLinkedQueue(); - _bwInRequests = new ConcurrentHashSet(2); - _bwOutRequests = new ConcurrentHashSet(8); + _readBufs = new ConcurrentLinkedQueue<ByteBuffer>(); + _writeBufs = new ConcurrentLinkedQueue<ByteBuffer>(); + _bwInRequests = new ConcurrentHashSet<Request>(2); + _bwOutRequests = new ConcurrentHashSet<Request>(8); //_outbound = new CoDelPriorityBlockingQueue(ctx, "NTCP-Connection", 32); - _outbound = new PriBlockingQueue(ctx, "NTCP-Connection", 32); + _outbound = new PriBlockingQueue<OutNetMessage>(ctx, "NTCP-Connection", 32); _isInbound = true; _decryptBlockBuf = new byte[BLOCK_SIZE]; _curReadState = new ReadState(); @@ -198,12 +197,12 @@ class NTCPConnection { _transport = transport; _remotePeer = remotePeer; _remAddr = remAddr; - _readBufs = new ConcurrentLinkedQueue(); - _writeBufs = new ConcurrentLinkedQueue(); - _bwInRequests = new ConcurrentHashSet(2); - _bwOutRequests = new ConcurrentHashSet(8); + _readBufs = new ConcurrentLinkedQueue<ByteBuffer>(); + _writeBufs = new ConcurrentLinkedQueue<ByteBuffer>(); + _bwInRequests = new ConcurrentHashSet<Request>(2); + _bwOutRequests = new ConcurrentHashSet<Request>(8); //_outbound = new CoDelPriorityBlockingQueue(ctx, "NTCP-Connection", 32); - _outbound = new PriBlockingQueue(ctx, "NTCP-Connection", 32); + _outbound = new PriBlockingQueue<OutNetMessage>(ctx, "NTCP-Connection", 32); _isInbound = false; _establishState = new EstablishState(ctx, transport, this); _decryptBlockBuf = new byte[BLOCK_SIZE]; @@ -381,7 +380,7 @@ class NTCPConnection { EventPumper.releaseBuf(bb); } - List<OutNetMessage> pending = new ArrayList(); + List<OutNetMessage> pending = new ArrayList<OutNetMessage>(); //_outbound.drainAllTo(pending); _outbound.drainTo(pending); for (OutNetMessage msg : pending) { @@ -869,7 +868,7 @@ class NTCPConnection { NUM_PREP_BUFS = (int) Math.max(MIN_BUFS, Math.min(MAX_BUFS, 1 + (maxMemory / (16*1024*1024)))); } - private final static LinkedBlockingQueue<PrepBuffer> _bufs = new LinkedBlockingQueue(NUM_PREP_BUFS); + private final static LinkedBlockingQueue<PrepBuffer> _bufs = new LinkedBlockingQueue<PrepBuffer>(NUM_PREP_BUFS); /** * 32KB each @@ -1330,7 +1329,7 @@ class NTCPConnection { /** * FIXME static queue mixes handlers from different contexts in multirouter JVM */ - private final static LinkedBlockingQueue<I2NPMessageHandler> _i2npHandlers = new LinkedBlockingQueue(MAX_HANDLERS); + private final static LinkedBlockingQueue<I2NPMessageHandler> _i2npHandlers = new LinkedBlockingQueue<I2NPMessageHandler>(MAX_HANDLERS); private final static I2NPMessageHandler acquireHandler(RouterContext ctx) { I2NPMessageHandler rv = _i2npHandlers.poll(); diff --git a/router/java/src/net/i2p/router/transport/ntcp/NTCPTransport.java b/router/java/src/net/i2p/router/transport/ntcp/NTCPTransport.java index 884737b31d5f84525ec68770145de57a65bacb63..4392fdc2b63268c3f2c37902529f157b59e69bc6 100644 --- a/router/java/src/net/i2p/router/transport/ntcp/NTCPTransport.java +++ b/router/java/src/net/i2p/router/transport/ntcp/NTCPTransport.java @@ -12,7 +12,6 @@ import java.text.NumberFormat; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; -import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; @@ -31,7 +30,6 @@ import net.i2p.data.RouterInfo; import net.i2p.router.CommSystemFacade; import net.i2p.router.OutNetMessage; import net.i2p.router.RouterContext; -import net.i2p.router.transport.CommSystemFacadeImpl; import net.i2p.router.transport.Transport; import static net.i2p.router.transport.Transport.AddressSource.*; import net.i2p.router.transport.TransportBid; @@ -39,7 +37,6 @@ import net.i2p.router.transport.TransportImpl; import net.i2p.router.transport.TransportUtil; import static net.i2p.router.transport.TransportUtil.IPv6Config.*; import net.i2p.router.transport.crypto.DHSessionKeyBuilder; -import net.i2p.router.transport.udp.UDPTransport; import net.i2p.util.Addresses; import net.i2p.util.ConcurrentHashSet; import net.i2p.util.Log; @@ -170,10 +167,10 @@ public class NTCPTransport extends TransportImpl { _context.statManager().createRateStat("ntcp.wantsQueuedWrite", "", "ntcp", RATES); //_context.statManager().createRateStat("ntcp.write", "", "ntcp", RATES); _context.statManager().createRateStat("ntcp.writeError", "", "ntcp", RATES); - _endpoints = new HashSet(4); - _establishing = new ConcurrentHashSet(16); + _endpoints = new HashSet<InetSocketAddress>(4); + _establishing = new ConcurrentHashSet<NTCPConnection>(16); _conLock = new Object(); - _conByIdent = new ConcurrentHashMap(64); + _conByIdent = new ConcurrentHashMap<Hash, NTCPConnection>(64); _finisher = new NTCPSendFinisher(ctx, this); @@ -472,7 +469,7 @@ public class NTCPTransport extends TransportImpl { */ @Override public Vector<Long> getClockSkews() { - Vector<Long> skews = new Vector(); + Vector<Long> skews = new Vector<Long>(); for (NTCPConnection con : _conByIdent.values()) { if (con.isEstablished()) @@ -1088,7 +1085,7 @@ public class NTCPTransport extends TransportImpl { _finisher.stop(); List<NTCPConnection> cons; synchronized (_conLock) { - cons = new ArrayList(_conByIdent.values()); + cons = new ArrayList<NTCPConnection>(_conByIdent.values()); _conByIdent.clear(); } for (NTCPConnection con : cons) { @@ -1105,7 +1102,7 @@ public class NTCPTransport extends TransportImpl { @Override public void renderStatusHTML(java.io.Writer out, String urlBase, int sortFlags) throws IOException { - TreeSet<NTCPConnection> peers = new TreeSet(getComparator(sortFlags)); + TreeSet<NTCPConnection> peers = new TreeSet<NTCPConnection>(getComparator(sortFlags)); peers.addAll(_conByIdent.values()); long offsetTotal = 0; @@ -1220,8 +1217,8 @@ public class NTCPTransport extends TransportImpl { synchronized (_rateFmt) { return _rateFmt.format(rate); } } - private Comparator getComparator(int sortFlags) { - Comparator rv = null; + private Comparator<NTCPConnection> getComparator(int sortFlags) { + Comparator<NTCPConnection> rv = null; switch (Math.abs(sortFlags)) { default: rv = AlphaComparator.instance(); diff --git a/router/java/src/net/i2p/router/transport/ntcp/Reader.java b/router/java/src/net/i2p/router/transport/ntcp/Reader.java index 87f332f517c39b9b23627ab96bbfa194c92d4668..d16ea85b7da675e0a50a1e64e46a1fb334489c94 100644 --- a/router/java/src/net/i2p/router/transport/ntcp/Reader.java +++ b/router/java/src/net/i2p/router/transport/ntcp/Reader.java @@ -30,10 +30,10 @@ class Reader { public Reader(RouterContext ctx) { _context = ctx; _log = ctx.logManager().getLog(getClass()); - _pendingConnections = new LinkedHashSet(16); - _runners = new ArrayList(8); - _liveReads = new HashSet(8); - _readAfterLive = new HashSet(8); + _pendingConnections = new LinkedHashSet<NTCPConnection>(16); + _runners = new ArrayList<Runner>(8); + _liveReads = new HashSet<NTCPConnection>(8); + _readAfterLive = new HashSet<NTCPConnection>(8); } public synchronized void startReading(int numReaders) { diff --git a/router/java/src/net/i2p/router/transport/ntcp/Writer.java b/router/java/src/net/i2p/router/transport/ntcp/Writer.java index af5bcb0b987ac2afd6ed059d521e76734ba0a204..3a5eb1884b5218b22dcb000bf042379e0f9ef803 100644 --- a/router/java/src/net/i2p/router/transport/ntcp/Writer.java +++ b/router/java/src/net/i2p/router/transport/ntcp/Writer.java @@ -26,10 +26,10 @@ class Writer { public Writer(RouterContext ctx) { _log = ctx.logManager().getLog(getClass()); - _pendingConnections = new LinkedHashSet(16); - _runners = new ArrayList(5); - _liveWrites = new HashSet(5); - _writeAfterLive = new HashSet(5); + _pendingConnections = new LinkedHashSet<NTCPConnection>(16); + _runners = new ArrayList<Runner>(5); + _liveWrites = new HashSet<NTCPConnection>(5); + _writeAfterLive = new HashSet<NTCPConnection>(5); } public synchronized void startWriting(int numWriters) { diff --git a/router/java/src/net/i2p/router/transport/udp/ACKSender.java b/router/java/src/net/i2p/router/transport/udp/ACKSender.java index 8fef9c434297d7f6f540d53108462052f2e93a32..7d935530263069a1cd67a087d8afbd7f987e96b9 100644 --- a/router/java/src/net/i2p/router/transport/udp/ACKSender.java +++ b/router/java/src/net/i2p/router/transport/udp/ACKSender.java @@ -34,7 +34,7 @@ class ACKSender implements Runnable { _context = ctx; _log = ctx.logManager().getLog(ACKSender.class); _transport = transport; - _peersToACK = new LinkedBlockingQueue(); + _peersToACK = new LinkedBlockingQueue<PeerState>(); _builder = new PacketBuilder(_context, transport); _alive = true; _context.statManager().createRateStat("udp.sendACKCount", "how many ack messages were sent to a peer", "udp", UDPTransport.RATES); @@ -86,7 +86,7 @@ class ACKSender implements Runnable { public void run() { // we use a Set to strip out dups that come in on the Queue - Set<PeerState> notYet = new HashSet(); + Set<PeerState> notYet = new HashSet<PeerState>(); while (_alive) { PeerState peer = null; long now = 0; diff --git a/router/java/src/net/i2p/router/transport/udp/EstablishmentManager.java b/router/java/src/net/i2p/router/transport/udp/EstablishmentManager.java index 05dd8c60231fa23475f19a6d8dfc73a3787cbefe..47d25f9714be45d93e6c98e53ebf79d07ab9b199 100644 --- a/router/java/src/net/i2p/router/transport/udp/EstablishmentManager.java +++ b/router/java/src/net/i2p/router/transport/udp/EstablishmentManager.java @@ -9,8 +9,6 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import net.i2p.data.Base64; -import net.i2p.data.DataHelper; import net.i2p.data.Hash; import net.i2p.data.RouterAddress; import net.i2p.data.RouterIdentity; @@ -127,12 +125,12 @@ class EstablishmentManager { _log = ctx.logManager().getLog(EstablishmentManager.class); _transport = transport; _builder = new PacketBuilder(ctx, transport); - _inboundStates = new ConcurrentHashMap(); - _outboundStates = new ConcurrentHashMap(); - _queuedOutbound = new ConcurrentHashMap(); - _liveIntroductions = new ConcurrentHashMap(); - _outboundByClaimedAddress = new ConcurrentHashMap(); - _outboundByHash = new ConcurrentHashMap(); + _inboundStates = new ConcurrentHashMap<RemoteHostId, InboundEstablishState>(); + _outboundStates = new ConcurrentHashMap<RemoteHostId, OutboundEstablishState>(); + _queuedOutbound = new ConcurrentHashMap<RemoteHostId, List<OutNetMessage>>(); + _liveIntroductions = new ConcurrentHashMap<Long, OutboundEstablishState>(); + _outboundByClaimedAddress = new ConcurrentHashMap<RemoteHostId, OutboundEstablishState>(); + _outboundByHash = new ConcurrentHashMap<Hash, OutboundEstablishState>(); _activityLock = new Object(); DEFAULT_MAX_CONCURRENT_ESTABLISH = Math.max(DEFAULT_LOW_MAX_CONCURRENT_ESTABLISH, Math.min(DEFAULT_HIGH_MAX_CONCURRENT_ESTABLISH, @@ -312,7 +310,7 @@ class EstablishmentManager { if (_queuedOutbound.size() >= MAX_QUEUED_OUTBOUND && !_queuedOutbound.containsKey(to)) { rejected = true; } else { - List<OutNetMessage> newQueued = new ArrayList(MAX_QUEUED_PER_PEER); + List<OutNetMessage> newQueued = new ArrayList<OutNetMessage>(MAX_QUEUED_PER_PEER); List<OutNetMessage> queued = _queuedOutbound.putIfAbsent(to, newQueued); if (queued == null) { queued = newQueued; @@ -622,7 +620,7 @@ class EstablishmentManager { } RemoteHostId to = entry.getKey(); List<OutNetMessage> allQueued = entry.getValue(); - List<OutNetMessage> queued = new ArrayList(); + List<OutNetMessage> queued = new ArrayList<OutNetMessage>(); long now = _context.clock().now(); synchronized (allQueued) { for (OutNetMessage msg : allQueued) { diff --git a/router/java/src/net/i2p/router/transport/udp/IPThrottler.java b/router/java/src/net/i2p/router/transport/udp/IPThrottler.java index 1308c2e70764c0c3306f643fea8c3e2ec2a4c734..782988ec3e9cb3082168add2e711c4a7b7bcea85 100644 --- a/router/java/src/net/i2p/router/transport/udp/IPThrottler.java +++ b/router/java/src/net/i2p/router/transport/udp/IPThrottler.java @@ -16,7 +16,7 @@ class IPThrottler { public IPThrottler(int max, long time) { _max = max; - _counter = new ObjectCounter(); + _counter = new ObjectCounter<Integer>(); SimpleScheduler.getInstance().addPeriodicEvent(new Cleaner(), time); } diff --git a/router/java/src/net/i2p/router/transport/udp/InboundEstablishState.java b/router/java/src/net/i2p/router/transport/udp/InboundEstablishState.java index d69e9b76d9aba6513ddb0f47af5a86b486877e28..2d545de7a290a16f74c54c72f6503635a2faf000 100644 --- a/router/java/src/net/i2p/router/transport/udp/InboundEstablishState.java +++ b/router/java/src/net/i2p/router/transport/udp/InboundEstablishState.java @@ -98,7 +98,7 @@ class InboundEstablishState { _currentState = InboundState.IB_STATE_UNKNOWN; _establishBegin = ctx.clock().now(); _keyBuilder = dh; - _queuedMessages = new LinkedBlockingQueue(); + _queuedMessages = new LinkedBlockingQueue<OutNetMessage>(); } public synchronized InboundState getState() { return _currentState; } diff --git a/router/java/src/net/i2p/router/transport/udp/IntroductionManager.java b/router/java/src/net/i2p/router/transport/udp/IntroductionManager.java index 03b70e2a7d7d6939751d45566112c3e6c05fa406..01ae042caab4766d540911c61e4ff2c3b65117e3 100644 --- a/router/java/src/net/i2p/router/transport/udp/IntroductionManager.java +++ b/router/java/src/net/i2p/router/transport/udp/IntroductionManager.java @@ -11,12 +11,10 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import net.i2p.data.Base64; -import net.i2p.data.DataHelper; import net.i2p.data.RouterAddress; import net.i2p.data.RouterInfo; import net.i2p.data.SessionKey; import net.i2p.router.RouterContext; -import net.i2p.router.transport.TransportImpl; import net.i2p.util.Addresses; import net.i2p.util.ConcurrentHashSet; import net.i2p.util.Log; @@ -104,9 +102,9 @@ class IntroductionManager { _log = ctx.logManager().getLog(IntroductionManager.class); _transport = transport; _builder = new PacketBuilder(ctx, transport); - _outbound = new ConcurrentHashMap(MAX_OUTBOUND); - _inbound = new ConcurrentHashSet(MAX_INBOUND); - _recentHolePunches = new HashSet(16); + _outbound = new ConcurrentHashMap<Long, PeerState>(MAX_OUTBOUND); + _inbound = new ConcurrentHashSet<PeerState>(MAX_INBOUND); + _recentHolePunches = new HashSet<InetAddress>(16); ctx.statManager().createRateStat("udp.receiveRelayIntro", "How often we get a relayed request for us to talk to someone?", "udp", UDPTransport.RATES); ctx.statManager().createRateStat("udp.receiveRelayRequest", "How often we receive a good request to relay to someone else?", "udp", UDPTransport.RATES); ctx.statManager().createRateStat("udp.receiveRelayRequestBadTag", "Received relay requests with bad/expired tag", "udp", UDPTransport.RATES); @@ -169,7 +167,7 @@ class IntroductionManager { if (_log.shouldLog(Log.DEBUG)) _log.debug("Picking inbound out of " + _inbound.size()); if (_inbound.isEmpty()) return 0; - List<PeerState> peers = new ArrayList(_inbound); + List<PeerState> peers = new ArrayList<PeerState>(_inbound); int sz = peers.size(); start = start % sz; int found = 0; diff --git a/router/java/src/net/i2p/router/transport/udp/MessageReceiver.java b/router/java/src/net/i2p/router/transport/udp/MessageReceiver.java index c0fa2eea2ba0921baeb948df4195bf1fac746e5e..74dba836b2674964a8f5b92752da6cc227b2cb4b 100644 --- a/router/java/src/net/i2p/router/transport/udp/MessageReceiver.java +++ b/router/java/src/net/i2p/router/transport/udp/MessageReceiver.java @@ -54,7 +54,7 @@ class MessageReceiver { _threadCount = Math.max(MIN_THREADS, Math.min(MAX_THREADS, ctx.bandwidthLimiter().getInboundKBytesPerSecond() / 20)); qsize = (int) Math.max(MIN_QUEUE_SIZE, Math.min(MAX_QUEUE_SIZE, maxMemory / (2*1024*1024))); } - _completeMessages = new CoDelBlockingQueue(ctx, "UDP-MessageReceiver", qsize); + _completeMessages = new CoDelBlockingQueue<InboundMessageState>(ctx, "UDP-MessageReceiver", qsize); // the runners run forever, no need to have a cache //_cache = ByteCache.getInstance(64, I2NPMessage.MAX_SIZE); diff --git a/router/java/src/net/i2p/router/transport/udp/OutboundEstablishState.java b/router/java/src/net/i2p/router/transport/udp/OutboundEstablishState.java index 9b0a55221cb76484086c5efe443ee33735596098..9d14a4a23d8c51c707d53e60763deb64500b1975 100644 --- a/router/java/src/net/i2p/router/transport/udp/OutboundEstablishState.java +++ b/router/java/src/net/i2p/router/transport/udp/OutboundEstablishState.java @@ -1,6 +1,5 @@ package net.i2p.router.transport.udp; -import java.net.InetAddress; import java.util.Queue; import java.util.concurrent.LinkedBlockingQueue; @@ -116,7 +115,7 @@ class OutboundEstablishState { _remoteHostId = remoteHostId; _remotePeer = remotePeer; _introKey = introKey; - _queuedMessages = new LinkedBlockingQueue(); + _queuedMessages = new LinkedBlockingQueue<OutNetMessage>(); _establishBegin = ctx.clock().now(); _remoteAddress = addr; _introductionNonce = -1; diff --git a/router/java/src/net/i2p/router/transport/udp/OutboundMessageFragments.java b/router/java/src/net/i2p/router/transport/udp/OutboundMessageFragments.java index 3feaa8e6ab5c3fa665852d52d5d853f378cb2f5d..034f3e60548e10671f2ca013e842cbe211a9e2ed 100644 --- a/router/java/src/net/i2p/router/transport/udp/OutboundMessageFragments.java +++ b/router/java/src/net/i2p/router/transport/udp/OutboundMessageFragments.java @@ -7,7 +7,6 @@ import java.util.Set; import net.i2p.data.Hash; import net.i2p.data.RouterInfo; -import net.i2p.data.i2np.I2NPMessage; import net.i2p.router.OutNetMessage; import net.i2p.router.RouterContext; import net.i2p.util.ConcurrentHashSet; @@ -68,7 +67,7 @@ class OutboundMessageFragments { _log = ctx.logManager().getLog(OutboundMessageFragments.class); _transport = transport; // _throttle = throttle; - _activePeers = new ConcurrentHashSet(256); + _activePeers = new ConcurrentHashSet<PeerState>(256); _builder = new PacketBuilder(ctx, transport); _alive = true; // _allowExcess = false; @@ -363,12 +362,12 @@ class OutboundMessageFragments { List<Long> msgIds = peer.getCurrentFullACKs(); int newFullAckCount = msgIds.size(); msgIds.addAll(peer.getCurrentResendACKs()); - List<ACKBitfield> partialACKBitfields = new ArrayList(); + List<ACKBitfield> partialACKBitfields = new ArrayList<ACKBitfield>(); peer.fetchPartialACKs(partialACKBitfields); int piggybackedPartialACK = partialACKBitfields.size(); // getCurrentFullACKs() already makes a copy, do we need to copy again? // YES because buildPacket() now removes them (maybe) - List<Long> remaining = new ArrayList(msgIds); + List<Long> remaining = new ArrayList<Long>(msgIds); int sparseCount = 0; UDPPacket rv[] = new UDPPacket[fragments]; //sparse for (int i = 0; i < fragments; i++) { diff --git a/router/java/src/net/i2p/router/transport/udp/PacketBuilder.java b/router/java/src/net/i2p/router/transport/udp/PacketBuilder.java index e16b34daaded42b105bcb0c3003c953ab7785b79..647c207ae2489fbb367115e4b22614c145e6d982 100644 --- a/router/java/src/net/i2p/router/transport/udp/PacketBuilder.java +++ b/router/java/src/net/i2p/router/transport/udp/PacketBuilder.java @@ -11,7 +11,6 @@ import java.util.List; import net.i2p.I2PAppContext; import net.i2p.data.Base64; -import net.i2p.data.ByteArray; import net.i2p.data.DataHelper; import net.i2p.data.Hash; import net.i2p.data.RouterIdentity; @@ -443,7 +442,7 @@ class PacketBuilder { * It doesn't generate a reply, but that's ok. */ public UDPPacket buildPing(PeerState peer) { - return buildACK(peer, Collections.EMPTY_LIST); + return buildACK(peer, Collections.<ACKBitfield> emptyList()); } /** @@ -1082,7 +1081,7 @@ class PacketBuilder { public List<UDPPacket> buildRelayRequest(UDPTransport transport, OutboundEstablishState state, SessionKey ourIntroKey) { UDPAddress addr = state.getRemoteAddress(); int count = addr.getIntroducerCount(); - List<UDPPacket> rv = new ArrayList(count); + List<UDPPacket> rv = new ArrayList<UDPPacket>(count); for (int i = 0; i < count; i++) { InetAddress iaddr = addr.getIntroducerHost(i); int iport = addr.getIntroducerPort(i); @@ -1095,7 +1094,7 @@ class PacketBuilder { iaddr.getAddress().length != 4 || (!_transport.isValid(iaddr.getAddress())) || (Arrays.equals(iaddr.getAddress(), _transport.getExternalIP()) && !_transport.allowLocal())) { - if (_log.shouldLog(_log.WARN)) + if (_log.shouldLog(Log.WARN)) _log.warn("Cannot build a relay request to " + state.getRemoteIdentity().calculateHash() + ", as their UDP address is invalid: addr=" + addr + " index=" + i); // TODO implement some sort of introducer banlist diff --git a/router/java/src/net/i2p/router/transport/udp/PacketHandler.java b/router/java/src/net/i2p/router/transport/udp/PacketHandler.java index 5a9c6eaf65e2a7d427a3fb83f2877ef3ea71f11b..5d3df1926ab5c38bcf21c7192e79146c82155700 100644 --- a/router/java/src/net/i2p/router/transport/udp/PacketHandler.java +++ b/router/java/src/net/i2p/router/transport/udp/PacketHandler.java @@ -56,11 +56,11 @@ class PacketHandler { _inbound = inbound; _testManager = testManager; _introManager = introManager; - _failCache = new LHMCache(24); + _failCache = new LHMCache<RemoteHostId, Object>(24); long maxMemory = SystemVersion.getMaxMemory(); int qsize = (int) Math.max(MIN_QUEUE_SIZE, Math.min(MAX_QUEUE_SIZE, maxMemory / (2*1024*1024))); - _inboundQueue = new CoDelBlockingQueue(ctx, "UDP-Receiver", qsize); + _inboundQueue = new CoDelBlockingQueue<UDPPacket>(ctx, "UDP-Receiver", qsize); int num_handlers; if (maxMemory < 32*1024*1024) num_handlers = 1; diff --git a/router/java/src/net/i2p/router/transport/udp/PeerState.java b/router/java/src/net/i2p/router/transport/udp/PeerState.java index 65e236019e7260441d5f0aadf9516165b4968e75..feb471abb02de2cfd7b11bc2c1768c71f717654a 100644 --- a/router/java/src/net/i2p/router/transport/udp/PeerState.java +++ b/router/java/src/net/i2p/router/transport/udp/PeerState.java @@ -312,8 +312,8 @@ class PeerState { _currentReceiveSecond = now - (now % 1000); _lastSendTime = now; _lastReceiveTime = now; - _currentACKs = new ConcurrentHashSet(); - _currentACKsResend = new LinkedBlockingQueue(); + _currentACKs = new ConcurrentHashSet<Long>(); + _currentACKsResend = new LinkedBlockingQueue<Long>(); _sendWindowBytes = DEFAULT_SEND_WINDOW_BYTES; _sendWindowBytesRemaining = DEFAULT_SEND_WINDOW_BYTES; _slowStartThreshold = MAX_SEND_WINDOW_BYTES/2; @@ -335,10 +335,10 @@ class PeerState { _rto = INIT_RTO; _rtt = INIT_RTT; _rttDeviation = _rtt; - _inboundMessages = new HashMap(8); + _inboundMessages = new HashMap<Long, InboundMessageState>(8); _outboundMessages = new CachedIteratorArrayList<OutboundMessageState>(32); //_outboundQueue = new CoDelPriorityBlockingQueue(ctx, "UDP-PeerState", 32); - _outboundQueue = new PriBlockingQueue(ctx, "UDP-PeerState", 32); + _outboundQueue = new PriBlockingQueue<OutboundMessageState>(ctx, "UDP-PeerState", 32); // all createRateStat() moved to EstablishmentManager _remoteIP = remoteIP; _remotePeer = remotePeer; @@ -820,7 +820,7 @@ class PeerState { */ public List<Long> getCurrentFullACKs() { // no such element exception seen here - List<Long> rv = new ArrayList(_currentACKs); + List<Long> rv = new ArrayList<Long>(_currentACKs); //if (_log.shouldLog(Log.DEBUG)) // _log.debug("Returning " + _currentACKs.size() + " current acks"); return rv; @@ -841,7 +841,7 @@ class PeerState { * @since 0.8.12 was included in getCurrentFullACKs() */ public List<Long> getCurrentResendACKs() { - List<Long> randomResends = new ArrayList(_currentACKsResend); + List<Long> randomResends = new ArrayList<Long>(_currentACKsResend); Collections.shuffle(randomResends, _context.random()); //if (_log.shouldLog(Log.DEBUG)) // _log.debug("Returning " + randomResends.size() + " resend acks"); @@ -915,10 +915,10 @@ class PeerState { maxResendAcks = MAX_RESEND_ACKS_SMALL; else maxResendAcks = MAX_RESEND_ACKS_LARGE; - List<ACKBitfield> rv = new ArrayList(maxResendAcks); + List<ACKBitfield> rv = new ArrayList<ACKBitfield>(maxResendAcks); // save to add to currentACKsResend later so we don't include twice - List<Long> currentACKsRemoved = new ArrayList(_currentACKs.size()); + List<Long> currentACKsRemoved = new ArrayList<Long>(_currentACKs.size()); // As explained above, we include the acks in any order // since we are unlikely to get backed up - // just take them using the Set iterator. @@ -934,7 +934,7 @@ class PeerState { if (_currentACKs.isEmpty()) _wantACKSendSince = -1; if (alwaysIncludeRetransmissions || !rv.isEmpty()) { - List<Long> randomResends = new ArrayList(_currentACKsResend); + List<Long> randomResends = new ArrayList<Long>(_currentACKsResend); // now repeat by putting in some old ACKs // randomly selected from the Resend queue. // Maybe we should only resend each one a certain number of times... @@ -968,7 +968,7 @@ class PeerState { // ok, there's room to *try* to fit in some partial ACKs, so // we should try to find some packets to partially ACK // (preferably the ones which have the most received fragments) - List<ACKBitfield> partial = new ArrayList(); + List<ACKBitfield> partial = new ArrayList<ACKBitfield>(); fetchPartialACKs(partial); // we may not be able to use them all, but lets try... for (int i = 0; (bytesRemaining > 4) && (i < partial.size()); i++) { @@ -1432,7 +1432,7 @@ class PeerState { List<OutboundMessageState> tempList; synchronized (_outboundMessages) { _retransmitter = null; - tempList = new ArrayList(_outboundMessages); + tempList = new ArrayList<OutboundMessageState>(_outboundMessages); _outboundMessages.clear(); } //_outboundQueue.drainAllTo(tempList); @@ -1481,21 +1481,21 @@ class PeerState { iter.remove(); if (_retransmitter == state) _retransmitter = null; - if (succeeded == null) succeeded = new ArrayList(4); + if (succeeded == null) succeeded = new ArrayList<OutboundMessageState>(4); succeeded.add(state); } else if (state.isExpired()) { iter.remove(); if (_retransmitter == state) _retransmitter = null; _context.statManager().addRateData("udp.sendFailed", state.getPushCount()); - if (failed == null) failed = new ArrayList(4); + if (failed == null) failed = new ArrayList<OutboundMessageState>(4); failed.add(state); } else if (state.getPushCount() > OutboundMessageFragments.MAX_VOLLEYS) { iter.remove(); if (state == _retransmitter) _retransmitter = null; _context.statManager().addRateData("udp.sendAggressiveFailed", state.getPushCount()); - if (failed == null) failed = new ArrayList(4); + if (failed == null) failed = new ArrayList<OutboundMessageState>(4); failed.add(state); } // end (pushCount > maxVolleys) } // end iterating over outbound messages @@ -1913,7 +1913,7 @@ class PeerState { _sendWindowBytes = oldPeer._sendWindowBytes; oldPeer._dead = true; - List<Long> tmp = new ArrayList(); + List<Long> tmp = new ArrayList<Long>(); // AIOOBE from concurrent access //tmp.addAll(oldPeer._currentACKs); for (Long l : oldPeer._currentACKs) { @@ -1933,7 +1933,7 @@ class PeerState { _currentACKsResend.addAll(tmp); } - Map<Long, InboundMessageState> msgs = new HashMap(); + Map<Long, InboundMessageState> msgs = new HashMap<Long, InboundMessageState>(); synchronized (oldPeer._inboundMessages) { msgs.putAll(oldPeer._inboundMessages); oldPeer._inboundMessages.clear(); @@ -1943,7 +1943,7 @@ class PeerState { } msgs.clear(); - List<OutboundMessageState> tmp2 = new ArrayList(); + List<OutboundMessageState> tmp2 = new ArrayList<OutboundMessageState>(); OutboundMessageState retransmitter = null; synchronized (oldPeer._outboundMessages) { tmp2.addAll(oldPeer._outboundMessages); diff --git a/router/java/src/net/i2p/router/transport/udp/PeerTestManager.java b/router/java/src/net/i2p/router/transport/udp/PeerTestManager.java index ffc512654b79188d990e2bdb3ac4e0ea13bcc003..ba80cb35a86594616db904548bde012ace411941 100644 --- a/router/java/src/net/i2p/router/transport/udp/PeerTestManager.java +++ b/router/java/src/net/i2p/router/transport/udp/PeerTestManager.java @@ -17,7 +17,6 @@ import net.i2p.router.RouterContext; import static net.i2p.router.transport.udp.PeerTestState.Role.*; import net.i2p.util.Addresses; import net.i2p.util.Log; -import net.i2p.util.SimpleScheduler; import net.i2p.util.SimpleTimer; /** @@ -161,8 +160,8 @@ class PeerTestManager { _context = context; _transport = transport; _log = context.logManager().getLog(PeerTestManager.class); - _activeTests = new ConcurrentHashMap(); - _recentTests = new LinkedBlockingQueue(); + _activeTests = new ConcurrentHashMap<Long, PeerTestState>(); + _recentTests = new LinkedBlockingQueue<Long>(); _packetBuilder = new PacketBuilder(context, transport); _throttle = new IPThrottler(MAX_PER_IP, THROTTLE_CLEAN_TIME); _context.statManager().createRateStat("udp.statusKnownCharlie", "How often the bob we pick passes us to a charlie we already have a session with?", "udp", UDPTransport.RATES); diff --git a/router/java/src/net/i2p/router/transport/udp/RemoteHostId.java b/router/java/src/net/i2p/router/transport/udp/RemoteHostId.java index 7f4b2fa4b2afeceb9547126404beee2f2a08158c..df5f37591724f51bdd8d30b3daa0bf25aa5897dd 100644 --- a/router/java/src/net/i2p/router/transport/udp/RemoteHostId.java +++ b/router/java/src/net/i2p/router/transport/udp/RemoteHostId.java @@ -1,6 +1,5 @@ package net.i2p.router.transport.udp; -import net.i2p.data.Base64; import net.i2p.data.DataHelper; import net.i2p.data.Hash; import net.i2p.util.Addresses; diff --git a/router/java/src/net/i2p/router/transport/udp/TimedWeightedPriorityMessageQueue.java b/router/java/src/net/i2p/router/transport/udp/TimedWeightedPriorityMessageQueue.java index 2973f89934d6a53a109851f505fce6bd1a0e18a5..3f03c133fc2cc3bfc740f8e0616775d9d2ffc570 100644 --- a/router/java/src/net/i2p/router/transport/udp/TimedWeightedPriorityMessageQueue.java +++ b/router/java/src/net/i2p/router/transport/udp/TimedWeightedPriorityMessageQueue.java @@ -24,7 +24,7 @@ class TimedWeightedPriorityMessageQueue implements MessageQueue, OutboundMessage private RouterContext _context; private Log _log; /** FIFO queue of messages in a particular priority */ - private List _queue[]; + private List<OutNetMessage> _queue[]; /** all messages in the indexed queue are at or below the given priority. */ private int _priorityLimits[]; /** weighting for each queue */ @@ -46,7 +46,7 @@ class TimedWeightedPriorityMessageQueue implements MessageQueue, OutboundMessage private Expirer _expirer; private FailedListener _listener; /** set of peers (Hash) whose congestion window is exceeded in the active queue */ - private Set _chokedPeers; + private Set<Hash> _chokedPeers; /** * Build up a new queue @@ -67,7 +67,7 @@ class TimedWeightedPriorityMessageQueue implements MessageQueue, OutboundMessage _bytesTransferred = new long[weighting.length]; _messagesFlushed = new int[weighting.length]; for (int i = 0; i < weighting.length; i++) { - _queue[i] = new ArrayList(8); + _queue[i] = new ArrayList<OutNetMessage>(8); _weighting[i] = weighting[i]; _priorityLimits[i] = priorityLimits[i]; _messagesFlushed[i] = 0; @@ -76,7 +76,7 @@ class TimedWeightedPriorityMessageQueue implements MessageQueue, OutboundMessage } _alive = true; _nextLock = this; - _chokedPeers = Collections.synchronizedSet(new HashSet(16)); + _chokedPeers = Collections.synchronizedSet(new HashSet<Hash>(16)); _listener = lsnr; _context.statManager().createRateStat("udp.timeToEntrance", "Message lifetime until it reaches the UDP system", "udp", UDPTransport.RATES); _context.statManager().createRateStat("udp.messageQueueSize", "How many messages are on the current class queue at removal", "udp", UDPTransport.RATES); @@ -233,7 +233,7 @@ class TimedWeightedPriorityMessageQueue implements MessageQueue, OutboundMessage */ private class Expirer implements Runnable { public void run() { - List removed = new ArrayList(1); + List<OutNetMessage> removed = new ArrayList<OutNetMessage>(1); while (_alive) { long now = _context.clock().now(); for (int i = 0; i < _queue.length; i++) { diff --git a/router/java/src/net/i2p/router/transport/udp/UDPAddress.java b/router/java/src/net/i2p/router/transport/udp/UDPAddress.java index 962ad31fad85ebf0fc3f1b976d97e73860aaa00f..8cc279fec7ac52b3c07ef30d86f14f8dc77cc344 100644 --- a/router/java/src/net/i2p/router/transport/udp/UDPAddress.java +++ b/router/java/src/net/i2p/router/transport/udp/UDPAddress.java @@ -229,7 +229,7 @@ class UDPAddress { long max = 2048; // 512 nominal for 128 MB int size = (int) Math.max(min, Math.min(max, 1 + (maxMemory / (256*1024)))); - _inetAddressCache = new LHMCache(size); + _inetAddressCache = new LHMCache<String, InetAddress>(size); } /** diff --git a/router/java/src/net/i2p/router/transport/udp/UDPPacket.java b/router/java/src/net/i2p/router/transport/udp/UDPPacket.java index 741aad8cae3e6247ab308eab8f6e0c6f7fa00ca5..a3cdf57a007c92187b80181139f7ef3bdbb6e0e5 100644 --- a/router/java/src/net/i2p/router/transport/udp/UDPPacket.java +++ b/router/java/src/net/i2p/router/transport/udp/UDPPacket.java @@ -51,7 +51,7 @@ class UDPPacket implements CDQEntry { if (CACHE) { long maxMemory = SystemVersion.getMaxMemory(); int csize = (int) Math.max(MIN_CACHE_SIZE, Math.min(MAX_CACHE_SIZE, maxMemory / (1024*1024))); - _packetCache = new LinkedBlockingQueue(csize); + _packetCache = new LinkedBlockingQueue<UDPPacket>(csize); } else { _packetCache = null; } diff --git a/router/java/src/net/i2p/router/transport/udp/UDPReceiver.java b/router/java/src/net/i2p/router/transport/udp/UDPReceiver.java index d8976d483eb8bd733af2949e657f67af0dc04923..be5b97dcf830cd5d06c1da20dfe9627ab4d17ebe 100644 --- a/router/java/src/net/i2p/router/transport/udp/UDPReceiver.java +++ b/router/java/src/net/i2p/router/transport/udp/UDPReceiver.java @@ -8,7 +8,6 @@ import net.i2p.router.RouterContext; import net.i2p.router.transport.FIFOBandwidthLimiter; import net.i2p.util.I2PThread; import net.i2p.util.Log; -import net.i2p.util.SimpleTimer; import net.i2p.util.SystemVersion; /** diff --git a/router/java/src/net/i2p/router/transport/udp/UDPSender.java b/router/java/src/net/i2p/router/transport/udp/UDPSender.java index c5aecf62727568be139dbc8ed1bb36bbbc0a9137..491be44b825386a2c2a4a3d6fc8601282b9b881b 100644 --- a/router/java/src/net/i2p/router/transport/udp/UDPSender.java +++ b/router/java/src/net/i2p/router/transport/udp/UDPSender.java @@ -40,7 +40,7 @@ class UDPSender { _log = ctx.logManager().getLog(UDPSender.class); long maxMemory = SystemVersion.getMaxMemory(); int qsize = (int) Math.max(MIN_QUEUE_SIZE, Math.min(MAX_QUEUE_SIZE, maxMemory / (1024*1024))); - _outboundQueue = new CoDelBlockingQueue(ctx, "UDP-Sender", qsize); + _outboundQueue = new CoDelBlockingQueue<UDPPacket>(ctx, "UDP-Sender", qsize); _socket = socket; _runner = new Runner(); _name = name; diff --git a/router/java/src/net/i2p/router/transport/udp/UDPTransport.java b/router/java/src/net/i2p/router/transport/udp/UDPTransport.java index bf53ca93a18aba8192fdea7f656e28e1747503ff..d934476cfdb9e0bbdfd45f84a9699a14bb4cbec3 100644 --- a/router/java/src/net/i2p/router/transport/udp/UDPTransport.java +++ b/router/java/src/net/i2p/router/transport/udp/UDPTransport.java @@ -14,7 +14,6 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Properties; import java.util.Set; import java.util.TreeSet; import java.util.Vector; @@ -48,7 +47,6 @@ import net.i2p.util.Addresses; import net.i2p.util.ConcurrentHashSet; import net.i2p.util.Log; import net.i2p.util.OrderedProperties; -import net.i2p.util.SimpleScheduler; import net.i2p.util.SimpleTimer; import net.i2p.util.SimpleTimer2; @@ -212,10 +210,10 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority super(ctx); _dhFactory = dh; _log = ctx.logManager().getLog(UDPTransport.class); - _peersByIdent = new ConcurrentHashMap(128); - _peersByRemoteHost = new ConcurrentHashMap(128); - _dropList = new ConcurrentHashSet(2); - _endpoints = new CopyOnWriteArrayList(); + _peersByIdent = new ConcurrentHashMap<Hash, PeerState>(128); + _peersByRemoteHost = new ConcurrentHashMap<RemoteHostId, PeerState>(128); + _dropList = new ConcurrentHashSet<RemoteHostId>(2); + _endpoints = new CopyOnWriteArrayList<UDPEndpoint>(); // See comments in DummyThrottle.java if (USE_PRIORITY) { @@ -280,7 +278,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority int port = getRequestedPort(); if (port < 0) { port = UDPEndpoint.selectRandomPort(_context); - Map<String, String> changes = new HashMap(); + Map<String, String> changes = new HashMap<String, String>(); changes.put(PROP_INTERNAL_PORT, Integer.toString(port)); changes.put(PROP_EXTERNAL_PORT, Integer.toString(port)); _context.router().saveConfig(changes, null); @@ -330,7 +328,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority } } - List<InetAddress> bindToAddrs = new ArrayList(4); + List<InetAddress> bindToAddrs = new ArrayList<InetAddress>(4); if (bindTo != null) { String[] bta = bindTo.split("[,; \r\n\t]"); for (int i = 0; i < bta.length; i++) { @@ -860,7 +858,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority _context.statManager().addRateData("udp.addressTestInsteadOfUpdate", 1); } else if (updated) { _context.statManager().addRateData("udp.addressUpdated", 1); - Map<String, String> changes = new HashMap(); + Map<String, String> changes = new HashMap<String, String>(); if (ourIP.length == 4 && !fixedPort) changes.put(PROP_EXTERNAL_PORT, Integer.toString(ourPort)); // queue a country code lookup of the new IP @@ -975,7 +973,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority * @since 0.9.3 */ List<PeerState> getPeerStatesByIP(RemoteHostId hostInfo) { - List<PeerState> rv = new ArrayList(4); + List<PeerState> rv = new ArrayList<PeerState>(4); byte[] ip = hostInfo.getIP(); if (ip != null && ip.length == 4) { for (PeerState ps : _peersByIdent.values()) { @@ -2160,7 +2158,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority */ @Override public Vector<Long> getClockSkews() { - Vector<Long> skews = new Vector(); + Vector<Long> skews = new Vector<Long>(); // If our clock is way off, we may not have many (or any) successful connections, // so try hard in that case to return good data @@ -2213,8 +2211,8 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority private static final int FLAG_UPTIME = 16; private static final int FLAG_DEBUG = 99; - private static Comparator getComparator(int sortFlags) { - Comparator rv = null; + private static Comparator<PeerState> getComparator(int sortFlags) { + Comparator<PeerState> rv = null; switch (Math.abs(sortFlags)) { case FLAG_IDLE_IN: rv = IdleInComparator.instance(); @@ -2503,7 +2501,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority @Override public void renderStatusHTML(Writer out, String urlBase, int sortFlags) throws IOException { - TreeSet<PeerState> peers = new TreeSet(getComparator(sortFlags)); + TreeSet<PeerState> peers = new TreeSet<PeerState>(getComparator(sortFlags)); peers.addAll(_peersByIdent.values()); long offsetTotal = 0; @@ -2844,8 +2842,8 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority public ExpirePeerEvent() { super(_context.simpleTimer2()); - _expirePeers = new ConcurrentHashSet(128); - _expireBuffer = new ArrayList(); + _expirePeers = new ConcurrentHashSet<PeerState>(128); + _expireBuffer = new ArrayList<PeerState>(); } public void timeReached() { @@ -3039,8 +3037,8 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority PeerState pickTestPeer(PeerTestState.Role peerRole, RemoteHostId dontInclude) { if (peerRole == ALICE) throw new IllegalArgumentException(); - List<PeerState> peers = new ArrayList(_peersByIdent.values()); - for (Iterator<PeerState> iter = new RandomIterator(peers); iter.hasNext(); ) { + List<PeerState> peers = new ArrayList<PeerState>(_peersByIdent.values()); + for (Iterator<PeerState> iter = new RandomIterator<PeerState>(peers); iter.hasNext(); ) { PeerState peer = iter.next(); if ( (dontInclude != null) && (dontInclude.equals(peer.getRemoteHostId())) ) continue; diff --git a/router/java/src/net/i2p/router/tunnel/BloomFilterIVValidator.java b/router/java/src/net/i2p/router/tunnel/BloomFilterIVValidator.java index c80f51f57c9e063bdbca4a801ac13f285c2e779b..578390aa3311d1ce1a7bb6cae70c21bde15cc73f 100644 --- a/router/java/src/net/i2p/router/tunnel/BloomFilterIVValidator.java +++ b/router/java/src/net/i2p/router/tunnel/BloomFilterIVValidator.java @@ -1,6 +1,5 @@ package net.i2p.router.tunnel; -import net.i2p.data.ByteArray; import net.i2p.data.DataHelper; import net.i2p.router.RouterContext; import net.i2p.router.util.DecayingBloomFilter; diff --git a/router/java/src/net/i2p/router/tunnel/BuildMessageGenerator.java b/router/java/src/net/i2p/router/tunnel/BuildMessageGenerator.java index ac79df401625933b1f180fb828fdcbd40b71c7ac..e956f4364bd7f4bce3830d227fdd5af05a95af1c 100644 --- a/router/java/src/net/i2p/router/tunnel/BuildMessageGenerator.java +++ b/router/java/src/net/i2p/router/tunnel/BuildMessageGenerator.java @@ -143,7 +143,7 @@ public abstract class BuildMessageGenerator { * Encrypt the records so their hop ident is visible at the appropriate times * @param order list of hop #s as Integers. For instance, if (order.get(1) is 4), it is peer cfg.getPeer(4) */ - public static void layeredEncrypt(I2PAppContext ctx, TunnelBuildMessage msg, TunnelCreatorConfig cfg, List order) { + public static void layeredEncrypt(I2PAppContext ctx, TunnelBuildMessage msg, TunnelCreatorConfig cfg, List<Integer> order) { //Log log = ctx.logManager().getLog(BuildMessageGenerator.class); // encrypt the records so that the right elements will be visible at the right time for (int i = 0; i < msg.getRecordCount(); i++) { diff --git a/router/java/src/net/i2p/router/tunnel/FragmentHandler.java b/router/java/src/net/i2p/router/tunnel/FragmentHandler.java index 855b5a61207d940a31bf0875294ff8dbb9099bf0..03ca9c3715b96bddb2772ed84b01ff38edddaacc 100644 --- a/router/java/src/net/i2p/router/tunnel/FragmentHandler.java +++ b/router/java/src/net/i2p/router/tunnel/FragmentHandler.java @@ -105,7 +105,7 @@ class FragmentHandler { public FragmentHandler(RouterContext context, DefragmentedReceiver receiver) { _context = context; _log = context.logManager().getLog(FragmentHandler.class); - _fragmentedMessages = new HashMap(16); + _fragmentedMessages = new HashMap<Long, FragmentedMessage>(16); _receiver = receiver; // all createRateStat in TunnelDispatcher } diff --git a/router/java/src/net/i2p/router/tunnel/HashSetIVValidator.java b/router/java/src/net/i2p/router/tunnel/HashSetIVValidator.java index e7022b55e2bbe49e87c9c713ae1046f18cb38501..e450f6827eb313890a96b4ca27f3ae11f8fd2c09 100644 --- a/router/java/src/net/i2p/router/tunnel/HashSetIVValidator.java +++ b/router/java/src/net/i2p/router/tunnel/HashSetIVValidator.java @@ -15,7 +15,7 @@ class HashSetIVValidator implements IVValidator { private final Set<ByteArray> _received; public HashSetIVValidator() { - _received = new ConcurrentHashSet(); + _received = new ConcurrentHashSet<ByteArray>(); } public boolean receiveIV(byte ivData[], int ivOffset, byte payload[], int payloadOffset) { diff --git a/router/java/src/net/i2p/router/tunnel/InboundEndpointProcessor.java b/router/java/src/net/i2p/router/tunnel/InboundEndpointProcessor.java index d27a6e733d9b296f3b72bf9a3e11bfa62479a2a4..cda394fa54e48e08c994ae73b00629ce29956e07 100644 --- a/router/java/src/net/i2p/router/tunnel/InboundEndpointProcessor.java +++ b/router/java/src/net/i2p/router/tunnel/InboundEndpointProcessor.java @@ -1,6 +1,5 @@ package net.i2p.router.tunnel; -import net.i2p.data.ByteArray; import net.i2p.data.Hash; import net.i2p.router.RouterContext; import net.i2p.util.Log; diff --git a/router/java/src/net/i2p/router/tunnel/InboundMessageDistributor.java b/router/java/src/net/i2p/router/tunnel/InboundMessageDistributor.java index 45ac012ec08b3ad3ee21b5b47925a43e5ba55a9a..6789dbb406c787017e6ada67bdf101c3604611cf 100644 --- a/router/java/src/net/i2p/router/tunnel/InboundMessageDistributor.java +++ b/router/java/src/net/i2p/router/tunnel/InboundMessageDistributor.java @@ -2,9 +2,7 @@ package net.i2p.router.tunnel; import net.i2p.data.DatabaseEntry; import net.i2p.data.Hash; -import net.i2p.data.LeaseSet; import net.i2p.data.Payload; -import net.i2p.data.RouterInfo; import net.i2p.data.TunnelId; import net.i2p.data.i2np.DataMessage; import net.i2p.data.i2np.DatabaseSearchReplyMessage; diff --git a/router/java/src/net/i2p/router/tunnel/OutboundGatewayProcessor.java b/router/java/src/net/i2p/router/tunnel/OutboundGatewayProcessor.java index 3d86d230ff75b27e70690bfc1c434bcfffcd81aa..8acb0e5bbb32d9101c8ff036c4cd843fbd6bd7e4 100644 --- a/router/java/src/net/i2p/router/tunnel/OutboundGatewayProcessor.java +++ b/router/java/src/net/i2p/router/tunnel/OutboundGatewayProcessor.java @@ -2,7 +2,6 @@ package net.i2p.router.tunnel; import net.i2p.I2PAppContext; import net.i2p.data.Base64; -import net.i2p.data.ByteArray; import net.i2p.util.Log; import net.i2p.util.SimpleByteCache; diff --git a/router/java/src/net/i2p/router/tunnel/PendingGatewayMessage.java b/router/java/src/net/i2p/router/tunnel/PendingGatewayMessage.java index 6e50e4e92f9b336d398a2b039e5f31a965c66020..29e3b139e0c98c58dd7add46bb669252138b9054 100644 --- a/router/java/src/net/i2p/router/tunnel/PendingGatewayMessage.java +++ b/router/java/src/net/i2p/router/tunnel/PendingGatewayMessage.java @@ -6,7 +6,6 @@ import java.util.List; import net.i2p.data.Hash; import net.i2p.data.TunnelId; import net.i2p.data.i2np.I2NPMessage; -import net.i2p.router.RouterContext; import net.i2p.router.util.CDQEntry; /** @@ -69,7 +68,7 @@ class PendingGatewayMessage implements CDQEntry { public void addMessageId(long id) { synchronized (this) { if (_messageIds == null) - _messageIds = new ArrayList(); + _messageIds = new ArrayList<Long>(); _messageIds.add(Long.valueOf(id)); } } @@ -81,9 +80,9 @@ class PendingGatewayMessage implements CDQEntry { public List<Long> getMessageIds() { synchronized (this) { if (_messageIds != null) - return new ArrayList(_messageIds); + return new ArrayList<Long>(_messageIds); else - return new ArrayList(); + return new ArrayList<Long>(); } } diff --git a/router/java/src/net/i2p/router/tunnel/PumpedTunnelGateway.java b/router/java/src/net/i2p/router/tunnel/PumpedTunnelGateway.java index 560fb7f39abfdcc78461c2f78101095d1decb926..9493932e658440d43270a9747e4b0961d7c998a5 100644 --- a/router/java/src/net/i2p/router/tunnel/PumpedTunnelGateway.java +++ b/router/java/src/net/i2p/router/tunnel/PumpedTunnelGateway.java @@ -68,7 +68,7 @@ class PumpedTunnelGateway extends TunnelGateway { _isInbound = false; } else if (receiver != null) { // extended by ThrottledPTG for IB // Bounded non-priority queue for inbound - _prequeue = new CoDelBlockingQueue(context, "IBGW", MAX_IB_QUEUE); + _prequeue = new CoDelBlockingQueue<PendingGatewayMessage>(context, "IBGW", MAX_IB_QUEUE); _nextHop = receiver.getSendTo(); _isInbound = true; } else { diff --git a/router/java/src/net/i2p/router/tunnel/TrivialPreprocessor.java b/router/java/src/net/i2p/router/tunnel/TrivialPreprocessor.java index e6edc3c85e35f46fb4cba1d183658c1b211d6ed5..0d8475ece717d50a1d1b27540ecf39da39e6e7ac 100644 --- a/router/java/src/net/i2p/router/tunnel/TrivialPreprocessor.java +++ b/router/java/src/net/i2p/router/tunnel/TrivialPreprocessor.java @@ -3,7 +3,6 @@ package net.i2p.router.tunnel; import java.util.List; import net.i2p.data.Base64; -import net.i2p.data.ByteArray; import net.i2p.data.DataHelper; import net.i2p.data.Hash; import net.i2p.router.RouterContext; diff --git a/router/java/src/net/i2p/router/tunnel/TunnelDispatcher.java b/router/java/src/net/i2p/router/tunnel/TunnelDispatcher.java index 6ba5269fb12bef6ad2ec00c1fbb3df5c3f90826b..d13c578d204539e6712833214039d447e7871ccc 100644 --- a/router/java/src/net/i2p/router/tunnel/TunnelDispatcher.java +++ b/router/java/src/net/i2p/router/tunnel/TunnelDispatcher.java @@ -5,7 +5,6 @@ import java.io.Writer; import java.util.concurrent.ConcurrentHashMap; import java.util.ArrayList; import java.util.List; -import java.util.Map; import java.util.concurrent.LinkedBlockingQueue; import net.i2p.data.DataHelper; @@ -97,11 +96,11 @@ public class TunnelDispatcher implements Service { public TunnelDispatcher(RouterContext ctx) { _context = ctx; _log = ctx.logManager().getLog(TunnelDispatcher.class); - _outboundGateways = new ConcurrentHashMap(); - _outboundEndpoints = new ConcurrentHashMap(); - _participants = new ConcurrentHashMap(); - _inboundGateways = new ConcurrentHashMap(); - _participatingConfig = new ConcurrentHashMap(); + _outboundGateways = new ConcurrentHashMap<TunnelId, TunnelGateway>(); + _outboundEndpoints = new ConcurrentHashMap<TunnelId, OutboundTunnelEndpoint>(); + _participants = new ConcurrentHashMap<TunnelId, TunnelParticipant>(); + _inboundGateways = new ConcurrentHashMap<TunnelId, TunnelGateway>(); + _participatingConfig = new ConcurrentHashMap<TunnelId, HopConfig>(); _pumper = new TunnelGatewayPumper(ctx); _leaveJob = new LeaveTunnel(ctx); ctx.statManager().createRequiredRateStat("tunnel.participatingTunnels", @@ -690,7 +689,7 @@ public class TunnelDispatcher implements Service { * @return a copy */ public List<HopConfig> listParticipatingTunnels() { - return new ArrayList(_participatingConfig.values()); + return new ArrayList<HopConfig>(_participatingConfig.values()); } /** @@ -949,7 +948,7 @@ public class TunnelDispatcher implements Service { public LeaveTunnel(RouterContext ctx) { super(ctx); - _configs = new LinkedBlockingQueue(); + _configs = new LinkedBlockingQueue<HopConfig>(); // 20 min no tunnels accepted + 10 min tunnel expiration getTiming().setStartAfter(ctx.clock().now() + 30*60*1000); getContext().jobQueue().addJob(LeaveTunnel.this); diff --git a/router/java/src/net/i2p/router/tunnel/TunnelGateway.java b/router/java/src/net/i2p/router/tunnel/TunnelGateway.java index fe54c9e02eede0f0ad62dc71f23b234dac6ac0af..242b3dc036747b58d7d3bfbd533f33b105f3d07c 100644 --- a/router/java/src/net/i2p/router/tunnel/TunnelGateway.java +++ b/router/java/src/net/i2p/router/tunnel/TunnelGateway.java @@ -7,7 +7,6 @@ import net.i2p.data.Hash; import net.i2p.data.TunnelId; import net.i2p.data.i2np.I2NPMessage; import net.i2p.data.i2np.TunnelGatewayMessage; -import net.i2p.router.Router; import net.i2p.router.RouterContext; import net.i2p.util.Log; import net.i2p.util.SimpleTimer2; @@ -57,7 +56,7 @@ class TunnelGateway { protected TunnelGateway(RouterContext context, QueuePreprocessor preprocessor, Sender sender, Receiver receiver) { _context = context; _log = context.logManager().getLog(getClass()); - _queue = new ArrayList(4); + _queue = new ArrayList<PendingGatewayMessage>(4); _preprocessor = preprocessor; _sender = sender; _receiver = receiver; diff --git a/router/java/src/net/i2p/router/tunnel/TunnelGatewayPumper.java b/router/java/src/net/i2p/router/tunnel/TunnelGatewayPumper.java index 024b1072b1157cf98cee09a7f107837989365249..17b9a9a8c5f4c8e0a178346e2867e2d4a5cdd15f 100644 --- a/router/java/src/net/i2p/router/tunnel/TunnelGatewayPumper.java +++ b/router/java/src/net/i2p/router/tunnel/TunnelGatewayPumper.java @@ -6,12 +6,8 @@ import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.LinkedBlockingQueue; - import net.i2p.router.RouterContext; import net.i2p.util.I2PThread; -import net.i2p.util.SimpleScheduler; import net.i2p.util.SimpleTimer; import net.i2p.util.SystemVersion; @@ -41,8 +37,8 @@ class TunnelGatewayPumper implements Runnable { /** Creates a new instance of TunnelGatewayPumper */ public TunnelGatewayPumper(RouterContext ctx) { _context = ctx; - _wantsPumping = new LinkedHashSet(16); - _backlogged = new HashSet(16); + _wantsPumping = new LinkedHashSet<PumpedTunnelGateway>(16); + _backlogged = new HashSet<PumpedTunnelGateway>(16); if (ctx.getBooleanProperty("i2p.dummyTunnelManager")) { _pumpers = 1; } else { @@ -79,7 +75,7 @@ class TunnelGatewayPumper implements Runnable { public void run() { PumpedTunnelGateway gw = null; - List<PendingGatewayMessage> queueBuf = new ArrayList(32); + List<PendingGatewayMessage> queueBuf = new ArrayList<PendingGatewayMessage>(32); boolean requeue = false; while (!_stop) { try { diff --git a/router/java/src/net/i2p/router/tunnel/pool/BuildExecutor.java b/router/java/src/net/i2p/router/tunnel/pool/BuildExecutor.java index ac3656052bc07a3057ab2c18cb531d06e8e11085..5d43deefba9315db24df15a65663d24cb47deee0 100644 --- a/router/java/src/net/i2p/router/tunnel/pool/BuildExecutor.java +++ b/router/java/src/net/i2p/router/tunnel/pool/BuildExecutor.java @@ -30,7 +30,7 @@ import net.i2p.util.Log; * As of 0.8.11, inbound request handling is done in a separate thread. */ class BuildExecutor implements Runnable { - private final ArrayList<Long> _recentBuildIds = new ArrayList(100); + private final ArrayList<Long> _recentBuildIds = new ArrayList<Long>(100); private final RouterContext _context; private final Log _log; private final TunnelPoolManager _manager; @@ -51,8 +51,8 @@ class BuildExecutor implements Runnable { _log = ctx.logManager().getLog(getClass()); _manager = mgr; _currentlyBuilding = new Object(); - _currentlyBuildingMap = new ConcurrentHashMap(MAX_CONCURRENT_BUILDS); - _recentlyBuildingMap = new ConcurrentHashMap(4 * MAX_CONCURRENT_BUILDS); + _currentlyBuildingMap = new ConcurrentHashMap<Long, PooledTunnelCreatorConfig>(MAX_CONCURRENT_BUILDS); + _recentlyBuildingMap = new ConcurrentHashMap<Long, PooledTunnelCreatorConfig>(4 * MAX_CONCURRENT_BUILDS); _context.statManager().createRateStat("tunnel.concurrentBuilds", "How many builds are going at once", "Tunnels", new long[] { 60*1000, 5*60*1000, 60*60*1000 }); _context.statManager().createRateStat("tunnel.concurrentBuildsLagged", "How many builds are going at once when we reject further builds, due to job lag (period is lag)", "Tunnels", new long[] { 60*1000, 5*60*1000, 60*60*1000 }); _context.statManager().createRequiredRateStat("tunnel.buildExploratoryExpire", "No response to our build request", "Tunnels", new long[] { 10*60*1000, 60*60*1000 }); @@ -153,7 +153,7 @@ class BuildExecutor implements Runnable { _recentlyBuildingMap.putIfAbsent(Long.valueOf(cfg.getReplyMessageId()), cfg); iter.remove(); if (expired == null) - expired = new ArrayList(); + expired = new ArrayList<PooledTunnelCreatorConfig>(); expired.add(cfg); } } @@ -284,8 +284,8 @@ class BuildExecutor implements Runnable { public void run() { _isRunning = true; - List<TunnelPool> wanted = new ArrayList(MAX_CONCURRENT_BUILDS); - List<TunnelPool> pools = new ArrayList(8); + List<TunnelPool> wanted = new ArrayList<TunnelPool>(MAX_CONCURRENT_BUILDS); + List<TunnelPool> pools = new ArrayList<TunnelPool>(8); while (_isRunning && !_manager.isShutdown()){ //loopBegin = System.currentTimeMillis(); diff --git a/router/java/src/net/i2p/router/tunnel/pool/BuildHandler.java b/router/java/src/net/i2p/router/tunnel/pool/BuildHandler.java index ebbe487d4ee52a90a20df9af446ac412dc6210ba..2142bee95cc5803968ff9082a7854a6e0b5be749 100644 --- a/router/java/src/net/i2p/router/tunnel/pool/BuildHandler.java +++ b/router/java/src/net/i2p/router/tunnel/pool/BuildHandler.java @@ -93,7 +93,7 @@ class BuildHandler implements Runnable { // Queue size = 12 * share BW / 48K int sz = Math.min(MAX_QUEUE, Math.max(MIN_QUEUE, TunnelDispatcher.getShareBandwidth(ctx) * MIN_QUEUE / 48)); //_inboundBuildMessages = new CoDelBlockingQueue(ctx, "BuildHandler", sz); - _inboundBuildMessages = new LinkedBlockingQueue(sz); + _inboundBuildMessages = new LinkedBlockingQueue<BuildMessageState>(sz); _context.statManager().createRateStat("tunnel.reject.10", "How often we reject a tunnel probabalistically", "Tunnels", new long[] { 60*1000, 10*60*1000 }); _context.statManager().createRateStat("tunnel.reject.20", "How often we reject a tunnel because of transient overload", "Tunnels", new long[] { 60*1000, 10*60*1000 }); diff --git a/router/java/src/net/i2p/router/tunnel/pool/BuildRequestor.java b/router/java/src/net/i2p/router/tunnel/pool/BuildRequestor.java index 6c8deb55ac327b5d19603a886b7363f738a71730..65ae2be276655a9c8bdaffe637f7691c74853382 100644 --- a/router/java/src/net/i2p/router/tunnel/pool/BuildRequestor.java +++ b/router/java/src/net/i2p/router/tunnel/pool/BuildRequestor.java @@ -25,7 +25,7 @@ import net.i2p.util.VersionComparator; * Methods for creating Tunnel Build Messages, i.e. requests */ abstract class BuildRequestor { - private static final List<Integer> ORDER = new ArrayList(TunnelBuildMessage.MAX_RECORD_COUNT); + private static final List<Integer> ORDER = new ArrayList<Integer>(TunnelBuildMessage.MAX_RECORD_COUNT); static { for (int i = 0; i < TunnelBuildMessage.MAX_RECORD_COUNT; i++) ORDER.add(Integer.valueOf(i)); @@ -225,7 +225,7 @@ abstract class BuildRequestor { private static final boolean SEND_VARIABLE = true; /** 5 (~2600 bytes) fits nicely in 3 tunnel messages */ private static final int SHORT_RECORDS = 5; - private static final List<Integer> SHORT_ORDER = new ArrayList(SHORT_RECORDS); + private static final List<Integer> SHORT_ORDER = new ArrayList<Integer>(SHORT_RECORDS); static { for (int i = 0; i < SHORT_RECORDS; i++) SHORT_ORDER.add(Integer.valueOf(i)); @@ -292,12 +292,12 @@ abstract class BuildRequestor { List<Integer> order; if (useVariable) { msg = new VariableTunnelBuildMessage(ctx, SHORT_RECORDS); - order = new ArrayList(SHORT_ORDER); + order = new ArrayList<Integer>(SHORT_ORDER); //if (log.shouldLog(Log.INFO)) // log.info("Using new VTBM"); } else { msg = new TunnelBuildMessage(ctx); - order = new ArrayList(ORDER); + order = new ArrayList<Integer>(ORDER); } // This is in BuildExecutor.buildTunnel() now diff --git a/router/java/src/net/i2p/router/tunnel/pool/ClientPeerSelector.java b/router/java/src/net/i2p/router/tunnel/pool/ClientPeerSelector.java index 468cacaf263e9eb26b7ae4bc084b52297a03a2b7..2e13c4c57f6f0be10c2119b490065a293497b32c 100644 --- a/router/java/src/net/i2p/router/tunnel/pool/ClientPeerSelector.java +++ b/router/java/src/net/i2p/router/tunnel/pool/ClientPeerSelector.java @@ -34,16 +34,16 @@ class ClientPeerSelector extends TunnelPeerSelector { return selectExplicit(settings, length); Set<Hash> exclude = getExclude(settings.isInbound(), false); - Set<Hash> matches = new HashSet(length); + Set<Hash> matches = new HashSet<Hash>(length); if (length == 1) { ctx.profileOrganizer().selectFastPeers(length, exclude, matches, 0); matches.remove(ctx.routerHash()); - rv = new ArrayList(matches); + rv = new ArrayList<Hash>(matches); } else { // build a tunnel using 4 subtiers. // For a 2-hop tunnel, the first hop comes from subtiers 0-1 and the last from subtiers 2-3. // For a longer tunnels, the first hop comes from subtier 0, the middle from subtiers 2-3, and the last from subtier 1. - rv = new ArrayList(length + 1); + rv = new ArrayList<Hash>(length + 1); // OBEP or IB last hop // group 0 or 1 if two hops, otherwise group 0 if (!settings.isInbound()) { @@ -61,7 +61,7 @@ class ClientPeerSelector extends TunnelPeerSelector { matches.remove(ctx.routerHash()); if (matches.size() > 1) { // order the middle peers for tunnels >= 4 hops - List<Hash> ordered = new ArrayList(matches); + List<Hash> ordered = new ArrayList<Hash>(matches); orderPeers(ordered, settings.getRandomKey()); rv.addAll(ordered); } else { @@ -80,7 +80,7 @@ class ClientPeerSelector extends TunnelPeerSelector { rv.addAll(matches); } } else { - rv = new ArrayList(1); + rv = new ArrayList<Hash>(1); } if (settings.isInbound()) diff --git a/router/java/src/net/i2p/router/tunnel/pool/ExploratoryPeerSelector.java b/router/java/src/net/i2p/router/tunnel/pool/ExploratoryPeerSelector.java index f16acf07eded6b8f7169363f7516945bdb1bfe4c..2564ce3d795a4ec5f449ea20eacdd63e1d7fb946 100644 --- a/router/java/src/net/i2p/router/tunnel/pool/ExploratoryPeerSelector.java +++ b/router/java/src/net/i2p/router/tunnel/pool/ExploratoryPeerSelector.java @@ -47,7 +47,7 @@ class ExploratoryPeerSelector extends TunnelPeerSelector { // so they don't get used for client tunnels either. // FloodfillNetworkDatabaseFacade fac = (FloodfillNetworkDatabaseFacade)ctx.netDb(); // exclude.addAll(fac.getFloodfillPeers()); - HashSet matches = new HashSet(length); + HashSet<Hash> matches = new HashSet<Hash>(length); boolean exploreHighCap = shouldPickHighCap(); // @@ -76,7 +76,7 @@ class ExploratoryPeerSelector extends TunnelPeerSelector { } matches.remove(ctx.routerHash()); - ArrayList<Hash> rv = new ArrayList(matches); + ArrayList<Hash> rv = new ArrayList<Hash>(matches); if (rv.size() > 1) orderPeers(rv, settings.getRandomKey()); if (l.shouldLog(Log.DEBUG)) diff --git a/router/java/src/net/i2p/router/tunnel/pool/ParticipatingThrottler.java b/router/java/src/net/i2p/router/tunnel/pool/ParticipatingThrottler.java index f0169cd5cec7fc3d37c61b886b3438b086dcba8f..e1e54764942990bf8155f19a1444206790a33f72 100644 --- a/router/java/src/net/i2p/router/tunnel/pool/ParticipatingThrottler.java +++ b/router/java/src/net/i2p/router/tunnel/pool/ParticipatingThrottler.java @@ -3,7 +3,6 @@ package net.i2p.router.tunnel.pool; import net.i2p.data.Hash; import net.i2p.router.RouterContext; import net.i2p.util.ObjectCounter; -import net.i2p.util.SimpleScheduler; import net.i2p.util.SimpleTimer; /** @@ -41,7 +40,7 @@ class ParticipatingThrottler { ParticipatingThrottler(RouterContext ctx) { this.context = ctx; - this.counter = new ObjectCounter(); + this.counter = new ObjectCounter<Hash>(); ctx.simpleScheduler().addPeriodicEvent(new Cleaner(), CLEAN_TIME); } diff --git a/router/java/src/net/i2p/router/tunnel/pool/RequestThrottler.java b/router/java/src/net/i2p/router/tunnel/pool/RequestThrottler.java index 4cbfe95fd5bc408a7620d0f117221d7b7c8999d9..8c3a3c8c6f2cc57793b9dd33408ec771ad187bac 100644 --- a/router/java/src/net/i2p/router/tunnel/pool/RequestThrottler.java +++ b/router/java/src/net/i2p/router/tunnel/pool/RequestThrottler.java @@ -3,7 +3,6 @@ package net.i2p.router.tunnel.pool; import net.i2p.data.Hash; import net.i2p.router.RouterContext; import net.i2p.util.ObjectCounter; -import net.i2p.util.SimpleScheduler; import net.i2p.util.SimpleTimer; /** @@ -26,7 +25,7 @@ class RequestThrottler { RequestThrottler(RouterContext ctx) { this.context = ctx; - this.counter = new ObjectCounter(); + this.counter = new ObjectCounter<Hash>(); ctx.simpleScheduler().addPeriodicEvent(new Cleaner(), CLEAN_TIME); } diff --git a/router/java/src/net/i2p/router/tunnel/pool/TestJob.java b/router/java/src/net/i2p/router/tunnel/pool/TestJob.java index bd17333efdede26470304120942cfc3a9694662c..6b3f0daedb52b8a4d987c235eb916c68958ed22e 100644 --- a/router/java/src/net/i2p/router/tunnel/pool/TestJob.java +++ b/router/java/src/net/i2p/router/tunnel/pool/TestJob.java @@ -127,7 +127,7 @@ class TestJob extends JobImpl { SessionTag encryptTag = new SessionTag(true); _encryptTag = encryptTag; SessionKey sentKey = new SessionKey(); - Set sentTags = null; + Set<SessionTag> sentTags = null; GarlicMessage msg = GarlicMessageBuilder.buildMessage(getContext(), payload, sentKey, sentTags, getContext().keyManager().getPublicKey(), encryptKey, encryptTag); @@ -137,7 +137,7 @@ class TestJob extends JobImpl { scheduleRetest(); return; } - Set<SessionTag> encryptTags = new RemovableSingletonSet(encryptTag); + Set<SessionTag> encryptTags = new RemovableSingletonSet<SessionTag>(encryptTag); // Register the single tag with the appropriate SKM if (_cfg.isInbound() && !_pool.getSettings().isExploratory()) { SessionKeyManager skm = getContext().clientManager().getClientSessionKeyManager(_pool.getSettings().getDestination()); diff --git a/router/java/src/net/i2p/router/tunnel/pool/TunnelPeerSelector.java b/router/java/src/net/i2p/router/tunnel/pool/TunnelPeerSelector.java index 84efa82153dcfc137854509b66d0d102624150b1..2b530405de044f260d5c36b079987f1d0cd47250 100644 --- a/router/java/src/net/i2p/router/tunnel/pool/TunnelPeerSelector.java +++ b/router/java/src/net/i2p/router/tunnel/pool/TunnelPeerSelector.java @@ -125,7 +125,7 @@ public abstract class TunnelPeerSelector { peers = I2PAppContext.getGlobalContext().getProperty("explicitPeers"); Log log = ctx.logManager().getLog(ClientPeerSelector.class); - List<Hash> rv = new ArrayList(); + List<Hash> rv = new ArrayList<Hash>(); StringTokenizer tok = new StringTokenizer(peers, ","); while (tok.hasMoreTokens()) { String peerStr = tok.nextToken(); @@ -198,7 +198,7 @@ public abstract class TunnelPeerSelector { // // Defaults changed to true for inbound only in filterUnreachable below. - Set<Hash> peers = new HashSet(1); + Set<Hash> peers = new HashSet<Hash>(1); peers.addAll(ctx.profileOrganizer().selectPeersRecentlyRejecting()); peers.addAll(ctx.tunnelManager().selectPeersInTooManyTunnels()); // if (false && filterUnreachable(ctx, isInbound, isExploratory)) { @@ -507,7 +507,7 @@ public abstract class TunnelPeerSelector { ****/ /** see HashComparator */ - protected void orderPeers(List rv, Hash hash) { + protected void orderPeers(List<Hash> rv, Hash hash) { if (rv.size() > 1) Collections.sort(rv, new HashComparator(hash)); } diff --git a/router/java/src/net/i2p/router/tunnel/pool/TunnelPool.java b/router/java/src/net/i2p/router/tunnel/pool/TunnelPool.java index 7257ad24f6e6e5dc91be1fd6f96cbe16fa33f143..92e19dbebee6f9685d362c77180cb86d2b4e25a2 100644 --- a/router/java/src/net/i2p/router/tunnel/pool/TunnelPool.java +++ b/router/java/src/net/i2p/router/tunnel/pool/TunnelPool.java @@ -9,7 +9,6 @@ import java.util.List; import java.util.Map; import java.util.TreeSet; -import net.i2p.data.DataHelper; import net.i2p.data.Hash; import net.i2p.data.Lease; import net.i2p.data.LeaseSet; @@ -29,7 +28,7 @@ import net.i2p.util.Log; * Public only for TunnelRenderer in router console. */ public class TunnelPool { - private final List<PooledTunnelCreatorConfig> _inProgress = new ArrayList(); + private final List<PooledTunnelCreatorConfig> _inProgress = new ArrayList<PooledTunnelCreatorConfig>(); private final RouterContext _context; private final Log _log; private TunnelPoolSettings _settings; @@ -58,7 +57,7 @@ public class TunnelPool { _log = ctx.logManager().getLog(TunnelPool.class); _manager = mgr; _settings = settings; - _tunnels = new ArrayList(settings.getTotalQuantity()); + _tunnels = new ArrayList<TunnelInfo>(settings.getTotalQuantity()); _peerSelector = sel; _expireSkew = _context.random().nextInt(90*1000); _started = System.currentTimeMillis(); @@ -292,7 +291,7 @@ public class TunnelPool { */ public List<TunnelInfo> listTunnels() { synchronized (_tunnels) { - return new ArrayList(_tunnels); + return new ArrayList<TunnelInfo>(_tunnels); } } @@ -394,7 +393,7 @@ public class TunnelPool { } /** list of tunnelInfo instances of tunnels currently being built */ - public List listPending() { synchronized (_inProgress) { return new ArrayList(_inProgress); } } + public List<PooledTunnelCreatorConfig> listPending() { synchronized (_inProgress) { return new ArrayList<PooledTunnelCreatorConfig>(_inProgress); } } /** duplicate of size(), let's pick one */ int getTunnelCount() { synchronized (_tunnels) { return _tunnels.size(); } } @@ -713,7 +712,7 @@ public class TunnelPool { TunnelInfo zeroHopTunnel = null; Lease zeroHopLease = null; - TreeSet<Lease> leases = new TreeSet(new LeaseComparator()); + TreeSet<Lease> leases = new TreeSet<Lease>(new LeaseComparator()); for (int i = 0; i < _tunnels.size(); i++) { TunnelInfo tunnel = _tunnels.get(i); if (tunnel.getExpiration() <= expireAfter) @@ -1106,7 +1105,7 @@ public class TunnelPool { if (ti.getLength() >= len && ti.getExpiration() < now + 3*60*1000 && !ti.wasReused()) { ti.setReused(); len = ti.getLength(); - peers = new ArrayList(len); + peers = new ArrayList<Hash>(len); // peers list is ordered endpoint first, but cfg.getPeer() is ordered gateway first for (int i = len - 1; i >= 0; i--) { peers.add(ti.getPeer(i)); diff --git a/router/java/src/net/i2p/router/tunnel/pool/TunnelPoolManager.java b/router/java/src/net/i2p/router/tunnel/pool/TunnelPoolManager.java index f97dbead1bc0b23353d2e9235dc0d8b2266ff8f8..6dcfa0af2357fd105bb002a0d308f8a8b02e1cd9 100644 --- a/router/java/src/net/i2p/router/tunnel/pool/TunnelPoolManager.java +++ b/router/java/src/net/i2p/router/tunnel/pool/TunnelPoolManager.java @@ -23,7 +23,6 @@ import net.i2p.router.tunnel.TunnelDispatcher; import net.i2p.util.I2PThread; import net.i2p.util.Log; import net.i2p.util.ObjectCounter; -import net.i2p.util.SimpleScheduler; import net.i2p.util.SimpleTimer; /** @@ -58,8 +57,8 @@ public class TunnelPoolManager implements TunnelManagerFacade { //ctx.inNetMessagePool().registerHandlerJobBuilder(TunnelGatewayMessage.MESSAGE_TYPE, b); //ctx.inNetMessagePool().registerHandlerJobBuilder(TunnelDataMessage.MESSAGE_TYPE, b); - _clientInboundPools = new ConcurrentHashMap(4); - _clientOutboundPools = new ConcurrentHashMap(4); + _clientInboundPools = new ConcurrentHashMap<Hash, TunnelPool>(4); + _clientOutboundPools = new ConcurrentHashMap<Hash, TunnelPool>(4); _clientPeerSelector = new ClientPeerSelector(ctx); ExploratoryPeerSelector selector = new ExploratoryPeerSelector(_context); @@ -319,7 +318,7 @@ public class TunnelPoolManager implements TunnelManagerFacade { int part = getParticipatingCount(); if (part <= 0) return 0d; - List<TunnelPool> pools = new ArrayList(); + List<TunnelPool> pools = new ArrayList<TunnelPool>(); listPools(pools); int count = 0; for (int i = 0; i < pools.size(); i++) { @@ -562,7 +561,7 @@ public class TunnelPoolManager implements TunnelManagerFacade { /** @return total number of non-fallback expl. + client tunnels */ private int countTunnelsPerPeer(ObjectCounter<Hash> lc) { - List<TunnelPool> pools = new ArrayList(); + List<TunnelPool> pools = new ArrayList<TunnelPool>(); listPools(pools); int tunnelCount = 0; for (TunnelPool tp : pools) { @@ -597,9 +596,9 @@ public class TunnelPoolManager implements TunnelManagerFacade { * @return Set of peers that should not be allowed in another tunnel */ public Set<Hash> selectPeersInTooManyTunnels() { - ObjectCounter<Hash> lc = new ObjectCounter(); + ObjectCounter<Hash> lc = new ObjectCounter<Hash>(); int tunnelCount = countTunnelsPerPeer(lc); - Set<Hash> rv = new HashSet(); + Set<Hash> rv = new HashSet<Hash>(); if (tunnelCount >= 4 && _context.router().getUptime() > 10*60*1000) { int max = _context.getProperty("router.maxTunnelPercentage", DEFAULT_MAX_PCT_TUNNELS); for (Hash h : lc.objects()) { @@ -612,12 +611,12 @@ public class TunnelPoolManager implements TunnelManagerFacade { /** for TunnelRenderer in router console */ public Map<Hash, TunnelPool> getInboundClientPools() { - return new HashMap(_clientInboundPools); + return new HashMap<Hash, TunnelPool>(_clientInboundPools); } /** for TunnelRenderer in router console */ public Map<Hash, TunnelPool> getOutboundClientPools() { - return new HashMap(_clientOutboundPools); + return new HashMap<Hash, TunnelPool>(_clientOutboundPools); } /** diff --git a/router/java/src/net/i2p/router/util/CoDelPriorityBlockingQueue.java b/router/java/src/net/i2p/router/util/CoDelPriorityBlockingQueue.java index a6f9926ab6e25dcc4db3cb2c085e6b254c5853c5..fdda06f520d3ef524550c2171b1b0cb59d5584a2 100644 --- a/router/java/src/net/i2p/router/util/CoDelPriorityBlockingQueue.java +++ b/router/java/src/net/i2p/router/util/CoDelPriorityBlockingQueue.java @@ -1,9 +1,6 @@ package net.i2p.router.util; import java.util.Collection; -import java.util.Comparator; -import java.util.concurrent.PriorityBlockingQueue; -import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; import net.i2p.I2PAppContext; diff --git a/router/java/src/net/i2p/router/util/DecayingBloomFilter.java b/router/java/src/net/i2p/router/util/DecayingBloomFilter.java index 7f5f2dee4ae0142da2d88455e534e86c90c587b8..9aa9c6715f3813d0ba5190ecdbd76ad545fd38e5 100644 --- a/router/java/src/net/i2p/router/util/DecayingBloomFilter.java +++ b/router/java/src/net/i2p/router/util/DecayingBloomFilter.java @@ -1,6 +1,5 @@ package net.i2p.router.util; -import java.util.Random; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.ReentrantReadWriteLock; diff --git a/router/java/src/net/i2p/router/util/DecayingHashSet.java b/router/java/src/net/i2p/router/util/DecayingHashSet.java index 62194a647559f759a7fb2e491839a9e44040a05e..23c2b43c9cca3bd52192993306d2b221cc4b3d3a 100644 --- a/router/java/src/net/i2p/router/util/DecayingHashSet.java +++ b/router/java/src/net/i2p/router/util/DecayingHashSet.java @@ -1,9 +1,6 @@ package net.i2p.router.util; -import java.util.Random; - import net.i2p.I2PAppContext; -import net.i2p.data.DataHelper; import net.i2p.util.ConcurrentHashSet; import net.i2p.util.Log; @@ -77,8 +74,8 @@ public class DecayingHashSet extends DecayingBloomFilter { super(durationMs, entryBytes, name, context); if (entryBytes <= 0 || entryBytes > 32) throw new IllegalArgumentException("Bad size"); - _current = new ConcurrentHashSet(128); - _previous = new ConcurrentHashSet(128); + _current = new ConcurrentHashSet<ArrayWrapper>(128); + _previous = new ConcurrentHashSet<ArrayWrapper>(128); if (_log.shouldLog(Log.DEBUG)) _log.debug("New DHS " + name + " entryBytes = " + entryBytes + " cycle (s) = " + (durationMs / 1000)); diff --git a/router/java/src/net/i2p/router/util/EventLog.java b/router/java/src/net/i2p/router/util/EventLog.java index 1c2f3139e47f332964aad15b2dc725819dcb3993..1f07f7f7d689176bed8ca86f0c5922213a01a57d 100644 --- a/router/java/src/net/i2p/router/util/EventLog.java +++ b/router/java/src/net/i2p/router/util/EventLog.java @@ -59,8 +59,8 @@ public class EventLog { // throw new IllegalArgumentException(); _context = ctx; _file = file; - _cache = new HashMap(4); - _cacheTime = new HashMap(4); + _cache = new HashMap<String, SortedMap<Long, String>>(4); + _cacheTime = new HashMap<String, Long>(4); } /** @@ -115,7 +115,7 @@ public class EventLog { return rv.tailMap(Long.valueOf(since)); } } - rv = new TreeMap(); + rv = new TreeMap<Long, String>(); InputStream in = null; try { in = new FileInputStream(_file); diff --git a/router/java/src/net/i2p/router/util/RandomIterator.java b/router/java/src/net/i2p/router/util/RandomIterator.java index 226c6e0009d043c178fb0159ea530d1e417189d0..2baa221c089167fe9a3e6ce1959aa6adbca1a452 100644 --- a/router/java/src/net/i2p/router/util/RandomIterator.java +++ b/router/java/src/net/i2p/router/util/RandomIterator.java @@ -192,11 +192,11 @@ public class RandomIterator<E> implements Iterator<E> { private static void test(int n) { System.out.println("testing with " + n); - List<Integer> l = new ArrayList(n); + List<Integer> l = new ArrayList<Integer>(n); for (int i = 0; i < n; i++) { l.add(Integer.valueOf(i)); } - for (Iterator<Integer> iter = new RandomIterator(l); iter.hasNext(); ) { + for (Iterator<Integer> iter = new RandomIterator<Integer>(l); iter.hasNext(); ) { System.out.println(iter.next().toString()); } } diff --git a/router/java/src/net/i2p/router/util/RemovableSingletonSet.java b/router/java/src/net/i2p/router/util/RemovableSingletonSet.java index 57aa1e9795f77dbf5e63fb43fcc8ac014097fdda..92e61fc13fba5fc1acd06a0c92bf948ee80b962c 100644 --- a/router/java/src/net/i2p/router/util/RemovableSingletonSet.java +++ b/router/java/src/net/i2p/router/util/RemovableSingletonSet.java @@ -1,10 +1,8 @@ package net.i2p.router.util; import java.util.AbstractSet; -import java.util.Collection; import java.util.Iterator; import java.util.NoSuchElementException; -import java.util.Set; /** * Like Collections.singleton() but item is removable, diff --git a/router/java/src/net/i2p/router/util/RouterPasswordManager.java b/router/java/src/net/i2p/router/util/RouterPasswordManager.java index 6b5fbb7f0cb5b4cf852a900aa128692f080152b2..97ef2468dbd815a7c70346e31f7e06d3f29406a7 100644 --- a/router/java/src/net/i2p/router/util/RouterPasswordManager.java +++ b/router/java/src/net/i2p/router/util/RouterPasswordManager.java @@ -9,7 +9,6 @@ import java.util.Map; import net.i2p.data.Base64; import net.i2p.data.DataHelper; import net.i2p.data.SessionKey; -import net.i2p.router.Router; import net.i2p.router.RouterContext; import net.i2p.util.PasswordManager; @@ -71,8 +70,8 @@ public class RouterPasswordManager extends PasswordManager { saveHash(PROP_I2CP_NEW, user, pw); } // obfuscation of plaintext passwords - Map<String, String> toAdd = new HashMap(5); - List<String> toDel = new ArrayList(5); + Map<String, String> toAdd = new HashMap<String, String>(5); + List<String> toDel = new ArrayList<String>(5); /**** for (int i = 0; i < MIGRATE_FROM.length; i++) { if ((pw = _context.getProperty(MIGRATE_FROM[i])) != null) { @@ -114,7 +113,7 @@ public class RouterPasswordManager extends PasswordManager { if (user != null && user.length() > 0) pfx += '.' + user; Map<String, String> toAdd = Collections.singletonMap(pfx + PROP_PW, pw); - List<String> toDel = new ArrayList(4); + List<String> toDel = new ArrayList<String>(4); toDel.add(pfx + PROP_B64); toDel.add(pfx + PROP_MD5); toDel.add(pfx + PROP_CRYPT); @@ -138,7 +137,7 @@ public class RouterPasswordManager extends PasswordManager { pfx += '.' + user; String b64 = Base64.encode(DataHelper.getUTF8(pw)); Map<String, String> toAdd = Collections.singletonMap(pfx + PROP_B64, b64); - List<String> toDel = new ArrayList(4); + List<String> toDel = new ArrayList<String>(4); toDel.add(pfx + PROP_PW); toDel.add(pfx + PROP_MD5); toDel.add(pfx + PROP_CRYPT); @@ -167,7 +166,7 @@ public class RouterPasswordManager extends PasswordManager { System.arraycopy(pwHash, 0, shashBytes, SALT_LENGTH, SessionKey.KEYSIZE_BYTES); String shash = Base64.encode(shashBytes); Map<String, String> toAdd = Collections.singletonMap(pfx + PROP_SHASH, shash); - List<String> toDel = new ArrayList(4); + List<String> toDel = new ArrayList<String>(4); toDel.add(pfx + PROP_PW); toDel.add(pfx + PROP_B64); toDel.add(pfx + PROP_MD5); @@ -186,7 +185,7 @@ public class RouterPasswordManager extends PasswordManager { String pfx = realm; if (user != null && user.length() > 0) pfx += '.' + user; - List<String> toDel = new ArrayList(5); + List<String> toDel = new ArrayList<String>(5); toDel.add(pfx + PROP_PW); toDel.add(pfx + PROP_B64); toDel.add(pfx + PROP_MD5);