Search in sources :

Example 1 with MessagePayloadMessage

use of net.i2p.data.i2cp.MessagePayloadMessage in project i2p.i2p by i2p.

the class I2PSessionImpl method receiveMessage.

/**
 * Pull the unencrypted data from the message that we've already prefetched and
 * notified the user that its available.
 */
public byte[] receiveMessage(int msgId) throws I2PSessionException {
    MessagePayloadMessage msg = _availableMessages.remove(Long.valueOf(msgId));
    if (msg == null) {
        _log.error("Receive message " + msgId + " had no matches");
        return null;
    }
    updateActivity();
    return msg.getPayload().getUnencryptedData();
}
Also used : MessagePayloadMessage(net.i2p.data.i2cp.MessagePayloadMessage)

Example 2 with MessagePayloadMessage

use of net.i2p.data.i2cp.MessagePayloadMessage in project i2p.i2p by i2p.

the class MessagePayloadMessageHandler method handleMessage.

public void handleMessage(I2CPMessage message, I2PSessionImpl session) {
    if (_log.shouldLog(Log.DEBUG))
        _log.debug("Handle message " + message + " for session " + session);
    try {
        MessagePayloadMessage msg = (MessagePayloadMessage) message;
        long id = msg.getMessageId();
        decryptPayload(msg, session);
        session.addNewMessage(msg);
        // (needs router version saving support in SetDateMessageHandler)
        if (!session.getFastReceive()) {
            ReceiveMessageEndMessage m = new ReceiveMessageEndMessage();
            m.setMessageId(id);
            m.setSessionId(msg.getSessionId());
            session.sendMessage(m);
        }
    } catch (DataFormatException dfe) {
        session.propogateError("Error handling a new payload message", dfe);
    } catch (I2PSessionException ise) {
        session.propogateError("Error handling a new payload message", ise);
    }
}
Also used : MessagePayloadMessage(net.i2p.data.i2cp.MessagePayloadMessage) DataFormatException(net.i2p.data.DataFormatException) ReceiveMessageEndMessage(net.i2p.data.i2cp.ReceiveMessageEndMessage) I2PSessionException(net.i2p.client.I2PSessionException)

Example 3 with MessagePayloadMessage

use of net.i2p.data.i2cp.MessagePayloadMessage 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)

Example 4 with MessagePayloadMessage

use of net.i2p.data.i2cp.MessagePayloadMessage in project i2p.i2p by i2p.

the class MessageReceivedJob method sendMessage.

/**
 *  Deliver the message directly, skip notification
 *  @since 0.9.4
 */
private void sendMessage(long id) throws I2CPMessageException {
    MessagePayloadMessage msg = new MessagePayloadMessage();
    msg.setMessageId(id);
    SessionId sid = _runner.getSessionId(_toDest.calculateHash());
    if (sid == null) {
        if (_log.shouldLog(Log.WARN))
            _log.warn("No session for " + _toDest.calculateHash());
        return;
    }
    msg.setSessionId(sid.getSessionId());
    msg.setPayload(_payload);
    _runner.doSend(msg);
}
Also used : MessagePayloadMessage(net.i2p.data.i2cp.MessagePayloadMessage) SessionId(net.i2p.data.i2cp.SessionId)

Aggregations

MessagePayloadMessage (net.i2p.data.i2cp.MessagePayloadMessage)4 I2PSessionException (net.i2p.client.I2PSessionException)1 DataFormatException (net.i2p.data.DataFormatException)1 Payload (net.i2p.data.Payload)1 I2CPMessageException (net.i2p.data.i2cp.I2CPMessageException)1 MessageId (net.i2p.data.i2cp.MessageId)1 ReceiveMessageEndMessage (net.i2p.data.i2cp.ReceiveMessageEndMessage)1 SessionId (net.i2p.data.i2cp.SessionId)1