forked from I2P_Developers/i2p.i2p
remove unnecessary casts (eclipse)
This commit is contained in:
@@ -218,7 +218,7 @@ public class MetaInfo
|
||||
if (l < oldTotal)
|
||||
throw new InvalidBEncodingException("Huge total length");
|
||||
|
||||
val = (BEValue)desc.get("path");
|
||||
val = desc.get("path");
|
||||
if (val == null)
|
||||
throw new InvalidBEncodingException("Missing path list");
|
||||
List<BEValue> path_list = val.getList();
|
||||
@@ -244,7 +244,7 @@ public class MetaInfo
|
||||
|
||||
m_files.add(Collections.unmodifiableList(file));
|
||||
|
||||
val = (BEValue)desc.get("path.utf-8");
|
||||
val = desc.get("path.utf-8");
|
||||
if (val != null) {
|
||||
path_list = val.getList();
|
||||
path_length = path_list.size();
|
||||
|
||||
@@ -143,7 +143,7 @@ class PeerConnectionOut implements Runnable
|
||||
}
|
||||
}
|
||||
if (m == null && !sendQueue.isEmpty()) {
|
||||
m = (Message)sendQueue.remove(0);
|
||||
m = sendQueue.remove(0);
|
||||
//SimpleTimer.getInstance().removeEvent(m.expireEvent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -662,7 +662,7 @@ public class SnarkManager implements Snark.CompleteListener {
|
||||
File dataDir = getDataDir();
|
||||
Snark torrent = null;
|
||||
synchronized (_snarks) {
|
||||
torrent = (Snark)_snarks.get(filename);
|
||||
torrent = _snarks.get(filename);
|
||||
}
|
||||
// don't hold the _snarks lock while verifying the torrent
|
||||
if (torrent == null) {
|
||||
@@ -1132,9 +1132,9 @@ public class SnarkManager implements Snark.CompleteListener {
|
||||
Snark torrent = null;
|
||||
synchronized (_snarks) {
|
||||
if (shouldRemove)
|
||||
torrent = (Snark)_snarks.remove(filename);
|
||||
torrent = _snarks.remove(filename);
|
||||
else
|
||||
torrent = (Snark)_snarks.get(filename);
|
||||
torrent = _snarks.get(filename);
|
||||
remaining = _snarks.size();
|
||||
}
|
||||
if (torrent != null) {
|
||||
|
||||
@@ -877,7 +877,7 @@ public class Storage
|
||||
{
|
||||
// First check if the piece is correct.
|
||||
// Copy the array first to be paranoid.
|
||||
byte[] bs = (byte[]) ba.clone();
|
||||
byte[] bs = ba.clone();
|
||||
int length = bs.length;
|
||||
boolean correctHash = metainfo.checkPiece(piece, bs, 0, length);
|
||||
if (listener != null)
|
||||
|
||||
@@ -302,7 +302,7 @@ public class I2PSnarkServlet extends DefaultServlet {
|
||||
if (!msgs.isEmpty()) {
|
||||
out.write("<div class=\"snarkMessages\"><ul>");
|
||||
for (int i = msgs.size()-1; i >= 0; i--) {
|
||||
String msg = (String)msgs.get(i);
|
||||
String msg = msgs.get(i);
|
||||
out.write("<li>" + msg + "</li>\n");
|
||||
}
|
||||
// lazy GET, lose p parameter
|
||||
@@ -1176,7 +1176,7 @@ public class I2PSnarkServlet extends DefaultServlet {
|
||||
out.write("<td align=\"right\" class=\"snarkTorrentStatus " + rowClass + "\">");
|
||||
float pct;
|
||||
if (isValid) {
|
||||
pct = (float) (100.0 * (float) peer.completed() / meta.getPieces());
|
||||
pct = (float) (100.0 * peer.completed() / meta.getPieces());
|
||||
if (pct == 100.0)
|
||||
out.write(_("Seed"));
|
||||
else {
|
||||
|
||||
@@ -395,7 +395,7 @@ public class I2PTunnel extends EventDispatcherImpl implements Logging {
|
||||
notifyEvent("serverTaskId", Integer.valueOf(-1));
|
||||
throw new IllegalArgumentException(getPrefix() + "Cannot open private key file " + args[2]);
|
||||
}
|
||||
I2PTunnelServer serv = new I2PTunnelServer(serverHost, portNum, privKeyFile, args[2], l, (EventDispatcher) this, this);
|
||||
I2PTunnelServer serv = new I2PTunnelServer(serverHost, portNum, privKeyFile, args[2], l, this, this);
|
||||
serv.setReadTimeout(readTimeout);
|
||||
serv.startRunning();
|
||||
addtask(serv);
|
||||
@@ -446,7 +446,7 @@ public class I2PTunnel extends EventDispatcherImpl implements Logging {
|
||||
notifyEvent("serverTaskId", Integer.valueOf(-1));
|
||||
throw new IllegalArgumentException(getPrefix() + "Cannot open private key file " + args[2]);
|
||||
}
|
||||
I2PTunnelServer serv = new I2PTunnelIRCServer(serverHost, portNum, privKeyFile, args[2], l, (EventDispatcher) this, this);
|
||||
I2PTunnelServer serv = new I2PTunnelIRCServer(serverHost, portNum, privKeyFile, args[2], l, this, this);
|
||||
serv.setReadTimeout(readTimeout);
|
||||
serv.startRunning();
|
||||
addtask(serv);
|
||||
@@ -507,7 +507,7 @@ public class I2PTunnel extends EventDispatcherImpl implements Logging {
|
||||
notifyEvent("serverTaskId", Integer.valueOf(-1));
|
||||
throw new IllegalArgumentException(getPrefix() + "Cannot open private key file " + args[3]);
|
||||
}
|
||||
I2PTunnelHTTPServer serv = new I2PTunnelHTTPServer(serverHost, portNum, privKeyFile, args[3], spoofedHost, l, (EventDispatcher) this, this);
|
||||
I2PTunnelHTTPServer serv = new I2PTunnelHTTPServer(serverHost, portNum, privKeyFile, args[3], spoofedHost, l, this, this);
|
||||
serv.setReadTimeout(readTimeout);
|
||||
serv.startRunning();
|
||||
addtask(serv);
|
||||
@@ -583,7 +583,7 @@ public class I2PTunnel extends EventDispatcherImpl implements Logging {
|
||||
throw new IllegalArgumentException(getPrefix() + "Cannot open private key file " + args[4]);
|
||||
}
|
||||
|
||||
I2PTunnelHTTPBidirServer serv = new I2PTunnelHTTPBidirServer(serverHost, portNum, port2Num, privKeyFile, args[3], spoofedHost, l, (EventDispatcher) this, this);
|
||||
I2PTunnelHTTPBidirServer serv = new I2PTunnelHTTPBidirServer(serverHost, portNum, port2Num, privKeyFile, args[3], spoofedHost, l, this, this);
|
||||
serv.setReadTimeout(readTimeout);
|
||||
serv.startRunning();
|
||||
addtask(serv);
|
||||
@@ -637,7 +637,7 @@ public class I2PTunnel extends EventDispatcherImpl implements Logging {
|
||||
if (portNum <= 0)
|
||||
throw new IllegalArgumentException(getPrefix() + "Bad port " + args[1]);
|
||||
|
||||
I2PTunnelServer serv = new I2PTunnelServer(serverHost, portNum, args[2], l, (EventDispatcher) this, this);
|
||||
I2PTunnelServer serv = new I2PTunnelServer(serverHost, portNum, args[2], l, this, this);
|
||||
serv.setReadTimeout(readTimeout);
|
||||
serv.startRunning();
|
||||
addtask(serv);
|
||||
@@ -685,7 +685,7 @@ public class I2PTunnel extends EventDispatcherImpl implements Logging {
|
||||
String privateKeyFile = null;
|
||||
if (args.length >= 4)
|
||||
privateKeyFile = args[3];
|
||||
task = new I2PTunnelClient(portNum, args[1], l, ownDest, (EventDispatcher) this, this, privateKeyFile);
|
||||
task = new I2PTunnelClient(portNum, args[1], l, ownDest, this, this, privateKeyFile);
|
||||
addtask(task);
|
||||
notifyEvent("clientTaskId", Integer.valueOf(task.getId()));
|
||||
} catch (IllegalArgumentException iae) {
|
||||
@@ -761,7 +761,7 @@ public class I2PTunnel extends EventDispatcherImpl implements Logging {
|
||||
I2PTunnelTask task;
|
||||
ownDest = !isShared;
|
||||
try {
|
||||
task = new I2PTunnelHTTPClient(clientPort, l, ownDest, proxy, (EventDispatcher) this, this);
|
||||
task = new I2PTunnelHTTPClient(clientPort, l, ownDest, proxy, this, this);
|
||||
addtask(task);
|
||||
notifyEvent("httpclientTaskId", Integer.valueOf(task.getId()));
|
||||
} catch (IllegalArgumentException iae) {
|
||||
@@ -830,7 +830,7 @@ public class I2PTunnel extends EventDispatcherImpl implements Logging {
|
||||
I2PTunnelTask task;
|
||||
ownDest = !isShared;
|
||||
try {
|
||||
task = new I2PTunnelConnectClient(_port, l, ownDest, proxy, (EventDispatcher) this, this);
|
||||
task = new I2PTunnelConnectClient(_port, l, ownDest, proxy, this, this);
|
||||
addtask(task);
|
||||
} catch (IllegalArgumentException iae) {
|
||||
String msg = "Invalid I2PTunnel configuration to create a CONNECT client connecting to the router at " + host + ':'+ port +
|
||||
@@ -895,7 +895,7 @@ public class I2PTunnel extends EventDispatcherImpl implements Logging {
|
||||
String privateKeyFile = null;
|
||||
if (args.length >= 4)
|
||||
privateKeyFile = args[3];
|
||||
task = new I2PTunnelIRCClient(_port, args[1], l, ownDest, (EventDispatcher) this, this, privateKeyFile);
|
||||
task = new I2PTunnelIRCClient(_port, args[1], l, ownDest, this, this, privateKeyFile);
|
||||
addtask(task);
|
||||
notifyEvent("ircclientTaskId", Integer.valueOf(task.getId()));
|
||||
} catch (IllegalArgumentException iae) {
|
||||
@@ -949,7 +949,7 @@ public class I2PTunnel extends EventDispatcherImpl implements Logging {
|
||||
|
||||
ownDest = !isShared;
|
||||
try {
|
||||
I2PTunnelTask task = new I2PSOCKSTunnel(_port, l, ownDest, (EventDispatcher) this, this, null);
|
||||
I2PTunnelTask task = new I2PSOCKSTunnel(_port, l, ownDest, this, this, null);
|
||||
addtask(task);
|
||||
notifyEvent("sockstunnelTaskId", Integer.valueOf(task.getId()));
|
||||
} catch (IllegalArgumentException iae) {
|
||||
@@ -996,7 +996,7 @@ public class I2PTunnel extends EventDispatcherImpl implements Logging {
|
||||
if (args.length == 3)
|
||||
privateKeyFile = args[2];
|
||||
try {
|
||||
I2PTunnelTask task = new I2PSOCKSIRCTunnel(_port, l, ownDest, (EventDispatcher) this, this, privateKeyFile);
|
||||
I2PTunnelTask task = new I2PSOCKSIRCTunnel(_port, l, ownDest, this, this, privateKeyFile);
|
||||
addtask(task);
|
||||
notifyEvent("sockstunnelTaskId", Integer.valueOf(task.getId()));
|
||||
} catch (IllegalArgumentException iae) {
|
||||
@@ -1045,7 +1045,7 @@ public class I2PTunnel extends EventDispatcherImpl implements Logging {
|
||||
throw new IllegalArgumentException(getPrefix() + "Bad port " + args[0]);
|
||||
|
||||
try {
|
||||
StreamrConsumer task = new StreamrConsumer(_host, _port, args[2], l, (EventDispatcher) this, this);
|
||||
StreamrConsumer task = new StreamrConsumer(_host, _port, args[2], l, this, this);
|
||||
task.startRunning();
|
||||
addtask(task);
|
||||
notifyEvent("streamrtunnelTaskId", Integer.valueOf(task.getId()));
|
||||
@@ -1094,7 +1094,7 @@ public class I2PTunnel extends EventDispatcherImpl implements Logging {
|
||||
return;
|
||||
}
|
||||
|
||||
StreamrProducer task = new StreamrProducer(_port, privKeyFile, args[1], l, (EventDispatcher) this, this);
|
||||
StreamrProducer task = new StreamrProducer(_port, privKeyFile, args[1], l, this, this);
|
||||
task.startRunning();
|
||||
addtask(task);
|
||||
notifyEvent("streamrtunnelTaskId", Integer.valueOf(task.getId()));
|
||||
@@ -1411,7 +1411,7 @@ public class I2PTunnel extends EventDispatcherImpl implements Logging {
|
||||
if (allargs.length() != 0) {
|
||||
I2PTunnelTask task;
|
||||
// pings always use the main destination
|
||||
task = new I2Ping(allargs, l, false, (EventDispatcher) this, this);
|
||||
task = new I2Ping(allargs, l, false, this, this);
|
||||
addtask(task);
|
||||
notifyEvent("pingTaskId", Integer.valueOf(task.getId()));
|
||||
} else {
|
||||
|
||||
@@ -176,7 +176,7 @@ public class ConfigTunnelsHelper extends HelperBase {
|
||||
"value=\"");
|
||||
for (Iterator iter = props.keySet().iterator(); iter.hasNext(); ) {
|
||||
String prop = (String)iter.next();
|
||||
String val = (String)props.getProperty(prop);
|
||||
String val = props.getProperty(prop);
|
||||
buf.append(prop).append('=').append(val).append(' ');
|
||||
}
|
||||
buf.append("\"></td></tr>\n");
|
||||
@@ -189,7 +189,7 @@ public class ConfigTunnelsHelper extends HelperBase {
|
||||
"value=\"");
|
||||
for (Iterator iter = props.keySet().iterator(); iter.hasNext(); ) {
|
||||
String prop = (String)iter.next();
|
||||
String val = (String)props.getProperty(prop);
|
||||
String val = props.getProperty(prop);
|
||||
buf.append(prop).append('=').append(val).append(' ');
|
||||
}
|
||||
buf.append("\"></td></tr>\n");
|
||||
|
||||
@@ -161,7 +161,7 @@ public class PluginUpdateHandler extends UpdateHandler {
|
||||
StringBuilder buf = new StringBuilder(64);
|
||||
buf.append("<b>").append(_("Downloading plugin")).append(' ');
|
||||
double pct = ((double)alreadyTransferred + (double)currentWrite) /
|
||||
((double)alreadyTransferred + (double)currentWrite + (double)bytesRemaining);
|
||||
((double)alreadyTransferred + (double)currentWrite + bytesRemaining);
|
||||
synchronized (_pct) {
|
||||
buf.append(_pct.format(pct));
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ class SummaryListener implements RateSummaryListener {
|
||||
// add one value to the db (the average value for the period)
|
||||
try {
|
||||
_sample.setTime(when);
|
||||
double val = eventCount > 0 ? (totalValue / (double)eventCount) : 0d;
|
||||
double val = eventCount > 0 ? (totalValue / eventCount) : 0d;
|
||||
_sample.setValue(_name, val);
|
||||
_sample.setValue(_eventName, eventCount);
|
||||
//_sample.setValue(0, val);
|
||||
|
||||
@@ -118,7 +118,7 @@ public class TunnelRenderer {
|
||||
lifetime = 1;
|
||||
if (lifetime > 10*60)
|
||||
lifetime = 10*60;
|
||||
int bps = 1024 * (int) cfg.getProcessedMessagesCount() / lifetime;
|
||||
int bps = 1024 * cfg.getProcessedMessagesCount() / lifetime;
|
||||
out.write("<td class=\"cells\" align=\"center\">" + bps + " Bps</td>");
|
||||
if (cfg.getSendTo() == null)
|
||||
out.write("<td class=\"cells\" align=\"center\">" + _("Outbound Endpoint") + "</td>");
|
||||
@@ -139,7 +139,7 @@ public class TunnelRenderer {
|
||||
|
||||
private static class TunnelComparator implements Comparator<HopConfig> {
|
||||
public int compare(HopConfig l, HopConfig r) {
|
||||
return (int) (r.getProcessedMessagesCount() - l.getProcessedMessagesCount());
|
||||
return (r.getProcessedMessagesCount() - l.getProcessedMessagesCount());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -236,7 +236,7 @@ public class UpdateHandler {
|
||||
StringBuilder buf = new StringBuilder(64);
|
||||
buf.append("<b>").append(_("Updating")).append("</b> ");
|
||||
double pct = ((double)alreadyTransferred + (double)currentWrite) /
|
||||
((double)alreadyTransferred + (double)currentWrite + (double)bytesRemaining);
|
||||
((double)alreadyTransferred + (double)currentWrite + bytesRemaining);
|
||||
synchronized (_pct) {
|
||||
buf.append(_pct.format(pct));
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ public class SAMBridge implements Runnable {
|
||||
*/
|
||||
public Destination getDestination(String name) {
|
||||
synchronized (nameToPrivKeys) {
|
||||
String val = (String)nameToPrivKeys.get(name);
|
||||
String val = nameToPrivKeys.get(name);
|
||||
if (val == null) return null;
|
||||
try {
|
||||
Destination d = new Destination();
|
||||
@@ -133,7 +133,7 @@ public class SAMBridge implements Runnable {
|
||||
*/
|
||||
public String getKeystream(String name) {
|
||||
synchronized (nameToPrivKeys) {
|
||||
String val = (String)nameToPrivKeys.get(name);
|
||||
String val = nameToPrivKeys.get(name);
|
||||
if (val == null) return null;
|
||||
return val;
|
||||
}
|
||||
@@ -191,7 +191,7 @@ public class SAMBridge implements Runnable {
|
||||
out = new FileOutputStream(persistFilename);
|
||||
for (Iterator iter = nameToPrivKeys.keySet().iterator(); iter.hasNext(); ) {
|
||||
String name = (String)iter.next();
|
||||
String privKeys = (String)nameToPrivKeys.get(name);
|
||||
String privKeys = nameToPrivKeys.get(name);
|
||||
out.write(name.getBytes());
|
||||
out.write('=');
|
||||
out.write(privKeys.getBytes());
|
||||
|
||||
@@ -144,8 +144,8 @@ public class SAMHandlerFactory {
|
||||
|
||||
if ((minMinor >= 10) || (maxMinor >= 10)) return null ;
|
||||
|
||||
float fminVer = (float) minMajor + (float) minMinor / 10 ;
|
||||
float fmaxVer = (float) maxMajor + (float) maxMinor / 10 ;
|
||||
float fminVer = minMajor + (float) minMinor / 10 ;
|
||||
float fmaxVer = maxMajor + (float) maxMinor / 10 ;
|
||||
|
||||
|
||||
if ( ( fminVer <= 3.0 ) && ( fmaxVer >= 3.0 ) ) return "3.0" ;
|
||||
|
||||
@@ -344,12 +344,12 @@ public class SAMStreamSession {
|
||||
*/
|
||||
protected SAMStreamSessionSocketReader getSocketReader ( int id ) {
|
||||
synchronized (handlersMapLock) {
|
||||
return (SAMStreamSessionSocketReader)handlersMap.get(new Integer(id));
|
||||
return handlersMap.get(new Integer(id));
|
||||
}
|
||||
}
|
||||
private StreamSender getSender(int id) {
|
||||
synchronized (handlersMapLock) {
|
||||
return (StreamSender)sendersMap.get(new Integer(id));
|
||||
return sendersMap.get(new Integer(id));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -375,8 +375,8 @@ public class SAMStreamSession {
|
||||
StreamSender sender = null;
|
||||
|
||||
synchronized (handlersMapLock) {
|
||||
reader = (SAMStreamSessionSocketReader)handlersMap.remove(new Integer(id));
|
||||
sender = (StreamSender)sendersMap.remove(new Integer(id));
|
||||
reader = handlersMap.remove(new Integer(id));
|
||||
sender = sendersMap.remove(new Integer(id));
|
||||
}
|
||||
|
||||
if (reader != null)
|
||||
@@ -402,8 +402,8 @@ public class SAMStreamSession {
|
||||
|
||||
while (iter.hasNext()) {
|
||||
id = (Integer)iter.next();
|
||||
((SAMStreamSessionSocketReader)handlersMap.get(id)).stopRunning();
|
||||
((StreamSender)sendersMap.get(id)).shutDownGracefully();
|
||||
handlersMap.get(id).stopRunning();
|
||||
sendersMap.get(id).shutDownGracefully();
|
||||
}
|
||||
handlersMap.clear();
|
||||
sendersMap.clear();
|
||||
@@ -740,7 +740,7 @@ public class SAMStreamSession {
|
||||
try {
|
||||
synchronized (_data) {
|
||||
if (!_data.isEmpty()) {
|
||||
data = (ByteArray)_data.remove(0);
|
||||
data = _data.remove(0);
|
||||
} else if (_shuttingDownGracefully) {
|
||||
/* No data left and shutting down gracefully?
|
||||
If so, stop the sender. */
|
||||
|
||||
@@ -374,7 +374,7 @@ public class SAMv2StreamSession extends SAMStreamSession
|
||||
if ( !_data.isEmpty() )
|
||||
{
|
||||
int formerSize = _dataSize ;
|
||||
data = ( ByteArray ) _data.remove ( 0 );
|
||||
data = _data.remove ( 0 );
|
||||
_dataSize -= data.getValid();
|
||||
|
||||
if ( ( formerSize >= SOCKET_HANDLER_BUF_SIZE ) && ( _dataSize < SOCKET_HANDLER_BUF_SIZE ) )
|
||||
|
||||
@@ -116,7 +116,7 @@ public class SAMEventHandler extends SAMClientEventListenerImpl {
|
||||
while (true) {
|
||||
try {
|
||||
synchronized (_namingReplyLock) {
|
||||
String val = (String)_namingReplies.remove(name);
|
||||
String val = _namingReplies.remove(name);
|
||||
if (val == null) {
|
||||
_namingReplyLock.wait();
|
||||
} else {
|
||||
|
||||
@@ -81,7 +81,7 @@ public class SAMStreamSend {
|
||||
public void streamClosedReceived(String result, int id, String message) {
|
||||
Sender sender = null;
|
||||
synchronized (_remotePeers) {
|
||||
sender = (Sender)_remotePeers.remove(new Integer(id));
|
||||
sender = _remotePeers.remove(new Integer(id));
|
||||
}
|
||||
if (sender != null) {
|
||||
sender.closed();
|
||||
|
||||
@@ -83,7 +83,7 @@ public class SAMStreamSink {
|
||||
public void streamClosedReceived(String result, int id, String message) {
|
||||
Sink sink = null;
|
||||
synchronized (_remotePeers) {
|
||||
sink = (Sink)_remotePeers.remove(new Integer(id));
|
||||
sink = _remotePeers.remove(new Integer(id));
|
||||
}
|
||||
if (sink != null) {
|
||||
sink.closed();
|
||||
@@ -96,7 +96,7 @@ public class SAMStreamSink {
|
||||
public void streamDataReceived(int id, byte data[], int offset, int length) {
|
||||
Sink sink = null;
|
||||
synchronized (_remotePeers) {
|
||||
sink = (Sink)_remotePeers.get(new Integer(id));
|
||||
sink = _remotePeers.get(new Integer(id));
|
||||
}
|
||||
if (sink != null) {
|
||||
sink.received(data, offset, length);
|
||||
|
||||
@@ -1532,7 +1532,7 @@ public class WebMail extends HttpServlet
|
||||
button( RELOAD, _("Reload Config") ) + spacer +
|
||||
button( LOGOUT, _("Logout") ) );
|
||||
|
||||
String from = (String)request.getParameter( NEW_FROM );
|
||||
String from = request.getParameter( NEW_FROM );
|
||||
String fixed = Config.getProperty( CONFIG_SENDER_FIXED, "true" );
|
||||
|
||||
if( from == null || fixed.compareToIgnoreCase( "false" ) != 0 ) {
|
||||
|
||||
@@ -125,7 +125,7 @@ public class Sha256Standalone extends BaseHashStandalone {
|
||||
this.h6 = md.h6;
|
||||
this.h7 = md.h7;
|
||||
this.count = md.count;
|
||||
this.buffer = (byte[]) md.buffer.clone();
|
||||
this.buffer = md.buffer.clone();
|
||||
}
|
||||
|
||||
// Class methods
|
||||
|
||||
@@ -77,7 +77,7 @@ public class AsyncFortunaStandalone extends FortunaStandalone implements Runnabl
|
||||
@Override
|
||||
public void seed(byte val[]) {
|
||||
Map props = new HashMap(1);
|
||||
props.put(SEED, (Object)val);
|
||||
props.put(SEED, val);
|
||||
init(props);
|
||||
//fillBlock();
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ public class FortunaStandalone extends BasePRNGStandalone implements Serializabl
|
||||
|
||||
public void seed(byte val[]) {
|
||||
Map props = new HashMap(1);
|
||||
props.put(SEED, (Object)val);
|
||||
props.put(SEED, val);
|
||||
init(props);
|
||||
fillBlock();
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ public class RandomEventStandalone extends EventObject
|
||||
this.poolNumber = poolNumber;
|
||||
if (data.length == 0 || data.length > 32)
|
||||
throw new IllegalArgumentException("random events take between 1 and 32 bytes of data");
|
||||
this.data = (byte[]) data.clone();
|
||||
this.data = data.clone();
|
||||
}
|
||||
|
||||
public byte getSourceNumber()
|
||||
|
||||
@@ -139,7 +139,7 @@ public final class SHA1 extends MessageDigest implements Cloneable {
|
||||
@Override
|
||||
public Object clone() throws CloneNotSupportedException {
|
||||
SHA1 that = (SHA1)super.clone();
|
||||
that.pad = (byte[])this.pad.clone();
|
||||
that.pad = this.pad.clone();
|
||||
return that;
|
||||
}
|
||||
|
||||
|
||||
@@ -504,7 +504,7 @@ public class TransientSessionKeyManager extends SessionKeyManager {
|
||||
removed.add(set);
|
||||
}
|
||||
for (int i = 0; i < removed.size(); i++) {
|
||||
TagSet cur = (TagSet)removed.get(i);
|
||||
TagSet cur = removed.get(i);
|
||||
for (Iterator<SessionTag> iter = cur.getTags().iterator(); iter.hasNext(); ) {
|
||||
SessionTag tag = iter.next();
|
||||
_inboundTagSets.remove(tag);
|
||||
@@ -533,7 +533,7 @@ public class TransientSessionKeyManager extends SessionKeyManager {
|
||||
public SessionKey consumeTag(SessionTag tag) {
|
||||
//if (false) aggressiveExpire();
|
||||
synchronized (_inboundTagSets) {
|
||||
TagSet tagSet = (TagSet) _inboundTagSets.remove(tag);
|
||||
TagSet tagSet = _inboundTagSets.remove(tag);
|
||||
if (tagSet == null) {
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Cannot consume IB " + tag + " as it is not known");
|
||||
|
||||
@@ -175,9 +175,9 @@ public class LeaseSet extends DatabaseEntry {
|
||||
|
||||
public Lease getLease(int index) {
|
||||
if (isEncrypted())
|
||||
return (Lease) _decryptedLeases.get(index);
|
||||
return _decryptedLeases.get(index);
|
||||
else
|
||||
return (Lease) _leases.get(index);
|
||||
return _leases.get(index);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -397,8 +397,8 @@ public class LeaseSet extends DatabaseEntry {
|
||||
int datalen = ((DATA_LEN * size / 16) + 1) * 16;
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream(datalen);
|
||||
for (int i = 0; i < size; i++) {
|
||||
((Lease)_leases.get(i)).getGateway().writeBytes(baos);
|
||||
((Lease)_leases.get(i)).getTunnelId().writeBytes(baos);
|
||||
_leases.get(i).getGateway().writeBytes(baos);
|
||||
_leases.get(i).getTunnelId().writeBytes(baos);
|
||||
}
|
||||
// pad out to multiple of 16 with random data before encryption
|
||||
int padlen = datalen - (DATA_LEN * size);
|
||||
@@ -415,17 +415,17 @@ public class LeaseSet extends DatabaseEntry {
|
||||
RandomSource.getInstance().nextBytes(enc, datalen, padlen);
|
||||
// add the padded lease...
|
||||
Lease padLease = new Lease();
|
||||
padLease.setEndDate(((Lease)_leases.get(0)).getEndDate());
|
||||
padLease.setEndDate(_leases.get(0).getEndDate());
|
||||
_leases.add(padLease);
|
||||
// ...and replace all the gateways and tunnel ids
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(enc);
|
||||
for (int i = 0; i < size+1; i++) {
|
||||
Hash h = new Hash();
|
||||
h.readBytes(bais);
|
||||
((Lease)_leases.get(i)).setGateway(h);
|
||||
_leases.get(i).setGateway(h);
|
||||
TunnelId t = new TunnelId();
|
||||
t.readBytes(bais);
|
||||
((Lease)_leases.get(i)).setTunnelId(t);
|
||||
_leases.get(i).setTunnelId(t);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -444,8 +444,8 @@ public class LeaseSet extends DatabaseEntry {
|
||||
int datalen = DATA_LEN * size;
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream(datalen);
|
||||
for (int i = 0; i < size; i++) {
|
||||
((Lease)_leases.get(i)).getGateway().writeBytes(baos);
|
||||
((Lease)_leases.get(i)).getTunnelId().writeBytes(baos);
|
||||
_leases.get(i).getGateway().writeBytes(baos);
|
||||
_leases.get(i).getTunnelId().writeBytes(baos);
|
||||
}
|
||||
byte[] iv = new byte[IV_LEN];
|
||||
System.arraycopy(_destination.getPublicKey().getData(), 0, iv, 0, IV_LEN);
|
||||
@@ -464,7 +464,7 @@ public class LeaseSet extends DatabaseEntry {
|
||||
TunnelId t = new TunnelId();
|
||||
t.readBytes(bais);
|
||||
l.setTunnelId(t);
|
||||
l.setEndDate(((Lease)_leases.get(i)).getEndDate());
|
||||
l.setEndDate(_leases.get(i).getEndDate());
|
||||
_decryptedLeases.add(l);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -521,7 +521,7 @@ public class Rate {
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return DataHelper.hashCode(_stat) ^ ((int)_period) ^ ((int) _creationDate);
|
||||
return DataHelper.hashCode(_stat) ^ _period ^ ((int) _creationDate);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -293,8 +293,8 @@ public class NtpMessage {
|
||||
|
||||
p[0] = (byte) (leapIndicator << 6 | version << 3 | mode);
|
||||
p[1] = (byte) stratum;
|
||||
p[2] = (byte) pollInterval;
|
||||
p[3] = (byte) precision;
|
||||
p[2] = pollInterval;
|
||||
p[3] = precision;
|
||||
|
||||
// root delay is a signed 16.16-bit FP, in Java an int is 32-bits
|
||||
int l = (int) (rootDelay * 65536.0);
|
||||
@@ -358,7 +358,7 @@ public class NtpMessage {
|
||||
if((b & 0x80)==0x80)
|
||||
return (short) (128 + (b & 0x7f));
|
||||
else
|
||||
return (short) b;
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
@@ -393,7 +393,7 @@ public class NtpMessage {
|
||||
array[pointer+i] = (byte) (timestamp / base);
|
||||
|
||||
// Subtract captured value from remaining total
|
||||
timestamp = timestamp - (double) (unsignedByteToShort(array[pointer+i]) * base);
|
||||
timestamp = timestamp - (unsignedByteToShort(array[pointer+i]) * base);
|
||||
}
|
||||
|
||||
// From RFC 2030: It is advisable to fill the non-significant
|
||||
|
||||
@@ -86,7 +86,7 @@ public class Timestamper implements Runnable {
|
||||
}
|
||||
public String getServer(int index) {
|
||||
synchronized (_servers) {
|
||||
return (String)_servers.get(index);
|
||||
return _servers.get(index);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -305,7 +305,7 @@ public class Timestamper implements Runnable {
|
||||
_servers.clear();
|
||||
StringTokenizer tok = new StringTokenizer(serverList, ", ");
|
||||
while (tok.hasMoreTokens()) {
|
||||
String val = (String)tok.nextToken();
|
||||
String val = tok.nextToken();
|
||||
val = val.trim();
|
||||
if (val.length() > 0)
|
||||
_servers.add(val);
|
||||
|
||||
@@ -184,14 +184,14 @@ public class BufferedRandomSource extends RandomSource {
|
||||
return nextBits(1) != 0;
|
||||
}
|
||||
|
||||
private static final double DOUBLE_DENOMENATOR = (double)(1L << 53);
|
||||
private static final double DOUBLE_DENOMENATOR = (1L << 53);
|
||||
/** defined per javadoc ( ((nextBits(26)<<27) + nextBits(27)) / (1 << 53)) */
|
||||
@Override
|
||||
public final double nextDouble() {
|
||||
long top = (((long)nextBits(26) << 27) + nextBits(27));
|
||||
long top = ((nextBits(26) << 27) + nextBits(27));
|
||||
return top / DOUBLE_DENOMENATOR;
|
||||
}
|
||||
private static final float FLOAT_DENOMENATOR = (float)(1 << 24);
|
||||
private static final float FLOAT_DENOMENATOR = (1 << 24);
|
||||
/** defined per javadoc (nextBits(24) / ((float)(1 << 24)) ) */
|
||||
@Override
|
||||
public float nextFloat() {
|
||||
|
||||
@@ -362,20 +362,20 @@ public class EepGet {
|
||||
buf.append(" ");
|
||||
if ( bytesRemaining > 0 ) {
|
||||
double pct = 100 * ((double)_written + _previousWritten) /
|
||||
((double)alreadyTransferred + (double)currentWrite + (double)bytesRemaining);
|
||||
((double)alreadyTransferred + (double)currentWrite + bytesRemaining);
|
||||
fmt.format("%4.1f", Double.valueOf(pct));
|
||||
buf.append("%: ");
|
||||
}
|
||||
fmt.format("%8d", Long.valueOf(_written));
|
||||
buf.append(" @ ");
|
||||
double lineKBytes = ((double)_markSize * (double)_lineSize)/1024.0d;
|
||||
double kbps = lineKBytes/((double)timeToSend/1000.0d);
|
||||
double kbps = lineKBytes/(timeToSend/1000.0d);
|
||||
fmt.format("%7.2f", Double.valueOf(kbps));
|
||||
buf.append(" KBps");
|
||||
|
||||
buf.append(" / ");
|
||||
long lifetime = _context.clock().now() - _startedOn;
|
||||
double lifetimeKBps = (1000.0d*(double)(_written)/((double)lifetime*1024.0d));
|
||||
double lifetimeKBps = (1000.0d*(_written)/(lifetime*1024.0d));
|
||||
fmt.format("%7.2f", Double.valueOf(lifetimeKBps));
|
||||
buf.append(" KBps");
|
||||
System.out.println(buf.toString());
|
||||
@@ -415,7 +415,7 @@ public class EepGet {
|
||||
if (transferred > 0) {
|
||||
StringBuilder buf = new StringBuilder(50);
|
||||
buf.append("== Transfer rate: ");
|
||||
double kbps = (1000.0d*(double)(transferred)/((double)timeToSend*1024.0d));
|
||||
double kbps = (1000.0d*(transferred)/(timeToSend*1024.0d));
|
||||
synchronized (_kbps) {
|
||||
buf.append(_kbps.format(kbps));
|
||||
}
|
||||
@@ -440,7 +440,7 @@ public class EepGet {
|
||||
+ (bytesRemaining < 0 ? "unknown" : ""+bytesRemaining) + " remaining");
|
||||
long timeToSend = _context.clock().now() - _startedOn;
|
||||
System.out.println("== Transfer time: " + DataHelper.formatDuration(timeToSend));
|
||||
double kbps = (timeToSend > 0 ? (1000.0d*(double)(bytesTransferred)/((double)timeToSend*1024.0d)) : 0);
|
||||
double kbps = (timeToSend > 0 ? (1000.0d*(bytesTransferred)/(timeToSend*1024.0d)) : 0);
|
||||
StringBuilder buf = new StringBuilder(50);
|
||||
buf.append("== Transfer rate: ");
|
||||
synchronized (_kbps) {
|
||||
|
||||
@@ -172,10 +172,10 @@ public class EepHead extends EepGet {
|
||||
if (_transferFailed) {
|
||||
// 404, etc - transferFailed is called after all attempts fail, by fetch() above
|
||||
for (int i = 0; i < _listeners.size(); i++)
|
||||
((StatusListener)_listeners.get(i)).attemptFailed(_url, 0, 0, _currentAttempt, _numRetries, new Exception("Attempt failed"));
|
||||
_listeners.get(i).attemptFailed(_url, 0, 0, _currentAttempt, _numRetries, new Exception("Attempt failed"));
|
||||
} else {
|
||||
for (int i = 0; i < _listeners.size(); i++)
|
||||
((StatusListener)_listeners.get(i)).transferComplete(
|
||||
_listeners.get(i).transferComplete(
|
||||
0, 0, 0, _url, "dummy", false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,7 +218,7 @@ public class EepPost {
|
||||
I2PAppContext.getGlobalContext().random().nextBytes(separator);
|
||||
StringBuilder sep = new StringBuilder(48);
|
||||
for (int i = 0; i < separator.length; i++)
|
||||
sep.append((char)((int)'a' + (int)(separator[i]&0x0F))).append((char)((int)'a' + (int)((separator[i] >>> 4) & 0x0F)));
|
||||
sep.append((char)('a' + (separator[i]&0x0F))).append((char)('a' + ((separator[i] >>> 4) & 0x0F)));
|
||||
return sep.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -409,7 +409,7 @@ public class NativeBigInteger extends BigInteger {
|
||||
System.out.println("native run time: \t" + totalTime + "ms (" + (totalTime / (runsProcessed + 1))
|
||||
+ "ms each)");
|
||||
System.out.println("java run time: \t" + javaTime + "ms (" + (javaTime / (runsProcessed + 1)) + "ms each)");
|
||||
System.out.println("native = " + ((totalTime * 100.0d) / (double) javaTime) + "% of pure java time");
|
||||
System.out.println("native = " + ((totalTime * 100.0d) / javaTime) + "% of pure java time");
|
||||
} else {
|
||||
System.out.println("java run time: \t" + javaTime + "ms (" + (javaTime / (runsProcessed + 1)) + "ms each)");
|
||||
System.out.println("However, we couldn't load the native library, so this doesn't test much");
|
||||
|
||||
@@ -128,7 +128,7 @@ public class SimpleTimer {
|
||||
Long time = Long.valueOf(eventTime);
|
||||
synchronized (_events) {
|
||||
// remove the old scheduled position, then reinsert it
|
||||
Long oldTime = (Long)_eventTimes.get(event);
|
||||
Long oldTime = _eventTimes.get(event);
|
||||
if (oldTime != null) {
|
||||
if (useEarliestTime) {
|
||||
if (oldTime.longValue() < eventTime) {
|
||||
@@ -155,8 +155,8 @@ public class SimpleTimer {
|
||||
_log.error("Skewed events: " + _events.size() + " for " + _eventTimes.size());
|
||||
for (Iterator iter = _eventTimes.keySet().iterator(); iter.hasNext(); ) {
|
||||
TimedEvent evt = (TimedEvent)iter.next();
|
||||
Long when = (Long)_eventTimes.get(evt);
|
||||
TimedEvent cur = (TimedEvent)_events.get(when);
|
||||
Long when = _eventTimes.get(evt);
|
||||
TimedEvent cur = _events.get(when);
|
||||
if (cur != evt) {
|
||||
_log.error("event " + evt + " @ " + when + ": " + cur);
|
||||
}
|
||||
@@ -182,7 +182,7 @@ public class SimpleTimer {
|
||||
public boolean removeEvent(TimedEvent evt) {
|
||||
if (evt == null) return false;
|
||||
synchronized (_events) {
|
||||
Long when = (Long)_eventTimes.remove(evt);
|
||||
Long when = _eventTimes.remove(evt);
|
||||
if (when != null)
|
||||
_events.remove(when);
|
||||
return null != when;
|
||||
@@ -222,9 +222,9 @@ public class SimpleTimer {
|
||||
if(_events.isEmpty()) {
|
||||
break;
|
||||
}
|
||||
Long when = (Long)_events.firstKey();
|
||||
Long when = _events.firstKey();
|
||||
if (when.longValue() <= now) {
|
||||
TimedEvent evt = (TimedEvent)_events.remove(when);
|
||||
TimedEvent evt = _events.remove(when);
|
||||
if (evt != null) {
|
||||
_eventTimes.remove(evt);
|
||||
eventsToFire.add(evt);
|
||||
|
||||
@@ -325,7 +325,7 @@ public class BlockFile {
|
||||
public static void pageSeek(RandomAccessInterface file, int page) throws IOException {
|
||||
if (page < METAINDEX_PAGE)
|
||||
throw new IOException("Negative page or superblock access attempt: " + page);
|
||||
file.seek((((long)page) - 1L) * PAGESIZE );
|
||||
file.seek((page - 1L) * PAGESIZE );
|
||||
}
|
||||
|
||||
public int allocPage() throws IOException {
|
||||
|
||||
@@ -42,10 +42,10 @@ public class IntBytes implements Serializer {
|
||||
}
|
||||
|
||||
public Object construct(byte[] b) {
|
||||
int v = (((int)(b[0] & 0xff) << 24) |
|
||||
((int)(b[1] & 0xff) << 16) |
|
||||
((int)(b[2] & 0xff) << 8) |
|
||||
((int)(b[3] & 0xff)));
|
||||
int v = (((b[0] & 0xff) << 24) |
|
||||
((b[1] & 0xff) << 16) |
|
||||
((b[2] & 0xff) << 8) |
|
||||
(b[3] & 0xff));
|
||||
return new Integer(v);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ public class LongBytes implements Serializer {
|
||||
((long)(b[4] & 0xff) << 24) |
|
||||
((long)(b[5] & 0xff) << 16) |
|
||||
((long)(b[6] & 0xff) << 8) |
|
||||
((long)(b[7] & 0xff)));
|
||||
(b[7] & 0xff));
|
||||
return new Long(v);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -296,7 +296,7 @@ public class BloomSHA1 {
|
||||
public final double falsePositives(int n) {
|
||||
// (1 - e(-kN/M))^k
|
||||
return java.lang.Math.pow (
|
||||
(1l - java.lang.Math.exp(0d- ((double)k) * (long)n / (long)filterBits)), (long)k);
|
||||
(1l - java.lang.Math.exp(0d- ((double)k) * (long)n / filterBits)), k);
|
||||
}
|
||||
|
||||
public final double falsePositives() {
|
||||
|
||||
@@ -109,8 +109,8 @@ public class HMACSHA256Bench {
|
||||
}
|
||||
|
||||
private static void display(int times, long before, long after, int len, String name) {
|
||||
double rate = ((double)times)/(((double)after-(double)before)/1000.0d);
|
||||
double kbps = ((double)len/1024.0d)*((double)times)/(((double)after-(double)before)/1000.0d);
|
||||
double rate = times/(((double)after-(double)before)/1000.0d);
|
||||
double kbps = (len/1024.0d)*times/(((double)after-(double)before)/1000.0d);
|
||||
System.out.println(name + " HMAC pulled " + kbps + "KBps or " + rate + " calcs per second");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ public class Blocklist {
|
||||
for (Iterator<Hash> iter = _peerBlocklist.keySet().iterator(); iter.hasNext(); ) {
|
||||
Hash peer = iter.next();
|
||||
String reason;
|
||||
String comment = (String) _peerBlocklist.get(peer);
|
||||
String comment = _peerBlocklist.get(peer);
|
||||
if (comment != null)
|
||||
reason = _x("Banned by router hash: {0}");
|
||||
else
|
||||
|
||||
@@ -561,7 +561,7 @@ public class Router implements RouterClock.ClockShiftListener {
|
||||
public void addCapabilities(RouterInfo ri) {
|
||||
int bwLim = Math.min(_context.bandwidthLimiter().getInboundKBytesPerSecond(),
|
||||
_context.bandwidthLimiter().getOutboundKBytesPerSecond());
|
||||
bwLim = (int)(((float)bwLim) * getSharePercentage());
|
||||
bwLim = (int)(bwLim * getSharePercentage());
|
||||
if (_log.shouldLog(Log.INFO))
|
||||
_log.info("Adding capabilities w/ bw limit @ " + bwLim, new Exception("caps"));
|
||||
|
||||
|
||||
@@ -381,7 +381,7 @@ class RouterThrottleImpl implements RouterThrottle {
|
||||
// Now see if 1m rates are too high
|
||||
long overage = Math.max(used1mIn - (maxKBpsIn*1024), used1mOut - (maxKBpsOut*1024));
|
||||
if ( (overage > 0) &&
|
||||
((overage/(float)(maxKBps*1024f)) > _context.random().nextFloat()) ) {
|
||||
((overage/(maxKBps*1024f)) > _context.random().nextFloat()) ) {
|
||||
if (_log.shouldLog(Log.WARN)) _log.warn("Reject tunnel, 1m rate (" + overage + " over) indicates overload.");
|
||||
setTunnelStatus(LIMIT_STR);
|
||||
return false;
|
||||
|
||||
@@ -213,7 +213,7 @@ public class StatisticsManager implements Service {
|
||||
double avgFrequency = rate.getLifetimeEventCount() / (double)numPeriods;
|
||||
buf.append(num(avgFrequency)).append(';');
|
||||
buf.append(num(rate.getExtremeEventCount())).append(';');
|
||||
buf.append(num((double)rate.getLifetimeEventCount())).append(';');
|
||||
buf.append(num(rate.getLifetimeEventCount())).append(';');
|
||||
}
|
||||
}
|
||||
return buf.toString();
|
||||
|
||||
@@ -568,7 +568,7 @@ public class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacade {
|
||||
|
||||
RepublishLeaseSetJob j = null;
|
||||
synchronized (_publishingLeaseSets) {
|
||||
j = (RepublishLeaseSetJob)_publishingLeaseSets.get(h);
|
||||
j = _publishingLeaseSets.get(h);
|
||||
if (j == null) {
|
||||
j = new RepublishLeaseSetJob(_context, this, h);
|
||||
_publishingLeaseSets.put(h, j);
|
||||
@@ -920,7 +920,7 @@ public class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacade {
|
||||
boolean isNew = true;
|
||||
SearchJob searchJob = null;
|
||||
synchronized (_activeRequests) {
|
||||
searchJob = (SearchJob)_activeRequests.get(key);
|
||||
searchJob = _activeRequests.get(key);
|
||||
if (searchJob == null) {
|
||||
searchJob = new SearchJob(_context, this, key, onFindJob, onFailedLookupJob,
|
||||
timeoutMs, true, isLease);
|
||||
|
||||
@@ -285,9 +285,9 @@ public class PeerProfile {
|
||||
|
||||
// weighted since we want to let the average grow quickly and shrink slowly
|
||||
if (ms < _tunnelTestResponseTimeAvg)
|
||||
_tunnelTestResponseTimeAvg = 0.95*_tunnelTestResponseTimeAvg + .05*(double)ms;
|
||||
_tunnelTestResponseTimeAvg = 0.95*_tunnelTestResponseTimeAvg + .05*ms;
|
||||
else
|
||||
_tunnelTestResponseTimeAvg = 0.75*_tunnelTestResponseTimeAvg + .25*(double)ms;
|
||||
_tunnelTestResponseTimeAvg = 0.75*_tunnelTestResponseTimeAvg + .25*ms;
|
||||
|
||||
if (_log.shouldLog(Log.INFO))
|
||||
_log.info("Updating tunnel test time for " + _peer.toBase64().substring(0,6)
|
||||
@@ -307,7 +307,7 @@ public class PeerProfile {
|
||||
double rv = 0;
|
||||
for (int i = 0; i < THROUGHPUT_COUNT; i++)
|
||||
rv += _peakThroughput[i];
|
||||
rv /= (60d*1024d*(double)THROUGHPUT_COUNT);
|
||||
rv /= (60d*1024d*THROUGHPUT_COUNT);
|
||||
return rv;
|
||||
}
|
||||
public void setPeakThroughputKBps(double kBps) {
|
||||
@@ -338,7 +338,7 @@ public class PeerProfile {
|
||||
double rv = 0;
|
||||
for (int i = 0; i < THROUGHPUT_COUNT; i++)
|
||||
rv += _peakTunnelThroughput[i];
|
||||
rv /= (10d*60d*1024d*(double)THROUGHPUT_COUNT);
|
||||
rv /= (10d*60d*1024d*THROUGHPUT_COUNT);
|
||||
return rv;
|
||||
}
|
||||
public void setPeakTunnelThroughputKBps(double kBps) {
|
||||
@@ -381,7 +381,7 @@ public class PeerProfile {
|
||||
double rv = 0;
|
||||
for (int i = 0; i < THROUGHPUT_COUNT; i++)
|
||||
rv += _peakTunnel1mThroughput[i];
|
||||
rv /= (60d*1024d*(double)THROUGHPUT_COUNT);
|
||||
rv /= (60d*1024d*THROUGHPUT_COUNT);
|
||||
return rv;
|
||||
}
|
||||
public void setPeakTunnel1mThroughputKBps(double kBps) {
|
||||
|
||||
@@ -613,7 +613,7 @@ public class ProfileOrganizer {
|
||||
start = _context.random().nextInt(_notFailingPeersList.size());
|
||||
for (int i = 0; i < _notFailingPeersList.size() && selected.size() < needed; i++) {
|
||||
int curIndex = (i+start) % _notFailingPeersList.size();
|
||||
Hash cur = (Hash)_notFailingPeersList.get(curIndex);
|
||||
Hash cur = _notFailingPeersList.get(curIndex);
|
||||
if (matches.contains(cur) ||
|
||||
(exclude != null && exclude.contains(cur))) {
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
|
||||
@@ -373,13 +373,13 @@ public class FIFOBandwidthLimiter {
|
||||
_lastStatsUpdated = now;
|
||||
|
||||
if (_sendBps <= 0)
|
||||
_sendBps = ((float)sent*1000f)/(float)time;
|
||||
_sendBps = (sent*1000f)/time;
|
||||
else
|
||||
_sendBps = (0.9f)*_sendBps + (0.1f)*((float)sent*1000f)/(float)time;
|
||||
_sendBps = (0.9f)*_sendBps + (0.1f)*(sent*1000f)/time;
|
||||
if (_recvBps <= 0)
|
||||
_recvBps = ((float)recv*1000f)/(float)time;
|
||||
_recvBps = (recv*1000f)/time;
|
||||
else
|
||||
_recvBps = (0.9f)*_recvBps + (0.1f)*((float)recv*1000)/(float)time;
|
||||
_recvBps = (0.9f)*_recvBps + (0.1f)*((float)recv*1000)/time;
|
||||
|
||||
// warning, getStatLog() can be null
|
||||
//if (_log.shouldLog(Log.WARN)) {
|
||||
@@ -395,12 +395,12 @@ public class FIFOBandwidthLimiter {
|
||||
//if (_sendBps15s <= 0)
|
||||
// _sendBps15s = (0.045f)*((float)sent*15*1000f)/(float)time;
|
||||
//else
|
||||
_sendBps15s = (0.955f)*_sendBps15s + (0.045f)*((float)sent*1000f)/(float)time;
|
||||
_sendBps15s = (0.955f)*_sendBps15s + (0.045f)*(sent*1000f)/time;
|
||||
|
||||
//if (_recvBps15s <= 0)
|
||||
// _recvBps15s = (0.045f)*((float)recv*15*1000f)/(float)time;
|
||||
//else
|
||||
_recvBps15s = (0.955f)*_recvBps15s + (0.045f)*((float)recv*1000)/(float)time;
|
||||
_recvBps15s = (0.955f)*_recvBps15s + (0.045f)*((float)recv*1000)/time;
|
||||
|
||||
// warning, getStatLog() can be null
|
||||
//if (_log.shouldLog(Log.WARN)) {
|
||||
|
||||
@@ -356,7 +356,7 @@ class GeoIP {
|
||||
int rv = 0;
|
||||
for (int i = 0; i < 4; i++)
|
||||
rv |= (ip[i] & 0xff) << ((3-i)*8);
|
||||
return ((long) rv) & 0xffffffffl;
|
||||
return rv & 0xffffffffl;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -271,7 +271,7 @@ public class OutboundMessageRegistry {
|
||||
//for (Iterator<MessageSelector> iter = _selectors.iterator(); iter.hasNext(); ) {
|
||||
// MessageSelector sel = iter.next();
|
||||
for (int i = 0; i < _selectors.size(); i++) {
|
||||
MessageSelector sel = (MessageSelector)_selectors.get(i);
|
||||
MessageSelector sel = _selectors.get(i);
|
||||
long expiration = sel.getExpiration();
|
||||
if (expiration <= now) {
|
||||
removing.add(sel);
|
||||
|
||||
@@ -507,7 +507,7 @@ public abstract class TransportImpl implements Transport {
|
||||
public boolean isUnreachable(Hash peer) {
|
||||
long now = _context.clock().now();
|
||||
synchronized (_unreachableEntries) {
|
||||
Long when = (Long)_unreachableEntries.get(peer);
|
||||
Long when = _unreachableEntries.get(peer);
|
||||
if (when == null) return false;
|
||||
if (when.longValue() + UNREACHABLE_PERIOD < now) {
|
||||
_unreachableEntries.remove(peer);
|
||||
@@ -543,7 +543,7 @@ public abstract class TransportImpl implements Transport {
|
||||
synchronized (_unreachableEntries) {
|
||||
for (Iterator iter = _unreachableEntries.keySet().iterator(); iter.hasNext(); ) {
|
||||
Hash peer = (Hash)iter.next();
|
||||
Long when = (Long)_unreachableEntries.get(peer);
|
||||
Long when = _unreachableEntries.get(peer);
|
||||
if (when.longValue() + UNREACHABLE_PERIOD < now)
|
||||
iter.remove();
|
||||
}
|
||||
|
||||
@@ -999,8 +999,8 @@ class NTCPConnection implements FIFOBandwidthLimiter.CompleteListener {
|
||||
_lastBytesReceived = totR;
|
||||
_lastRateUpdated = now;
|
||||
|
||||
_sendBps = (0.9f)*_sendBps + (0.1f)*((float)sent*1000f)/(float)time;
|
||||
_recvBps = (0.9f)*_recvBps + (0.1f)*((float)recv*1000)/(float)time;
|
||||
_sendBps = (0.9f)*_sendBps + (0.1f)*(sent*1000f)/time;
|
||||
_recvBps = (0.9f)*_recvBps + (0.1f)*((float)recv*1000)/time;
|
||||
|
||||
// Maintain an approximate average with a 15-second halflife
|
||||
// Weights (0.955 and 0.045) are tuned so that transition between two values (e.g. 0..10)
|
||||
|
||||
@@ -163,7 +163,7 @@ public class NTCPTransport extends TransportImpl {
|
||||
//_context.shitlist().unshitlistRouter(con.getRemotePeer().calculateHash());
|
||||
NTCPConnection old = null;
|
||||
synchronized (_conLock) {
|
||||
old = (NTCPConnection)_conByIdent.put(con.getRemotePeer().calculateHash(), con);
|
||||
old = _conByIdent.put(con.getRemotePeer().calculateHash(), con);
|
||||
}
|
||||
if (old != null) {
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
@@ -181,7 +181,7 @@ public class NTCPTransport extends TransportImpl {
|
||||
NTCPConnection con = null;
|
||||
boolean isNew = false;
|
||||
synchronized (_conLock) {
|
||||
con = (NTCPConnection)_conByIdent.get(ih);
|
||||
con = _conByIdent.get(ih);
|
||||
if (con == null) {
|
||||
isNew = true;
|
||||
RouterAddress addr = msg.getTarget().getTargetAddress(STYLE);
|
||||
@@ -356,7 +356,7 @@ public class NTCPTransport extends TransportImpl {
|
||||
@Override
|
||||
public boolean isEstablished(Hash dest) {
|
||||
synchronized (_conLock) {
|
||||
NTCPConnection con = (NTCPConnection)_conByIdent.get(dest);
|
||||
NTCPConnection con = _conByIdent.get(dest);
|
||||
return (con != null) && con.isEstablished() && !con.isClosed();
|
||||
}
|
||||
}
|
||||
@@ -364,7 +364,7 @@ public class NTCPTransport extends TransportImpl {
|
||||
@Override
|
||||
public boolean isBacklogged(Hash dest) {
|
||||
synchronized (_conLock) {
|
||||
NTCPConnection con = (NTCPConnection)_conByIdent.get(dest);
|
||||
NTCPConnection con = _conByIdent.get(dest);
|
||||
return (con != null) && con.isEstablished() && con.tooBacklogged();
|
||||
}
|
||||
}
|
||||
@@ -374,7 +374,7 @@ public class NTCPTransport extends TransportImpl {
|
||||
synchronized (_conLock) {
|
||||
RouterIdentity ident = con.getRemotePeer();
|
||||
if (ident != null)
|
||||
removed = (NTCPConnection)_conByIdent.remove(ident.calculateHash());
|
||||
removed = _conByIdent.remove(ident.calculateHash());
|
||||
}
|
||||
if ( (removed != null) && (removed != con) ) {// multiple cons, close 'em both
|
||||
if (_log.shouldLog(Log.WARN))
|
||||
|
||||
@@ -459,7 +459,7 @@ class PacketBuilder {
|
||||
int fullACKCount = 0;
|
||||
int partialACKCount = 0;
|
||||
for (int i = 0; i < ackBitfields.size(); i++) {
|
||||
if (((ACKBitfield)ackBitfields.get(i)).receivedComplete())
|
||||
if (ackBitfields.get(i).receivedComplete())
|
||||
fullACKCount++;
|
||||
else
|
||||
partialACKCount++;
|
||||
@@ -496,7 +496,7 @@ class PacketBuilder {
|
||||
DataHelper.toLong(data, off, 1, partialACKCount);
|
||||
off++;
|
||||
for (int i = 0; i < ackBitfields.size(); i++) {
|
||||
ACKBitfield bitfield = (ACKBitfield)ackBitfields.get(i);
|
||||
ACKBitfield bitfield = ackBitfields.get(i);
|
||||
if (bitfield.receivedComplete()) continue;
|
||||
DataHelper.toLong(data, off, 4, bitfield.getMessageId());
|
||||
off += 4;
|
||||
|
||||
@@ -481,7 +481,7 @@ class PeerState {
|
||||
* A positive number means our clock is ahead of theirs.
|
||||
*/
|
||||
public void adjustClockSkew(long skew) {
|
||||
_clockSkew = (long) (0.9*(float)_clockSkew + 0.1*(float)(skew - (_rtt / 2)));
|
||||
_clockSkew = (long) (0.9*_clockSkew + 0.1*(skew - (_rtt / 2)));
|
||||
}
|
||||
|
||||
/** what is the current receive second, for congestion control? */
|
||||
@@ -542,7 +542,7 @@ class PeerState {
|
||||
if (duration >= 1000) {
|
||||
_sendWindowBytesRemaining = _sendWindowBytes;
|
||||
_sendBytes += size;
|
||||
_sendBps = (int)(0.9f*(float)_sendBps + 0.1f*((float)_sendBytes * (1000f/(float)duration)));
|
||||
_sendBps = (int)(0.9f*_sendBps + 0.1f*(_sendBytes * (1000f/duration)));
|
||||
//if (isForACK) {
|
||||
// _sendACKBytes += size;
|
||||
// _sendACKBps = (int)(0.9f*(float)_sendACKBps + 0.1f*((float)_sendACKBytes * (1000f/(float)duration)));
|
||||
@@ -628,7 +628,7 @@ class PeerState {
|
||||
long now = _context.clock().now();
|
||||
long duration = now - _receivePeriodBegin;
|
||||
if (duration >= 1000) {
|
||||
_receiveBps = (int)(0.9f*(float)_receiveBps + 0.1f*((float)_receiveBytes * (1000f/(float)duration)));
|
||||
_receiveBps = (int)(0.9f*_receiveBps + 0.1f*(_receiveBytes * (1000f/duration)));
|
||||
//if (isForACK)
|
||||
// _receiveACKBps = (int)(0.9f*(float)_receiveACKBps + 0.1f*((float)_receiveACKBytes * (1000f/(float)duration)));
|
||||
//_receiveACKBytes = 0;
|
||||
@@ -1008,10 +1008,10 @@ class PeerState {
|
||||
// the faster we are going, the slower we want to reduce the rtt
|
||||
float scale = 0.1f;
|
||||
if (_sendBps > 0)
|
||||
scale = ((float)lifetime) / (float)((float)lifetime + (float)_sendBps);
|
||||
scale = lifetime / ((float)lifetime + (float)_sendBps);
|
||||
if (scale < 0.001f) scale = 0.001f;
|
||||
|
||||
_rtt = (int)(((float)_rtt)*(1.0f-scale) + (scale)*(float)lifetime);
|
||||
_rtt = (int)(_rtt*(1.0f-scale) + (scale)*lifetime);
|
||||
_rto = _rtt + (_rttDeviation<<2);
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Recalculating timeouts w/ lifetime=" + lifetime + ": rtt=" + _rtt
|
||||
|
||||
@@ -331,7 +331,7 @@ class UDPPacketReader {
|
||||
off++;
|
||||
off += size;
|
||||
}
|
||||
return (int)_message[off];
|
||||
return _message[off];
|
||||
}
|
||||
|
||||
public long readMessageId(int fragmentNum) {
|
||||
@@ -459,7 +459,7 @@ class UDPPacketReader {
|
||||
off++;
|
||||
buf.append(" frag# ").append(fragNum);
|
||||
buf.append(" isLast? ").append(isLast);
|
||||
buf.append(" info ").append((int)_message[off-1]);
|
||||
buf.append(" info ").append(_message[off-1]);
|
||||
int size = ((int)DataHelper.fromLong(_message, off, 2)) & 0x3FFF;
|
||||
buf.append(" with ").append(size).append(" bytes");
|
||||
buf.append(' ');
|
||||
|
||||
@@ -242,7 +242,7 @@ class TrivialPreprocessor implements TunnelGateway.QueuePreprocessor {
|
||||
target[offset] |= 1;
|
||||
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("CONTROL: " + Integer.toHexString((int)target[offset]) + "/"
|
||||
_log.debug("CONTROL: " + Integer.toHexString(target[offset]) + "/"
|
||||
+ Base64.encode(target, offset, 1) + " at offset " + offset);
|
||||
|
||||
offset++;
|
||||
|
||||
@@ -136,7 +136,7 @@ public class TunnelCreatorConfig implements TunnelInfo {
|
||||
long timeSince = now - _peakThroughputLastCoallesce;
|
||||
if (timeSince >= 60*1000) {
|
||||
long tot = _peakThroughputCurrentTotal;
|
||||
double normalized = (double)tot * 60d*1000d / (double)timeSince;
|
||||
double normalized = tot * 60d*1000d / timeSince;
|
||||
_peakThroughputLastCoallesce = now;
|
||||
_peakThroughputCurrentTotal = 0;
|
||||
if (_context != null)
|
||||
@@ -158,7 +158,7 @@ public class TunnelCreatorConfig implements TunnelInfo {
|
||||
double rv = 0;
|
||||
for (int i = 0; i < THROUGHPUT_COUNT; i++)
|
||||
rv += _peakThroughput[i];
|
||||
rv /= (60d*1024d*(double)THROUGHPUT_COUNT);
|
||||
rv /= (60d*1024d*THROUGHPUT_COUNT);
|
||||
return rv;
|
||||
}
|
||||
public void setPeakThroughputKBps(double kBps) {
|
||||
|
||||
@@ -275,7 +275,7 @@ abstract class BuildRequestor {
|
||||
log.debug("Build order: " + order + " for " + cfg);
|
||||
|
||||
for (int i = 0; i < msg.getRecordCount(); i++) {
|
||||
int hop = ((Integer)order.get(i)).intValue();
|
||||
int hop = order.get(i).intValue();
|
||||
PublicKey key = null;
|
||||
|
||||
if (BuildMessageGenerator.isBlank(cfg, hop)) {
|
||||
|
||||
Reference in New Issue
Block a user