use of net.i2p.router.Job in project i2p.i2p by i2p.
the class BootCommSystemJob method runJob.
public void runJob() {
// The netDb and the peer manager both take a long time to start up,
// as they may have to read in ~1000 files or more each
// So turn on the multiple job queues and start these two first.
// These two (plus the current job) will consume 3 of the 4 runners,
// leaving one for everything else, which allows us to start without
// a huge job lag displayed on the console.
getContext().jobQueue().allowParallelOperation();
startupDb();
getContext().jobQueue().addJob(new BootPeerManagerJob(getContext()));
// start up the network comm system
getContext().commSystem().startup();
getContext().tunnelManager().startup();
// start I2CP
getContext().jobQueue().addJob(new StartAcceptingClientsJob(getContext()));
if (!SystemVersion.isAndroid()) {
Job j = new ReadConfigJob(getContext());
j.getTiming().setStartAfter(getContext().clock().now() + 2 * 60 * 1000);
getContext().jobQueue().addJob(j);
}
((RouterClock) getContext().clock()).addShiftListener(getContext().router());
}
use of net.i2p.router.Job in project i2p.i2p by i2p.
the class HandleDatabaseLookupMessageJob method sendMessage.
protected void sendMessage(I2NPMessage message, Hash toPeer, TunnelId replyTunnel) {
if (replyTunnel != null) {
sendThroughTunnel(message, toPeer, replyTunnel);
} else {
if (_log.shouldLog(Log.DEBUG))
_log.debug("Sending reply directly to " + toPeer);
Job send = new SendMessageDirectJob(getContext(), message, toPeer, REPLY_TIMEOUT, MESSAGE_PRIORITY);
send.runJob();
// getContext().netDb().lookupRouterInfo(toPeer, send, null, REPLY_TIMEOUT);
}
}
use of net.i2p.router.Job in project i2p.i2p by i2p.
the class StoreJob method sendStoreThroughClient.
/**
* Send a leaseset store message out the client tunnel,
* with the reply to come back through a client tunnel.
* Stores are garlic encrypted to hide the identity from the OBEP.
*
* This makes it harder for an exploratory OBEP or IBGW to correlate it
* with one or more destinations. Since we are publishing the leaseset,
* it's easy to find out that an IB tunnel belongs to this dest, and
* it isn't much harder to do the same for an OB tunnel.
*
* As a side benefit, client tunnels should be faster and more reliable than
* exploratory tunnels.
*
* @param msg must contain a leaseset
* @since 0.7.10
*/
private void sendStoreThroughClient(DatabaseStoreMessage msg, RouterInfo peer, long expiration) {
long token = 1 + getContext().random().nextLong(I2NPMessage.MAX_ID_VALUE);
Hash client = msg.getKey();
Hash to = peer.getIdentity().getHash();
TunnelInfo replyTunnel = getContext().tunnelManager().selectInboundTunnel(client, to);
if (replyTunnel == null) {
if (_log.shouldLog(Log.WARN))
_log.warn("No reply inbound tunnels available!");
fail();
return;
}
TunnelId replyTunnelId = replyTunnel.getReceiveTunnelId(0);
msg.setReplyToken(token);
msg.setReplyTunnel(replyTunnelId);
msg.setReplyGateway(replyTunnel.getPeer(0));
if (_log.shouldLog(Log.DEBUG))
_log.debug(getJobId() + ": send(dbStore) w/ token expected " + token);
TunnelInfo outTunnel = getContext().tunnelManager().selectOutboundTunnel(client, to);
if (outTunnel != null) {
I2NPMessage sent;
boolean shouldEncrypt = supportsEncryption(peer);
if (shouldEncrypt) {
// garlic encrypt
MessageWrapper.WrappedMessage wm = MessageWrapper.wrap(getContext(), msg, client, peer);
if (wm == null) {
if (_log.shouldLog(Log.WARN))
_log.warn("Fail garlic encrypting from: " + client);
fail();
return;
}
sent = wm.getMessage();
_state.addPending(to, wm);
} else {
_state.addPending(to);
// now that almost all floodfills are at 0.7.10,
// just refuse to store unencrypted to older ones.
_state.replyTimeout(to);
getContext().jobQueue().addJob(new WaitJob(getContext()));
return;
}
SendSuccessJob onReply = new SendSuccessJob(getContext(), peer, outTunnel, sent.getMessageSize());
FailedJob onFail = new FailedJob(getContext(), peer, getContext().clock().now());
StoreMessageSelector selector = new StoreMessageSelector(getContext(), getJobId(), peer, token, expiration);
if (_log.shouldLog(Log.DEBUG)) {
if (shouldEncrypt)
_log.debug("sending encrypted store to " + peer.getIdentity().getHash() + " through " + outTunnel + ": " + sent);
else
_log.debug("sending store to " + peer.getIdentity().getHash() + " through " + outTunnel + ": " + sent);
// _log.debug("Expiration is " + new Date(sent.getMessageExpiration()));
}
getContext().messageRegistry().registerPending(selector, onReply, onFail);
getContext().tunnelDispatcher().dispatchOutbound(sent, outTunnel.getSendTunnelId(0), null, to);
} else {
if (_log.shouldLog(Log.WARN))
_log.warn("No outbound tunnels to send a dbStore out - delaying...");
// continueSending() above did an addPending() so remove it here.
// This means we will skip the peer next time, can't be helped for now
// without modding StoreState
_state.replyTimeout(to);
Job waiter = new WaitJob(getContext());
waiter.getTiming().setStartAfter(getContext().clock().now() + 3 * 1000);
getContext().jobQueue().addJob(waiter);
// fail();
}
}
use of net.i2p.router.Job in project i2p.i2p by i2p.
the class RouterWatchdog method verifyJobQueueLiveliness.
public boolean verifyJobQueueLiveliness() {
long when = _context.jobQueue().getLastJobBegin();
if (when < 0)
return true;
long howLongAgo = _context.clock().now() - when;
if (howLongAgo > MAX_JOB_RUN_LAG) {
Job cur = _context.jobQueue().getLastJob();
if (cur != null) {
if (_log.shouldLog(Log.ERROR))
_log.error("Last job was queued up " + DataHelper.formatDuration(howLongAgo) + " ago: " + cur);
return false;
} else {
// no prob, just normal lag
return true;
}
} else {
return true;
}
}
use of net.i2p.router.Job in project i2p.i2p by i2p.
the class BootCommSystemJob method startupDb.
private void startupDb() {
Job bootDb = new BootNetworkDbJob(getContext());
boolean useTrusted = getContext().getBooleanProperty(PROP_USE_TRUSTED_LINKS);
if (useTrusted) {
_log.debug("Using trusted links...");
getContext().jobQueue().addJob(new BuildTrustedLinksJob(getContext(), bootDb));
return;
} else {
_log.debug("Not using trusted links - boot db");
getContext().jobQueue().addJob(bootDb);
}
}
Aggregations