Search in sources :

Example 1 with MessageStatusMessage

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

the class ClientMessageEventListener method handleSendMessage.

/**
 * Handle a SendMessageMessage: give it a message Id, have the ClientManager distribute
 * it, and send the client an ACCEPTED message
 */
private void handleSendMessage(SendMessageMessage message) {
    SessionId sid = message.getSessionId();
    SessionConfig cfg = _runner.getConfig(sid);
    if (cfg == null) {
        List<SessionId> current = _runner.getSessionIds();
        String msg = "SendMessage invalid session: " + sid + " current: " + current;
        if (_log.shouldLog(Log.ERROR))
            _log.error(msg);
        // do this instead:
        if (sid != null && message.getNonce() > 0) {
            MessageStatusMessage status = new MessageStatusMessage();
            status.setMessageId(_runner.getNextMessageId());
            status.setSessionId(sid.getSessionId());
            status.setSize(0);
            status.setNonce(message.getNonce());
            status.setStatus(MessageStatusMessage.STATUS_SEND_FAILURE_BAD_SESSION);
            try {
                _runner.doSend(status);
            } catch (I2CPMessageException ime) {
                if (_log.shouldLog(Log.WARN))
                    _log.warn("Error writing out the message status message", ime);
            }
        }
        return;
    }
    if (_log.shouldLog(Log.DEBUG))
        _log.debug("handleSendMessage called");
    long beforeDistribute = _context.clock().now();
    MessageId id = _runner.distributeMessage(message);
    long timeToDistribute = _context.clock().now() - beforeDistribute;
    // TODO validate session id
    _runner.ackSendMessage(sid, id, message.getNonce());
    _context.statManager().addRateData("client.distributeTime", timeToDistribute);
    if ((timeToDistribute > 50) && (_log.shouldLog(Log.DEBUG)))
        _log.debug("Took too long to distribute the message (which holds up the ack): " + timeToDistribute);
}
Also used : I2CPMessageException(net.i2p.data.i2cp.I2CPMessageException) SessionConfig(net.i2p.data.i2cp.SessionConfig) MessageStatusMessage(net.i2p.data.i2cp.MessageStatusMessage) SessionId(net.i2p.data.i2cp.SessionId) MessageId(net.i2p.data.i2cp.MessageId)

Example 2 with MessageStatusMessage

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

the class LocalClientConnectionRunner method updateMessageDeliveryStatus.

/**
 *  No job queue, so super NPEs
 */
@Override
void updateMessageDeliveryStatus(Destination dest, MessageId id, long messageNonce, int status) {
    if (messageNonce <= 0)
        return;
    MessageStatusMessage msg = new MessageStatusMessage();
    msg.setMessageId(id.getMessageId());
    msg.setSessionId(getSessionId(dest.calculateHash()).getSessionId());
    // has to be >= 0, it is initialized to -1
    msg.setNonce(messageNonce);
    msg.setSize(0);
    msg.setStatus(status);
    try {
        doSend(msg);
    } catch (I2CPMessageException ime) {
        _log.warn("Error updating the status for " + id, ime);
    }
}
Also used : I2CPMessageException(net.i2p.data.i2cp.I2CPMessageException) MessageStatusMessage(net.i2p.data.i2cp.MessageStatusMessage)

Example 3 with MessageStatusMessage

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

the class MessageStatusMessageHandler method handleMessage.

public void handleMessage(I2CPMessage message, I2PSessionImpl session) {
    if (_log.shouldLog(Log.DEBUG))
        _log.debug("Handle message " + message);
    MessageStatusMessage msg = (MessageStatusMessage) message;
    int status = msg.getStatus();
    long id = msg.getMessageId();
    switch(status) {
        case MessageStatusMessage.STATUS_AVAILABLE:
            ReceiveMessageBeginMessage m = new ReceiveMessageBeginMessage();
            m.setMessageId(id);
            m.setSessionId(msg.getSessionId());
            try {
                session.sendMessage(m);
            } catch (I2PSessionException ise) {
                _log.error("Error asking for the message", ise);
            }
            return;
        case MessageStatusMessage.STATUS_SEND_ACCEPTED:
            session.receiveStatus((int) id, msg.getNonce(), status);
            // noop
            return;
        default:
            if (msg.isSuccessful()) {
                if (_log.shouldLog(Log.DEBUG))
                    _log.debug("Message delivery succeeded for message " + id);
            } else {
                if (_log.shouldLog(Log.INFO))
                    _log.info("Message delivery FAILED (" + status + ") for message " + id);
            }
            // if (!skipStatus)
            session.receiveStatus((int) id, msg.getNonce(), status);
            return;
    }
}
Also used : I2PSessionException(net.i2p.client.I2PSessionException) MessageStatusMessage(net.i2p.data.i2cp.MessageStatusMessage) ReceiveMessageBeginMessage(net.i2p.data.i2cp.ReceiveMessageBeginMessage)

Example 4 with MessageStatusMessage

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

the class ClientConnectionRunner method ackSendMessage.

/**
 * Send a notification to the client that their message (id specified) was accepted
 * for delivery (but not necessarily delivered)
 * Doesn't do anything if i2cp.messageReliability = "none"
 * or if the nonce is 0.
 *
 * @param id OUR id for the message
 * @param nonce HIS id for the message
 */
void ackSendMessage(SessionId sid, MessageId id, long nonce) {
    if (_dontSendMSM || nonce == 0)
        return;
    if (_log.shouldLog(Log.DEBUG))
        _log.debug("Acking message send [accepted]" + id + " / " + nonce + " for sessionId " + sid);
    MessageStatusMessage status = new MessageStatusMessage();
    status.setMessageId(id.getMessageId());
    status.setSessionId(sid.getSessionId());
    status.setSize(0L);
    status.setNonce(nonce);
    status.setStatus(MessageStatusMessage.STATUS_SEND_ACCEPTED);
    try {
        doSend(status);
        _acceptedPending.remove(id);
    } catch (I2CPMessageException ime) {
        if (_log.shouldLog(Log.WARN))
            _log.warn("Error writing out the message status message", ime);
    }
}
Also used : I2CPMessageException(net.i2p.data.i2cp.I2CPMessageException) MessageStatusMessage(net.i2p.data.i2cp.MessageStatusMessage)

Example 5 with MessageStatusMessage

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

the class MessageReceivedJob method messageAvailable.

/**
 * Deliver notification to the client that the given message is available.
 */
private void messageAvailable(MessageId id, long size) throws I2CPMessageException {
    // if (_log.shouldLog(Log.DEBUG))
    // _log.debug("Sending message available: " + id + " to sessionId " + _runner.getSessionId()
    // + " (with nonce=1)", new Exception("available"));
    MessageStatusMessage msg = new MessageStatusMessage();
    msg.setMessageId(id.getMessageId());
    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.setSize(size);
    // has to be >= 0, it is initialized to -1
    msg.setNonce(1);
    msg.setStatus(MessageStatusMessage.STATUS_AVAILABLE);
    _runner.doSend(msg);
}
Also used : MessageStatusMessage(net.i2p.data.i2cp.MessageStatusMessage) SessionId(net.i2p.data.i2cp.SessionId)

Aggregations

MessageStatusMessage (net.i2p.data.i2cp.MessageStatusMessage)5 I2CPMessageException (net.i2p.data.i2cp.I2CPMessageException)3 SessionId (net.i2p.data.i2cp.SessionId)2 I2PSessionException (net.i2p.client.I2PSessionException)1 MessageId (net.i2p.data.i2cp.MessageId)1 ReceiveMessageBeginMessage (net.i2p.data.i2cp.ReceiveMessageBeginMessage)1 SessionConfig (net.i2p.data.i2cp.SessionConfig)1