Search in sources :

Example 86 with Log

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

the class FreeListBlock method flbck.

/**
 * Recursive.
 * @since 0.9.7
 */
public boolean flbck(boolean fix) throws IOException {
    Log log = I2PAppContext.getGlobalContext().logManager().getLog(BlockFile.class);
    log.info(toString());
    if (nextPage > 0)
        (new FreeListBlock(file, nextPage)).flbck(fix);
    return true;
}
Also used : Log(net.i2p.util.Log)

Example 87 with Log

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

the class FreeListBlock method addPage.

/**
 *  Adds free page and writes new len to disk
 *  @throws IllegalStateException if full
 */
public void addPage(int freePage) throws IOException {
    if (len >= MAX_SIZE)
        throw new IllegalStateException("full");
    if (getMagic(freePage) == MAGIC_FREE) {
        Log log = I2PAppContext.getGlobalContext().logManager().getLog(BlockFile.class);
        log.error("Double free page " + freePage, new Exception());
        return;
    }
    branches[len++] = freePage;
    markFree(freePage);
    writeFreePage();
}
Also used : Log(net.i2p.util.Log) IOException(java.io.IOException)

Example 88 with Log

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

the class KeyGenerator method generateSigningKeys.

/**
 *  Generic signature type, supports DSA, RSA, ECDSA, EdDSA
 *  @since 0.9.9
 */
public SimpleDataStructure[] generateSigningKeys(SigType type) throws GeneralSecurityException {
    if (type == SigType.DSA_SHA1)
        return generateSigningKeys();
    KeyPair kp;
    if (type.getBaseAlgorithm() == SigAlgo.EdDSA) {
        net.i2p.crypto.eddsa.KeyPairGenerator kpg = new net.i2p.crypto.eddsa.KeyPairGenerator();
        kpg.initialize(type.getParams(), _context.random());
        kp = kpg.generateKeyPair();
    } else {
        KeyPairGenerator kpg = KeyPairGenerator.getInstance(type.getBaseAlgorithm().getName());
        try {
            kpg.initialize(type.getParams(), _context.random());
            kp = kpg.generateKeyPair();
        } catch (ProviderException pe) {
            // java.security.ProviderException: sun.security.pkcs11.wrapper.PKCS11Exception: CKR_DOMAIN_PARAMS_INVALID
            // This is a RuntimeException, thx Sun
            // Fails for P-192 only, on Ubuntu
            Log log = _context.logManager().getLog(KeyGenerator.class);
            String pname = kpg.getProvider().getName();
            if ("BC".equals(pname)) {
                if (log.shouldLog(Log.WARN))
                    log.warn("BC KPG failed for " + type, pe);
                throw new GeneralSecurityException("BC KPG for " + type, pe);
            }
            if (!ECConstants.isBCAvailable())
                throw new GeneralSecurityException(pname + " KPG failed for " + type, pe);
            if (log.shouldLog(Log.WARN))
                log.warn(pname + " KPG failed for " + type + ", trying BC");
            try {
                kpg = KeyPairGenerator.getInstance(type.getBaseAlgorithm().getName(), "BC");
                kpg.initialize(type.getParams(), _context.random());
                kp = kpg.generateKeyPair();
            } catch (ProviderException pe2) {
                if (log.shouldLog(Log.WARN))
                    log.warn("BC KPG failed for " + type + " also", pe2);
                // throw original exception
                throw new GeneralSecurityException(pname + " KPG for " + type, pe);
            } catch (GeneralSecurityException gse) {
                if (log.shouldLog(Log.WARN))
                    log.warn("BC KPG failed for " + type + " also", gse);
                // throw original exception
                throw new GeneralSecurityException(pname + " KPG for " + type, pe);
            }
        }
    }
    java.security.PublicKey pubkey = kp.getPublic();
    java.security.PrivateKey privkey = kp.getPrivate();
    SimpleDataStructure[] keys = new SimpleDataStructure[2];
    keys[0] = SigUtil.fromJavaKey(pubkey, type);
    keys[1] = SigUtil.fromJavaKey(privkey, type);
    return keys;
}
Also used : KeyPair(java.security.KeyPair) ProviderException(java.security.ProviderException) Log(net.i2p.util.Log) GeneralSecurityException(java.security.GeneralSecurityException) KeyPairGenerator(java.security.KeyPairGenerator) SimpleDataStructure(net.i2p.data.SimpleDataStructure)

Example 89 with Log

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

the class CertUtil method log.

// private static void error(I2PAppContext ctx, String msg, Throwable t) {
// log(ctx, Log.ERROR, msg, t);
// }
private static void log(I2PAppContext ctx, int level, String msg, Throwable t) {
    Log l = ctx.logManager().getLog(CertUtil.class);
    l.log(level, msg, t);
}
Also used : Log(net.i2p.util.Log)

Example 90 with Log

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

the class RouterClock method setNow.

/**
 *  @param stratum used to determine whether we should ignore
 *  @since 0.7.12
 */
@Override
public void setNow(long realTime, int stratum) {
    if (realTime < BuildTime.getEarliestTime() || realTime > BuildTime.getLatestTime()) {
        Log log = getLog();
        String msg = "Invalid time received: " + new Date(realTime);
        if (log.shouldWarn())
            log.warn(msg, new Exception());
        else
            log.logAlways(Log.WARN, msg);
        return;
    }
    long diff = realTime - System.currentTimeMillis();
    setOffset(diff, stratum);
}
Also used : Log(net.i2p.util.Log) Date(java.util.Date)

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