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());
}
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);
}
}
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;
}
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);
}
}
}
Aggregations