use of net.i2p.data.i2cp.I2CPMessageException in project i2p.i2p by i2p.
the class LocalClientMessageEventListener method handleHostLookup.
/**
* Look only in current local dests
*/
@Override
protected void handleHostLookup(HostLookupMessage message) {
Hash h = message.getHash();
String name = message.getHostname();
long reqID = message.getReqID();
SessionId sessID = message.getSessionId();
if (h == null && name != null && name.length() == 60) {
// convert a b32 lookup to a hash lookup
String nlc = name.toLowerCase(Locale.US);
if (nlc.endsWith(".b32.i2p")) {
byte[] b = Base32.decode(nlc.substring(0, 52));
if (b != null && b.length == Hash.HASH_LENGTH) {
h = Hash.create(b);
}
}
}
Destination d = null;
if (h != null)
d = ((LocalClientConnectionRunner) _runner).localLookup(h);
HostReplyMessage msg;
if (d != null)
msg = new HostReplyMessage(sessID, d, reqID);
else
msg = new HostReplyMessage(sessID, HostReplyMessage.RESULT_FAILURE, reqID);
try {
_runner.doSend(msg);
} catch (I2CPMessageException ime) {
ime.printStackTrace();
}
}
use of net.i2p.data.i2cp.I2CPMessageException in project i2p.i2p by i2p.
the class RequestLeaseSetJob method runJob.
public void runJob() {
if (_runner.isDead())
return;
LeaseSet requested = _requestState.getRequested();
long endTime = requested.getEarliestLeaseDate();
// Add a small number of ms (0 to MAX_FUDGE) that increases as we approach the expire time.
// Since the earliest date functions as a version number,
// this will force the floodfill to flood each new version;
// otherwise it won't if the earliest time hasn't changed.
long fudge = MAX_FUDGE - ((endTime - getContext().clock().now()) / (10 * 60 * 1000 / MAX_FUDGE));
// if (_log.shouldLog(Log.DEBUG))
// _log.debug("Adding fudge " + fudge);
endTime += fudge;
SessionId id = _runner.getSessionId(requested.getDestination().calculateHash());
if (id == null) {
_runner.failLeaseRequest(_requestState);
return;
}
I2CPMessage msg;
if (getContext().getProperty(PROP_VARIABLE, DFLT_VARIABLE) && (_runner instanceof QueuedClientConnectionRunner || RequestVariableLeaseSetMessage.isSupported(_runner.getClientVersion()))) {
// new style - leases will have individual expirations
RequestVariableLeaseSetMessage rmsg = new RequestVariableLeaseSetMessage();
rmsg.setSessionId(id);
for (int i = 0; i < requested.getLeaseCount(); i++) {
Lease lease = requested.getLease(i);
if (lease.getEndDate().getTime() < endTime) {
// don't modify old object, we don't know where it came from
Lease nl = new Lease();
nl.setGateway(lease.getGateway());
nl.setTunnelId(lease.getTunnelId());
nl.setEndDate(new Date(endTime));
lease = nl;
// if (_log.shouldLog(Log.INFO))
// _log.info("Adjusted end date to " + endTime + " for " + lease);
}
rmsg.addEndpoint(lease);
}
msg = rmsg;
} else {
// old style - all leases will have same expiration
RequestLeaseSetMessage rmsg = new RequestLeaseSetMessage();
Date end = new Date(endTime);
rmsg.setEndDate(end);
rmsg.setSessionId(id);
for (int i = 0; i < requested.getLeaseCount(); i++) {
Lease lease = requested.getLease(i);
rmsg.addEndpoint(lease.getGateway(), lease.getTunnelId());
}
msg = rmsg;
}
try {
// _runner.setLeaseRequest(state);
_runner.doSend(msg);
getContext().jobQueue().addJob(new CheckLeaseRequestStatus());
} catch (I2CPMessageException ime) {
getContext().statManager().addRateData("client.requestLeaseSetDropped", 1);
_log.error("Error sending I2CP message requesting the lease set", ime);
_requestState.setIsSuccessful(false);
if (_requestState.getOnFailed() != null)
RequestLeaseSetJob.this.getContext().jobQueue().addJob(_requestState.getOnFailed());
_runner.failLeaseRequest(_requestState);
// Don't disconnect, the tunnel will retry
// _runner.disconnectClient("I2CP error requesting leaseSet");
}
}
use of net.i2p.data.i2cp.I2CPMessageException in project i2p.i2p by i2p.
the class ClientConnectionRunner method ackSendMessage.
/**
* Send a notification to the client that their message (id specified) was accepted
* for delivery (but not necessarily delivered)
* Doesn't do anything if i2cp.messageReliability = "none"
* or if the nonce is 0.
*
* @param id OUR id for the message
* @param nonce HIS id for the message
*/
void ackSendMessage(SessionId sid, MessageId id, long nonce) {
if (_dontSendMSM || nonce == 0)
return;
if (_log.shouldLog(Log.DEBUG))
_log.debug("Acking message send [accepted]" + id + " / " + nonce + " for sessionId " + sid);
MessageStatusMessage status = new MessageStatusMessage();
status.setMessageId(id.getMessageId());
status.setSessionId(sid.getSessionId());
status.setSize(0L);
status.setNonce(nonce);
status.setStatus(MessageStatusMessage.STATUS_SEND_ACCEPTED);
try {
doSend(status);
_acceptedPending.remove(id);
} catch (I2CPMessageException ime) {
if (_log.shouldLog(Log.WARN))
_log.warn("Error writing out the message status message", ime);
}
}
use of net.i2p.data.i2cp.I2CPMessageException 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();
}
use of net.i2p.data.i2cp.I2CPMessageException in project i2p.i2p by i2p.
the class ClientMessageEventListener method handleGetBWLimits.
/**
* Divide router limit by 1.75 for overhead.
* This could someday give a different answer to each client.
* But it's not enforced anywhere.
*/
protected void handleGetBWLimits(GetBandwidthLimitsMessage message) {
if (_log.shouldLog(Log.INFO))
_log.info("Got BW Limits request");
int in = _context.bandwidthLimiter().getInboundKBytesPerSecond() * 4 / 7;
int out = _context.bandwidthLimiter().getOutboundKBytesPerSecond() * 4 / 7;
BandwidthLimitsMessage msg = new BandwidthLimitsMessage(in, out);
try {
_runner.doSend(msg);
} catch (I2CPMessageException ime) {
if (_log.shouldLog(Log.WARN))
_log.warn("Error writing bw limits msg", ime);
}
}
Aggregations