use of net.i2p.data.i2cp.I2CPMessage 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.I2CPMessage in project i2p.i2p by i2p.
the class ClientManager method internalConnect.
/**
* The InternalClientManager interface.
* Connects to the router, receiving a message queue to talk to the router with.
* @throws I2PSessionException if the router isn't ready
* @since 0.8.3
*/
public I2CPMessageQueue internalConnect() throws I2PSessionException {
if (!_isStarted)
throw new I2PSessionException("Router client manager is shut down");
LinkedBlockingQueue<I2CPMessage> in = new LinkedBlockingQueue<I2CPMessage>(INTERNAL_QUEUE_SIZE);
LinkedBlockingQueue<I2CPMessage> out = new LinkedBlockingQueue<I2CPMessage>(INTERNAL_QUEUE_SIZE);
I2CPMessageQueue myQueue = new I2CPMessageQueueImpl(in, out);
I2CPMessageQueue hisQueue = new I2CPMessageQueueImpl(out, in);
ClientConnectionRunner runner = new QueuedClientConnectionRunner(_ctx, this, myQueue);
registerConnection(runner);
return hisQueue;
}
use of net.i2p.data.i2cp.I2CPMessage 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");
}
}
Aggregations