Search in sources :

Example 1 with Payload

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;
}
Also used : I2PSessionException(net.i2p.client.I2PSessionException) Payload(net.i2p.data.Payload)

Example 2 with Payload

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);
}
Also used : SendMessageMessage(net.i2p.data.i2cp.SendMessageMessage) SendMessageExpiresMessage(net.i2p.data.i2cp.SendMessageExpiresMessage) Payload(net.i2p.data.Payload) SessionId(net.i2p.data.i2cp.SessionId) DataFormatException(net.i2p.data.DataFormatException) I2PSessionException(net.i2p.client.I2PSessionException)

Example 3 with Payload

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);
    }
}
Also used : DataFormatException(net.i2p.data.DataFormatException) Payload(net.i2p.data.Payload)

Example 4 with Payload

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;
}
Also used : Destination(net.i2p.data.Destination) SendMessageExpiresMessage(net.i2p.data.i2cp.SendMessageExpiresMessage) Payload(net.i2p.data.Payload) MessageId(net.i2p.data.i2cp.MessageId)

Example 5 with Payload

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()));
    }
}
Also used : I2CPMessageException(net.i2p.data.i2cp.I2CPMessageException) MessagePayloadMessage(net.i2p.data.i2cp.MessagePayloadMessage) Payload(net.i2p.data.Payload) MessageId(net.i2p.data.i2cp.MessageId)

Aggregations

Payload (net.i2p.data.Payload)10 DataFormatException (net.i2p.data.DataFormatException)4 I2PSessionException (net.i2p.client.I2PSessionException)3 SendMessageExpiresMessage (net.i2p.data.i2cp.SendMessageExpiresMessage)3 MessageId (net.i2p.data.i2cp.MessageId)2 SendMessageMessage (net.i2p.data.i2cp.SendMessageMessage)2 SessionId (net.i2p.data.i2cp.SessionId)2 DataMessage (net.i2p.data.i2np.DataMessage)2 IOException (java.io.IOException)1 Destination (net.i2p.data.Destination)1 Hash (net.i2p.data.Hash)1 I2CPMessageException (net.i2p.data.i2cp.I2CPMessageException)1 MessagePayloadMessage (net.i2p.data.i2cp.MessagePayloadMessage)1 DatabaseSearchReplyMessage (net.i2p.data.i2np.DatabaseSearchReplyMessage)1 DatabaseStoreMessage (net.i2p.data.i2np.DatabaseStoreMessage)1 DeliveryInstructions (net.i2p.data.i2np.DeliveryInstructions)1 ClientMessage (net.i2p.router.ClientMessage)1 TunnelPoolSettings (net.i2p.router.TunnelPoolSettings)1