forked from I2P_Developers/i2p.i2p
merge of '8a3fab47a669f61548d9807e8e047b19248a23ab'
and 'a3189032197fadc3ecba67c5568b8841e8a6105e'
This commit is contained in:
@@ -106,7 +106,7 @@ public class DataMessage extends I2NPMessageImpl {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append("[DataMessage: ");
|
||||
buf.append("\n\tData: ").append(DataHelper.toString(getData(), 64));
|
||||
buf.append("]");
|
||||
|
||||
@@ -238,7 +238,7 @@ public class DatabaseLookupMessage extends I2NPMessageImpl {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append("[DatabaseLookupMessage: ");
|
||||
buf.append("\n\tSearch Key: ").append(getSearchKey());
|
||||
buf.append("\n\tFrom: ").append(getFrom());
|
||||
|
||||
@@ -131,7 +131,7 @@ public class DatabaseSearchReplyMessage extends I2NPMessageImpl {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append("[DatabaseSearchReplyMessage: ");
|
||||
buf.append("\n\tSearch Key: ").append(getSearchKey());
|
||||
buf.append("\n\tReplies: # = ").append(getNumReplies());
|
||||
|
||||
@@ -260,7 +260,7 @@ public class DatabaseStoreMessage extends I2NPMessageImpl {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append("[DatabaseStoreMessage: ");
|
||||
buf.append("\n\tExpiration: ").append(getMessageExpiration());
|
||||
buf.append("\n\tUnique ID: ").append(getUniqueId());
|
||||
|
||||
@@ -70,7 +70,7 @@ public class DateMessage extends I2NPMessageImpl {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append("[DateMessage: ");
|
||||
buf.append("Now: ").append(_now);
|
||||
buf.append("]");
|
||||
|
||||
@@ -377,7 +377,7 @@ public class DeliveryInstructions extends DataStructureImpl {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer(128);
|
||||
StringBuilder buf = new StringBuilder(128);
|
||||
buf.append("[DeliveryInstructions: ");
|
||||
buf.append("\n\tDelivery mode: ");
|
||||
switch (getDeliveryMode()) {
|
||||
|
||||
@@ -82,7 +82,7 @@ public class DeliveryStatusMessage extends I2NPMessageImpl {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append("[DeliveryStatusMessage: ");
|
||||
buf.append("\n\tMessage ID: ").append(getMessageId());
|
||||
buf.append("\n\tArrival: ").append(_context.clock().now() - _arrival);
|
||||
|
||||
@@ -107,25 +107,25 @@ public class GarlicClove extends DataStructureImpl {
|
||||
|
||||
|
||||
public void writeBytes(OutputStream out) throws DataFormatException, IOException {
|
||||
StringBuffer error = null;
|
||||
StringBuilder error = null;
|
||||
if (_instructions == null) {
|
||||
if (error == null) error = new StringBuffer();
|
||||
if (error == null) error = new StringBuilder();
|
||||
error.append("No instructions ");
|
||||
}
|
||||
if (_msg == null) {
|
||||
if (error == null) error = new StringBuffer();
|
||||
if (error == null) error = new StringBuilder();
|
||||
error.append("No message ");
|
||||
}
|
||||
if (_cloveId < 0) {
|
||||
if (error == null) error = new StringBuffer();
|
||||
if (error == null) error = new StringBuilder();
|
||||
error.append("CloveID < 0 [").append(_cloveId).append("] ");
|
||||
}
|
||||
if (_expiration == null) {
|
||||
if (error == null) error = new StringBuffer();
|
||||
if (error == null) error = new StringBuilder();
|
||||
error.append("Expiration is null ");
|
||||
}
|
||||
if (_certificate == null) {
|
||||
if (error == null) error = new StringBuffer();
|
||||
if (error == null) error = new StringBuilder();
|
||||
error.append("Certificate is null ");
|
||||
}
|
||||
|
||||
@@ -210,7 +210,7 @@ public class GarlicClove extends DataStructureImpl {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer(128);
|
||||
StringBuilder buf = new StringBuilder(128);
|
||||
buf.append("[GarlicClove: ");
|
||||
buf.append("\n\tInstructions: ").append(getInstructions());
|
||||
buf.append("\n\tCertificate: ").append(getCertificate());
|
||||
|
||||
@@ -90,7 +90,7 @@ public class GarlicMessage extends I2NPMessageImpl {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append("[GarlicMessage: ");
|
||||
buf.append("\n\tData length: ").append(getData().length).append(" bytes");
|
||||
buf.append("]");
|
||||
|
||||
@@ -263,7 +263,7 @@ public class TunnelCreateMessage extends I2NPMessageImpl {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append("[TunnelCreateMessage: ");
|
||||
buf.append("\n\tNext Router: ").append(getNextRouter());
|
||||
buf.append("\n\tNext Tunnel: ").append(getNextTunnelId());
|
||||
|
||||
@@ -108,7 +108,7 @@ public class TunnelCreateStatusMessage extends I2NPMessageImpl {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append("[TunnelCreateStatusMessage: ");
|
||||
buf.append("\n\tTunnel ID: ").append(getReceiveTunnelId());
|
||||
buf.append("\n\tStatus: ").append(getStatus());
|
||||
|
||||
@@ -139,7 +139,7 @@ public class TunnelDataMessage extends I2NPMessageImpl {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append("[TunnelDataMessage:");
|
||||
buf.append(" MessageId: ").append(getUniqueId());
|
||||
buf.append(" Tunnel ID: ").append(getTunnelId());
|
||||
|
||||
@@ -131,7 +131,7 @@ public class TunnelGatewayMessage extends I2NPMessageImpl {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append("[TunnelGatewayMessage:");
|
||||
buf.append(" Tunnel ID: ").append(getTunnelId());
|
||||
buf.append(" Message: ").append(_msg);
|
||||
|
||||
@@ -188,7 +188,7 @@ public class Blocklist {
|
||||
FileInputStream in = null;
|
||||
try {
|
||||
in = new FileInputStream(BLFile);
|
||||
StringBuffer buf = new StringBuffer(128);
|
||||
StringBuilder buf = new StringBuilder(128);
|
||||
while (DataHelper.readLine(in, buf) && count < maxSize) {
|
||||
Entry e = parse(buf, true);
|
||||
buf.setLength(0);
|
||||
@@ -267,7 +267,7 @@ public class Blocklist {
|
||||
}
|
||||
}
|
||||
|
||||
private Entry parse(StringBuffer buf, boolean bitch) {
|
||||
private Entry parse(StringBuilder buf, boolean bitch) {
|
||||
byte[] ip1;
|
||||
byte[] ip2;
|
||||
int start1 = 0;
|
||||
@@ -378,7 +378,7 @@ public class Blocklist {
|
||||
FileInputStream in = null;
|
||||
try {
|
||||
in = new FileInputStream(BLFile);
|
||||
StringBuffer buf = new StringBuffer(128);
|
||||
StringBuilder buf = new StringBuilder(128);
|
||||
while (DataHelper.readLine(in, buf)) {
|
||||
lines++;
|
||||
buf.setLength(0);
|
||||
@@ -628,7 +628,7 @@ public class Blocklist {
|
||||
}
|
||||
|
||||
private static String toStr(long entry) {
|
||||
StringBuffer buf = new StringBuffer(32);
|
||||
StringBuilder buf = new StringBuilder(32);
|
||||
for (int i = 7; i >= 0; i--) {
|
||||
buf.append((entry >> (8*i)) & 0xff);
|
||||
if (i == 4)
|
||||
@@ -640,7 +640,7 @@ public class Blocklist {
|
||||
}
|
||||
|
||||
private static String toStr(int ip) {
|
||||
StringBuffer buf = new StringBuffer(16);
|
||||
StringBuilder buf = new StringBuilder(16);
|
||||
for (int i = 3; i >= 0; i--) {
|
||||
buf.append((ip >> (8*i)) & 0xff);
|
||||
if (i > 0)
|
||||
@@ -719,7 +719,7 @@ public class Blocklist {
|
||||
FileInputStream in = null;
|
||||
try {
|
||||
in = new FileInputStream(BLFile);
|
||||
StringBuffer buf = new StringBuffer(128);
|
||||
StringBuilder buf = new StringBuilder(128);
|
||||
// assume the file is unsorted, so go through the whole thing
|
||||
while (DataHelper.readLine(in, buf)) {
|
||||
Entry e = parse(buf, false);
|
||||
|
||||
@@ -46,7 +46,7 @@ public class ClientTunnelSettings {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
StringBuilder buf = new StringBuilder();
|
||||
Properties p = new Properties();
|
||||
writeToProperties(p);
|
||||
buf.append("Client tunnel settings:\n");
|
||||
|
||||
@@ -35,7 +35,7 @@ public abstract class JobImpl implements Job {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer(128);
|
||||
StringBuilder buf = new StringBuilder(128);
|
||||
buf.append(super.toString());
|
||||
buf.append(": Job ").append(_id).append(": ").append(getName());
|
||||
return buf.toString();
|
||||
|
||||
@@ -245,7 +245,7 @@ public class JobQueue {
|
||||
_jobLock.notifyAll();
|
||||
}
|
||||
if (_log.shouldLog(Log.WARN)) {
|
||||
StringBuffer buf = new StringBuffer(1024);
|
||||
StringBuilder buf = new StringBuilder(1024);
|
||||
buf.append("current jobs: \n");
|
||||
for (Iterator iter = _queueRunners.values().iterator(); iter.hasNext(); ) {
|
||||
JobQueueRunner runner = (JobQueueRunner)iter.next();
|
||||
@@ -587,7 +587,7 @@ public class JobQueue {
|
||||
numRunners = _queueRunners.size();
|
||||
}
|
||||
|
||||
StringBuffer str = new StringBuffer(128);
|
||||
StringBuilder str = new StringBuilder(128);
|
||||
str.append("<!-- after queueRunner sync: states: ");
|
||||
for (int i = 0; states != null && i < states.length; i++)
|
||||
str.append(states[i]).append(" ");
|
||||
@@ -606,7 +606,7 @@ public class JobQueue {
|
||||
out.write("<!-- jobQueue rendering: after jobLock sync -->\n");
|
||||
out.flush();
|
||||
|
||||
StringBuffer buf = new StringBuffer(32*1024);
|
||||
StringBuilder buf = new StringBuilder(32*1024);
|
||||
buf.append("<h2>JobQueue</h2>");
|
||||
buf.append("# runners: ").append(numRunners).append(" [states=");
|
||||
if (states != null)
|
||||
@@ -667,7 +667,7 @@ public class JobQueue {
|
||||
}
|
||||
|
||||
/** render the HTML for the job stats */
|
||||
private void getJobStats(StringBuffer buf) {
|
||||
private void getJobStats(StringBuilder buf) {
|
||||
buf.append("<table border=\"1\">\n");
|
||||
buf.append("<tr><th>Job</th><th>Runs</th>");
|
||||
buf.append("<th>Time</th><th><i>Avg</i></th><th><i>Max</i></th><th><i>Min</i></th>");
|
||||
|
||||
@@ -77,7 +77,7 @@ class JobStats {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append("Over ").append(getRuns()).append(" runs, job <b>").append(getName()).append("</b> took ");
|
||||
buf.append(getTotalTime()).append("ms (").append(getAvgTime()).append("ms/").append(getMaxTime()).append("ms/");
|
||||
buf.append(getMinTime()).append("ms avg/max/min) after a total lag of ");
|
||||
|
||||
@@ -144,7 +144,7 @@ public class MessageHistory {
|
||||
*/
|
||||
public void requestTunnelCreate(TunnelId createTunnel, TunnelId outTunnel, Hash peerRequested, Hash nextPeer, TunnelId replyTunnel, Hash replyThrough) {
|
||||
if (!_doLog) return;
|
||||
StringBuffer buf = new StringBuffer(128);
|
||||
StringBuilder buf = new StringBuilder(128);
|
||||
buf.append(getPrefix());
|
||||
buf.append("request [").append(getName(peerRequested)).append("] to create tunnel [");
|
||||
buf.append(createTunnel.getTunnelId()).append("] ");
|
||||
@@ -169,7 +169,7 @@ public class MessageHistory {
|
||||
*/
|
||||
public void receiveTunnelCreate(TunnelId createTunnel, Hash nextPeer, Date expire, boolean ok, Hash sourceRoutePeer) {
|
||||
if (!_doLog) return;
|
||||
StringBuffer buf = new StringBuffer(128);
|
||||
StringBuilder buf = new StringBuilder(128);
|
||||
buf.append(getPrefix());
|
||||
buf.append("receive tunnel create [").append(createTunnel.getTunnelId()).append("] ");
|
||||
if (nextPeer != null)
|
||||
@@ -187,7 +187,7 @@ public class MessageHistory {
|
||||
public void tunnelJoined(String state, TunnelInfo tunnel) {
|
||||
if (!_doLog) return;
|
||||
if (tunnel == null) return;
|
||||
StringBuffer buf = new StringBuffer(128);
|
||||
StringBuilder buf = new StringBuilder(128);
|
||||
buf.append(getPrefix());
|
||||
buf.append("joining as [").append(state);
|
||||
buf.append("] to tunnel: ").append(tunnel.toString());
|
||||
@@ -203,7 +203,7 @@ public class MessageHistory {
|
||||
public void tunnelJoined(String state, HopConfig tunnel) {
|
||||
if (!_doLog) return;
|
||||
if (tunnel == null) return;
|
||||
StringBuffer buf = new StringBuffer(128);
|
||||
StringBuilder buf = new StringBuilder(128);
|
||||
buf.append(getPrefix());
|
||||
buf.append("joining as [").append(state);
|
||||
buf.append("] to tunnel: ").append(tunnel.toString());
|
||||
@@ -242,7 +242,7 @@ public class MessageHistory {
|
||||
public void tunnelFailed(TunnelId tunnel) {
|
||||
if (!_doLog) return;
|
||||
if (tunnel == null) return;
|
||||
StringBuffer buf = new StringBuffer(128);
|
||||
StringBuilder buf = new StringBuilder(128);
|
||||
buf.append(getPrefix());
|
||||
buf.append("failing tunnel [").append(tunnel.getTunnelId()).append("]");
|
||||
addEntry(buf.toString());
|
||||
@@ -258,7 +258,7 @@ public class MessageHistory {
|
||||
public void tunnelValid(TunnelInfo tunnel, long timeToTest) {
|
||||
if (!_doLog) return;
|
||||
if (tunnel == null) return;
|
||||
StringBuffer buf = new StringBuffer(128);
|
||||
StringBuilder buf = new StringBuilder(128);
|
||||
buf.append(getPrefix());
|
||||
buf.append("tunnel ").append(tunnel).append(" tested ok after ").append(timeToTest).append("ms");
|
||||
addEntry(buf.toString());
|
||||
@@ -271,7 +271,7 @@ public class MessageHistory {
|
||||
public void tunnelRejected(Hash peer, TunnelId tunnel, Hash replyThrough, String reason) {
|
||||
if (!_doLog) return;
|
||||
if ( (tunnel == null) || (peer == null) ) return;
|
||||
StringBuffer buf = new StringBuffer(128);
|
||||
StringBuilder buf = new StringBuilder(128);
|
||||
buf.append(getPrefix());
|
||||
buf.append("tunnel [").append(tunnel.getTunnelId()).append("] was rejected by [");
|
||||
buf.append(getName(peer)).append("] for [").append(reason).append("]");
|
||||
@@ -283,7 +283,7 @@ public class MessageHistory {
|
||||
public void tunnelParticipantRejected(Hash peer, String msg) {
|
||||
if (!_doLog) return;
|
||||
if (peer == null) return;
|
||||
StringBuffer buf = new StringBuffer(128);
|
||||
StringBuilder buf = new StringBuilder(128);
|
||||
buf.append(getPrefix());
|
||||
buf.append("tunnel participation rejected by [");
|
||||
buf.append(getName(peer)).append("]: ").append(msg);
|
||||
@@ -298,7 +298,7 @@ public class MessageHistory {
|
||||
public void tunnelRequestTimedOut(Hash peer, TunnelId tunnel) {
|
||||
if (!_doLog) return;
|
||||
if ( (tunnel == null) || (peer == null) ) return;
|
||||
StringBuffer buf = new StringBuffer(128);
|
||||
StringBuilder buf = new StringBuilder(128);
|
||||
buf.append(getPrefix());
|
||||
buf.append("tunnel [").append(tunnel.getTunnelId()).append("] timed out on [");
|
||||
buf.append(getName(peer)).append("]");
|
||||
@@ -314,7 +314,7 @@ public class MessageHistory {
|
||||
*/
|
||||
public void droppedTunnelMessage(TunnelId id, long msgId, Date expiration, Hash from) {
|
||||
if (!_doLog) return;
|
||||
StringBuffer buf = new StringBuffer(128);
|
||||
StringBuilder buf = new StringBuilder(128);
|
||||
buf.append(getPrefix());
|
||||
buf.append("dropped message ").append(msgId).append(" for unknown tunnel [").append(id.getTunnelId());
|
||||
buf.append("] from [").append(getName(from)).append("]").append(" expiring on ");
|
||||
@@ -328,7 +328,7 @@ public class MessageHistory {
|
||||
public void droppedOtherMessage(I2NPMessage message, Hash from) {
|
||||
if (!_doLog) return;
|
||||
if (message == null) return;
|
||||
StringBuffer buf = new StringBuffer(512);
|
||||
StringBuilder buf = new StringBuilder(512);
|
||||
buf.append(getPrefix());
|
||||
buf.append("dropped [").append(message.getClass().getName()).append("] ").append(message.getUniqueId());
|
||||
buf.append(" [").append(message.toString()).append("] from [");
|
||||
@@ -342,7 +342,7 @@ public class MessageHistory {
|
||||
|
||||
public void droppedInboundMessage(long messageId, Hash from, String info) {
|
||||
if (!_doLog) return;
|
||||
StringBuffer buf = new StringBuffer(512);
|
||||
StringBuilder buf = new StringBuilder(512);
|
||||
buf.append(getPrefix());
|
||||
buf.append("dropped inbound message ").append(messageId);
|
||||
buf.append(" from ");
|
||||
@@ -364,7 +364,7 @@ public class MessageHistory {
|
||||
public void replyTimedOut(OutNetMessage sentMessage) {
|
||||
if (!_doLog) return;
|
||||
if (sentMessage == null) return;
|
||||
StringBuffer buf = new StringBuffer(512);
|
||||
StringBuilder buf = new StringBuilder(512);
|
||||
buf.append(getPrefix());
|
||||
buf.append("timed out waiting for a reply to [").append(sentMessage.getMessageType());
|
||||
buf.append("] [").append(sentMessage.getMessageId()).append("] expiring on [");
|
||||
@@ -383,7 +383,7 @@ public class MessageHistory {
|
||||
*/
|
||||
public void messageProcessingError(long messageId, String messageType, String error) {
|
||||
if (!_doLog) return;
|
||||
StringBuffer buf = new StringBuffer(128);
|
||||
StringBuilder buf = new StringBuilder(128);
|
||||
buf.append(getPrefix());
|
||||
buf.append("Error processing [").append(messageType).append("] [").append(messageId).append("] failed with [").append(error).append("]");
|
||||
addEntry(buf.toString());
|
||||
@@ -420,7 +420,7 @@ public class MessageHistory {
|
||||
public void sendMessage(String messageType, long messageId, long expiration, Hash peer, boolean sentOk, String info) {
|
||||
if (!_doLog) return;
|
||||
if (false) return;
|
||||
StringBuffer buf = new StringBuffer(256);
|
||||
StringBuilder buf = new StringBuilder(256);
|
||||
buf.append(getPrefix());
|
||||
buf.append("send [").append(messageType).append("] message [").append(messageId).append("] ");
|
||||
buf.append("to [").append(getName(peer)).append("] ");
|
||||
@@ -448,7 +448,7 @@ public class MessageHistory {
|
||||
public void receiveMessage(String messageType, long messageId, long expiration, Hash from, boolean isValid) {
|
||||
if (!_doLog) return;
|
||||
if (false) return;
|
||||
StringBuffer buf = new StringBuffer(256);
|
||||
StringBuilder buf = new StringBuilder(256);
|
||||
buf.append(getPrefix());
|
||||
buf.append("receive [").append(messageType).append("] with id [").append(messageId).append("] ");
|
||||
if (from != null)
|
||||
@@ -470,7 +470,7 @@ public class MessageHistory {
|
||||
*/
|
||||
public void wrap(String bodyMessageType, long bodyMessageId, String containerMessageType, long containerMessageId) {
|
||||
if (!_doLog) return;
|
||||
StringBuffer buf = new StringBuffer(128);
|
||||
StringBuilder buf = new StringBuilder(128);
|
||||
buf.append(getPrefix());
|
||||
buf.append("Wrap message [").append(bodyMessageType).append("] id [").append(bodyMessageId).append("] ");
|
||||
buf.append("in [").append(containerMessageType).append("] id [").append(containerMessageId).append("]");
|
||||
@@ -483,7 +483,7 @@ public class MessageHistory {
|
||||
*/
|
||||
public void receivePayloadMessage(long messageId) {
|
||||
if (!_doLog) return;
|
||||
StringBuffer buf = new StringBuffer(64);
|
||||
StringBuilder buf = new StringBuilder(64);
|
||||
buf.append(getPrefix());
|
||||
buf.append("Receive payload message [").append(messageId).append("]");
|
||||
addEntry(buf.toString());
|
||||
@@ -498,7 +498,7 @@ public class MessageHistory {
|
||||
*/
|
||||
public void sendPayloadMessage(long messageId, boolean successfullySent, long timeToSend) {
|
||||
if (!_doLog) return;
|
||||
StringBuffer buf = new StringBuffer(128);
|
||||
StringBuilder buf = new StringBuilder(128);
|
||||
buf.append(getPrefix());
|
||||
buf.append("Send payload message in [").append(messageId).append("] in [").append(timeToSend).append("] successfully? ").append(successfullySent);
|
||||
addEntry(buf.toString());
|
||||
@@ -507,7 +507,7 @@ public class MessageHistory {
|
||||
public void receiveTunnelFragment(long messageId, int fragmentId, Object status) {
|
||||
if (!_doLog) return;
|
||||
if (messageId == -1) throw new IllegalArgumentException("why are you -1?");
|
||||
StringBuffer buf = new StringBuffer(48);
|
||||
StringBuilder buf = new StringBuilder(48);
|
||||
buf.append(getPrefix());
|
||||
buf.append("Receive fragment ").append(fragmentId).append(" in ").append(messageId);
|
||||
buf.append(" status: ").append(status.toString());
|
||||
@@ -516,7 +516,7 @@ public class MessageHistory {
|
||||
public void receiveTunnelFragmentComplete(long messageId) {
|
||||
if (!_doLog) return;
|
||||
if (messageId == -1) throw new IllegalArgumentException("why are you -1?");
|
||||
StringBuffer buf = new StringBuffer(48);
|
||||
StringBuilder buf = new StringBuilder(48);
|
||||
buf.append(getPrefix());
|
||||
buf.append("Receive fragmented message completely: ").append(messageId);
|
||||
addEntry(buf.toString());
|
||||
@@ -524,7 +524,7 @@ public class MessageHistory {
|
||||
public void droppedFragmentedMessage(long messageId, String status) {
|
||||
if (!_doLog) return;
|
||||
if (messageId == -1) throw new IllegalArgumentException("why are you -1?");
|
||||
StringBuffer buf = new StringBuffer(48);
|
||||
StringBuilder buf = new StringBuilder(48);
|
||||
buf.append(getPrefix());
|
||||
buf.append("Fragmented message dropped: ").append(messageId);
|
||||
buf.append(" ").append(status);
|
||||
@@ -533,7 +533,7 @@ public class MessageHistory {
|
||||
public void fragmentMessage(long messageId, int numFragments, int totalLength, List messageIds, String msg) {
|
||||
if (!_doLog) return;
|
||||
//if (messageId == -1) throw new IllegalArgumentException("why are you -1?");
|
||||
StringBuffer buf = new StringBuffer(48);
|
||||
StringBuilder buf = new StringBuilder(48);
|
||||
buf.append(getPrefix());
|
||||
buf.append("Break message ").append(messageId).append(" into fragments: ").append(numFragments);
|
||||
buf.append(" total size ").append(totalLength);
|
||||
@@ -545,7 +545,7 @@ public class MessageHistory {
|
||||
public void fragmentMessage(long messageId, int numFragments, int totalLength, List messageIds, Object tunnel, String msg) {
|
||||
if (!_doLog) return;
|
||||
//if (messageId == -1) throw new IllegalArgumentException("why are you -1?");
|
||||
StringBuffer buf = new StringBuffer(48);
|
||||
StringBuilder buf = new StringBuilder(48);
|
||||
buf.append(getPrefix());
|
||||
buf.append("Break message ").append(messageId).append(" into fragments: ").append(numFragments);
|
||||
buf.append(" total size ").append(totalLength);
|
||||
@@ -559,7 +559,7 @@ public class MessageHistory {
|
||||
public void droppedTunnelDataMessageUnknown(long msgId, long tunnelId) {
|
||||
if (!_doLog) return;
|
||||
if (msgId == -1) throw new IllegalArgumentException("why are you -1?");
|
||||
StringBuffer buf = new StringBuffer(48);
|
||||
StringBuilder buf = new StringBuilder(48);
|
||||
buf.append(getPrefix());
|
||||
buf.append("Dropped data message ").append(msgId).append(" for unknown tunnel ").append(tunnelId);
|
||||
addEntry(buf.toString());
|
||||
@@ -567,7 +567,7 @@ public class MessageHistory {
|
||||
public void droppedTunnelGatewayMessageUnknown(long msgId, long tunnelId) {
|
||||
if (!_doLog) return;
|
||||
if (msgId == -1) throw new IllegalArgumentException("why are you -1?");
|
||||
StringBuffer buf = new StringBuffer(48);
|
||||
StringBuilder buf = new StringBuilder(48);
|
||||
buf.append(getPrefix());
|
||||
buf.append("Dropped gateway message ").append(msgId).append(" for unknown tunnel ").append(tunnelId);
|
||||
addEntry(buf.toString());
|
||||
@@ -585,7 +585,7 @@ public class MessageHistory {
|
||||
}
|
||||
|
||||
private final String getPrefix() {
|
||||
StringBuffer buf = new StringBuffer(48);
|
||||
StringBuilder buf = new StringBuilder(48);
|
||||
buf.append(getTime(_context.clock().now()));
|
||||
buf.append(' ').append(_localIdent).append(": ");
|
||||
return buf.toString();
|
||||
|
||||
@@ -77,7 +77,7 @@ public class MultiRouterBuilder {
|
||||
buildStartupScriptNix(args);
|
||||
}
|
||||
private static void buildStartupScriptNix(String args[]) {
|
||||
StringBuffer buf = new StringBuffer(4096);
|
||||
StringBuilder buf = new StringBuilder(4096);
|
||||
buf.append("#!/bin/sh\n");
|
||||
buf.append("export CP=.; for LIB in lib/* ; do export CP=$CP:$LIB ; done\n");
|
||||
buf.append("nohup java -cp $CP ");
|
||||
@@ -106,7 +106,7 @@ public class MultiRouterBuilder {
|
||||
File baseDir = new File(dir);
|
||||
baseDir.mkdirs();
|
||||
File cfgFile = new File(baseDir, "router.config");
|
||||
StringBuffer buf = new StringBuffer(8*1024);
|
||||
StringBuilder buf = new StringBuilder(8*1024);
|
||||
buf.append("router.profileDir=").append(baseDir.getPath()).append("/peerProfiles\n");
|
||||
buf.append("router.historyFilename=").append(baseDir.getPath()).append("/messageHistory.txt\n");
|
||||
buf.append("router.sessionKeys.location=").append(baseDir.getPath()).append("/sessionKeys.dat\n");
|
||||
|
||||
@@ -287,7 +287,7 @@ public class OutNetMessage {
|
||||
public void finalize() throws Throwable {
|
||||
if (_message != null) {
|
||||
if (_log.shouldLog(Log.WARN)) {
|
||||
StringBuffer buf = new StringBuffer(1024);
|
||||
StringBuilder buf = new StringBuilder(1024);
|
||||
buf.append("Undiscarded ").append(_messageSize).append("byte ");
|
||||
buf.append(_messageType).append(" message created ");
|
||||
buf.append((_context.clock().now() - _created)).append("ms ago: ");
|
||||
@@ -304,7 +304,7 @@ public class OutNetMessage {
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer(128);
|
||||
StringBuilder buf = new StringBuilder(128);
|
||||
buf.append("[OutNetMessage contains ");
|
||||
if (_message == null) {
|
||||
buf.append("*no message*");
|
||||
@@ -334,7 +334,7 @@ public class OutNetMessage {
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
private void renderTimestamps(StringBuffer buf) {
|
||||
private void renderTimestamps(StringBuilder buf) {
|
||||
if (_log.shouldLog(Log.INFO)) {
|
||||
synchronized (this) {
|
||||
long lastWhen = -1;
|
||||
|
||||
@@ -66,7 +66,7 @@ public class PersistentKeyRing extends KeyRing {
|
||||
|
||||
@Override
|
||||
public void renderStatusHTML(Writer out) throws IOException {
|
||||
StringBuffer buf = new StringBuffer(1024);
|
||||
StringBuilder buf = new StringBuilder(1024);
|
||||
buf.append("\n<table border=\"1\"><tr><th align=\"left\">Destination Hash<th align=\"left\">Name or Dest.<th align=\"left\">Session Key</tr>");
|
||||
for (Entry<Hash, SessionKey> e : entrySet()) {
|
||||
buf.append("\n<tr><td>");
|
||||
|
||||
@@ -589,7 +589,7 @@ public class Router {
|
||||
"</select> <input type=\"submit\" value=\"GO\" /> </form>" +
|
||||
"<hr />\n");
|
||||
|
||||
StringBuffer buf = new StringBuffer(32*1024);
|
||||
StringBuilder buf = new StringBuilder(32*1024);
|
||||
|
||||
if ( (_routerInfo != null) && (_routerInfo.getIdentity() != null) )
|
||||
buf.append("<b>Router: </b> ").append(_routerInfo.getIdentity().getHash().toBase64()).append("<br />\n");
|
||||
@@ -762,7 +762,7 @@ public class Router {
|
||||
}
|
||||
|
||||
private static int MAX_MSG_LENGTH = 120;
|
||||
private static final void appendLogMessage(StringBuffer buf, String msg) {
|
||||
private static final void appendLogMessage(StringBuilder buf, String msg) {
|
||||
// disable this code for the moment because i think it
|
||||
// looks ugly (on the router console)
|
||||
if (true) {
|
||||
@@ -804,7 +804,7 @@ public class Router {
|
||||
|
||||
/** main-ish method for testing appendLogMessage */
|
||||
private static final void testAppendLog() {
|
||||
StringBuffer buf = new StringBuffer(1024);
|
||||
StringBuilder buf = new StringBuilder(1024);
|
||||
Router.appendLogMessage(buf, "hi\nhow are you\nh0h0h0");
|
||||
System.out.println("line: [" + buf.toString() + "]");
|
||||
buf.setLength(0);
|
||||
@@ -1005,7 +1005,7 @@ public class Router {
|
||||
FileOutputStream fos = null;
|
||||
try {
|
||||
fos = new FileOutputStream(_configFilename);
|
||||
StringBuffer buf = new StringBuffer(8*1024);
|
||||
StringBuilder buf = new StringBuilder(8*1024);
|
||||
synchronized (_config) {
|
||||
TreeSet ordered = new TreeSet(_config.keySet());
|
||||
for (Iterator iter = ordered.iterator() ; iter.hasNext(); ) {
|
||||
|
||||
@@ -268,7 +268,7 @@ public class RouterContext extends I2PAppContext {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer(512);
|
||||
StringBuilder buf = new StringBuilder(512);
|
||||
buf.append("RouterContext: ").append(super.toString()).append('\n');
|
||||
buf.append(_router).append('\n');
|
||||
buf.append(_clientManagerFacade).append('\n');
|
||||
|
||||
@@ -18,7 +18,7 @@ public class RouterVersion {
|
||||
/** deprecated */
|
||||
public final static String ID = "Monotone";
|
||||
public final static String VERSION = CoreVersion.VERSION;
|
||||
public final static long BUILD = 2;
|
||||
public final static long BUILD = 4;
|
||||
/** for example "-test" */
|
||||
public final static String EXTRA = "";
|
||||
public final static String FULL_VERSION = VERSION + "-" + BUILD + EXTRA;
|
||||
|
||||
@@ -1,281 +0,0 @@
|
||||
package net.i2p.router;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.data.Base64;
|
||||
import net.i2p.data.DataFormatException;
|
||||
import net.i2p.data.Hash;
|
||||
import net.i2p.data.RouterIdentity;
|
||||
import net.i2p.data.RouterInfo;
|
||||
import net.i2p.data.i2np.DatabaseStoreMessage;
|
||||
import net.i2p.data.i2np.I2NPMessage;
|
||||
import net.i2p.data.i2np.I2NPMessageException;
|
||||
import net.i2p.data.i2np.I2NPMessageImpl;
|
||||
|
||||
/**
|
||||
* Demo of a stripped down router - no tunnels, no netDb, no i2cp, no peer profiling,
|
||||
* just the SSU comm layer, crypto, and associated infrastructure, extended to handle
|
||||
* a new type of message ("FooMessage").
|
||||
*
|
||||
*/
|
||||
public class SSUDemo {
|
||||
RouterContext _us;
|
||||
|
||||
public static void main(String args[]) {
|
||||
SSUDemo demo = new SSUDemo();
|
||||
demo.run();
|
||||
}
|
||||
|
||||
public SSUDemo() {}
|
||||
public void run() {
|
||||
String cfgFile = "router.config";
|
||||
Properties envProps = getEnv();
|
||||
Router r = new Router(cfgFile, envProps);
|
||||
r.runRouter();
|
||||
_us = r.getContext();
|
||||
setupHandlers();
|
||||
// wait for it to warm up a bit
|
||||
try { Thread.sleep(30*1000); } catch (InterruptedException ie) {}
|
||||
// now write out our ident and info
|
||||
RouterInfo myInfo = _us.router().getRouterInfo();
|
||||
storeMyInfo(myInfo);
|
||||
// look for any other peers written to the same directory, and send each
|
||||
// a single Foo message (0x0123), unless they've already contacted us first.
|
||||
// this call never returns
|
||||
loadPeers();
|
||||
}
|
||||
|
||||
private Properties getEnv() {
|
||||
Properties envProps = System.getProperties();
|
||||
// disable the TCP transport, as its deprecated
|
||||
envProps.setProperty("i2np.tcp.disable", "true");
|
||||
// we want SNTP synchronization for replay prevention
|
||||
envProps.setProperty("time.disabled", "false");
|
||||
// allow 127.0.0.1/10.0.0.1/etc (useful for testing). If this is false,
|
||||
// peers who say they're on an invalid IP are shitlisted
|
||||
envProps.setProperty("i2np.udp.allowLocal", "true");
|
||||
// explicit IP+port. at least one router on the net has to have their IP+port
|
||||
// set, since there has to be someone to detect one's IP off. most don't need
|
||||
// to set these though
|
||||
envProps.setProperty("i2np.udp.host", "127.0.0.1");
|
||||
envProps.setProperty("i2np.udp.internalPort", "12000");
|
||||
envProps.setProperty("i2np.udp.port", "12000");
|
||||
// disable I2CP, the netDb, peer testing/profile persistence, and tunnel
|
||||
// creation/management
|
||||
envProps.setProperty("i2p.dummyClientFacade", "true");
|
||||
envProps.setProperty("i2p.dummyNetDb", "true");
|
||||
envProps.setProperty("i2p.dummyPeerManager", "true");
|
||||
envProps.setProperty("i2p.dummyTunnelManager", "true");
|
||||
// set to false if you want to use HMAC-SHA256-128 instead of HMAC-MD5-128 as
|
||||
// the SSU MAC
|
||||
envProps.setProperty("i2p.HMACMD5", "true");
|
||||
// if you're using the HMAC MD5, by default it will use a 32 byte MAC field,
|
||||
// which is a bug, as it doesn't generate the same values as a 16 byte MAC field.
|
||||
// set this to false if you don't want the bug
|
||||
envProps.setProperty("i2p.HMACBrokenSize", "false");
|
||||
// no need to include any stats in the routerInfo we send to people on SSU
|
||||
// session establishment
|
||||
envProps.setProperty("router.publishPeerRankings", "false");
|
||||
// write the logs to ./logs/log-router-*.txt (logger configured with the file
|
||||
// ./logger.config, or another config file specified as
|
||||
// -Dlogger.configLocation=blah)
|
||||
envProps.setProperty("loggerFilenameOverride", "logs/log-router-@.txt");
|
||||
return envProps;
|
||||
}
|
||||
|
||||
private void setupHandlers() {
|
||||
// netDb store is sent on connection establishment, which includes contact info
|
||||
// for the peer. the DBStoreJobBuilder builds a new asynchronous Job to process
|
||||
// each one received (storing it in our in-memory, passive netDb)
|
||||
_us.inNetMessagePool().registerHandlerJobBuilder(DatabaseStoreMessage.MESSAGE_TYPE, new DBStoreJobBuilder());
|
||||
// handle any Foo messages by displaying them on stdout
|
||||
_us.inNetMessagePool().registerHandlerJobBuilder(FooMessage.MESSAGE_TYPE, new FooJobBuilder());
|
||||
}
|
||||
|
||||
/** random place for storing router info files - written as $dir/base64(SHA256(info.getIdentity)) */
|
||||
private File getInfoDir() { return new File("/tmp/ssuDemoInfo/"); }
|
||||
|
||||
private void storeMyInfo(RouterInfo info) {
|
||||
File infoDir = getInfoDir();
|
||||
if (!infoDir.exists())
|
||||
infoDir.mkdirs();
|
||||
FileOutputStream fos = null;
|
||||
File infoFile = new File(infoDir, info.getIdentity().calculateHash().toBase64());
|
||||
try {
|
||||
fos = new FileOutputStream(infoFile);
|
||||
info.writeBytes(fos);
|
||||
} catch (IOException ioe) {
|
||||
ioe.printStackTrace();
|
||||
} catch (DataFormatException dfe) {
|
||||
dfe.printStackTrace();
|
||||
} finally {
|
||||
if (fos != null) try { fos.close(); } catch (IOException ioe) {}
|
||||
}
|
||||
|
||||
System.out.println("Our info stored at: " + infoFile.getAbsolutePath());
|
||||
}
|
||||
|
||||
private void loadPeers() {
|
||||
File infoDir = getInfoDir();
|
||||
if (!infoDir.exists())
|
||||
infoDir.mkdirs();
|
||||
while (true) {
|
||||
File peerFiles[] = infoDir.listFiles();
|
||||
if ( (peerFiles != null) && (peerFiles.length > 0) ) {
|
||||
for (int i = 0; i < peerFiles.length; i++) {
|
||||
if (peerFiles[i].isFile() && !peerFiles[i].isHidden()) {
|
||||
if (!_us.routerHash().toBase64().equals(peerFiles[i].getName())) {
|
||||
System.out.println("Reading info: " + peerFiles[i].getAbsolutePath());
|
||||
try {
|
||||
FileInputStream in = new FileInputStream(peerFiles[i]);
|
||||
RouterInfo ri = new RouterInfo();
|
||||
ri.readBytes(in);
|
||||
peerRead(ri);
|
||||
} catch (IOException ioe) {
|
||||
System.err.println("Error reading " + peerFiles[i].getAbsolutePath());
|
||||
ioe.printStackTrace();
|
||||
} catch (DataFormatException dfe) {
|
||||
System.err.println("Corrupt " + peerFiles[i].getAbsolutePath());
|
||||
dfe.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
try { Thread.sleep(30*1000); } catch (InterruptedException ie) {}
|
||||
}
|
||||
}
|
||||
|
||||
private void peerRead(RouterInfo ri) {
|
||||
RouterInfo old = _us.netDb().store(ri.getIdentity().calculateHash(), ri);
|
||||
if (old == null)
|
||||
newPeerRead(ri);
|
||||
}
|
||||
|
||||
private void newPeerRead(RouterInfo ri) {
|
||||
OutNetMessage out = new OutNetMessage(_us);
|
||||
// _us.clock() is an ntp synchronized clock. give up on sending this message
|
||||
// if it doesn't get ACKed within the next 10 seconds
|
||||
out.setExpiration(_us.clock().now() + 10*1000);
|
||||
out.setPriority(100);
|
||||
out.setTarget(ri);
|
||||
FooMessage data = new FooMessage(_us, new byte[] { 0x0, 0x1, 0x2, 0x3 });
|
||||
System.out.println("SEND: " + Base64.encode(data.getData()));
|
||||
out.setMessage(data);
|
||||
// job fired if we can't contact them, or if it takes too long to get an ACK
|
||||
out.setOnFailedSendJob(null);
|
||||
// job fired once the transport gets a full ACK of the message
|
||||
out.setOnSendJob(new AfterACK());
|
||||
// queue up the message, establishing a new SSU session if necessary, using
|
||||
// their direct SSU address if they have one, or their indirect SSU addresses
|
||||
// if they don't. If we cannot contact them, we will 'shitlist' their address,
|
||||
// during which time we will not even attempt to send messages to them. We also
|
||||
// drop their netDb info when we shitlist them, in case their info is no longer
|
||||
// correct. Since the netDb is disabled for all meaningful purposes, the SSUDemo
|
||||
// will be responsible for fetching such information.
|
||||
_us.outNetMessagePool().add(out);
|
||||
}
|
||||
|
||||
/** fired if and only if the FooMessage is ACKed before we time out */
|
||||
private class AfterACK extends JobImpl {
|
||||
public AfterACK() { super(_us); }
|
||||
public void runJob() { System.out.println("Foo message sent completely"); }
|
||||
public String getName() { return "After Foo message send"; }
|
||||
}
|
||||
|
||||
////
|
||||
// Foo and netDb store handling below
|
||||
|
||||
/**
|
||||
* Deal with an Foo message received
|
||||
*/
|
||||
private class FooJobBuilder implements HandlerJobBuilder {
|
||||
public FooJobBuilder() {
|
||||
I2NPMessageImpl.registerBuilder(new FooBuilder(), FooMessage.MESSAGE_TYPE);
|
||||
}
|
||||
public Job createJob(I2NPMessage receivedMessage, RouterIdentity from, Hash fromHash) {
|
||||
return new FooHandleJob(_us, receivedMessage, from, fromHash);
|
||||
}
|
||||
}
|
||||
private class FooHandleJob extends JobImpl {
|
||||
private I2NPMessage _msg;
|
||||
public FooHandleJob(RouterContext ctx, I2NPMessage receivedMessage, RouterIdentity from, Hash fromHash) {
|
||||
super(ctx);
|
||||
_msg = receivedMessage;
|
||||
}
|
||||
public void runJob() {
|
||||
// we know its a FooMessage, since thats the type of message that the handler
|
||||
// is registered as
|
||||
FooMessage m = (FooMessage)_msg;
|
||||
System.out.println("RECV: " + Base64.encode(m.getData()));
|
||||
}
|
||||
public String getName() { return "Handle Foo message"; }
|
||||
}
|
||||
private class FooBuilder implements I2NPMessageImpl.Builder {
|
||||
public I2NPMessage build(I2PAppContext ctx) { return new FooMessage(ctx, null); }
|
||||
}
|
||||
|
||||
/**
|
||||
* Just carry some data...
|
||||
*/
|
||||
class FooMessage extends I2NPMessageImpl {
|
||||
private byte[] _data;
|
||||
public static final int MESSAGE_TYPE = 17;
|
||||
public FooMessage(I2PAppContext ctx, byte data[]) {
|
||||
super(ctx);
|
||||
_data = data;
|
||||
}
|
||||
/** pull the read data off */
|
||||
public byte[] getData() { return _data; }
|
||||
/** specify the payload to be sent */
|
||||
public void setData(byte data[]) { _data = data; }
|
||||
|
||||
public int getType() { return MESSAGE_TYPE; }
|
||||
protected int calculateWrittenLength() { return _data.length; }
|
||||
public void readMessage(byte[] data, int offset, int dataSize, int type) throws I2NPMessageException, IOException {
|
||||
_data = new byte[dataSize];
|
||||
System.arraycopy(data, offset, _data, 0, dataSize);
|
||||
}
|
||||
|
||||
protected int writeMessageBody(byte[] out, int curIndex) throws I2NPMessageException {
|
||||
System.arraycopy(_data, 0, out, curIndex, _data.length);
|
||||
return curIndex + _data.length;
|
||||
}
|
||||
}
|
||||
|
||||
////
|
||||
// netDb store handling below
|
||||
|
||||
/**
|
||||
* Handle any netDb stores from the peer - they send us their netDb as part of
|
||||
* their SSU establishment (and we send them ours).
|
||||
*/
|
||||
private class DBStoreJobBuilder implements HandlerJobBuilder {
|
||||
public Job createJob(I2NPMessage receivedMessage, RouterIdentity from, Hash fromHash) {
|
||||
return new HandleJob(_us, receivedMessage, from, fromHash);
|
||||
}
|
||||
}
|
||||
private class HandleJob extends JobImpl {
|
||||
private I2NPMessage _msg;
|
||||
public HandleJob(RouterContext ctx, I2NPMessage receivedMessage, RouterIdentity from, Hash fromHash) {
|
||||
super(ctx);
|
||||
_msg = receivedMessage;
|
||||
}
|
||||
public void runJob() {
|
||||
// we know its a DatabaseStoreMessage, since thats the type of message that the handler
|
||||
// is registered as
|
||||
DatabaseStoreMessage m = (DatabaseStoreMessage)_msg;
|
||||
try {
|
||||
_us.netDb().store(m.getKey(), m.getRouterInfo());
|
||||
} catch (IllegalArgumentException iae) {
|
||||
iae.printStackTrace();
|
||||
}
|
||||
}
|
||||
public String getName() { return "Handle netDb store"; }
|
||||
}
|
||||
}
|
||||
@@ -252,7 +252,7 @@ public class Shitlist {
|
||||
}
|
||||
|
||||
public void renderStatusHTML(Writer out) throws IOException {
|
||||
StringBuffer buf = new StringBuffer(1024);
|
||||
StringBuilder buf = new StringBuilder(1024);
|
||||
buf.append("<h2>Shitlist</h2>");
|
||||
Map<Hash, Entry> entries = new TreeMap(new HashComparator());
|
||||
|
||||
|
||||
@@ -200,7 +200,7 @@ public class StatisticsManager implements Service {
|
||||
}
|
||||
|
||||
private String renderRate(Rate rate, boolean fudgeQuantity) {
|
||||
StringBuffer buf = new StringBuffer(128);
|
||||
StringBuilder buf = new StringBuilder(128);
|
||||
buf.append(num(rate.getAverageValue())).append(';');
|
||||
buf.append(num(rate.getExtremeAverageValue())).append(';');
|
||||
buf.append(pct(rate.getPercentageOfLifetimeValue())).append(';');
|
||||
@@ -259,7 +259,7 @@ public class StatisticsManager implements Service {
|
||||
}
|
||||
|
||||
private String renderRate(Rate rate, double fudgeQuantity) {
|
||||
StringBuffer buf = new StringBuffer(128);
|
||||
StringBuilder buf = new StringBuilder(128);
|
||||
buf.append(num(rate.getAverageValue())).append(';');
|
||||
buf.append(num(rate.getExtremeAverageValue())).append(';');
|
||||
buf.append(pct(rate.getPercentageOfLifetimeValue())).append(';');
|
||||
|
||||
@@ -187,7 +187,7 @@ public class TunnelPoolSettings {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
StringBuilder buf = new StringBuilder();
|
||||
Properties p = new Properties();
|
||||
writeToProperties("", p);
|
||||
buf.append("Tunnel pool settings:\n");
|
||||
|
||||
@@ -73,7 +73,7 @@ class AdminRunner implements Runnable {
|
||||
}
|
||||
|
||||
private void reply(OutputStream out, String content) throws IOException {
|
||||
StringBuffer reply = new StringBuffer(10240);
|
||||
StringBuilder reply = new StringBuilder(10240);
|
||||
reply.append("HTTP/1.1 200 OK\n");
|
||||
reply.append("Connection: close\n");
|
||||
reply.append("Cache-control: no-cache\n");
|
||||
@@ -90,7 +90,7 @@ class AdminRunner implements Runnable {
|
||||
}
|
||||
|
||||
private void replyText(OutputStream out, String content) throws IOException {
|
||||
StringBuffer reply = new StringBuffer(10240);
|
||||
StringBuilder reply = new StringBuilder(10240);
|
||||
reply.append("HTTP/1.1 200 OK\n");
|
||||
reply.append("Connection: close\n");
|
||||
reply.append("Cache-control: no-cache\n");
|
||||
|
||||
@@ -28,7 +28,7 @@ public class StatsGenerator {
|
||||
}
|
||||
|
||||
public void generateStatsPage(Writer out) throws IOException {
|
||||
StringBuffer buf = new StringBuffer(16*1024);
|
||||
StringBuilder buf = new StringBuilder(16*1024);
|
||||
buf.append("<form action=\"/oldstats.jsp\">");
|
||||
buf.append("<select name=\"go\" onChange='location.href=this.value'>");
|
||||
out.write(buf.toString());
|
||||
@@ -93,7 +93,7 @@ public class StatsGenerator {
|
||||
out.flush();
|
||||
}
|
||||
|
||||
private void renderFrequency(String name, StringBuffer buf) {
|
||||
private void renderFrequency(String name, StringBuilder buf) {
|
||||
FrequencyStat freq = _context.statManager().getFrequency(name);
|
||||
buf.append("<i>");
|
||||
buf.append(freq.getDescription());
|
||||
@@ -129,7 +129,7 @@ public class StatsGenerator {
|
||||
buf.append("<br />");
|
||||
}
|
||||
|
||||
private void renderRate(String name, StringBuffer buf) {
|
||||
private void renderRate(String name, StringBuilder buf) {
|
||||
RateStat rate = _context.statManager().getRate(name);
|
||||
String d = rate.getDescription();
|
||||
if (! "".equals(d)) {
|
||||
@@ -222,7 +222,7 @@ public class StatsGenerator {
|
||||
buf.append("<br />");
|
||||
}
|
||||
|
||||
private static void renderPeriod(StringBuffer buf, long period, String name) {
|
||||
private static void renderPeriod(StringBuilder buf, long period, String name) {
|
||||
buf.append("<b>");
|
||||
buf.append(DataHelper.formatDuration(period));
|
||||
buf.append(" ");
|
||||
|
||||
@@ -387,7 +387,7 @@ public class ClientManager {
|
||||
}
|
||||
|
||||
public void renderStatusHTML(Writer out) throws IOException {
|
||||
StringBuffer buf = new StringBuffer(8*1024);
|
||||
StringBuilder buf = new StringBuilder(8*1024);
|
||||
buf.append("<u><b>Local destinations</b></u><br />");
|
||||
|
||||
Map runners = null;
|
||||
|
||||
@@ -44,7 +44,7 @@ public class CloveSet {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer(128);
|
||||
StringBuilder buf = new StringBuilder(128);
|
||||
buf.append("{");
|
||||
for (int i = 0; i < _cloves.size(); i++) {
|
||||
GarlicClove clove = (GarlicClove)_cloves.get(i);
|
||||
|
||||
@@ -158,7 +158,7 @@ public class GarlicConfig {
|
||||
private final static String NL = System.getProperty("line.separator");
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append("<garlicConfig>").append(NL);
|
||||
buf.append("<certificate>").append(getCertificate()).append("</certificate>").append(NL);
|
||||
buf.append("<instructions>").append(getDeliveryInstructions()).append("</instructions>").append(NL);
|
||||
|
||||
@@ -35,7 +35,7 @@ public class PayloadGarlicConfig extends GarlicConfig {
|
||||
|
||||
@Override
|
||||
protected String getSubData() {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append("<payloadMessage>").append(_payload).append("</payloadMessage>");
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
@@ -330,7 +330,7 @@ class KBucketImpl implements KBucket {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer(1024);
|
||||
StringBuilder buf = new StringBuilder(1024);
|
||||
buf.append("KBucketImpl: ");
|
||||
synchronized (_entries) {
|
||||
buf.append(_entries.toString()).append("\n");
|
||||
@@ -380,7 +380,7 @@ class KBucketImpl implements KBucket {
|
||||
}
|
||||
|
||||
private static void testRand() {
|
||||
StringBuffer buf = new StringBuffer(2048);
|
||||
StringBuilder buf = new StringBuilder(2048);
|
||||
int low = 1;
|
||||
int high = 3;
|
||||
Log log = I2PAppContext.getGlobalContext().logManager().getLog(KBucketImpl.class);
|
||||
@@ -416,7 +416,7 @@ class KBucketImpl implements KBucket {
|
||||
|
||||
private static void testRand2() {
|
||||
Log log = I2PAppContext.getGlobalContext().logManager().getLog(KBucketImpl.class);
|
||||
StringBuffer buf = new StringBuffer(1024*1024*16);
|
||||
StringBuilder buf = new StringBuilder(1024*1024*16);
|
||||
int low = 1;
|
||||
int high = 200;
|
||||
byte hash[] = new byte[Hash.HASH_LENGTH];
|
||||
@@ -452,7 +452,7 @@ class KBucketImpl implements KBucket {
|
||||
|
||||
private final static String toString(byte b[]) {
|
||||
if (true) return DataHelper.toHexString(b);
|
||||
StringBuffer buf = new StringBuffer(b.length);
|
||||
StringBuilder buf = new StringBuilder(b.length);
|
||||
for (int i = 0; i < b.length; i++) {
|
||||
buf.append(toString(b[i]));
|
||||
buf.append(" ");
|
||||
@@ -461,7 +461,7 @@ class KBucketImpl implements KBucket {
|
||||
}
|
||||
|
||||
private final static String toString(byte b) {
|
||||
StringBuffer buf = new StringBuffer(8);
|
||||
StringBuilder buf = new StringBuilder(8);
|
||||
for (int i = 7; i >= 0; i--) {
|
||||
boolean bb = (0 != (b & (1<<i)));
|
||||
if (bb)
|
||||
|
||||
@@ -141,7 +141,7 @@ class KBucketSet {
|
||||
@Override
|
||||
public String toString() {
|
||||
BigInteger us = new BigInteger(1, _us.getData());
|
||||
StringBuffer buf = new StringBuffer(1024);
|
||||
StringBuilder buf = new StringBuilder(1024);
|
||||
buf.append("Bucket set rooted on: ").append(us.toString()).append(" (aka ").append(us.toString(2)).append("): \n");
|
||||
for (int i = 0; i < NUM_BUCKETS; i++) {
|
||||
buf.append("* Bucket ").append(i).append("/").append(NUM_BUCKETS-1).append(": )\n");
|
||||
@@ -159,7 +159,7 @@ class KBucketSet {
|
||||
System.arraycopy(b, 0, val, Hash.HASH_LENGTH-b.length-1, b.length);
|
||||
else
|
||||
System.arraycopy(b, Hash.HASH_LENGTH-b.length, val, 0, val.length);
|
||||
StringBuffer buf = new StringBuffer(KEYSIZE_BITS);
|
||||
StringBuilder buf = new StringBuilder(KEYSIZE_BITS);
|
||||
for (int i = 0; i < val.length; i++) {
|
||||
for (int j = 7; j >= 0; j--) {
|
||||
boolean bb = (0 != (val[i] & (1<<j)));
|
||||
|
||||
@@ -910,7 +910,7 @@ public class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacade {
|
||||
|
||||
@Override
|
||||
public void renderRouterInfoHTML(Writer out, String routerPrefix) throws IOException {
|
||||
StringBuffer buf = new StringBuffer(4*1024);
|
||||
StringBuilder buf = new StringBuilder(4*1024);
|
||||
buf.append("<h2>Network Database RouterInfo Lookup</h2>\n");
|
||||
if (".".equals(routerPrefix)) {
|
||||
renderRouterInfo(buf, _context.router().getRouterInfo(), true, true);
|
||||
@@ -938,7 +938,7 @@ public class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacade {
|
||||
|
||||
@Override
|
||||
public void renderLeaseSetHTML(Writer out) throws IOException {
|
||||
StringBuffer buf = new StringBuffer(4*1024);
|
||||
StringBuilder buf = new StringBuilder(4*1024);
|
||||
buf.append("<h2>Network Database Contents</h2>\n");
|
||||
buf.append("<a href=\"netdb.jsp\">View RouterInfo</a>");
|
||||
buf.append("<h3>LeaseSets</h3>\n");
|
||||
@@ -992,7 +992,7 @@ public class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacade {
|
||||
int size = getKnownRouters() * 512;
|
||||
if (full)
|
||||
size *= 4;
|
||||
StringBuffer buf = new StringBuffer(size);
|
||||
StringBuilder buf = new StringBuilder(size);
|
||||
out.write("<h2>Network Database Contents</h2>\n");
|
||||
if (!_initialized) {
|
||||
buf.append("<i>Not initialized</i>\n");
|
||||
@@ -1073,7 +1073,7 @@ public class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacade {
|
||||
out.flush();
|
||||
}
|
||||
|
||||
private void renderRouterInfo(StringBuffer buf, RouterInfo info, boolean isUs, boolean full) {
|
||||
private void renderRouterInfo(StringBuilder buf, RouterInfo info, boolean isUs, boolean full) {
|
||||
String hash = info.getIdentity().getHash().toBase64();
|
||||
buf.append("<a name=\"").append(hash.substring(0, 6)).append("\" />");
|
||||
if (isUs) {
|
||||
|
||||
@@ -168,7 +168,7 @@ class SearchState {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer(256);
|
||||
StringBuilder buf = new StringBuilder(256);
|
||||
buf.append("Searching for ").append(_searchKey);
|
||||
buf.append(" ");
|
||||
if (_completed <= 0)
|
||||
|
||||
@@ -57,7 +57,7 @@ class StoreMessageSelector implements MessageSelector {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer rv = new StringBuffer(64);
|
||||
StringBuilder rv = new StringBuilder(64);
|
||||
rv.append("Waiting for netDb confirm from ").append(_peer.toBase64()).append(", found? ");
|
||||
rv.append(_found).append(" waiting for ").append(_waitingForId);
|
||||
return rv.toString();
|
||||
|
||||
@@ -149,7 +149,7 @@ class StoreState {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer(256);
|
||||
StringBuilder buf = new StringBuilder(256);
|
||||
buf.append("Storing ").append(_key);
|
||||
buf.append(" ");
|
||||
if (_completed <= 0)
|
||||
|
||||
@@ -147,7 +147,7 @@ class TransientDataStore implements DataStore {
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append("Transient DataStore: ").append(_data.size()).append("\nKeys: ");
|
||||
for (Map.Entry<Hash, DataStructure> e : _data.entrySet()) {
|
||||
Hash key = e.getKey();
|
||||
|
||||
@@ -34,7 +34,10 @@ public class Reseeder {
|
||||
// Reject unreasonably big files, because we download into a ByteArrayOutputStream.
|
||||
private static final long MAX_RESEED_RESPONSE_SIZE = 8 * 1024 * 1024;
|
||||
|
||||
private static final String DEFAULT_SEED_URL = "http://i2pdb.tin0.de/netDb/,http://netdb.i2p2.de/";
|
||||
private static final String DEFAULT_SEED_URL = "http://netdb.i2p2.de/,http://b.netdb.i2p2.de/";
|
||||
private static final String PROP_INPROGRESS = "net.i2p.router.web.ReseedHandler.reseedInProgress";
|
||||
private static final String PROP_ERROR = "net.i2p.router.web.ReseedHandler.errorMessage";
|
||||
private static final String PROP_STATUS = "net.i2p.router.web.ReseedHandler.statusMessage";
|
||||
|
||||
public Reseeder(RouterContext ctx) {
|
||||
_context = ctx;
|
||||
@@ -48,7 +51,7 @@ public class Reseeder {
|
||||
if (_reseedRunner.isRunning()) {
|
||||
return;
|
||||
} else {
|
||||
System.setProperty("net.i2p.router.web.Reseeder.reseedInProgress", "true");
|
||||
System.setProperty(PROP_INPROGRESS, "true");
|
||||
I2PThread reseed = new I2PThread(_reseedRunner, "Reseed");
|
||||
reseed.start();
|
||||
}
|
||||
@@ -61,7 +64,7 @@ public class Reseeder {
|
||||
|
||||
public ReseedRunner() {
|
||||
_isRunning = false;
|
||||
System.setProperty("net.i2p.router.web.Reseeder.statusMessage","Reseeding.");
|
||||
System.setProperty(PROP_STATUS, "Reseeding.");
|
||||
}
|
||||
public boolean isRunning() { return _isRunning; }
|
||||
public void run() {
|
||||
@@ -69,7 +72,7 @@ public class Reseeder {
|
||||
System.out.println("Reseed start");
|
||||
reseed(false);
|
||||
System.out.println("Reseed complete");
|
||||
System.setProperty("net.i2p.router.web.Reseeder.reseedInProgress", "false");
|
||||
System.setProperty(PROP_INPROGRESS, "false");
|
||||
_isRunning = false;
|
||||
}
|
||||
|
||||
@@ -126,13 +129,13 @@ public class Reseeder {
|
||||
private void reseedOne(String seedURL, boolean echoStatus) {
|
||||
|
||||
try {
|
||||
System.setProperty("net.i2p.router.web.Reseeder.errorMessage","");
|
||||
System.setProperty("net.i2p.router.web.Reseeder.statusMessage","Reseeding: fetching seed URL.");
|
||||
System.setProperty(PROP_ERROR, "");
|
||||
System.setProperty(PROP_STATUS, "Reseeding: fetching seed URL.");
|
||||
System.err.println("Reseed from " + seedURL);
|
||||
URL dir = new URL(seedURL);
|
||||
byte contentRaw[] = readURL(dir);
|
||||
if (contentRaw == null) {
|
||||
System.setProperty("net.i2p.router.web.Reseeder.errorMessage",
|
||||
System.setProperty(PROP_ERROR,
|
||||
"Last reseed failed fully (failed reading seed URL). " +
|
||||
RESEED_TIPS);
|
||||
// Logging deprecated here since attemptFailed() provides better info
|
||||
@@ -158,7 +161,7 @@ public class Reseeder {
|
||||
}
|
||||
if (total <= 0) {
|
||||
_log.error("Read " + contentRaw.length + " bytes from seed " + seedURL + ", but found no routerInfo URLs.");
|
||||
System.setProperty("net.i2p.router.web.Reseeder.errorMessage",
|
||||
System.setProperty(PROP_ERROR,
|
||||
"Last reseed failed fully (no routerInfo URLs at seed URL). " +
|
||||
RESEED_TIPS);
|
||||
return;
|
||||
@@ -171,7 +174,7 @@ public class Reseeder {
|
||||
// 200 max from one URL
|
||||
for (Iterator iter = urlList.iterator(); iter.hasNext() && fetched < 200; ) {
|
||||
try {
|
||||
System.setProperty("net.i2p.router.web.Reseeder.statusMessage",
|
||||
System.setProperty(PROP_STATUS,
|
||||
"Reseeding: fetching router info from seed URL (" +
|
||||
fetched + " successful, " + errors + " errors, " + total + " total).");
|
||||
|
||||
@@ -193,12 +196,12 @@ public class Reseeder {
|
||||
// Less than 10% of failures is considered success,
|
||||
// because some routerInfos will always fail.
|
||||
if ((failPercent >= 10) && (failPercent < 90)) {
|
||||
System.setProperty("net.i2p.router.web.Reseeder.errorMessage",
|
||||
System.setProperty(PROP_ERROR,
|
||||
"Last reseed failed partly (" + failPercent + "% of " + total + "). " +
|
||||
RESEED_TIPS);
|
||||
}
|
||||
if (failPercent >= 90) {
|
||||
System.setProperty("net.i2p.router.web.Reseeder.errorMessage",
|
||||
System.setProperty(PROP_ERROR,
|
||||
"Last reseed failed (" + failPercent + "% of " + total + "). " +
|
||||
RESEED_TIPS);
|
||||
}
|
||||
@@ -208,7 +211,7 @@ public class Reseeder {
|
||||
if (fetched >= 100)
|
||||
_isRunning = false;
|
||||
} catch (Throwable t) {
|
||||
System.setProperty("net.i2p.router.web.Reseeder.errorMessage",
|
||||
System.setProperty(PROP_ERROR,
|
||||
"Last reseed failed fully (exception caught). " +
|
||||
RESEED_TIPS);
|
||||
_log.error("Error reseeding", t);
|
||||
|
||||
@@ -165,7 +165,7 @@ public class DBHistory {
|
||||
private final static String NL = System.getProperty("line.separator");
|
||||
|
||||
public void store(OutputStream out) throws IOException {
|
||||
StringBuffer buf = new StringBuffer(512);
|
||||
StringBuilder buf = new StringBuilder(512);
|
||||
buf.append(NL);
|
||||
buf.append("#################").append(NL);
|
||||
buf.append("# DB history").append(NL);
|
||||
@@ -186,7 +186,7 @@ public class DBHistory {
|
||||
_invalidReplyRate.store(out, "dbHistory.invalidReplyRate");
|
||||
}
|
||||
|
||||
private void add(StringBuffer buf, String name, long val, String description) {
|
||||
private void add(StringBuilder buf, String name, long val, String description) {
|
||||
buf.append("# ").append(name.toUpperCase()).append(NL).append("# ").append(description).append(NL);
|
||||
buf.append("dbHistory.").append(name).append('=').append(val).append(NL).append(NL);
|
||||
}
|
||||
|
||||
@@ -297,7 +297,7 @@ public class PeerProfile {
|
||||
}
|
||||
|
||||
if (_log.shouldLog(Log.DEBUG) ) {
|
||||
StringBuffer buf = new StringBuffer(128);
|
||||
StringBuilder buf = new StringBuilder(128);
|
||||
buf.append("Updating 1m throughput after ").append(size).append(" to ");
|
||||
for (int i = 0; i < THROUGHPUT_COUNT; i++)
|
||||
buf.append(_peakTunnel1mThroughput[i]).append(',');
|
||||
@@ -509,7 +509,7 @@ public class PeerProfile {
|
||||
fmt.setPositivePrefix("+");
|
||||
ProfilePersistenceHelper helper = new ProfilePersistenceHelper(ctx);
|
||||
try { Thread.sleep(5*1000); } catch (InterruptedException e) {}
|
||||
StringBuffer buf = new StringBuffer(1024);
|
||||
StringBuilder buf = new StringBuilder(1024);
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
PeerProfile profile = helper.readProfile(new File(args[i]));
|
||||
if (profile == null) {
|
||||
|
||||
@@ -224,7 +224,7 @@ public class PeerTestJob extends JobImpl {
|
||||
public boolean matchFound() { return _matchFound; }
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer(64);
|
||||
StringBuilder buf = new StringBuilder(64);
|
||||
buf.append("Test peer ").append(_peer.toBase64().substring(0,4));
|
||||
buf.append(" with nonce ").append(_nonce);
|
||||
return buf.toString();
|
||||
|
||||
@@ -304,7 +304,7 @@ public class ProfileManagerImpl implements ProfileManager {
|
||||
PeerProfile prof = getProfile(peer);
|
||||
if (prof == null) continue;
|
||||
|
||||
StringBuffer buf = new StringBuffer(64);
|
||||
StringBuilder buf = new StringBuilder(64);
|
||||
|
||||
buf.append("status: ");
|
||||
if (_context.profileOrganizer().isFast(peer)) {
|
||||
|
||||
@@ -676,7 +676,7 @@ public class ProfileOrganizer {
|
||||
+ ", capacity: " + _thresholdCapacityValue + ", speed: " + _thresholdSpeedValue + "]");
|
||||
/*****
|
||||
if (_log.shouldLog(Log.DEBUG)) {
|
||||
StringBuffer buf = new StringBuffer(512);
|
||||
StringBuilder buf = new StringBuilder(512);
|
||||
for (Iterator iter = _strictCapacityOrder.iterator(); iter.hasNext(); ) {
|
||||
PeerProfile prof = (PeerProfile)iter.next();
|
||||
buf.append('[').append(prof.toString()).append('=').append(prof.getCapacityValue()).append("] ");
|
||||
|
||||
@@ -56,7 +56,7 @@ class ProfileOrganizerRenderer {
|
||||
int reliable = 0;
|
||||
int integrated = 0;
|
||||
int failing = 0;
|
||||
StringBuffer buf = new StringBuffer(16*1024);
|
||||
StringBuilder buf = new StringBuilder(16*1024);
|
||||
buf.append("<h2>Peer Profiles</h2>\n");
|
||||
buf.append("<p>Showing ").append(order.size()).append(" recent profiles, hiding ").append(peers.size()-order.size()).append(" older profiles</p>");
|
||||
buf.append("<table border=\"1\">");
|
||||
|
||||
@@ -89,7 +89,7 @@ class ProfilePersistenceHelper {
|
||||
groups = groups + ", well integrated";
|
||||
}
|
||||
|
||||
StringBuffer buf = new StringBuffer(512);
|
||||
StringBuilder buf = new StringBuilder(512);
|
||||
buf.append("########################################################################").append(NL);
|
||||
buf.append("# profile for ").append(profile.getPeer().toBase64()).append(NL);
|
||||
if (_us != null)
|
||||
|
||||
@@ -131,7 +131,7 @@ public class TunnelHistory {
|
||||
private final static String NL = System.getProperty("line.separator");
|
||||
|
||||
public void store(OutputStream out) throws IOException {
|
||||
StringBuffer buf = new StringBuffer(512);
|
||||
StringBuilder buf = new StringBuilder(512);
|
||||
buf.append(NL);
|
||||
buf.append("#################").append(NL);
|
||||
buf.append("# Tunnel history").append(NL);
|
||||
@@ -150,7 +150,7 @@ public class TunnelHistory {
|
||||
_failRate.store(out, "tunnelHistory.failRate");
|
||||
}
|
||||
|
||||
private void add(StringBuffer buf, String name, long val, String description) {
|
||||
private void add(StringBuilder buf, String name, long val, String description) {
|
||||
buf.append("# ").append(name.toUpperCase()).append(NL).append("# ").append(description).append(NL);
|
||||
buf.append("tunnels.").append(name).append('=').append(val).append(NL).append(NL);
|
||||
}
|
||||
|
||||
@@ -47,13 +47,15 @@ public class ClientAppConfig {
|
||||
cfgFile = new File(ctx.getConfigDir(), clientConfigFile);
|
||||
|
||||
// fall back to use router.config's clientApp.* lines
|
||||
if (!cfgFile.exists())
|
||||
if (!cfgFile.exists()) {
|
||||
System.out.println("Warning - No client config file " + cfgFile.getAbsolutePath());
|
||||
return ctx.router().getConfigMap();
|
||||
}
|
||||
|
||||
try {
|
||||
DataHelper.loadProps(rv, cfgFile);
|
||||
} catch (IOException ioe) {
|
||||
// _log.warn("Error loading the client app properties from " + cfgFile.getName(), ioe);
|
||||
System.out.println("Error loading the client app properties from " + cfgFile.getAbsolutePath() + ' ' + ioe);
|
||||
}
|
||||
|
||||
return rv;
|
||||
@@ -99,7 +101,7 @@ public class ClientAppConfig {
|
||||
FileOutputStream fos = null;
|
||||
try {
|
||||
fos = new FileOutputStream(cfgFile);
|
||||
StringBuffer buf = new StringBuffer(2048);
|
||||
StringBuilder buf = new StringBuilder(2048);
|
||||
for(int i = 0; i < apps.size(); i++) {
|
||||
ClientAppConfig app = (ClientAppConfig) apps.get(i);
|
||||
buf.append(PREFIX).append(i).append(".main=").append(app.className).append("\n");
|
||||
|
||||
@@ -29,6 +29,11 @@ public class LoadClientAppsJob extends JobImpl {
|
||||
_loaded = true;
|
||||
}
|
||||
List apps = ClientAppConfig.getClientApps(getContext());
|
||||
if (apps.size() <= 0) {
|
||||
_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");
|
||||
return;
|
||||
}
|
||||
for(int i = 0; i < apps.size(); i++) {
|
||||
ClientAppConfig app = (ClientAppConfig) apps.get(i);
|
||||
if (app.disabled)
|
||||
@@ -64,7 +69,7 @@ public class LoadClientAppsJob extends JobImpl {
|
||||
List argList = new ArrayList(4);
|
||||
if (args != null) {
|
||||
char data[] = args.toCharArray();
|
||||
StringBuffer buf = new StringBuffer(32);
|
||||
StringBuilder buf = new StringBuilder(32);
|
||||
boolean isQuoted = false;
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
switch (data[i]) {
|
||||
@@ -74,7 +79,7 @@ public class LoadClientAppsJob extends JobImpl {
|
||||
String str = buf.toString().trim();
|
||||
if (str.length() > 0)
|
||||
argList.add(str);
|
||||
buf = new StringBuffer(32);
|
||||
buf = new StringBuilder(32);
|
||||
} else {
|
||||
isQuoted = true;
|
||||
}
|
||||
@@ -89,7 +94,7 @@ public class LoadClientAppsJob extends JobImpl {
|
||||
String str = buf.toString().trim();
|
||||
if (str.length() > 0)
|
||||
argList.add(str);
|
||||
buf = new StringBuffer(32);
|
||||
buf = new StringBuilder(32);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -206,14 +206,15 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
|
||||
public final static String PROP_I2NP_NTCP_AUTO_IP = "i2np.ntcp.autoip";
|
||||
|
||||
/**
|
||||
* This only creates an address if the hostname AND port are set in router.config,
|
||||
* which should be rare.
|
||||
* Otherwise, notifyReplaceAddress() below takes care of it.
|
||||
* Note this is called both from above and from NTCPTransport.startListening()
|
||||
*
|
||||
* This should really be moved to ntcp/NTCPTransport.java, why is it here?
|
||||
*/
|
||||
public static RouterAddress createNTCPAddress(RouterContext ctx) {
|
||||
if (!TransportManager.enableNTCP(ctx)) return null;
|
||||
RouterAddress addr = new RouterAddress();
|
||||
addr.setCost(10);
|
||||
addr.setExpiration(null);
|
||||
Properties props = new Properties();
|
||||
String name = ctx.router().getConfigSetting(PROP_I2NP_NTCP_HOSTNAME);
|
||||
String port = ctx.router().getConfigSetting(PROP_I2NP_NTCP_PORT);
|
||||
/*
|
||||
@@ -236,12 +237,16 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
|
||||
} catch (NumberFormatException nfe) {
|
||||
return null;
|
||||
}
|
||||
Properties props = new Properties();
|
||||
props.setProperty(NTCPAddress.PROP_HOST, name);
|
||||
props.setProperty(NTCPAddress.PROP_PORT, port);
|
||||
RouterAddress addr = new RouterAddress();
|
||||
addr.setCost(10);
|
||||
addr.setExpiration(null);
|
||||
addr.setOptions(props);
|
||||
addr.setTransportStyle(NTCPTransport.STYLE);
|
||||
//if (isNew) {
|
||||
if (false) return null;
|
||||
// why save the same thing?
|
||||
ctx.router().setConfigSetting(PROP_I2NP_NTCP_HOSTNAME, name);
|
||||
ctx.router().setConfigSetting(PROP_I2NP_NTCP_PORT, port);
|
||||
ctx.router().saveConfig();
|
||||
@@ -334,6 +339,15 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
|
||||
}
|
||||
} else if (ohost == null || ohost.length() <= 0) {
|
||||
return;
|
||||
} else if (enabled.equalsIgnoreCase("true") && status != STATUS_OK) {
|
||||
// UDP transitioned to not-OK, turn off NTCP address
|
||||
// This will commonly happen at startup if we were initially OK
|
||||
// because UPnP was successful, but a subsequent SSU Peer Test determines
|
||||
// we are still firewalled (SW firewall, bad UPnP indication, etc.)
|
||||
if (_log.shouldLog(Log.INFO))
|
||||
_log.info("old: " + ohost + " config: " + name + " new: null");
|
||||
newAddr = null;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (!changed) {
|
||||
@@ -346,10 +360,12 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
|
||||
//
|
||||
// really need to fix this so that we can change or create an inbound address
|
||||
// without tearing down everything
|
||||
// Especially on disabling the address, we shouldn't tear everything down.
|
||||
//
|
||||
_log.warn("Halting NTCP to change address");
|
||||
t.stopListening();
|
||||
newAddr.setOptions(newProps);
|
||||
if (newAddr != null)
|
||||
newAddr.setOptions(newProps);
|
||||
// Wait for NTCP Pumper to stop so we don't end up with two...
|
||||
while (t.isAlive()) {
|
||||
try { Thread.sleep(5*1000); } catch (InterruptedException ie) {}
|
||||
@@ -448,7 +464,7 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
|
||||
/** Provide a consistent "look" for displaying router IDs in the console */
|
||||
public String renderPeerHTML(Hash peer) {
|
||||
String h = peer.toBase64().substring(0, 4);
|
||||
StringBuffer buf = new StringBuffer(128);
|
||||
StringBuilder buf = new StringBuilder(128);
|
||||
String c = getCountry(peer);
|
||||
if (c != null) {
|
||||
buf.append("<img alt=\"").append(c.toUpperCase()).append("\" title=\"");
|
||||
|
||||
@@ -199,8 +199,8 @@ public class FIFOBandwidthLimiter {
|
||||
void setInboundBurstBytes(int bytes) { _maxInboundBurst = bytes; }
|
||||
void setOutboundBurstBytes(int bytes) { _maxOutboundBurst = bytes; }
|
||||
|
||||
StringBuffer getStatus() {
|
||||
StringBuffer rv = new StringBuffer(64);
|
||||
StringBuilder getStatus() {
|
||||
StringBuilder rv = new StringBuilder(64);
|
||||
rv.append("Available: ").append(_availableInbound).append('/').append(_availableOutbound).append(' ');
|
||||
rv.append("Max: ").append(_maxInbound).append('/').append(_maxOutbound).append(' ');
|
||||
rv.append("Burst: ").append(_unavailableInboundBurst).append('/').append(_unavailableOutboundBurst).append(' ');
|
||||
@@ -618,7 +618,7 @@ public class FIFOBandwidthLimiter {
|
||||
|
||||
public void renderStatusHTML(Writer out) throws IOException {
|
||||
long now = now();
|
||||
StringBuffer buf = new StringBuffer(4096);
|
||||
StringBuilder buf = new StringBuilder(4096);
|
||||
buf.append("<p><b id=\"bwlim\">Limiter Status:</b><br />").append(getStatus().toString()).append("</p>\n");
|
||||
buf.append("<p><b>Pending bandwidth requests:</b><ul>");
|
||||
buf.append("<li>Inbound requests: <ol>");
|
||||
|
||||
@@ -140,7 +140,7 @@ public class GeoIP {
|
||||
FileInputStream in = null;
|
||||
try {
|
||||
in = new FileInputStream(GeoFile);
|
||||
StringBuffer buf = new StringBuffer(128);
|
||||
StringBuilder buf = new StringBuilder(128);
|
||||
while (DataHelper.readLine(in, buf)) {
|
||||
try {
|
||||
if (buf.charAt(0) == '#') {
|
||||
@@ -202,7 +202,7 @@ public class GeoIP {
|
||||
FileInputStream in = null;
|
||||
try {
|
||||
in = new FileInputStream(GeoFile);
|
||||
StringBuffer buf = new StringBuffer(128);
|
||||
StringBuilder buf = new StringBuilder(128);
|
||||
while (DataHelper.readLine(in, buf) && idx < search.length) {
|
||||
try {
|
||||
if (buf.charAt(0) == '#') {
|
||||
|
||||
@@ -364,7 +364,7 @@ public abstract class TransportImpl implements Transport {
|
||||
if (msToReceive > 5000)
|
||||
level = Log.WARN;
|
||||
if (_log.shouldLog(level)) {
|
||||
StringBuffer buf = new StringBuffer(128);
|
||||
StringBuilder buf = new StringBuilder(128);
|
||||
buf.append("Message received: ").append(inMsg.getClass().getName());
|
||||
buf.append(" / ").append(inMsg.getUniqueId());
|
||||
buf.append(" in ").append(msToReceive).append("ms containing ");
|
||||
|
||||
@@ -486,7 +486,7 @@ public class TransportManager implements TransportEventListener {
|
||||
Transport t= (Transport)iter.next();
|
||||
t.renderStatusHTML(out, urlBase, sortFlags);
|
||||
}
|
||||
StringBuffer buf = new StringBuffer(4*1024);
|
||||
StringBuilder buf = new StringBuilder(4*1024);
|
||||
buf.append("<p><b>Router Transport Addresses:</b><br /><pre>\n");
|
||||
for (int i = 0; i < _transports.size(); i++) {
|
||||
Transport t = (Transport)_transports.get(i);
|
||||
|
||||
@@ -662,7 +662,7 @@ public class EstablishState {
|
||||
private String prefix() { return toString(); }
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer(64);
|
||||
StringBuilder buf = new StringBuilder(64);
|
||||
buf.append("est").append(System.identityHashCode(this));
|
||||
if (_con.isInbound()) buf.append(" inbound");
|
||||
else buf.append(" outbound");
|
||||
|
||||
@@ -417,7 +417,7 @@ public class NTCPTransport extends TransportImpl {
|
||||
private static final int NUM_CONCURRENT_WRITERS = 3;
|
||||
|
||||
public synchronized RouterAddress startListening() {
|
||||
if (_log.shouldLog(Log.DEBUG)) _log.debug("Starting ntcp transport listening");
|
||||
if (_log.shouldLog(Log.WARN)) _log.warn("Starting ntcp transport listening");
|
||||
_finisher.start();
|
||||
_pumper.startPumping();
|
||||
|
||||
@@ -429,14 +429,17 @@ public class NTCPTransport extends TransportImpl {
|
||||
}
|
||||
|
||||
public synchronized RouterAddress restartListening(RouterAddress addr) {
|
||||
if (_log.shouldLog(Log.DEBUG)) _log.debug("Restarting ntcp transport listening");
|
||||
if (_log.shouldLog(Log.WARN)) _log.warn("Restarting ntcp transport listening");
|
||||
_finisher.start();
|
||||
_pumper.startPumping();
|
||||
|
||||
_reader.startReading(NUM_CONCURRENT_READERS);
|
||||
_writer.startWriting(NUM_CONCURRENT_WRITERS);
|
||||
|
||||
_myAddress = new NTCPAddress(addr);
|
||||
if (addr == null)
|
||||
_myAddress = null;
|
||||
else
|
||||
_myAddress = new NTCPAddress(addr);
|
||||
return bindAddress();
|
||||
}
|
||||
|
||||
@@ -603,7 +606,7 @@ public class NTCPTransport extends TransportImpl {
|
||||
* before calling startListening() or restartListening()
|
||||
*/
|
||||
public synchronized void stopListening() {
|
||||
if (_log.shouldLog(Log.DEBUG)) _log.debug("Stopping ntcp transport");
|
||||
if (_log.shouldLog(Log.WARN)) _log.warn("Stopping ntcp transport");
|
||||
_pumper.stopPumping();
|
||||
_writer.stopWriting();
|
||||
_reader.stopReading();
|
||||
@@ -643,7 +646,7 @@ public class NTCPTransport extends TransportImpl {
|
||||
long totalSend = 0;
|
||||
long totalRecv = 0;
|
||||
|
||||
StringBuffer buf = new StringBuffer(512);
|
||||
StringBuilder buf = new StringBuilder(512);
|
||||
buf.append("<p><b id=\"ntcpcon\">NTCP connections: ").append(peers.size());
|
||||
buf.append(" limit: ").append(getMaxConnections());
|
||||
buf.append(" timeout: ").append(DataHelper.formatDuration(_pumper.getIdleTimeout()));
|
||||
|
||||
@@ -181,7 +181,7 @@ public class InboundEstablishState {
|
||||
_sentSignature = _context.dsa().sign(signed, _context.keyManager().getSigningPrivateKey());
|
||||
|
||||
if (_log.shouldLog(Log.DEBUG)) {
|
||||
StringBuffer buf = new StringBuffer(128);
|
||||
StringBuilder buf = new StringBuilder(128);
|
||||
buf.append("Signing sessionCreated:");
|
||||
buf.append(" ReceivedX: ").append(Base64.encode(_receivedX));
|
||||
buf.append(" SentY: ").append(Base64.encode(_sentY));
|
||||
@@ -333,7 +333,7 @@ public class InboundEstablishState {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer(128);
|
||||
StringBuilder buf = new StringBuilder(128);
|
||||
buf.append(super.toString());
|
||||
if (_receivedX != null)
|
||||
buf.append(" ReceivedX: ").append(Base64.encode(_receivedX, 0, 4));
|
||||
|
||||
@@ -140,7 +140,7 @@ public class InboundMessageState {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer(64);
|
||||
StringBuilder buf = new StringBuilder(64);
|
||||
buf.append("Partial ACK of ");
|
||||
buf.append(_bitfieldMessageId);
|
||||
buf.append(" with ACKs for: ");
|
||||
@@ -165,7 +165,7 @@ public class InboundMessageState {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer(32);
|
||||
StringBuilder buf = new StringBuilder(32);
|
||||
buf.append("Message: ").append(_messageId);
|
||||
if (isComplete()) {
|
||||
buf.append(" completely received with ");
|
||||
|
||||
@@ -291,7 +291,7 @@ public class OutboundEstablishState {
|
||||
DataHelper.toLong(signed, off, 4, _receivedSignedOnTime);
|
||||
boolean valid = _context.dsa().verifySignature(_receivedSignature, signed, _remotePeer.getSigningPublicKey());
|
||||
if (!valid || _log.shouldLog(Log.DEBUG)) {
|
||||
StringBuffer buf = new StringBuffer(128);
|
||||
StringBuilder buf = new StringBuilder(128);
|
||||
buf.append("Signed sessionCreated:");
|
||||
buf.append(" AliceIP: ").append(Base64.encode(_aliceIP));
|
||||
buf.append(" AlicePort: ").append(_alicePort);
|
||||
|
||||
@@ -295,7 +295,7 @@ public class OutboundMessageState {
|
||||
public String toString() {
|
||||
short sends[] = _fragmentSends;
|
||||
ByteArray messageBuf = _messageBuf;
|
||||
StringBuffer buf = new StringBuffer(64);
|
||||
StringBuilder buf = new StringBuilder(64);
|
||||
buf.append("Message ").append(_messageId);
|
||||
if (sends != null)
|
||||
buf.append(" with ").append(sends.length).append(" fragments");
|
||||
|
||||
@@ -61,10 +61,10 @@ public class PacketBuilder {
|
||||
public UDPPacket buildPacket(OutboundMessageState state, int fragment, PeerState peer, List ackIdsRemaining, List partialACKsRemaining) {
|
||||
UDPPacket packet = UDPPacket.acquire(_context, false);
|
||||
|
||||
StringBuffer msg = null;
|
||||
StringBuilder msg = null;
|
||||
boolean acksIncluded = false;
|
||||
if (_log.shouldLog(Log.INFO)) {
|
||||
msg = new StringBuffer(128);
|
||||
msg = new StringBuilder(128);
|
||||
msg.append("Send to ").append(peer.getRemotePeer().toBase64());
|
||||
msg.append(" msg ").append(state.getMessageId()).append(":").append(fragment);
|
||||
if (fragment == state.getFragmentCount() - 1)
|
||||
@@ -219,9 +219,9 @@ public class PacketBuilder {
|
||||
public UDPPacket buildACK(PeerState peer, List ackBitfields) {
|
||||
UDPPacket packet = UDPPacket.acquire(_context, false);
|
||||
|
||||
StringBuffer msg = null;
|
||||
StringBuilder msg = null;
|
||||
if (_log.shouldLog(Log.DEBUG)) {
|
||||
msg = new StringBuffer(128);
|
||||
msg = new StringBuilder(128);
|
||||
msg.append("building ACK packet to ").append(peer.getRemotePeer().toBase64().substring(0,6));
|
||||
}
|
||||
|
||||
@@ -379,7 +379,7 @@ public class PacketBuilder {
|
||||
off += 8;
|
||||
|
||||
if (_log.shouldLog(Log.DEBUG)) {
|
||||
StringBuffer buf = new StringBuffer(128);
|
||||
StringBuilder buf = new StringBuilder(128);
|
||||
buf.append("Sending sessionCreated:");
|
||||
buf.append(" AliceIP: ").append(Base64.encode(sentIP));
|
||||
buf.append(" AlicePort: ").append(state.getSentPort());
|
||||
|
||||
@@ -93,7 +93,7 @@ public class PacketHandler {
|
||||
}
|
||||
|
||||
String getHandlerStatus() {
|
||||
StringBuffer rv = new StringBuffer();
|
||||
StringBuilder rv = new StringBuilder();
|
||||
int size = _handlers.size();
|
||||
rv.append("Handlers: ").append(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
@@ -324,7 +324,7 @@ public class PacketHandler {
|
||||
private void receivePacket(UDPPacketReader reader, UDPPacket packet, InboundEstablishState state, boolean allowFallback) {
|
||||
_state = 31;
|
||||
if ( (state != null) && (_log.shouldLog(Log.DEBUG)) ) {
|
||||
StringBuffer buf = new StringBuffer(128);
|
||||
StringBuilder buf = new StringBuilder(128);
|
||||
buf.append("Attempting to receive a packet on a known inbound state: ");
|
||||
buf.append(state);
|
||||
buf.append(" MAC key: ").append(state.getMACKey());
|
||||
@@ -362,7 +362,7 @@ public class PacketHandler {
|
||||
private void receivePacket(UDPPacketReader reader, UDPPacket packet, OutboundEstablishState state) {
|
||||
_state = 35;
|
||||
if ( (state != null) && (_log.shouldLog(Log.DEBUG)) ) {
|
||||
StringBuffer buf = new StringBuffer(128);
|
||||
StringBuilder buf = new StringBuilder(128);
|
||||
buf.append("Attempting to receive a packet on a known outbound state: ");
|
||||
buf.append(state);
|
||||
buf.append(" MAC key: ").append(state.getMACKey());
|
||||
@@ -470,7 +470,7 @@ public class PacketHandler {
|
||||
if (state != null) {
|
||||
UDPPacketReader.DataReader dr = reader.getDataReader();
|
||||
if (_log.shouldLog(Log.INFO)) {
|
||||
StringBuffer msg = new StringBuffer();
|
||||
StringBuilder msg = new StringBuilder();
|
||||
msg.append("Receive ").append(System.identityHashCode(packet));
|
||||
msg.append(" from ").append(state.getRemotePeer().toBase64()).append(" ").append(state.getRemoteHostId());
|
||||
for (int i = 0; i < dr.readFragmentCount(); i++) {
|
||||
|
||||
@@ -1555,7 +1555,7 @@ public class PeerState {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer(64);
|
||||
StringBuilder buf = new StringBuilder(64);
|
||||
buf.append(_remoteHostId.toString());
|
||||
if (_remotePeer != null)
|
||||
buf.append(" ").append(_remotePeer.toBase64().substring(0,6));
|
||||
|
||||
@@ -98,7 +98,7 @@ class PeerTestState {
|
||||
|
||||
@Override
|
||||
public synchronized String toString() {
|
||||
StringBuffer buf = new StringBuffer(512);
|
||||
StringBuilder buf = new StringBuilder(512);
|
||||
buf.append("Role: ");
|
||||
if (_ourRole == ALICE) buf.append("Alice");
|
||||
else if (_ourRole == BOB) buf.append("Bob");
|
||||
|
||||
@@ -60,7 +60,7 @@ final class RemoteHostId {
|
||||
}
|
||||
}
|
||||
public static String toString(byte ip[]) {
|
||||
StringBuffer buf = new StringBuffer(ip.length+5);
|
||||
StringBuilder buf = new StringBuilder(ip.length+5);
|
||||
for (int i = 0; i < ip.length; i++) {
|
||||
buf.append(ip[i]&0xFF);
|
||||
if (i + 1 < ip.length)
|
||||
|
||||
@@ -42,7 +42,7 @@ public class UDPAddress {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer rv = new StringBuffer(64);
|
||||
StringBuilder rv = new StringBuilder(64);
|
||||
if (_introHosts != null) {
|
||||
for (int i = 0; i < _introHosts.length; i++) {
|
||||
rv.append("ssu://");
|
||||
|
||||
@@ -168,7 +168,7 @@ public class UDPPacket {
|
||||
Hash hmac = _context.hmac().calculate(macKey, buf.getData(), 0, off);
|
||||
|
||||
if (_log.shouldLog(Log.DEBUG)) {
|
||||
StringBuffer str = new StringBuffer(128);
|
||||
StringBuilder str = new StringBuilder(128);
|
||||
str.append(_packet.getLength()).append(" byte packet received, payload length ");
|
||||
str.append(payloadLength);
|
||||
str.append("\nIV: ").append(Base64.encode(buf.getData(), payloadLength, IV_SIZE));
|
||||
@@ -237,7 +237,7 @@ public class UDPPacket {
|
||||
@Override
|
||||
public String toString() {
|
||||
verifyNotReleased();
|
||||
StringBuffer buf = new StringBuffer(64);
|
||||
StringBuilder buf = new StringBuilder(64);
|
||||
buf.append(_packet.getLength());
|
||||
buf.append(" byte packet with ");
|
||||
buf.append(_packet.getAddress().getHostAddress()).append(":");
|
||||
|
||||
@@ -129,7 +129,7 @@ public class UDPPacketReader {
|
||||
}
|
||||
}
|
||||
|
||||
public void toRawString(StringBuffer buf) {
|
||||
public void toRawString(StringBuilder buf) {
|
||||
if (_message != null)
|
||||
buf.append(Base64.encode(_message, _payloadBeginOffset, _payloadLength));
|
||||
}
|
||||
@@ -401,7 +401,7 @@ public class UDPPacketReader {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer(256);
|
||||
StringBuilder buf = new StringBuilder(256);
|
||||
long msAgo = _context.clock().now() - readTimestamp()*1000;
|
||||
buf.append("Data packet sent ").append(msAgo).append("ms ago ");
|
||||
buf.append("IV ");
|
||||
@@ -463,7 +463,7 @@ public class UDPPacketReader {
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public void toRawString(StringBuffer buf) {
|
||||
public void toRawString(StringBuilder buf) {
|
||||
UDPPacketReader.this.toRawString(buf);
|
||||
buf.append(" payload: ");
|
||||
|
||||
@@ -506,7 +506,7 @@ public class UDPPacketReader {
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer(64);
|
||||
StringBuilder buf = new StringBuilder(64);
|
||||
buf.append("Read partial ACK of ");
|
||||
buf.append(getMessageId());
|
||||
buf.append(" with ACKs for: ");
|
||||
|
||||
@@ -164,7 +164,7 @@ public class UDPReceiver {
|
||||
packet.release();
|
||||
_context.statManager().addRateData("udp.droppedInbound", queueSize, headPeriod);
|
||||
if (_log.shouldLog(Log.WARN)) {
|
||||
StringBuffer msg = new StringBuffer();
|
||||
StringBuilder msg = new StringBuilder();
|
||||
msg.append("Dropping inbound packet with ");
|
||||
msg.append(queueSize);
|
||||
msg.append(" queued for ");
|
||||
|
||||
@@ -437,12 +437,16 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
synchronized (this) {
|
||||
if ( (_externalListenHost == null) ||
|
||||
(!eq(_externalListenHost.getAddress(), _externalListenPort, ourIP, ourPort)) ) {
|
||||
if (_log.shouldLog(Log.WARN))
|
||||
_log.warn("Change address? status = " + _reachabilityStatus +
|
||||
" diff = " + (_context.clock().now() - _reachabilityStatusLastUpdated) +
|
||||
" old = " + _externalListenHost + ':' + _externalListenPort);
|
||||
if ( (_reachabilityStatus != CommSystemFacade.STATUS_OK) ||
|
||||
(_externalListenHost == null) || (_externalListenPort <= 0) ||
|
||||
(_context.clock().now() - _reachabilityStatusLastUpdated > 2*TEST_FREQUENCY) ) {
|
||||
// they told us something different and our tests are either old or failing
|
||||
if (_log.shouldLog(Log.INFO))
|
||||
_log.info("Trying to change our external address...");
|
||||
if (_log.shouldLog(Log.WARN))
|
||||
_log.warn("Trying to change our external address...");
|
||||
try {
|
||||
_externalListenHost = InetAddress.getByAddress(ourIP);
|
||||
// fixed port defaults to true so we never do this
|
||||
@@ -455,15 +459,15 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
}
|
||||
} catch (UnknownHostException uhe) {
|
||||
_externalListenHost = null;
|
||||
if (_log.shouldLog(Log.INFO))
|
||||
_log.info("Error trying to change our external address", uhe);
|
||||
if (_log.shouldLog(Log.WARN))
|
||||
_log.warn("Error trying to change our external address", uhe);
|
||||
}
|
||||
} else {
|
||||
// they told us something different, but our tests are recent and positive,
|
||||
// so lets test again
|
||||
fireTest = true;
|
||||
if (_log.shouldLog(Log.INFO))
|
||||
_log.info("Different address, but we're fine.. (" + _reachabilityStatus + ")");
|
||||
if (_log.shouldLog(Log.WARN))
|
||||
_log.warn("Different address, but we're fine.. (" + _reachabilityStatus + ")");
|
||||
}
|
||||
} else {
|
||||
// matched what we expect
|
||||
@@ -760,7 +764,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
private void dropPeer(PeerState peer, boolean shouldShitlist, String why) {
|
||||
if (_log.shouldLog(Log.WARN)) {
|
||||
long now = _context.clock().now();
|
||||
StringBuffer buf = new StringBuffer(4096);
|
||||
StringBuilder buf = new StringBuilder(4096);
|
||||
long timeSinceSend = now - peer.getLastSendTime();
|
||||
long timeSinceRecv = now - peer.getLastReceiveTime();
|
||||
long timeSinceAck = now - peer.getLastACKSend();
|
||||
@@ -1282,7 +1286,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
|
||||
OutNetMessage m = msg.getMessage();
|
||||
PeerState p = msg.getPeer();
|
||||
StringBuffer buf = new StringBuffer(64);
|
||||
StringBuilder buf = new StringBuilder(64);
|
||||
buf.append(" lifetime: ").append(msg.getLifetime());
|
||||
buf.append(" sends: ").append(sends);
|
||||
buf.append(" pushes: ").append(pushCount);
|
||||
@@ -1727,7 +1731,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
}
|
||||
}
|
||||
|
||||
private void appendSortLinks(StringBuffer buf, String urlBase, int sortFlags, String descr, int ascending) {
|
||||
private void appendSortLinks(StringBuilder buf, String urlBase, int sortFlags, String descr, int ascending) {
|
||||
if (sortFlags == ascending) {
|
||||
buf.append(" <a href=\"").append(urlBase).append("?sort=").append(0-ascending);
|
||||
buf.append("\" title=\"").append(descr).append("\">V</a><b>^</b> ");
|
||||
@@ -1763,7 +1767,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
long dupRecvTotal = 0;
|
||||
int numPeers = 0;
|
||||
|
||||
StringBuffer buf = new StringBuffer(512);
|
||||
StringBuilder buf = new StringBuilder(512);
|
||||
buf.append("<p><b id=\"udpcon\">UDP connections: ").append(peers.size());
|
||||
buf.append(" limit: ").append(getMaxConnections());
|
||||
buf.append(" timeout: ").append(DataHelper.formatDuration(_expireTimeout));
|
||||
|
||||
@@ -65,10 +65,10 @@ public class BatchedPreprocessor extends TrivialPreprocessor {
|
||||
|
||||
@Override
|
||||
public boolean preprocessQueue(List pending, TunnelGateway.Sender sender, TunnelGateway.Receiver rec) {
|
||||
StringBuffer timingBuf = null;
|
||||
StringBuilder timingBuf = null;
|
||||
if (_log.shouldLog(Log.DEBUG)) {
|
||||
_log.debug("Preprocess queue with " + pending.size() + " to send");
|
||||
timingBuf = new StringBuffer(128);
|
||||
timingBuf = new StringBuilder(128);
|
||||
timingBuf.append("Preprocess with " + pending.size() + " to send. ");
|
||||
}
|
||||
if (DISABLE_BATCHING) {
|
||||
@@ -246,7 +246,7 @@ public class BatchedPreprocessor extends TrivialPreprocessor {
|
||||
private void display(long allocated, List pending, String title) {
|
||||
if (_log.shouldLog(Log.INFO)) {
|
||||
long highestDelay = 0;
|
||||
StringBuffer buf = new StringBuffer();
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append(_name).append(": ");
|
||||
buf.append(title);
|
||||
buf.append(" allocated: ").append(allocated);
|
||||
@@ -286,7 +286,7 @@ public class BatchedPreprocessor extends TrivialPreprocessor {
|
||||
// generate the final preprocessed data
|
||||
|
||||
if (offset <= 0) {
|
||||
StringBuffer buf = new StringBuffer(128);
|
||||
StringBuilder buf = new StringBuilder(128);
|
||||
buf.append("wtf, written offset is ").append(offset);
|
||||
buf.append(" for ").append(startAt).append(" through ").append(sendThrough);
|
||||
for (int i = startAt; i <= sendThrough; i++) {
|
||||
|
||||
@@ -275,7 +275,7 @@ public class FragmentedMessage {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer(128);
|
||||
StringBuilder buf = new StringBuilder(128);
|
||||
buf.append("Fragments for ").append(_messageId).append(": ");
|
||||
for (int i = 0; i <= _highFragmentNum; i++) {
|
||||
ByteArray ba = _fragments[i];
|
||||
|
||||
@@ -137,7 +137,7 @@ public class HopConfig {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer(64);
|
||||
StringBuilder buf = new StringBuilder(64);
|
||||
if (_receiveTunnelId != null) {
|
||||
buf.append("recv on ");
|
||||
buf.append(DataHelper.fromLong(_receiveTunnelId, 0, 4));
|
||||
|
||||
@@ -43,9 +43,9 @@ public class TrivialPreprocessor implements TunnelGateway.QueuePreprocessor {
|
||||
*/
|
||||
public boolean preprocessQueue(List pending, TunnelGateway.Sender sender, TunnelGateway.Receiver rec) {
|
||||
long begin = System.currentTimeMillis();
|
||||
StringBuffer buf = null;
|
||||
StringBuilder buf = null;
|
||||
if (_log.shouldLog(Log.DEBUG)) {
|
||||
buf = new StringBuffer(256);
|
||||
buf = new StringBuilder(256);
|
||||
buf.append("Trivial preprocessing of ").append(pending.size()).append(" ");
|
||||
}
|
||||
while (pending.size() > 0) {
|
||||
|
||||
@@ -166,7 +166,7 @@ public class TunnelCreatorConfig implements TunnelInfo {
|
||||
@Override
|
||||
public String toString() {
|
||||
// H0:1235-->H1:2345-->H2:2345
|
||||
StringBuffer buf = new StringBuffer(128);
|
||||
StringBuilder buf = new StringBuilder(128);
|
||||
if (_isInbound)
|
||||
buf.append("inbound");
|
||||
else
|
||||
|
||||
@@ -238,7 +238,7 @@ public class TunnelGateway {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer(64);
|
||||
StringBuilder buf = new StringBuilder(64);
|
||||
buf.append("Message ").append(_messageId).append(" on ");
|
||||
buf.append(TunnelGateway.this.toString());
|
||||
if (_toRouter != null) {
|
||||
|
||||
@@ -221,7 +221,7 @@ public class TunnelParticipant {
|
||||
@Override
|
||||
public String toString() {
|
||||
if (_config != null) {
|
||||
StringBuffer buf = new StringBuffer(64);
|
||||
StringBuilder buf = new StringBuilder(64);
|
||||
buf.append("participant at ").append(_config.toString());
|
||||
return buf.toString();
|
||||
} else {
|
||||
|
||||
@@ -206,7 +206,7 @@ class BuildHandler {
|
||||
long replyMessageId = state.msg.getUniqueId();
|
||||
PooledTunnelCreatorConfig cfg = null;
|
||||
List building = _exec.locked_getCurrentlyBuilding();
|
||||
StringBuffer buf = null;
|
||||
StringBuilder buf = null;
|
||||
synchronized (building) {
|
||||
for (int i = 0; i < building.size(); i++) {
|
||||
PooledTunnelCreatorConfig cur = (PooledTunnelCreatorConfig)building.get(i);
|
||||
@@ -217,7 +217,7 @@ class BuildHandler {
|
||||
}
|
||||
}
|
||||
if ( (cfg == null) && (_log.shouldLog(Log.DEBUG)) )
|
||||
buf = new StringBuffer(building.toString());
|
||||
buf = new StringBuilder(building.toString());
|
||||
}
|
||||
|
||||
if (cfg == null) {
|
||||
|
||||
@@ -252,7 +252,7 @@ class TestJob extends JobImpl {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer rv = new StringBuffer(64);
|
||||
StringBuilder rv = new StringBuilder(64);
|
||||
rv.append("Testing tunnel ").append(_cfg.toString()).append(" waiting for ");
|
||||
rv.append(_id).append(" found? ").append(_found);
|
||||
return rv.toString();
|
||||
@@ -284,7 +284,7 @@ class TestJob extends JobImpl {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer rv = new StringBuffer(64);
|
||||
StringBuilder rv = new StringBuilder(64);
|
||||
rv.append("Testing tunnel ").append(_cfg.toString());
|
||||
rv.append(" successful after ").append(_successTime);
|
||||
return rv.toString();
|
||||
@@ -310,7 +310,7 @@ class TestJob extends JobImpl {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer rv = new StringBuffer(64);
|
||||
StringBuilder rv = new StringBuilder(64);
|
||||
rv.append("Testing tunnel ").append(_cfg.toString());
|
||||
rv.append(" timed out");
|
||||
return rv.toString();
|
||||
|
||||
@@ -129,7 +129,7 @@ public abstract class TunnelPeerSelector {
|
||||
rv.remove(0);
|
||||
|
||||
if (log.shouldLog(Log.INFO)) {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
StringBuilder buf = new StringBuilder();
|
||||
if (settings.getDestinationNickname() != null)
|
||||
buf.append("peers for ").append(settings.getDestinationNickname());
|
||||
else if (settings.getDestination() != null)
|
||||
|
||||
@@ -892,7 +892,7 @@ public class TunnelPool {
|
||||
else
|
||||
return "Outbound exploratory pool";
|
||||
} else {
|
||||
StringBuffer rv = new StringBuffer(32);
|
||||
StringBuilder rv = new StringBuilder(32);
|
||||
if (_settings.isInbound())
|
||||
rv.append("Inbound client pool for ");
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user