Search in sources :

Example 1 with MessageId

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

the class I2CPMessageProducer method reportAbuse.

/**
 * Send an abuse message to the router
 */
public void reportAbuse(I2PSessionImpl session, int msgId, int severity) throws I2PSessionException {
    ReportAbuseMessage msg = new ReportAbuseMessage();
    MessageId id = new MessageId();
    id.setMessageId(msgId);
    msg.setMessageId(id);
    AbuseReason reason = new AbuseReason();
    reason.setReason("Not specified");
    msg.setReason(reason);
    AbuseSeverity sv = new AbuseSeverity();
    sv.setSeverity(severity);
    msg.setSeverity(sv);
    session.sendMessage(msg);
}
Also used : ReportAbuseMessage(net.i2p.data.i2cp.ReportAbuseMessage) AbuseSeverity(net.i2p.data.i2cp.AbuseSeverity) AbuseReason(net.i2p.data.i2cp.AbuseReason) MessageId(net.i2p.data.i2cp.MessageId)

Example 2 with MessageId

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

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

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

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

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