Search in sources :

Example 36 with Log

use of net.i2p.util.Log in project i2p.i2p by i2p.

the class GracefulShutdown method run.

public void run() {
    Log log = _context.logManager().getLog(Router.class);
    while (true) {
        boolean shutdown = _context.router().gracefulShutdownInProgress();
        if (shutdown) {
            int gracefulExitCode = _context.router().scheduledGracefulExitCode();
            if (gracefulExitCode == Router.EXIT_HARD || gracefulExitCode == Router.EXIT_HARD_RESTART || _context.tunnelManager().getParticipatingCount() <= 0) {
                if (gracefulExitCode == Router.EXIT_HARD)
                    log.log(Log.CRIT, "Shutting down after a brief delay");
                else if (gracefulExitCode == Router.EXIT_HARD_RESTART)
                    log.log(Log.CRIT, "Restarting after a brief delay");
                else
                    log.log(Log.CRIT, "Graceful shutdown progress: No more tunnels, starting final shutdown");
                // Allow time for a UI reponse
                try {
                    synchronized (Thread.currentThread()) {
                        Thread.currentThread().wait(2 * 1000);
                    }
                } catch (InterruptedException ie) {
                }
                _context.router().shutdown(gracefulExitCode);
                return;
            } else {
                try {
                    synchronized (Thread.currentThread()) {
                        Thread.currentThread().wait(10 * 1000);
                    }
                } catch (InterruptedException ie) {
                }
            }
        } else {
            try {
                synchronized (Thread.currentThread()) {
                    Thread.currentThread().wait();
                }
            } catch (InterruptedException ie) {
            }
        }
    }
}
Also used : Log(net.i2p.util.Log)

Example 37 with Log

use of net.i2p.util.Log in project i2p.i2p by i2p.

the class GetBidsJob method getBids.

static void getBids(RouterContext context, TransportManager tmgr, OutNetMessage msg) {
    Log log = context.logManager().getLog(GetBidsJob.class);
    Hash to = msg.getTarget().getIdentity().getHash();
    msg.timestamp("bid");
    if (context.banlist().isBanlisted(to)) {
        if (log.shouldLog(Log.WARN))
            log.warn("Attempt to send a message to a banlisted peer - " + to);
        // context.messageRegistry().peerFailed(to);
        context.statManager().addRateData("transport.bidFailBanlisted", msg.getLifetime());
        fail(context, msg);
        return;
    }
    Hash us = context.routerHash();
    if (to.equals(us)) {
        if (log.shouldLog(Log.ERROR))
            log.error("send a message to ourselves?  nuh uh. msg = " + msg);
        context.statManager().addRateData("transport.bidFailSelf", msg.getLifetime());
        fail(context, msg);
        return;
    }
    TransportBid bid = tmgr.getNextBid(msg);
    if (bid == null) {
        int failedCount = msg.getFailedTransports().size();
        if (failedCount == 0) {
            context.statManager().addRateData("transport.bidFailNoTransports", msg.getLifetime());
            // This used to be "no common transports" but it is almost always no transports at all
            context.banlist().banlistRouter(to, _x("No transports (hidden or starting up?)"));
        } else if (failedCount >= tmgr.getTransportCount()) {
            context.statManager().addRateData("transport.bidFailAllTransports", msg.getLifetime());
            // fail after all transports were unsuccessful
            context.netDb().fail(to);
        }
        fail(context, msg);
    } else {
        if (log.shouldLog(Log.INFO))
            log.info("Attempting to send on transport " + bid.getTransport().getStyle() + ": " + bid);
        bid.getTransport().send(msg);
    }
}
Also used : Log(net.i2p.util.Log) Hash(net.i2p.data.Hash)

Example 38 with Log

use of net.i2p.util.Log in project i2p.i2p by i2p.

the class PersistRouterInfoJob method runJob.

public void runJob() {
    Log _log = getContext().logManager().getLog(PersistRouterInfoJob.class);
    if (_log.shouldLog(Log.DEBUG))
        _log.debug("Persisting updated router info");
    File infoFile = new File(getContext().getRouterDir(), CreateRouterInfoJob.INFO_FILENAME);
    RouterInfo info = getContext().router().getRouterInfo();
    FileOutputStream fos = null;
    synchronized (getContext().router().routerInfoFileLock) {
        try {
            fos = new SecureFileOutputStream(infoFile);
            info.writeBytes(fos);
        } catch (DataFormatException dfe) {
            _log.error("Error rebuilding the router information", dfe);
        } catch (IOException ioe) {
            _log.error("Error writing out the rebuilt router information", ioe);
        } finally {
            if (fos != null)
                try {
                    fos.close();
                } catch (IOException ioe) {
                }
        }
    }
}
Also used : DataFormatException(net.i2p.data.DataFormatException) Log(net.i2p.util.Log) RouterInfo(net.i2p.data.router.RouterInfo) FileOutputStream(java.io.FileOutputStream) SecureFileOutputStream(net.i2p.util.SecureFileOutputStream) SecureFileOutputStream(net.i2p.util.SecureFileOutputStream) IOException(java.io.IOException) File(java.io.File)

Example 39 with Log

use of net.i2p.util.Log in project i2p.i2p by i2p.

the class ReadConfigJob method runJob.

public void runJob() {
    File configFile = new File(getContext().router().getConfigFilename());
    if (shouldReread(configFile)) {
        getContext().router().readConfig();
        _lastRead = getContext().clock().now();
        Log log = getContext().logManager().getLog(ReadConfigJob.class);
        if (log.shouldDebug())
            log.debug("Reloaded " + configFile);
    }
    requeue(DELAY);
}
Also used : Log(net.i2p.util.Log) File(java.io.File)

Example 40 with Log

use of net.i2p.util.Log in project i2p.i2p by i2p.

the class ShutdownHook method run.

@Override
public void run() {
    setName("Router " + _id + " shutdown");
    Log l = _context.logManager().getLog(Router.class);
    l.log(Log.CRIT, "Shutting down the router...");
    // Needed to make the wrapper happy, otherwise it gets confused
    // and thinks we haven't shut down, possibly because it
    // prevents other shutdown hooks from running
    _context.router().eventLog().addEvent(EventLog.CRASHED, RouterVersion.FULL_VERSION);
    _context.router().setKillVMOnEnd(false);
    _context.router().shutdown2(Router.EXIT_HARD);
}
Also used : EventLog(net.i2p.router.util.EventLog) Log(net.i2p.util.Log)

Aggregations

Log (net.i2p.util.Log)94 IOException (java.io.IOException)30 File (java.io.File)13 Properties (java.util.Properties)11 DataFormatException (net.i2p.data.DataFormatException)11 FileInputStream (java.io.FileInputStream)7 GeneralSecurityException (java.security.GeneralSecurityException)7 ArrayList (java.util.ArrayList)7 Hash (net.i2p.data.Hash)6 HashMap (java.util.HashMap)5 InputStream (java.io.InputStream)4 EventLog (net.i2p.router.util.EventLog)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Map (java.util.Map)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 I2PAppContext (net.i2p.I2PAppContext)3 I2PSession (net.i2p.client.I2PSession)3 I2PSessionException (net.i2p.client.I2PSessionException)3 SigType (net.i2p.crypto.SigType)3 RouterInfo (net.i2p.data.router.RouterInfo)3