Search in sources :

Example 1 with I2CPMessageException

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

the class ClientWriterRunner method run.

public void run() {
    I2CPMessage msg;
    while (!_session.isClosed()) {
        try {
            msg = _messagesToWrite.take();
        } catch (InterruptedException ie) {
            continue;
        }
        if (msg.getType() == PoisonI2CPMessage.MESSAGE_TYPE)
            break;
        // only thread, we don't need synchronized
        try {
            msg.writeMessage(_out);
            if (_messagesToWrite.isEmpty())
                _out.flush();
        } catch (I2CPMessageException ime) {
            _session.propogateError("Error writing out the message", ime);
            _session.disconnect();
            break;
        } catch (IOException ioe) {
            _session.propogateError("Error writing out the message", ioe);
            _session.disconnect();
            break;
        }
    }
    _messagesToWrite.clear();
}
Also used : I2CPMessageException(net.i2p.data.i2cp.I2CPMessageException) PoisonI2CPMessage(net.i2p.internal.PoisonI2CPMessage) I2CPMessage(net.i2p.data.i2cp.I2CPMessage) IOException(java.io.IOException)

Example 2 with I2CPMessageException

use of net.i2p.data.i2cp.I2CPMessageException 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 3 with I2CPMessageException

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

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

the class ClientMessageEventListener method handleGetDate.

/**
 *  Defaults in GetDateMessage options are NOT honored.
 *  Defaults are not serialized out-of-JVM, and the router does not recognize defaults in-JVM.
 *  Client side must promote defaults to the primary map.
 */
private void handleGetDate(GetDateMessage message) {
    // sent by clients >= 0.8.7
    String clientVersion = message.getVersion();
    if (clientVersion != null)
        _runner.setClientVersion(clientVersion);
    Properties props = message.getOptions();
    if (!checkAuth(props))
        return;
    try {
        // only send version if the client can handle it (0.8.7 or greater)
        _runner.doSend(new SetDateMessage(clientVersion != null ? CoreVersion.VERSION : null));
    } catch (I2CPMessageException ime) {
        if (_log.shouldLog(Log.ERROR))
            _log.error("Error writing out the setDate message", ime);
    }
}
Also used : I2CPMessageException(net.i2p.data.i2cp.I2CPMessageException) Properties(java.util.Properties) SetDateMessage(net.i2p.data.i2cp.SetDateMessage)

Example 5 with I2CPMessageException

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

the class MessageReceivedJob method receiveMessage.

/**
 *  Same as runJob() but with a return value
 *  @return success
 *  @since 0.9.29
 */
public boolean receiveMessage() {
    if (_runner.isDead())
        return false;
    MessageId id = null;
    try {
        long nextID = _runner.getNextMessageId();
        if (_sendDirect) {
            sendMessage(nextID);
        } else {
            id = new MessageId(nextID);
            _runner.setPayload(id, _payload);
            messageAvailable(id, _payload.getSize());
        }
        return true;
    } catch (I2CPMessageException ime) {
        String msg = "Error sending data to client " + _runner.getDestHash();
        if (_log.shouldWarn())
            _log.warn(msg, ime);
        else
            _log.logAlways(Log.WARN, msg);
        if (id != null && !_sendDirect)
            _runner.removePayload(id);
        return false;
    }
}
Also used : I2CPMessageException(net.i2p.data.i2cp.I2CPMessageException) MessageId(net.i2p.data.i2cp.MessageId)

Aggregations

I2CPMessageException (net.i2p.data.i2cp.I2CPMessageException)16 SessionId (net.i2p.data.i2cp.SessionId)4 MessageId (net.i2p.data.i2cp.MessageId)3 MessageStatusMessage (net.i2p.data.i2cp.MessageStatusMessage)3 Destination (net.i2p.data.Destination)2 Hash (net.i2p.data.Hash)2 Lease (net.i2p.data.Lease)2 BandwidthLimitsMessage (net.i2p.data.i2cp.BandwidthLimitsMessage)2 GetBandwidthLimitsMessage (net.i2p.data.i2cp.GetBandwidthLimitsMessage)2 I2CPMessage (net.i2p.data.i2cp.I2CPMessage)2 RequestVariableLeaseSetMessage (net.i2p.data.i2cp.RequestVariableLeaseSetMessage)2 IOException (java.io.IOException)1 Date (java.util.Date)1 Properties (java.util.Properties)1 LeaseSet (net.i2p.data.LeaseSet)1 Payload (net.i2p.data.Payload)1 AbuseReason (net.i2p.data.i2cp.AbuseReason)1 AbuseSeverity (net.i2p.data.i2cp.AbuseSeverity)1 DestReplyMessage (net.i2p.data.i2cp.DestReplyMessage)1 DisconnectMessage (net.i2p.data.i2cp.DisconnectMessage)1