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();
}
}
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();
}
Aggregations