forked from I2P_Developers/i2p.i2p
Router: Replace GarlicConfig setters with constructor args
This commit is contained in:
@@ -27,11 +27,11 @@ import net.i2p.data.i2np.DeliveryInstructions;
|
||||
class GarlicConfig {
|
||||
private RouterInfo _recipient;
|
||||
private PublicKey _recipientPublicKey;
|
||||
private Certificate _cert;
|
||||
private long _id;
|
||||
private long _expiration;
|
||||
private final Certificate _cert;
|
||||
private final long _id;
|
||||
private final long _expiration;
|
||||
private final List<GarlicConfig> _cloveConfigs;
|
||||
private DeliveryInstructions _instructions;
|
||||
private final DeliveryInstructions _instructions;
|
||||
// unused
|
||||
//private boolean _requestAck;
|
||||
//private RouterInfo _replyThroughRouter; // router through which any replies will be sent before delivery to us
|
||||
@@ -41,14 +41,17 @@ class GarlicConfig {
|
||||
//private long _replyBlockMessageId;
|
||||
//private long _replyBlockExpiration;
|
||||
|
||||
public GarlicConfig() {
|
||||
this(new ArrayList<GarlicConfig>(4));
|
||||
public GarlicConfig(Certificate cert, long id, long expiration, DeliveryInstructions di) {
|
||||
this(new ArrayList<GarlicConfig>(4), cert, id, expiration, di);
|
||||
}
|
||||
|
||||
protected GarlicConfig(List<GarlicConfig> cloveConfigs) {
|
||||
_id = -1;
|
||||
_expiration = -1;
|
||||
protected GarlicConfig(List<GarlicConfig> cloveConfigs, Certificate cert, long id,
|
||||
long expiration, DeliveryInstructions di) {
|
||||
_cert = cert;
|
||||
_id = id;
|
||||
_expiration = expiration;
|
||||
_cloveConfigs = cloveConfigs;
|
||||
_instructions = di;
|
||||
//_replyBlockMessageId = -1;
|
||||
//_replyBlockExpiration = -1;
|
||||
}
|
||||
@@ -79,28 +82,24 @@ class GarlicConfig {
|
||||
* Certificate for the getRecipient() to pay for their processing
|
||||
*
|
||||
*/
|
||||
public void setCertificate(Certificate cert) { _cert = cert; }
|
||||
public Certificate getCertificate() { return _cert; }
|
||||
|
||||
/**
|
||||
* Unique ID of the clove
|
||||
*
|
||||
*/
|
||||
public void setId(long id) { _id = id; }
|
||||
public long getId() { return _id; }
|
||||
|
||||
/**
|
||||
* Expiration of the clove, after which it should be dropped
|
||||
*
|
||||
*/
|
||||
public void setExpiration(long expiration) { _expiration = expiration; }
|
||||
public long getExpiration() { return _expiration; }
|
||||
|
||||
/**
|
||||
* Specify how the I2NPMessage in the clove should be handled.
|
||||
*
|
||||
*/
|
||||
public void setDeliveryInstructions(DeliveryInstructions instructions) { _instructions = instructions; }
|
||||
public DeliveryInstructions getDeliveryInstructions() { return _instructions; }
|
||||
|
||||
/**
|
||||
|
||||
@@ -146,7 +146,9 @@ class OutboundClientMessageJobHelper {
|
||||
Log log = ctx.logManager().getLog(OutboundClientMessageJobHelper.class);
|
||||
if (replyToken >= 0 && log.shouldLog(Log.DEBUG))
|
||||
log.debug("Reply token: " + replyToken);
|
||||
GarlicConfig config = new GarlicConfig();
|
||||
GarlicConfig config = new GarlicConfig(Certificate.NULL_CERT,
|
||||
ctx.random().nextLong(I2NPMessage.MAX_ID_VALUE),
|
||||
expiration, DeliveryInstructions.LOCAL);
|
||||
|
||||
if (requireAck) {
|
||||
// extend the expiration of the return message
|
||||
@@ -167,10 +169,6 @@ class OutboundClientMessageJobHelper {
|
||||
// and get the leaseset stored before handling the data
|
||||
config.addClove(dataClove);
|
||||
|
||||
config.setCertificate(Certificate.NULL_CERT);
|
||||
config.setDeliveryInstructions(DeliveryInstructions.LOCAL);
|
||||
config.setId(ctx.random().nextLong(I2NPMessage.MAX_ID_VALUE));
|
||||
config.setExpiration(expiration); // +2*Router.CLOCK_FUDGE_FACTOR);
|
||||
config.setRecipientPublicKey(recipientPK);
|
||||
|
||||
if (log.shouldLog(Log.INFO))
|
||||
@@ -213,11 +211,6 @@ class OutboundClientMessageJobHelper {
|
||||
//ackInstructions.setDelaySeconds(0);
|
||||
//ackInstructions.setEncrypted(false);
|
||||
|
||||
PayloadGarlicConfig ackClove = new PayloadGarlicConfig();
|
||||
ackClove.setCertificate(Certificate.NULL_CERT);
|
||||
ackClove.setDeliveryInstructions(ackInstructions);
|
||||
ackClove.setExpiration(expiration);
|
||||
ackClove.setId(ctx.random().nextLong(I2NPMessage.MAX_ID_VALUE));
|
||||
DeliveryStatusMessage dsm = buildDSM(ctx, replyToken);
|
||||
GarlicMessage msg = wrapDSM(ctx, skm, dsm);
|
||||
if (msg == null) {
|
||||
@@ -225,7 +218,9 @@ class OutboundClientMessageJobHelper {
|
||||
log.warn("Failed to wrap ack clove");
|
||||
return null;
|
||||
}
|
||||
ackClove.setPayload(msg);
|
||||
PayloadGarlicConfig ackClove = new PayloadGarlicConfig(Certificate.NULL_CERT,
|
||||
ctx.random().nextLong(I2NPMessage.MAX_ID_VALUE),
|
||||
expiration, ackInstructions, msg);
|
||||
// this does nothing, the clove is not separately encrypted
|
||||
//ackClove.setRecipient(ctx.router().getRouterInfo());
|
||||
// defaults
|
||||
@@ -283,14 +278,11 @@ class OutboundClientMessageJobHelper {
|
||||
//instructions.setDelaySeconds(0);
|
||||
//instructions.setEncrypted(false);
|
||||
|
||||
PayloadGarlicConfig clove = new PayloadGarlicConfig();
|
||||
clove.setCertificate(Certificate.NULL_CERT);
|
||||
clove.setDeliveryInstructions(instructions);
|
||||
clove.setExpiration(expiration);
|
||||
clove.setId(ctx.random().nextLong(I2NPMessage.MAX_ID_VALUE));
|
||||
DataMessage msg = new DataMessage(ctx);
|
||||
msg.setData(data.getEncryptedData());
|
||||
clove.setPayload(msg);
|
||||
PayloadGarlicConfig clove = new PayloadGarlicConfig(Certificate.NULL_CERT,
|
||||
ctx.random().nextLong(I2NPMessage.MAX_ID_VALUE),
|
||||
expiration, instructions, msg);
|
||||
// defaults
|
||||
//clove.setRecipientPublicKey(null);
|
||||
//clove.setRequestAck(false);
|
||||
@@ -303,15 +295,12 @@ class OutboundClientMessageJobHelper {
|
||||
* Build a clove that stores the leaseSet locally
|
||||
*/
|
||||
private static PayloadGarlicConfig buildLeaseSetClove(RouterContext ctx, long expiration, LeaseSet replyLeaseSet) {
|
||||
PayloadGarlicConfig clove = new PayloadGarlicConfig();
|
||||
clove.setCertificate(Certificate.NULL_CERT);
|
||||
clove.setDeliveryInstructions(DeliveryInstructions.LOCAL);
|
||||
clove.setExpiration(expiration);
|
||||
clove.setId(ctx.random().nextLong(I2NPMessage.MAX_ID_VALUE));
|
||||
DatabaseStoreMessage msg = new DatabaseStoreMessage(ctx);
|
||||
msg.setEntry(replyLeaseSet);
|
||||
msg.setMessageExpiration(expiration);
|
||||
clove.setPayload(msg);
|
||||
PayloadGarlicConfig clove = new PayloadGarlicConfig(Certificate.NULL_CERT,
|
||||
ctx.random().nextLong(I2NPMessage.MAX_ID_VALUE),
|
||||
expiration, DeliveryInstructions.LOCAL, msg);
|
||||
// defaults
|
||||
//clove.setRecipientPublicKey(null);
|
||||
//clove.setRequestAck(false);
|
||||
|
||||
@@ -903,8 +903,6 @@ public class OutboundClientMessageOneShotJob extends JobImpl {
|
||||
* @return null on failure
|
||||
*/
|
||||
private PayloadGarlicConfig buildClove() {
|
||||
PayloadGarlicConfig clove = new PayloadGarlicConfig();
|
||||
|
||||
DeliveryInstructions instructions = new DeliveryInstructions();
|
||||
instructions.setDeliveryMode(DeliveryInstructions.DELIVERY_MODE_DESTINATION);
|
||||
instructions.setDestination(_to.calculateHash());
|
||||
@@ -914,11 +912,6 @@ public class OutboundClientMessageOneShotJob extends JobImpl {
|
||||
//instructions.setDelaySeconds(0);
|
||||
//instructions.setEncrypted(false);
|
||||
|
||||
clove.setCertificate(Certificate.NULL_CERT);
|
||||
clove.setDeliveryInstructions(instructions);
|
||||
clove.setExpiration(OVERALL_TIMEOUT_MS_DEFAULT+getContext().clock().now());
|
||||
clove.setId(getContext().random().nextLong(I2NPMessage.MAX_ID_VALUE));
|
||||
|
||||
DataMessage msg = new DataMessage(getContext());
|
||||
Payload p = _clientMessage.getPayload();
|
||||
if (p == null)
|
||||
@@ -927,9 +920,13 @@ public class OutboundClientMessageOneShotJob extends JobImpl {
|
||||
if (d == null)
|
||||
return null;
|
||||
msg.setData(d);
|
||||
msg.setMessageExpiration(clove.getExpiration());
|
||||
long expires = OVERALL_TIMEOUT_MS_DEFAULT + getContext().clock().now();
|
||||
msg.setMessageExpiration(expires);
|
||||
PayloadGarlicConfig clove = new PayloadGarlicConfig(Certificate.NULL_CERT,
|
||||
getContext().random().nextLong(I2NPMessage.MAX_ID_VALUE),
|
||||
expires,
|
||||
instructions, msg);
|
||||
|
||||
clove.setPayload(msg);
|
||||
// defaults
|
||||
//clove.setRecipientPublicKey(null);
|
||||
//clove.setRequestAck(false);
|
||||
|
||||
@@ -8,6 +8,8 @@ package net.i2p.router.message;
|
||||
*
|
||||
*/
|
||||
|
||||
import net.i2p.data.Certificate;
|
||||
import net.i2p.data.i2np.DeliveryInstructions;
|
||||
import net.i2p.data.i2np.I2NPMessage;
|
||||
|
||||
/**
|
||||
@@ -17,20 +19,18 @@ import net.i2p.data.i2np.I2NPMessage;
|
||||
* for a single garlic-wrapped message by netdb MessageWrapper and tunnel TestJob.
|
||||
*/
|
||||
public class PayloadGarlicConfig extends GarlicConfig {
|
||||
private I2NPMessage _payload;
|
||||
private final I2NPMessage _payload;
|
||||
|
||||
public PayloadGarlicConfig() {
|
||||
super(null);
|
||||
public PayloadGarlicConfig(Certificate cert, long id, long expiration,
|
||||
DeliveryInstructions di, I2NPMessage message) {
|
||||
super(null, cert, id, expiration, di);
|
||||
_payload = message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the I2NP message to be sent - if this is set, no other cloves can be included
|
||||
* in this block
|
||||
*/
|
||||
public void setPayload(I2NPMessage message) {
|
||||
_payload = message;
|
||||
}
|
||||
|
||||
public I2NPMessage getPayload() { return _payload; }
|
||||
|
||||
@Override
|
||||
|
||||
@@ -43,13 +43,11 @@ public class MessageWrapper {
|
||||
* @return null on encrypt failure
|
||||
*/
|
||||
static WrappedMessage wrap(RouterContext ctx, I2NPMessage m, Hash from, RouterInfo to) {
|
||||
PayloadGarlicConfig payload = new PayloadGarlicConfig();
|
||||
payload.setCertificate(Certificate.NULL_CERT);
|
||||
payload.setId(ctx.random().nextLong(I2NPMessage.MAX_ID_VALUE));
|
||||
payload.setPayload(m);
|
||||
PayloadGarlicConfig payload = new PayloadGarlicConfig(Certificate.NULL_CERT,
|
||||
ctx.random().nextLong(I2NPMessage.MAX_ID_VALUE),
|
||||
m.getMessageExpiration(),
|
||||
DeliveryInstructions.LOCAL, m);
|
||||
payload.setRecipient(to);
|
||||
payload.setDeliveryInstructions(DeliveryInstructions.LOCAL);
|
||||
payload.setExpiration(m.getMessageExpiration());
|
||||
|
||||
SessionKeyManager skm;
|
||||
if (from != null)
|
||||
@@ -124,13 +122,11 @@ public class MessageWrapper {
|
||||
* @since 0.9.5
|
||||
*/
|
||||
static GarlicMessage wrap(RouterContext ctx, I2NPMessage m, RouterInfo to) {
|
||||
PayloadGarlicConfig payload = new PayloadGarlicConfig();
|
||||
payload.setCertificate(Certificate.NULL_CERT);
|
||||
payload.setId(ctx.random().nextLong(I2NPMessage.MAX_ID_VALUE));
|
||||
payload.setPayload(m);
|
||||
PayloadGarlicConfig payload = new PayloadGarlicConfig(Certificate.NULL_CERT,
|
||||
ctx.random().nextLong(I2NPMessage.MAX_ID_VALUE),
|
||||
m.getMessageExpiration(),
|
||||
DeliveryInstructions.LOCAL, m);
|
||||
payload.setRecipient(to);
|
||||
payload.setDeliveryInstructions(DeliveryInstructions.LOCAL);
|
||||
payload.setExpiration(m.getMessageExpiration());
|
||||
|
||||
SessionKey sentKey = ctx.keyGenerator().generateSessionKey();
|
||||
PublicKey key = to.getIdentity().getPublicKey();
|
||||
@@ -224,12 +220,10 @@ public class MessageWrapper {
|
||||
* @since 0.9.7
|
||||
*/
|
||||
public static GarlicMessage wrap(RouterContext ctx, I2NPMessage m, SessionKey encryptKey, SessionTag encryptTag) {
|
||||
PayloadGarlicConfig payload = new PayloadGarlicConfig();
|
||||
payload.setCertificate(Certificate.NULL_CERT);
|
||||
payload.setId(ctx.random().nextLong(I2NPMessage.MAX_ID_VALUE));
|
||||
payload.setPayload(m);
|
||||
payload.setDeliveryInstructions(DeliveryInstructions.LOCAL);
|
||||
payload.setExpiration(m.getMessageExpiration());
|
||||
PayloadGarlicConfig payload = new PayloadGarlicConfig(Certificate.NULL_CERT,
|
||||
ctx.random().nextLong(I2NPMessage.MAX_ID_VALUE),
|
||||
m.getMessageExpiration(),
|
||||
DeliveryInstructions.LOCAL, m);
|
||||
|
||||
GarlicMessage msg = GarlicMessageBuilder.buildMessage(ctx, payload, null, null,
|
||||
null, encryptKey, encryptTag);
|
||||
|
||||
@@ -115,13 +115,11 @@ class TestJob extends JobImpl {
|
||||
// can't tell its a test. to simplify this, we encrypt it with a random key and tag,
|
||||
// remembering that key+tag so that we can decrypt it later. this means we can do the
|
||||
// garlic encryption without any ElGamal (yay)
|
||||
PayloadGarlicConfig payload = new PayloadGarlicConfig();
|
||||
payload.setCertificate(Certificate.NULL_CERT);
|
||||
payload.setId(getContext().random().nextLong(I2NPMessage.MAX_ID_VALUE));
|
||||
payload.setPayload(m);
|
||||
PayloadGarlicConfig payload = new PayloadGarlicConfig(Certificate.NULL_CERT,
|
||||
getContext().random().nextLong(I2NPMessage.MAX_ID_VALUE),
|
||||
m.getMessageExpiration(),
|
||||
DeliveryInstructions.LOCAL, m);
|
||||
payload.setRecipient(getContext().router().getRouterInfo());
|
||||
payload.setDeliveryInstructions(DeliveryInstructions.LOCAL);
|
||||
payload.setExpiration(m.getMessageExpiration());
|
||||
|
||||
SessionKey encryptKey = getContext().keyGenerator().generateSessionKey();
|
||||
SessionTag encryptTag = new SessionTag(true);
|
||||
|
||||
@@ -103,20 +103,20 @@ public class BuildTestMessageJob extends JobImpl {
|
||||
_testMessageKey = getContext().random().nextLong(I2NPMessage.MAX_ID_VALUE);
|
||||
if (_log.shouldLog(Log.INFO))
|
||||
_log.info("Test message key: " + _testMessageKey);
|
||||
GarlicConfig config = new GarlicConfig();
|
||||
|
||||
PayloadGarlicConfig ackClove = buildAckClove();
|
||||
config.addClove(ackClove);
|
||||
|
||||
|
||||
DeliveryInstructions instructions = new DeliveryInstructions();
|
||||
instructions.setDeliveryMode(DeliveryInstructions.DELIVERY_MODE_ROUTER);
|
||||
instructions.setRouter(_target.getIdentity().getHash());
|
||||
instructions.setTunnelId(null);
|
||||
|
||||
config.setCertificate(new Certificate(Certificate.CERTIFICATE_TYPE_NULL, null));
|
||||
config.setDeliveryInstructions(instructions);
|
||||
config.setId(getContext().random().nextLong(I2NPMessage.MAX_ID_VALUE));
|
||||
config.setExpiration(_timeoutMs+getContext().clock().now()+2*Router.CLOCK_FUDGE_FACTOR);
|
||||
GarlicConfig config = new GarlicConfig(new Certificate(Certificate.CERTIFICATE_TYPE_NULL, null),
|
||||
getContext().random().nextLong(I2NPMessage.MAX_ID_VALUE),
|
||||
_timeoutMs+getContext().clock().now()+2*Router.CLOCK_FUDGE_FACTOR,
|
||||
instructions);
|
||||
|
||||
PayloadGarlicConfig ackClove = buildAckClove();
|
||||
config.addClove(ackClove);
|
||||
|
||||
config.setRecipient(_target);
|
||||
|
||||
return config;
|
||||
@@ -126,7 +126,6 @@ public class BuildTestMessageJob extends JobImpl {
|
||||
* Build a clove that sends a DeliveryStatusMessage to us
|
||||
*/
|
||||
private PayloadGarlicConfig buildAckClove() {
|
||||
PayloadGarlicConfig ackClove = new PayloadGarlicConfig();
|
||||
|
||||
DeliveryInstructions ackInstructions = new DeliveryInstructions();
|
||||
ackInstructions.setDeliveryMode(DeliveryInstructions.DELIVERY_MODE_ROUTER);
|
||||
@@ -138,11 +137,11 @@ public class BuildTestMessageJob extends JobImpl {
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Delivery status message key: " + _testMessageKey + " arrival: " + msg.getArrival());
|
||||
|
||||
ackClove.setCertificate(new Certificate(Certificate.CERTIFICATE_TYPE_NULL, null));
|
||||
ackClove.setDeliveryInstructions(ackInstructions);
|
||||
ackClove.setExpiration(_timeoutMs+getContext().clock().now());
|
||||
ackClove.setId(getContext().random().nextLong(I2NPMessage.MAX_ID_VALUE));
|
||||
ackClove.setPayload(msg);
|
||||
PayloadGarlicConfig ackClove = new PayloadGarlicConfig(new Certificate(Certificate.CERTIFICATE_TYPE_NULL, null),
|
||||
getContext().random().nextLong(I2NPMessage.MAX_ID_VALUE),
|
||||
_timeoutMs+getContext().clock().now(),
|
||||
ackInstructions,
|
||||
msg);
|
||||
ackClove.setRecipient(_target);
|
||||
|
||||
return ackClove;
|
||||
|
||||
Reference in New Issue
Block a user