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