Search in sources :

Example 6 with MessageId

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

the class I2PSessionImpl2 method receiveStatus.

/**
 *  Only call this with nonzero status, i.e. for outbound messages
 *  whose MessageState may be queued on _sendingStates.
 *
 *  Even when using sendBestEffort(), this is a waste, because the
 *  MessageState is removed from _sendingStates immediately and
 *  so the lookup here fails.
 *
 *  This is now pretty much avoided since streaming now sets
 *  i2cp.messageReliability = none, which forces sendNoEffort() instead of sendBestEffort(),
 *  so the router won't send us any MSM's for outbound traffic.
 *
 *  @param status != 0
 */
@Override
public void receiveStatus(int msgId, long nonce, int status) {
    if (_log.shouldLog(Log.DEBUG))
        _log.debug(getPrefix() + "Received status " + status + " for msgId " + msgId + " / " + nonce);
    MessageState state = null;
    if ((state = _sendingStates.get(Long.valueOf(nonce))) != null) {
        if (_log.shouldLog(Log.DEBUG))
            _log.debug(getPrefix() + "Found a matching state");
    } else if (!_sendingStates.isEmpty()) {
        // shouldn't happen, router sends good nonce for all statuses as of 0.9.14
        for (MessageState s : _sendingStates.values()) {
            if (s.getMessageId() != null && s.getMessageId().getMessageId() == msgId) {
                if (_log.shouldLog(Log.DEBUG))
                    _log.debug(getPrefix() + "Found a matching state by msgId");
                state = s;
                break;
            }
        }
    }
    if (state != null) {
        if (state.getMessageId() == null) {
            MessageId id = new MessageId();
            id.setMessageId(msgId);
            state.setMessageId(id);
        }
        state.receive(status);
        if (state.wasSuccessful())
            _sendingStates.remove(Long.valueOf(nonce));
        long lifetime = state.getElapsed();
        switch(status) {
            case 1:
                _context.statManager().addRateData("i2cp.receiveStatusTime.1", lifetime);
                break;
            // break;
            case 4:
                _context.statManager().addRateData("i2cp.receiveStatusTime.4", lifetime);
                break;
            case 5:
                _context.statManager().addRateData("i2cp.receiveStatusTime.5", lifetime);
                break;
        }
    } else {
        if (_log.shouldLog(Log.INFO))
            _log.info(getPrefix() + "No matching state for messageId " + msgId + " / " + nonce + " w/ status = " + status);
    }
}
Also used : MessageId(net.i2p.data.i2cp.MessageId)

Aggregations

MessageId (net.i2p.data.i2cp.MessageId)6 I2CPMessageException (net.i2p.data.i2cp.I2CPMessageException)3 Payload (net.i2p.data.Payload)2 Destination (net.i2p.data.Destination)1 AbuseReason (net.i2p.data.i2cp.AbuseReason)1 AbuseSeverity (net.i2p.data.i2cp.AbuseSeverity)1 MessagePayloadMessage (net.i2p.data.i2cp.MessagePayloadMessage)1 MessageStatusMessage (net.i2p.data.i2cp.MessageStatusMessage)1 ReportAbuseMessage (net.i2p.data.i2cp.ReportAbuseMessage)1 SendMessageExpiresMessage (net.i2p.data.i2cp.SendMessageExpiresMessage)1 SessionConfig (net.i2p.data.i2cp.SessionConfig)1 SessionId (net.i2p.data.i2cp.SessionId)1