Search in sources :

Example 11 with Job

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());
}
Also used : ReadConfigJob(net.i2p.router.tasks.ReadConfigJob) Job(net.i2p.router.Job) ReadConfigJob(net.i2p.router.tasks.ReadConfigJob) RouterClock(net.i2p.router.RouterClock)

Example 12 with Job

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);
    }
}
Also used : SendMessageDirectJob(net.i2p.router.message.SendMessageDirectJob) Job(net.i2p.router.Job) SendMessageDirectJob(net.i2p.router.message.SendMessageDirectJob)

Example 13 with Job

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();
    }
}
Also used : TunnelInfo(net.i2p.router.TunnelInfo) Hash(net.i2p.data.Hash) TunnelId(net.i2p.data.TunnelId) I2NPMessage(net.i2p.data.i2np.I2NPMessage) ReplyJob(net.i2p.router.ReplyJob) Job(net.i2p.router.Job)

Example 14 with Job

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;
    }
}
Also used : Job(net.i2p.router.Job)

Example 15 with Job

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);
    }
}
Also used : Job(net.i2p.router.Job) ReadConfigJob(net.i2p.router.tasks.ReadConfigJob)

Aggregations

Job (net.i2p.router.Job)20 Hash (net.i2p.data.Hash)9 ReplyJob (net.i2p.router.ReplyJob)7 RouterInfo (net.i2p.data.router.RouterInfo)4 TunnelInfo (net.i2p.router.TunnelInfo)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 TunnelId (net.i2p.data.TunnelId)2 DatabaseLookupMessage (net.i2p.data.i2np.DatabaseLookupMessage)2 DatabaseStoreMessage (net.i2p.data.i2np.DatabaseStoreMessage)2 I2NPMessage (net.i2p.data.i2np.I2NPMessage)2 MessageSelector (net.i2p.router.MessageSelector)2 OutNetMessage (net.i2p.router.OutNetMessage)2 SendMessageDirectJob (net.i2p.router.message.SendMessageDirectJob)2 ReadConfigJob (net.i2p.router.tasks.ReadConfigJob)2 Date (java.util.Date)1 SessionConfig (net.i2p.data.i2cp.SessionConfig)1 DeliveryStatusMessage (net.i2p.data.i2np.DeliveryStatusMessage)1 TunnelGatewayMessage (net.i2p.data.i2np.TunnelGatewayMessage)1 RouterKeyGenerator (net.i2p.data.router.RouterKeyGenerator)1