Search in sources :

Example 1 with DisconnectMessage

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

the class DisconnectMessageHandler method handleMessage.

public void handleMessage(I2CPMessage message, I2PSessionImpl session) {
    if (_log.shouldLog(Log.DEBUG))
        _log.debug("Handle message " + message);
    String reason = ((DisconnectMessage) message).getReason();
    session.propogateError(reason, new I2PSessionException("Disconnect Message received: " + reason));
    session.destroySession(false);
    if (reason.contains("restart")) {
        Thread t = new I2PAppThread(new Reconnector(session), "Reconnect " + session, true);
        t.start();
    }
}
Also used : DisconnectMessage(net.i2p.data.i2cp.DisconnectMessage) I2PSessionException(net.i2p.client.I2PSessionException) I2PAppThread(net.i2p.util.I2PAppThread) I2PAppThread(net.i2p.util.I2PAppThread)

Example 2 with DisconnectMessage

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

the class ClientConnectionRunner method disconnectClient.

/**
 * @param reason will be truncated to 255 bytes
 * @param logLevel e.g. Log.WARN
 * @since 0.8.2
 */
void disconnectClient(String reason, int logLevel) {
    if (_log.shouldLog(logLevel))
        _log.log(logLevel, "Disconnecting the client - " + reason);
    DisconnectMessage msg = new DisconnectMessage();
    if (reason.length() > 255)
        reason = reason.substring(0, 255);
    msg.setReason(reason);
    try {
        doSend(msg);
    } catch (I2CPMessageException ime) {
        if (_log.shouldLog(Log.WARN))
            _log.warn("Error writing out the disconnect message", ime);
    }
    // even better would be to have stopRunning() flush it?
    try {
        Thread.sleep(50);
    } catch (InterruptedException ie) {
    }
    stopRunning();
}
Also used : I2CPMessageException(net.i2p.data.i2cp.I2CPMessageException) DisconnectMessage(net.i2p.data.i2cp.DisconnectMessage)

Aggregations

DisconnectMessage (net.i2p.data.i2cp.DisconnectMessage)2 I2PSessionException (net.i2p.client.I2PSessionException)1 I2CPMessageException (net.i2p.data.i2cp.I2CPMessageException)1 I2PAppThread (net.i2p.util.I2PAppThread)1