use of net.i2p.data.i2np.DeliveryInstructions in project i2p.i2p by i2p.
the class OutboundClientMessageJobHelper method buildAckClove.
/**
* Build a clove that sends a DeliveryStatusMessage to us.
* As of 0.9.12, the DSM is wrapped in a GarlicMessage.
* @param skm encrypt dsm with this skm non-null
* @return null on error
*/
private static PayloadGarlicConfig buildAckClove(RouterContext ctx, Hash from, TunnelInfo replyToTunnel, long replyToken, long expiration, SessionKeyManager skm) {
Log log = ctx.logManager().getLog(OutboundClientMessageJobHelper.class);
if (replyToTunnel == null) {
if (log.shouldLog(Log.WARN))
log.warn("Unable to send client message from " + from.toBase64() + ", as there are no inbound tunnels available");
return null;
}
// tunnel id on that gateway
TunnelId replyToTunnelId = replyToTunnel.getReceiveTunnelId(0);
// inbound tunnel gateway
Hash replyToTunnelRouter = replyToTunnel.getPeer(0);
if (log.shouldLog(Log.DEBUG))
log.debug("Ack for the data message will come back along tunnel " + replyToTunnelId + ": " + replyToTunnel);
DeliveryInstructions ackInstructions = new DeliveryInstructions();
ackInstructions.setDeliveryMode(DeliveryInstructions.DELIVERY_MODE_TUNNEL);
ackInstructions.setRouter(replyToTunnelRouter);
ackInstructions.setTunnelId(replyToTunnelId);
// defaults
// ackInstructions.setDelayRequested(false);
// 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) {
if (log.shouldLog(Log.WARN))
log.warn("Failed to wrap ack clove");
return null;
}
ackClove.setPayload(msg);
return ackClove;
}
use of net.i2p.data.i2np.DeliveryInstructions in project i2p.i2p by i2p.
the class OutboundClientMessageJobHelper method buildDataClove.
/**
* Build a clove that sends the payload to the destination
*/
private static PayloadGarlicConfig buildDataClove(RouterContext ctx, Payload data, Destination dest, long expiration) {
DeliveryInstructions instructions = new DeliveryInstructions();
instructions.setDeliveryMode(DeliveryInstructions.DELIVERY_MODE_DESTINATION);
instructions.setDestination(dest.calculateHash());
// defaults
// instructions.setDelayRequested(false);
// 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);
return clove;
}
use of net.i2p.data.i2np.DeliveryInstructions in project i2p.i2p by i2p.
the class BuildTestMessageJob method buildAckClove.
/**
* 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);
// yikes!
ackInstructions.setRouter(_replyTo);
DeliveryStatusMessage msg = new DeliveryStatusMessage(getContext());
msg.setArrival(getContext().clock().now());
msg.setMessageId(_testMessageKey);
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);
ackClove.setRecipient(_target);
return ackClove;
}
use of net.i2p.data.i2np.DeliveryInstructions in project i2p.i2p by i2p.
the class BuildTestMessageJob method buildGarlicCloveConfig.
private GarlicConfig buildGarlicCloveConfig() {
_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);
config.setRecipient(_target);
return config;
}
use of net.i2p.data.i2np.DeliveryInstructions in project i2p.i2p by i2p.
the class OutboundClientMessageOneShotJob method buildClove.
/**
* Build the payload clove that will be used for all of the messages,
* placing the clove in the status structure.
*
* @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());
// defaults
// instructions.setDelayRequested(false);
// 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)
return null;
byte[] d = p.getEncryptedData();
if (d == null)
return null;
msg.setData(d);
msg.setMessageExpiration(clove.getExpiration());
clove.setPayload(msg);
// _log.debug(getJobId() + ": Built payload clove with id " + clove.getId());
return clove;
}
Aggregations