Search in sources :

Example 91 with Log

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

the class GarlicMessageBuilder method buildMessage.

/**
 * Unused and probably a bad idea.
 *
 * Used below only on a recursive call if the garlic message contains a garlic message.
 * We don't need the SessionKey or SesssionTags returned
 * This uses the router's SKM, which is probably not what you want.
 * This isn't fully implemented, because the key and tags aren't saved - maybe
 * it should force elGamal?
 *
 * @param ctx scope
 * @param config how/what to wrap
 * @throws IllegalArgumentException on error
 */
private static GarlicMessage buildMessage(RouterContext ctx, GarlicConfig config) {
    Log log = ctx.logManager().getLog(GarlicMessageBuilder.class);
    log.error("buildMessage 2 args, using router SKM", new Exception("who did it"));
    return buildMessage(ctx, config, new SessionKey(), new HashSet<SessionTag>(), ctx.sessionKeyManager());
}
Also used : Log(net.i2p.util.Log) SessionKey(net.i2p.data.SessionKey) SessionTag(net.i2p.data.SessionTag) DataFormatException(net.i2p.data.DataFormatException) IOException(java.io.IOException)

Example 92 with Log

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

the class CommunicationPacket method createPacket.

/**
 * Creates a packet object from its byte array representation. If there is an error,
 * <code>null</code> is returned.
 * @param data
 * @throws MalformedPacketException
 */
public static CommunicationPacket createPacket(byte[] data) throws MalformedPacketException {
    if (data == null) {
        Log log = new Log(CommunicationPacket.class);
        log.error("Packet data is null");
        return null;
    }
    if (data.length < HEADER_LENGTH) {
        Log log = new Log(CommunicationPacket.class);
        log.error("Packet is too short to be a CommunicationPacket");
        return null;
    }
    // byte 4 of a communication packet is the packet type code
    char packetTypeCode = (char) data[4];
    Class<? extends I2PBotePacket> packetType = decodePacketTypeCode(packetTypeCode);
    if (packetType == null || !CommunicationPacket.class.isAssignableFrom(packetType)) {
        Log log = new Log(CommunicationPacket.class);
        log.error("Type code is not a CommunicationPacket type code: <" + packetTypeCode + ">");
        return null;
    }
    Class<? extends CommunicationPacket> commPacketType = packetType.asSubclass(CommunicationPacket.class);
    try {
        return commPacketType.getConstructor(byte[].class).newInstance(data);
    } catch (Exception e) {
        if (e instanceof MalformedPacketException)
            throw (MalformedPacketException) e;
        else
            throw new MalformedPacketException("Can't instantiate packet for type code <" + packetTypeCode + ">", e);
    }
}
Also used : Log(net.i2p.util.Log) IOException(java.io.IOException)

Example 93 with Log

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

the class I2PBotePacket method decodePacketTypeCode.

protected static Class<? extends I2PBotePacket> decodePacketTypeCode(char packetTypeCode) {
    for (Class<? extends I2PBotePacket> packetType : ALL_PACKET_TYPES) if (packetType.getAnnotation(TypeCode.class).value() == packetTypeCode)
        return packetType;
    Log log = new Log(I2PBotePacket.class);
    log.debug("Invalid type code for I2PBotePacket: <" + packetTypeCode + ">");
    return null;
}
Also used : Log(net.i2p.util.Log)

Example 94 with Log

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

the class Util method readLines.

/**
 * Opens a <code>URL</code> and reads one line at a time.
 * Returns the lines as a <code>List</code> of <code>String</code>s,
 * or an empty <code>List</code> if an error occurred.
 * @param url
 * @see #readLines(File)
 */
public static List<String> readLines(URL url) {
    Log log = new Log(Util.class);
    log.info("Reading URL: <" + url + ">");
    InputStream stream = null;
    try {
        stream = url.openStream();
        return readLines(stream);
    } catch (IOException e) {
        log.error("Error reading URL.", e);
        return Collections.emptyList();
    } finally {
        if (stream != null)
            try {
                stream.close();
            } catch (IOException e) {
                log.error("Can't close input stream.", e);
            }
    }
}
Also used : Log(net.i2p.util.Log) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException)

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