use of net.i2p.data.Payload in project i2p.i2p by i2p.
the class I2CPMessageProducer method createPayload.
/**
* Create a new signed payload and send it off to the destination
*
* @param tag unused - no end-to-end crypto
* @param tags unused - no end-to-end crypto
* @param key unused - no end-to-end crypto
* @param newKey unused - no end-to-end crypto
*/
private Payload createPayload(Destination dest, byte[] payload, SessionTag tag, SessionKey key, Set<SessionTag> tags, SessionKey newKey) throws I2PSessionException {
if (dest == null)
throw new I2PSessionException("No destination specified");
if (payload == null)
throw new I2PSessionException("No payload specified");
Payload data = new Payload();
if (!END_TO_END_CRYPTO) {
data.setEncryptedData(payload);
return data;
}
// no padding at this level
// the garlic may pad, and the tunnels may pad, and the transports may pad
int size = payload.length;
byte[] encr = _context.elGamalAESEngine().encrypt(payload, dest.getPublicKey(), key, tags, tag, newKey, size);
// yes, in an intelligent component, newTags would be queued for confirmation along with key, and
// generateNewTags would only generate tags if necessary
data.setEncryptedData(encr);
// + data.calculateHash());
return data;
}
use of net.i2p.data.Payload in project i2p.i2p by i2p.
the class I2CPMessageProducer method sendMessage.
/**
* Package up and send the payload to the router for delivery
*
* @param nonce 0 to 0xffffffff; if 0, the router will not reply with a MessageStatusMessage
* @since 0.9.2
*/
public void sendMessage(I2PSessionImpl session, Destination dest, long nonce, byte[] payload, SendMessageOptions options) throws I2PSessionException {
long expires = options.getTime();
if (!updateBps(payload.length, expires))
// drop the message... send fail notification?
return;
SendMessageMessage msg = new SendMessageExpiresMessage(options);
msg.setDestination(dest);
SessionId sid = session.getSessionId();
if (sid == null) {
_log.error(session.toString() + " send message w/o session", new Exception());
return;
}
msg.setSessionId(sid);
msg.setNonce(nonce);
Payload data = createPayload(dest, payload, null, null, null, null);
msg.setPayload(data);
session.sendMessage(msg);
}
use of net.i2p.data.Payload in project i2p.i2p by i2p.
the class MessagePayloadMessage method doReadMessage.
@Override
protected void doReadMessage(InputStream in, int size) throws I2CPMessageException, IOException {
try {
_sessionId = (int) DataHelper.readLong(in, 2);
_messageId = DataHelper.readLong(in, 4);
_payload = new Payload();
_payload.readBytes(in);
} catch (DataFormatException dfe) {
throw new I2CPMessageException("Unable to load the message data", dfe);
}
}
use of net.i2p.data.Payload in project i2p.i2p by i2p.
the class ClientConnectionRunner method distributeMessage.
/**
* Distribute the message. If the dest is local, it blocks until its passed
* to the target ClientConnectionRunner (which then fires it into a MessageReceivedJob).
* If the dest is remote, it blocks until it is added into the ClientMessagePool
*/
MessageId distributeMessage(SendMessageMessage message) {
Payload payload = message.getPayload();
Destination dest = message.getDestination();
MessageId id = new MessageId();
id.setMessageId(getNextMessageId());
long expiration = 0;
int flags = 0;
if (message.getType() == SendMessageExpiresMessage.MESSAGE_TYPE) {
SendMessageExpiresMessage msg = (SendMessageExpiresMessage) message;
expiration = msg.getExpirationTime();
flags = msg.getFlags();
}
if ((!_dontSendMSM) && message.getNonce() != 0)
_acceptedPending.add(id);
if (_log.shouldLog(Log.DEBUG))
_log.debug("** Receiving message " + id.getMessageId() + " with payload of size " + payload.getSize() + " for session " + message.getSessionId());
// long beforeDistribute = _context.clock().now();
// the following blocks as described above
Destination fromDest = getDestination(message.getSessionId());
if (fromDest != null)
_manager.distributeMessage(fromDest, dest, payload, id, message.getNonce(), expiration, flags);
// + timeToDistribute);
return id;
}
use of net.i2p.data.Payload in project i2p.i2p by i2p.
the class ClientMessageEventListener method handleReceiveBegin.
/**
* The client asked for a message, so we send it to them.
*
* This is only when not in fast receive mode.
* In the default fast receive mode, data is sent in MessageReceivedJob.
*/
private void handleReceiveBegin(ReceiveMessageBeginMessage message) {
if (_runner.isDead())
return;
if (_log.shouldLog(Log.DEBUG))
_log.debug("Handling receive begin: id = " + message.getMessageId());
MessagePayloadMessage msg = new MessagePayloadMessage();
msg.setMessageId(message.getMessageId());
// TODO validate session id
msg.setSessionId(message.getSessionId());
Payload payload = _runner.getPayload(new MessageId(message.getMessageId()));
if (payload == null) {
if (_log.shouldLog(Log.WARN))
_log.warn("Payload for message id [" + message.getMessageId() + "] is null! Dropped or Unknown message id");
return;
}
msg.setPayload(payload);
try {
_runner.doSend(msg);
} catch (I2CPMessageException ime) {
String emsg = "Error sending data to client " + _runner.getDestHash();
if (_log.shouldWarn())
_log.warn(emsg, ime);
else
_log.logAlways(Log.WARN, emsg);
_runner.removePayload(new MessageId(message.getMessageId()));
}
}
Aggregations