make BuildResponseRecord static
This commit is contained in:
@ -5,28 +5,36 @@ import net.i2p.data.Base64;
|
||||
import net.i2p.data.DataHelper;
|
||||
import net.i2p.data.Hash;
|
||||
import net.i2p.data.SessionKey;
|
||||
import net.i2p.util.Log;
|
||||
//import net.i2p.util.Log;
|
||||
|
||||
/**
|
||||
* Read and write the reply to a tunnel build message record.
|
||||
*
|
||||
* The reply record is the same size as the request record (528 bytes).
|
||||
* Bytes 0-526 contain random data.
|
||||
* Byte 527 contains the reply.
|
||||
*/
|
||||
public class BuildResponseRecord {
|
||||
|
||||
/**
|
||||
* Create a new encrypted response
|
||||
*
|
||||
* @param status the response
|
||||
* @param responseMessageID unused except for debugging
|
||||
* @param a 528-byte response record
|
||||
*/
|
||||
public byte[] create(I2PAppContext ctx, int status, SessionKey replyKey, byte replyIV[], long responseMessageId) {
|
||||
Log log = ctx.logManager().getLog(BuildResponseRecord.class);
|
||||
public static byte[] create(I2PAppContext ctx, int status, SessionKey replyKey, byte replyIV[], long responseMessageId) {
|
||||
//Log log = ctx.logManager().getLog(BuildResponseRecord.class);
|
||||
byte rv[] = new byte[TunnelBuildReplyMessage.RECORD_SIZE];
|
||||
ctx.random().nextBytes(rv);
|
||||
DataHelper.toLong(rv, TunnelBuildMessage.RECORD_SIZE-1, 1, status);
|
||||
// rv = AES(SHA256(padding+status) + padding + status, replyKey, replyIV)
|
||||
ctx.sha().calculateHash(rv, Hash.HASH_LENGTH, rv.length - Hash.HASH_LENGTH, rv, 0);
|
||||
if (log.shouldLog(Log.DEBUG))
|
||||
log.debug(responseMessageId + ": before encrypt: " + Base64.encode(rv, 0, 128) + " with " + replyKey.toBase64() + "/" + Base64.encode(replyIV));
|
||||
//if (log.shouldLog(Log.DEBUG))
|
||||
// log.debug(responseMessageId + ": before encrypt: " + Base64.encode(rv, 0, 128) + " with " + replyKey.toBase64() + "/" + Base64.encode(replyIV));
|
||||
ctx.aes().encrypt(rv, 0, rv, 0, replyKey, replyIV, rv.length);
|
||||
if (log.shouldLog(Log.DEBUG))
|
||||
log.debug(responseMessageId + ": after encrypt: " + Base64.encode(rv, 0, 128));
|
||||
//if (log.shouldLog(Log.DEBUG))
|
||||
// log.debug(responseMessageId + ": after encrypt: " + Base64.encode(rv, 0, 128));
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
@ -113,10 +113,10 @@ class BuildHandler {
|
||||
if (toHandle > MAX_HANDLE_AT_ONCE)
|
||||
toHandle = MAX_HANDLE_AT_ONCE;
|
||||
handled = new ArrayList(toHandle);
|
||||
if (false) {
|
||||
for (int i = 0; i < toHandle; i++) // LIFO for lower response time (should we RED it for DoS?)
|
||||
handled.add(_inboundBuildMessages.remove(_inboundBuildMessages.size()-1));
|
||||
} else {
|
||||
//if (false) {
|
||||
// for (int i = 0; i < toHandle; i++) // LIFO for lower response time (should we RED it for DoS?)
|
||||
// handled.add(_inboundBuildMessages.remove(_inboundBuildMessages.size()-1));
|
||||
//} else {
|
||||
// drop any expired messages
|
||||
long dropBefore = System.currentTimeMillis() - (BuildRequestor.REQUEST_TIMEOUT/4);
|
||||
do {
|
||||
@ -140,7 +140,7 @@ class BuildHandler {
|
||||
// when adding)
|
||||
for (int i = 0; i < toHandle && _inboundBuildMessages.size() > 0; i++)
|
||||
handled.add(_inboundBuildMessages.remove(0));
|
||||
}
|
||||
//}
|
||||
}
|
||||
remaining = _inboundBuildMessages.size();
|
||||
}
|
||||
@ -482,6 +482,14 @@ class BuildHandler {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Actually process the request and send the reply.
|
||||
*
|
||||
* Todo: Replies are not subject to RED for bandwidth reasons,
|
||||
* and the bandwidth is not credited to any tunnel.
|
||||
* If we did credit the reply to the tunnel, it would
|
||||
* prevent the classification of the tunnel as 'inactive' on tunnels.jsp.
|
||||
*/
|
||||
@SuppressWarnings("static-access")
|
||||
private void handleReq(RouterInfo nextPeerInfo, BuildMessageState state, BuildRequestRecord req, Hash nextPeer) {
|
||||
long ourId = req.readReceiveTunnelId();
|
||||
@ -604,8 +612,7 @@ class BuildHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
BuildResponseRecord resp = new BuildResponseRecord();
|
||||
byte reply[] = resp.create(_context, response, req.readReplyKey(), req.readReplyIV(), state.msg.getUniqueId());
|
||||
byte reply[] = BuildResponseRecord.create(_context, response, req.readReplyKey(), req.readReplyIV(), state.msg.getUniqueId());
|
||||
for (int j = 0; j < TunnelBuildMessage.RECORD_COUNT; j++) {
|
||||
if (state.msg.getRecord(j) == null) {
|
||||
ourSlot = j;
|
||||
|
Reference in New Issue
Block a user