Search in sources :

Example 6 with SessionId

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

the class ClientMessageEventListener method handleDestroySession.

private void handleDestroySession(DestroySessionMessage message) {
    SessionId id = message.getSessionId();
    if (id != null) {
        _runner.removeSession(id);
    } else {
        if (_log.shouldLog(Log.WARN))
            _log.warn("destroy session with null ID");
    }
    int left = _runner.getSessionIds().size();
    if (left <= 0 || id == null) {
        _runner.stopRunning();
    } else {
        if (_log.shouldLog(Log.INFO))
            _log.info("Still " + left + " sessions left");
    }
}
Also used : SessionId(net.i2p.data.i2cp.SessionId)

Example 7 with SessionId

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

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

the class ClientMessageEventListener method handleHostLookup.

/**
 * override for testing
 * @since 0.9.11
 */
protected void handleHostLookup(HostLookupMessage message) {
    SessionId sid = message.getSessionId();
    Hash h;
    if (sid != null) {
        h = _runner.getDestHash(sid);
    } else {
        // fixup if necessary
        if (message.getReqID() >= 0)
            sid = new SessionId(65535);
        h = null;
    }
    if (h == null) {
        h = _runner.getDestHash();
    // h may still be null, an LS lookup for b32 will go out expl. tunnels
    }
    _context.jobQueue().addJob(new LookupDestJob(_context, _runner, message.getReqID(), message.getTimeout(), sid, message.getHash(), message.getHostname(), h));
}
Also used : Hash(net.i2p.data.Hash) SessionId(net.i2p.data.i2cp.SessionId)

Example 9 with SessionId

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

Example 10 with SessionId

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

the class ReportAbuseJob method runJob.

public void runJob() {
    if (_runner.isDead())
        return;
    AbuseReason res = new AbuseReason();
    res.setReason(_reason);
    AbuseSeverity sev = new AbuseSeverity();
    sev.setSeverity(_severity);
    ReportAbuseMessage msg = new ReportAbuseMessage();
    msg.setReason(res);
    SessionId id = _runner.getSessionId(_dest.calculateHash());
    if (id == null)
        return;
    msg.setSessionId(id);
    msg.setSeverity(sev);
    try {
        _runner.doSend(msg);
    } catch (I2CPMessageException ime) {
        _log.error("Error reporting abuse", ime);
    }
}
Also used : I2CPMessageException(net.i2p.data.i2cp.I2CPMessageException) AbuseSeverity(net.i2p.data.i2cp.AbuseSeverity) ReportAbuseMessage(net.i2p.data.i2cp.ReportAbuseMessage) AbuseReason(net.i2p.data.i2cp.AbuseReason) SessionId(net.i2p.data.i2cp.SessionId)

Aggregations

SessionId (net.i2p.data.i2cp.SessionId)24 I2PSessionException (net.i2p.client.I2PSessionException)7 Destination (net.i2p.data.Destination)7 DataFormatException (net.i2p.data.DataFormatException)5 SessionConfig (net.i2p.data.i2cp.SessionConfig)5 Hash (net.i2p.data.Hash)4 I2CPMessageException (net.i2p.data.i2cp.I2CPMessageException)4 Properties (java.util.Properties)3 Payload (net.i2p.data.Payload)2 HostLookupMessage (net.i2p.data.i2cp.HostLookupMessage)2 MessageStatusMessage (net.i2p.data.i2cp.MessageStatusMessage)2 SendMessageExpiresMessage (net.i2p.data.i2cp.SendMessageExpiresMessage)2 SendMessageMessage (net.i2p.data.i2cp.SendMessageMessage)2 ClientTunnelSettings (net.i2p.router.ClientTunnelSettings)2 Date (java.util.Date)1 SigType (net.i2p.crypto.SigType)1 Lease (net.i2p.data.Lease)1 LeaseSet (net.i2p.data.LeaseSet)1 PublicKey (net.i2p.data.PublicKey)1 AbuseReason (net.i2p.data.i2cp.AbuseReason)1