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