forked from I2P_Developers/i2p.i2p
Java 5 cleanups
This commit is contained in:
@ -11,7 +11,16 @@ import java.io.FileInputStream;
|
||||
import java.io.Writer;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
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 net.i2p.data.Base64;
|
||||
import net.i2p.data.DataHelper;
|
||||
@ -56,9 +65,9 @@ public class Blocklist {
|
||||
private int _blocklistSize;
|
||||
private final Object _lock = new Object();
|
||||
private Entry _wrapSave;
|
||||
private final Set<Hash> _inProcess = new HashSet(0);
|
||||
private Map<Hash, String> _peerBlocklist = new HashMap(0);
|
||||
private final Set<Integer> _singleIPBlocklist = new ConcurrentHashSet(0);
|
||||
private final Set<Hash> _inProcess = new HashSet(4);
|
||||
private Map<Hash, String> _peerBlocklist = new HashMap(4);
|
||||
private final Set<Integer> _singleIPBlocklist = new ConcurrentHashSet(4);
|
||||
|
||||
public Blocklist(RouterContext context) {
|
||||
_context = context;
|
||||
@ -109,8 +118,8 @@ public class Blocklist {
|
||||
return;
|
||||
}
|
||||
}
|
||||
for (Iterator iter = _peerBlocklist.keySet().iterator(); iter.hasNext(); ) {
|
||||
Hash peer = (Hash) iter.next();
|
||||
for (Iterator<Hash> iter = _peerBlocklist.keySet().iterator(); iter.hasNext(); ) {
|
||||
Hash peer = iter.next();
|
||||
String reason;
|
||||
String comment = (String) _peerBlocklist.get(peer);
|
||||
if (comment != null)
|
||||
@ -125,8 +134,8 @@ public class Blocklist {
|
||||
return;
|
||||
FloodfillNetworkDatabaseFacade fndf = (FloodfillNetworkDatabaseFacade) _context.netDb();
|
||||
int count = 0;
|
||||
for (Iterator iter = fndf.getKnownRouterData().iterator(); iter.hasNext(); ) {
|
||||
RouterInfo ri = (RouterInfo) iter.next();
|
||||
for (Iterator<RouterInfo> iter = fndf.getKnownRouterData().iterator(); iter.hasNext(); ) {
|
||||
RouterInfo ri = iter.next();
|
||||
Hash peer = ri.getIdentity().getHash();
|
||||
if (isBlocklisted(peer))
|
||||
count++;
|
||||
@ -458,15 +467,15 @@ public class Blocklist {
|
||||
* this tries to not return duplicates
|
||||
* but I suppose it could.
|
||||
*/
|
||||
public List getAddresses(Hash peer) {
|
||||
List rv = new ArrayList(1);
|
||||
public List<byte[]> getAddresses(Hash peer) {
|
||||
List<byte[]> rv = new ArrayList(1);
|
||||
RouterInfo pinfo = _context.netDb().lookupRouterInfoLocally(peer);
|
||||
if (pinfo == null) return rv;
|
||||
Set paddr = pinfo.getAddresses();
|
||||
Set<RouterAddress> paddr = pinfo.getAddresses();
|
||||
if (paddr == null || paddr.size() == 0)
|
||||
return rv;
|
||||
String oldphost = null;
|
||||
List pladdr = new ArrayList(paddr);
|
||||
List<RouterAddress> pladdr = new ArrayList(paddr);
|
||||
// for each peer address
|
||||
for (int j = 0; j < paddr.size(); j++) {
|
||||
RouterAddress pa = (RouterAddress) pladdr.get(j);
|
||||
@ -495,9 +504,9 @@ public class Blocklist {
|
||||
* If so, and it isn't shitlisted, shitlist it forever...
|
||||
*/
|
||||
public boolean isBlocklisted(Hash peer) {
|
||||
List ips = getAddresses(peer);
|
||||
for (Iterator iter = ips.iterator(); iter.hasNext(); ) {
|
||||
byte ip[] = (byte[]) iter.next();
|
||||
List<byte[]> ips = getAddresses(peer);
|
||||
for (Iterator<byte[]> iter = ips.iterator(); iter.hasNext(); ) {
|
||||
byte ip[] = iter.next();
|
||||
if (isBlocklisted(ip)) {
|
||||
if (! _context.shitlist().isShitlisted(peer))
|
||||
// nice knowing you...
|
||||
@ -715,8 +724,8 @@ public class Blocklist {
|
||||
|
||||
// look through the file for each address to find which one was the cause
|
||||
List ips = getAddresses(peer);
|
||||
for (Iterator iter = ips.iterator(); iter.hasNext(); ) {
|
||||
byte ip[] = (byte[]) iter.next();
|
||||
for (Iterator<byte[]> iter = ips.iterator(); iter.hasNext(); ) {
|
||||
byte ip[] = iter.next();
|
||||
int ipint = toInt(ip);
|
||||
FileInputStream in = null;
|
||||
try {
|
||||
@ -762,12 +771,12 @@ public class Blocklist {
|
||||
public void renderStatusHTML(Writer out) throws IOException {
|
||||
// move to the jsp
|
||||
//out.write("<h2>Banned IPs</h2>");
|
||||
Set singles = new TreeSet();
|
||||
Set<Integer> singles = new TreeSet();
|
||||
singles.addAll(_singleIPBlocklist);
|
||||
if (singles.size() > 0) {
|
||||
out.write("<table><tr><td><b>Transient IPs</b></td></tr>");
|
||||
for (Iterator iter = singles.iterator(); iter.hasNext(); ) {
|
||||
int ip = ((Integer) iter.next()).intValue();
|
||||
for (Iterator<Integer> iter = singles.iterator(); iter.hasNext(); ) {
|
||||
int ip = iter.next().intValue();
|
||||
out.write("<tr><td align=right>"); out.write(toStr(ip)); out.write("</td></tr>\n");
|
||||
}
|
||||
out.write("</table>");
|
||||
|
@ -11,7 +11,6 @@ package net.i2p.router;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@ -30,7 +29,7 @@ public abstract class CommSystemFacade implements Service {
|
||||
public void renderStatusHTML(Writer out) throws IOException { renderStatusHTML(out, null, 0); }
|
||||
|
||||
/** Create the set of RouterAddress structures based on the router's config */
|
||||
public Set createAddresses() { return new HashSet(); }
|
||||
public Set<RouterAddress> createAddresses() { return Collections.EMPTY_SET; }
|
||||
|
||||
public int countActivePeers() { return 0; }
|
||||
public int countActiveSendPeers() { return 0; }
|
||||
|
@ -116,7 +116,7 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
|
||||
return sum * 1000 / frameSize;
|
||||
}
|
||||
|
||||
public List getBids(OutNetMessage msg) {
|
||||
public List<TransportBid> getBids(OutNetMessage msg) {
|
||||
return _manager.getBids(msg);
|
||||
}
|
||||
public TransportBid getBid(OutNetMessage msg) {
|
||||
@ -174,8 +174,8 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set createAddresses() {
|
||||
Map addresses = null;
|
||||
public Set<RouterAddress> createAddresses() {
|
||||
Map<String, RouterAddress> addresses = null;
|
||||
boolean newCreated = false;
|
||||
|
||||
if (_manager != null) {
|
||||
|
@ -12,8 +12,8 @@ import net.i2p.util.Log;
|
||||
public class FIFOBandwidthLimiter {
|
||||
private Log _log;
|
||||
private I2PAppContext _context;
|
||||
private final List _pendingInboundRequests;
|
||||
private final List _pendingOutboundRequests;
|
||||
private final List<Request> _pendingInboundRequests;
|
||||
private final List<Request> _pendingOutboundRequests;
|
||||
/** how many bytes we can consume for inbound transmission immediately */
|
||||
private volatile int _availableInbound;
|
||||
/** how many bytes we can consume for outbound transmission immediately */
|
||||
@ -176,7 +176,7 @@ public class FIFOBandwidthLimiter {
|
||||
}
|
||||
public void requestOutbound(Request req, int bytesOut, String purpose) {
|
||||
req.init(0, bytesOut, purpose);
|
||||
if (false) { ((SimpleRequest)req).allocateAll(); return; }
|
||||
//if (false) { ((SimpleRequest)req).allocateAll(); return; }
|
||||
int pending = 0;
|
||||
synchronized (_pendingOutboundRequests) {
|
||||
pending = _pendingOutboundRequests.size();
|
||||
@ -215,7 +215,7 @@ public class FIFOBandwidthLimiter {
|
||||
* @param maxBurstIn allow up to this many bytes in from the burst section for this time period (may be negative)
|
||||
* @param maxBurstOut allow up to this many bytes in from the burst section for this time period (may be negative)
|
||||
*/
|
||||
final void refillBandwidthQueues(List buf, long bytesInbound, long bytesOutbound, long maxBurstIn, long maxBurstOut) {
|
||||
final void refillBandwidthQueues(List<Request> buf, long bytesInbound, long bytesOutbound, long maxBurstIn, long maxBurstOut) {
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Refilling the queues with " + bytesInbound + "/" + bytesOutbound + ": " + getStatus().toString());
|
||||
_availableInbound += bytesInbound;
|
||||
@ -338,14 +338,14 @@ public class FIFOBandwidthLimiter {
|
||||
* Go through the queue, satisfying as many requests as possible (notifying
|
||||
* each one satisfied that the request has been granted).
|
||||
*/
|
||||
private final void satisfyRequests(List buffer) {
|
||||
private final void satisfyRequests(List<Request> buffer) {
|
||||
buffer.clear();
|
||||
satisfyInboundRequests(buffer);
|
||||
buffer.clear();
|
||||
satisfyOutboundRequests(buffer);
|
||||
}
|
||||
|
||||
private final void satisfyInboundRequests(List satisfied) {
|
||||
private final void satisfyInboundRequests(List<Request> satisfied) {
|
||||
synchronized (_pendingInboundRequests) {
|
||||
if (_inboundUnlimited) {
|
||||
locked_satisfyInboundUnlimited(satisfied);
|
||||
@ -400,7 +400,7 @@ public class FIFOBandwidthLimiter {
|
||||
* There are no limits, so just give every inbound request whatever they want
|
||||
*
|
||||
*/
|
||||
private final void locked_satisfyInboundUnlimited(List satisfied) {
|
||||
private final void locked_satisfyInboundUnlimited(List<Request> satisfied) {
|
||||
while (_pendingInboundRequests.size() > 0) {
|
||||
SimpleRequest req = (SimpleRequest)_pendingInboundRequests.remove(0);
|
||||
int allocated = req.getPendingInboundRequested();
|
||||
@ -425,7 +425,7 @@ public class FIFOBandwidthLimiter {
|
||||
*
|
||||
* @return list of requests that were completely satisfied
|
||||
*/
|
||||
private final void locked_satisfyInboundAvailable(List satisfied) {
|
||||
private final void locked_satisfyInboundAvailable(List<Request> satisfied) {
|
||||
for (int i = 0; i < _pendingInboundRequests.size(); i++) {
|
||||
if (_availableInbound <= 0) break;
|
||||
SimpleRequest req = (SimpleRequest)_pendingInboundRequests.get(i);
|
||||
@ -485,7 +485,7 @@ public class FIFOBandwidthLimiter {
|
||||
}
|
||||
}
|
||||
|
||||
private final void satisfyOutboundRequests(List satisfied) {
|
||||
private final void satisfyOutboundRequests(List<Request> satisfied) {
|
||||
synchronized (_pendingOutboundRequests) {
|
||||
if (_outboundUnlimited) {
|
||||
locked_satisfyOutboundUnlimited(satisfied);
|
||||
@ -514,7 +514,7 @@ public class FIFOBandwidthLimiter {
|
||||
* There are no limits, so just give every outbound request whatever they want
|
||||
*
|
||||
*/
|
||||
private final void locked_satisfyOutboundUnlimited(List satisfied) {
|
||||
private final void locked_satisfyOutboundUnlimited(List<Request> satisfied) {
|
||||
while (_pendingOutboundRequests.size() > 0) {
|
||||
SimpleRequest req = (SimpleRequest)_pendingOutboundRequests.remove(0);
|
||||
int allocated = req.getPendingOutboundRequested();
|
||||
@ -540,7 +540,7 @@ public class FIFOBandwidthLimiter {
|
||||
*
|
||||
* @return list of requests that were completely satisfied
|
||||
*/
|
||||
private final void locked_satisfyOutboundAvailable(List satisfied) {
|
||||
private final void locked_satisfyOutboundAvailable(List<Request> satisfied) {
|
||||
for (int i = 0; i < _pendingOutboundRequests.size(); i++) {
|
||||
if (_availableOutbound <= 0) break;
|
||||
SimpleRequest req = (SimpleRequest)_pendingOutboundRequests.get(i);
|
||||
@ -665,7 +665,7 @@ public class FIFOBandwidthLimiter {
|
||||
private int _allocationsSinceWait;
|
||||
private boolean _aborted;
|
||||
private boolean _waited;
|
||||
List satisfiedBuffer;
|
||||
List<Request> satisfiedBuffer;
|
||||
private CompleteListener _lsnr;
|
||||
private Object _attachment;
|
||||
|
||||
|
@ -71,7 +71,7 @@ public class FIFOBandwidthRefiller implements Runnable {
|
||||
public void run() {
|
||||
// bootstrap 'em with nothing
|
||||
_lastRefillTime = _limiter.now();
|
||||
List buffer = new ArrayList(2);
|
||||
List<FIFOBandwidthLimiter.Request> buffer = new ArrayList(2);
|
||||
while (true) {
|
||||
long now = _limiter.now();
|
||||
if (now >= _lastCheckConfigTime + _configCheckPeriodMs) {
|
||||
@ -95,7 +95,7 @@ public class FIFOBandwidthRefiller implements Runnable {
|
||||
_lastCheckConfigTime = _lastRefillTime;
|
||||
}
|
||||
|
||||
private boolean updateQueues(List buffer, long now) {
|
||||
private boolean updateQueues(List<FIFOBandwidthLimiter.Request> buffer, long now) {
|
||||
long numMs = (now - _lastRefillTime);
|
||||
if (_log.shouldLog(Log.INFO))
|
||||
_log.info("Updating bandwidth after " + numMs + " (status: " + _limiter.getStatus().toString()
|
||||
|
@ -140,7 +140,7 @@ public class TransportManager implements TransportEventListener {
|
||||
configTransports();
|
||||
_log.debug("Starting up the transport manager");
|
||||
for (int i = 0; i < _transports.size(); i++) {
|
||||
Transport t = (Transport)_transports.get(i);
|
||||
Transport t = _transports.get(i);
|
||||
RouterAddress addr = t.startListening();
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Transport " + i + " (" + t.getStyle() + ") started");
|
||||
@ -161,14 +161,14 @@ public class TransportManager implements TransportEventListener {
|
||||
if (_upnpManager != null)
|
||||
_upnpManager.stop();
|
||||
for (int i = 0; i < _transports.size(); i++) {
|
||||
((Transport)_transports.get(i)).stopListening();
|
||||
_transports.get(i).stopListening();
|
||||
}
|
||||
_transports.clear();
|
||||
}
|
||||
|
||||
public Transport getTransport(String style) {
|
||||
for (int i = 0; i < _transports.size(); i++) {
|
||||
Transport t = (Transport)_transports.get(i);
|
||||
Transport t = _transports.get(i);
|
||||
if(style.equals(t.getStyle()))
|
||||
return t;
|
||||
}
|
||||
@ -189,7 +189,7 @@ public class TransportManager implements TransportEventListener {
|
||||
public int countActivePeers() {
|
||||
int peers = 0;
|
||||
for (int i = 0; i < _transports.size(); i++) {
|
||||
peers += ((Transport)_transports.get(i)).countActivePeers();
|
||||
peers += _transports.get(i).countActivePeers();
|
||||
}
|
||||
return peers;
|
||||
}
|
||||
@ -197,7 +197,7 @@ public class TransportManager implements TransportEventListener {
|
||||
public int countActiveSendPeers() {
|
||||
int peers = 0;
|
||||
for (int i = 0; i < _transports.size(); i++) {
|
||||
peers += ((Transport)_transports.get(i)).countActiveSendPeers();
|
||||
peers += _transports.get(i).countActiveSendPeers();
|
||||
}
|
||||
return peers;
|
||||
}
|
||||
@ -210,7 +210,7 @@ public class TransportManager implements TransportEventListener {
|
||||
*/
|
||||
public boolean haveOutboundCapacity(int pct) {
|
||||
for (int i = 0; i < _transports.size(); i++) {
|
||||
if (((Transport)_transports.get(i)).haveCapacity(pct))
|
||||
if (_transports.get(i).haveCapacity(pct))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -225,7 +225,7 @@ public class TransportManager implements TransportEventListener {
|
||||
if (_transports.size() <= 0)
|
||||
return false;
|
||||
for (int i = 0; i < _transports.size(); i++) {
|
||||
if (!((Transport)_transports.get(i)).haveCapacity(HIGH_CAPACITY_PCT))
|
||||
if (!_transports.get(i).haveCapacity(HIGH_CAPACITY_PCT))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -253,7 +253,7 @@ public class TransportManager implements TransportEventListener {
|
||||
public Vector getClockSkews() {
|
||||
Vector skews = new Vector();
|
||||
for (int i = 0; i < _transports.size(); i++) {
|
||||
Vector tempSkews = ((Transport)_transports.get(i)).getClockSkews();
|
||||
Vector tempSkews = _transports.get(i).getClockSkews();
|
||||
if ((tempSkews == null) || (tempSkews.size() <= 0)) continue;
|
||||
skews.addAll(tempSkews);
|
||||
}
|
||||
@ -275,12 +275,12 @@ public class TransportManager implements TransportEventListener {
|
||||
|
||||
public void recheckReachability() {
|
||||
for (int i = 0; i < _transports.size(); i++)
|
||||
((Transport)_transports.get(i)).recheckReachability();
|
||||
_transports.get(i).recheckReachability();
|
||||
}
|
||||
|
||||
public boolean isBacklogged(Hash dest) {
|
||||
for (int i = 0; i < _transports.size(); i++) {
|
||||
Transport t = (Transport)_transports.get(i);
|
||||
Transport t = _transports.get(i);
|
||||
if (t.isBacklogged(dest))
|
||||
return true;
|
||||
}
|
||||
@ -289,7 +289,7 @@ public class TransportManager implements TransportEventListener {
|
||||
|
||||
public boolean isEstablished(Hash dest) {
|
||||
for (int i = 0; i < _transports.size(); i++) {
|
||||
Transport t = (Transport)_transports.get(i);
|
||||
Transport t = _transports.get(i);
|
||||
if (t.isEstablished(dest))
|
||||
return true;
|
||||
}
|
||||
@ -303,7 +303,7 @@ public class TransportManager implements TransportEventListener {
|
||||
*/
|
||||
public boolean wasUnreachable(Hash dest) {
|
||||
for (int i = 0; i < _transports.size(); i++) {
|
||||
Transport t = (Transport)_transports.get(i);
|
||||
Transport t = _transports.get(i);
|
||||
if (!t.wasUnreachable(dest))
|
||||
return false;
|
||||
}
|
||||
@ -371,22 +371,22 @@ public class TransportManager implements TransportEventListener {
|
||||
}
|
||||
|
||||
public TransportBid getBid(OutNetMessage msg) {
|
||||
List bids = getBids(msg);
|
||||
List<TransportBid> bids = getBids(msg);
|
||||
if ( (bids == null) || (bids.size() <= 0) )
|
||||
return null;
|
||||
else
|
||||
return (TransportBid)bids.get(0);
|
||||
return bids.get(0);
|
||||
}
|
||||
public List getBids(OutNetMessage msg) {
|
||||
public List<TransportBid> getBids(OutNetMessage msg) {
|
||||
if (msg == null)
|
||||
throw new IllegalArgumentException("Null message? no bidding on a null outNetMessage!");
|
||||
if (_context.router().getRouterInfo().equals(msg.getTarget()))
|
||||
throw new IllegalArgumentException("WTF, bids for a message bound to ourselves?");
|
||||
|
||||
List rv = new ArrayList(_transports.size());
|
||||
List<TransportBid> rv = new ArrayList(_transports.size());
|
||||
Set failedTransports = msg.getFailedTransports();
|
||||
for (int i = 0; i < _transports.size(); i++) {
|
||||
Transport t = (Transport)_transports.get(i);
|
||||
Transport t = _transports.get(i);
|
||||
if (failedTransports.contains(t.getStyle())) {
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Skipping transport " + t.getStyle() + " as it already failed");
|
||||
@ -415,7 +415,7 @@ public class TransportManager implements TransportEventListener {
|
||||
Set failedTransports = msg.getFailedTransports();
|
||||
TransportBid rv = null;
|
||||
for (int i = 0; i < _transports.size(); i++) {
|
||||
Transport t = (Transport)_transports.get(i);
|
||||
Transport t = _transports.get(i);
|
||||
if (t.isUnreachable(peer)) {
|
||||
unreachableTransports++;
|
||||
// this keeps GetBids() from shitlisting for "no common transports"
|
||||
@ -482,7 +482,7 @@ public class TransportManager implements TransportEventListener {
|
||||
public List getMostRecentErrorMessages() {
|
||||
List rv = new ArrayList(16);
|
||||
for (int i = 0; i < _transports.size(); i++) {
|
||||
Transport t = (Transport)_transports.get(i);
|
||||
Transport t = _transports.get(i);
|
||||
rv.addAll(t.getMostRecentErrorMessages());
|
||||
}
|
||||
return rv;
|
||||
@ -491,7 +491,7 @@ public class TransportManager implements TransportEventListener {
|
||||
public void renderStatusHTML(Writer out, String urlBase, int sortFlags) throws IOException {
|
||||
TreeMap transports = new TreeMap();
|
||||
for (int i = 0; i < _transports.size(); i++) {
|
||||
Transport t = (Transport)_transports.get(i);
|
||||
Transport t = _transports.get(i);
|
||||
transports.put(t.getStyle(), t);
|
||||
}
|
||||
for (Iterator iter = transports.values().iterator(); iter.hasNext(); ) {
|
||||
@ -501,7 +501,7 @@ public class TransportManager implements TransportEventListener {
|
||||
StringBuilder buf = new StringBuilder(4*1024);
|
||||
buf.append("<h3>Router Transport Addresses</h3><pre>\n");
|
||||
for (int i = 0; i < _transports.size(); i++) {
|
||||
Transport t = (Transport)_transports.get(i);
|
||||
Transport t = _transports.get(i);
|
||||
if (t.getCurrentAddress() != null)
|
||||
buf.append(t.getCurrentAddress()).append("\n\n");
|
||||
else
|
||||
|
Reference in New Issue
Block a user