forked from I2P_Developers/i2p.i2p
more shouldLog()
This commit is contained in:
@ -228,7 +228,8 @@ public class I2PSnarkUtil {
|
|||||||
public File get(String url, boolean rewrite) { return get(url, rewrite, 0); }
|
public File get(String url, boolean rewrite) { return get(url, rewrite, 0); }
|
||||||
public File get(String url, int retries) { return get(url, true, retries); }
|
public File get(String url, int retries) { return get(url, true, retries); }
|
||||||
public File get(String url, boolean rewrite, int retries) {
|
public File get(String url, boolean rewrite, int retries) {
|
||||||
_log.debug("Fetching [" + url + "] proxy=" + _proxyHost + ":" + _proxyPort + ": " + _shouldProxy);
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
|
_log.debug("Fetching [" + url + "] proxy=" + _proxyHost + ":" + _proxyPort + ": " + _shouldProxy);
|
||||||
File out = null;
|
File out = null;
|
||||||
try {
|
try {
|
||||||
// we could use the system tmp dir but deleteOnExit() doesn't seem to work on all platforms...
|
// we could use the system tmp dir but deleteOnExit() doesn't seem to work on all platforms...
|
||||||
@ -252,10 +253,12 @@ public class I2PSnarkUtil {
|
|||||||
}
|
}
|
||||||
EepGet get = new I2PSocketEepGet(_context, _manager, retries, out.getAbsolutePath(), fetchURL);
|
EepGet get = new I2PSocketEepGet(_context, _manager, retries, out.getAbsolutePath(), fetchURL);
|
||||||
if (get.fetch()) {
|
if (get.fetch()) {
|
||||||
_log.debug("Fetch successful [" + url + "]: size=" + out.length());
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
|
_log.debug("Fetch successful [" + url + "]: size=" + out.length());
|
||||||
return out;
|
return out;
|
||||||
} else {
|
} else {
|
||||||
_log.warn("Fetch failed [" + url + "]");
|
if (_log.shouldLog(Log.WARN))
|
||||||
|
_log.warn("Fetch failed [" + url + "]");
|
||||||
out.delete();
|
out.delete();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -109,7 +109,8 @@ public class MetaInfo
|
|||||||
*/
|
*/
|
||||||
public MetaInfo(Map m) throws InvalidBEncodingException
|
public MetaInfo(Map m) throws InvalidBEncodingException
|
||||||
{
|
{
|
||||||
_log.debug("Creating a metaInfo: " + m, new Exception("source"));
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
|
_log.debug("Creating a metaInfo: " + m, new Exception("source"));
|
||||||
BEValue val = (BEValue)m.get("announce");
|
BEValue val = (BEValue)m.get("announce");
|
||||||
if (val == null)
|
if (val == null)
|
||||||
throw new InvalidBEncodingException("Missing announce string");
|
throw new InvalidBEncodingException("Missing announce string");
|
||||||
@ -446,14 +447,16 @@ public class MetaInfo
|
|||||||
else
|
else
|
||||||
buf.append(val.toString());
|
buf.append(val.toString());
|
||||||
}
|
}
|
||||||
_log.debug(buf.toString());
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
|
_log.debug(buf.toString());
|
||||||
byte[] infoBytes = BEncoder.bencode(info);
|
byte[] infoBytes = BEncoder.bencode(info);
|
||||||
//_log.debug("info bencoded: [" + Base64.encode(infoBytes, true) + "]");
|
//_log.debug("info bencoded: [" + Base64.encode(infoBytes, true) + "]");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
MessageDigest digest = MessageDigest.getInstance("SHA");
|
MessageDigest digest = MessageDigest.getInstance("SHA");
|
||||||
byte hash[] = digest.digest(infoBytes);
|
byte hash[] = digest.digest(infoBytes);
|
||||||
_log.debug("info hash: [" + net.i2p.data.Base64.encode(hash) + "]");
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
|
_log.debug("info hash: [" + net.i2p.data.Base64.encode(hash) + "]");
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
catch(NoSuchAlgorithmException nsa)
|
catch(NoSuchAlgorithmException nsa)
|
||||||
|
@ -92,7 +92,8 @@ public class Peer implements Comparable
|
|||||||
byte[] id = handshake(in, out);
|
byte[] id = handshake(in, out);
|
||||||
this.peerID = new PeerID(id, sock.getPeerDestination());
|
this.peerID = new PeerID(id, sock.getPeerDestination());
|
||||||
_id = ++__id;
|
_id = ++__id;
|
||||||
_log.debug("Creating a new peer with " + peerID.getAddress().calculateHash().toBase64(), new Exception("creating " + _id));
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
|
_log.debug("Creating a new peer with " + peerID.getAddress().calculateHash().toBase64(), new Exception("creating " + _id));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -182,14 +183,16 @@ public class Peer implements Comparable
|
|||||||
if (state != null)
|
if (state != null)
|
||||||
throw new IllegalStateException("Peer already started");
|
throw new IllegalStateException("Peer already started");
|
||||||
|
|
||||||
_log.debug("Running connection to " + peerID.getAddress().calculateHash().toBase64(), new Exception("connecting"));
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
|
_log.debug("Running connection to " + peerID.getAddress().calculateHash().toBase64(), new Exception("connecting"));
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Do we need to handshake?
|
// Do we need to handshake?
|
||||||
if (din == null)
|
if (din == null)
|
||||||
{
|
{
|
||||||
sock = util.connect(peerID);
|
sock = util.connect(peerID);
|
||||||
_log.debug("Connected to " + peerID + ": " + sock);
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
|
_log.debug("Connected to " + peerID + ": " + sock);
|
||||||
if ((sock == null) || (sock.isClosed())) {
|
if ((sock == null) || (sock.isClosed())) {
|
||||||
throw new IOException("Unable to reach " + peerID);
|
throw new IOException("Unable to reach " + peerID);
|
||||||
}
|
}
|
||||||
@ -208,17 +211,20 @@ public class Peer implements Comparable
|
|||||||
// = new BufferedOutputStream(sock.getOutputStream());
|
// = new BufferedOutputStream(sock.getOutputStream());
|
||||||
byte [] id = handshake(in, out); //handshake(bis, bos);
|
byte [] id = handshake(in, out); //handshake(bis, bos);
|
||||||
byte [] expected_id = peerID.getID();
|
byte [] expected_id = peerID.getID();
|
||||||
if (expected_id == null)
|
if (expected_id == null) {
|
||||||
peerID.setID(id);
|
peerID.setID(id);
|
||||||
else if (Arrays.equals(expected_id, id))
|
} else if (Arrays.equals(expected_id, id)) {
|
||||||
_log.debug("Handshake got matching IDs with " + toString());
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
else
|
_log.debug("Handshake got matching IDs with " + toString());
|
||||||
|
} else {
|
||||||
throw new IOException("Unexpected peerID '"
|
throw new IOException("Unexpected peerID '"
|
||||||
+ PeerID.idencode(id)
|
+ PeerID.idencode(id)
|
||||||
+ "' expected '"
|
+ "' expected '"
|
||||||
+ PeerID.idencode(expected_id) + "'");
|
+ PeerID.idencode(expected_id) + "'");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
_log.debug("Already have din [" + sock + "] with " + toString());
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
|
_log.debug("Already have din [" + sock + "] with " + toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
PeerConnectionIn in = new PeerConnectionIn(this, din);
|
PeerConnectionIn in = new PeerConnectionIn(this, din);
|
||||||
@ -233,7 +239,8 @@ public class Peer implements Comparable
|
|||||||
state = s;
|
state = s;
|
||||||
listener.connected(this);
|
listener.connected(this);
|
||||||
|
|
||||||
_log.debug("Start running the reader with " + toString());
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
|
_log.debug("Start running the reader with " + toString());
|
||||||
// Use this thread for running the incomming connection.
|
// Use this thread for running the incomming connection.
|
||||||
// The outgoing connection creates its own Thread.
|
// The outgoing connection creates its own Thread.
|
||||||
out.startup();
|
out.startup();
|
||||||
@ -283,7 +290,8 @@ public class Peer implements Comparable
|
|||||||
dout.write(my_id);
|
dout.write(my_id);
|
||||||
dout.flush();
|
dout.flush();
|
||||||
|
|
||||||
_log.debug("Wrote my shared hash and ID to " + toString());
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
|
_log.debug("Wrote my shared hash and ID to " + toString());
|
||||||
|
|
||||||
// Handshake read - header
|
// Handshake read - header
|
||||||
byte b = din.readByte();
|
byte b = din.readByte();
|
||||||
@ -310,7 +318,8 @@ public class Peer implements Comparable
|
|||||||
|
|
||||||
// Handshake read - peer id
|
// Handshake read - peer id
|
||||||
din.readFully(bs);
|
din.readFully(bs);
|
||||||
_log.debug("Read the remote side's hash and peerID fully from " + toString());
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
|
_log.debug("Read the remote side's hash and peerID fully from " + toString());
|
||||||
return bs;
|
return bs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,10 +76,12 @@ public class PeerAcceptor
|
|||||||
// is this working right?
|
// is this working right?
|
||||||
try {
|
try {
|
||||||
peerInfoHash = readHash(in);
|
peerInfoHash = readHash(in);
|
||||||
_log.info("infohash read from " + socket.getPeerDestination().calculateHash().toBase64()
|
if (_log.shouldLog(Log.INFO))
|
||||||
+ ": " + Base64.encode(peerInfoHash));
|
_log.info("infohash read from " + socket.getPeerDestination().calculateHash().toBase64()
|
||||||
|
+ ": " + Base64.encode(peerInfoHash));
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
_log.info("Unable to read the infohash from " + socket.getPeerDestination().calculateHash().toBase64());
|
if (_log.shouldLog(Log.INFO))
|
||||||
|
_log.info("Unable to read the infohash from " + socket.getPeerDestination().calculateHash().toBase64());
|
||||||
throw ioe;
|
throw ioe;
|
||||||
}
|
}
|
||||||
in = new SequenceInputStream(new ByteArrayInputStream(peerInfoHash), in);
|
in = new SequenceInputStream(new ByteArrayInputStream(peerInfoHash), in);
|
||||||
|
@ -202,7 +202,8 @@ public class SnarkManager implements Snark.CompleteListener {
|
|||||||
}
|
}
|
||||||
if (i2cpHost != null) {
|
if (i2cpHost != null) {
|
||||||
_util.setI2CPConfig(i2cpHost, i2cpPort, i2cpOpts);
|
_util.setI2CPConfig(i2cpHost, i2cpPort, i2cpOpts);
|
||||||
_log.debug("Configuring with I2CP options " + i2cpOpts);
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
|
_log.debug("Configuring with I2CP options " + i2cpOpts);
|
||||||
}
|
}
|
||||||
//I2PSnarkUtil.instance().setI2CPConfig("66.111.51.110", 7654, new Properties());
|
//I2PSnarkUtil.instance().setI2CPConfig("66.111.51.110", 7654, new Properties());
|
||||||
//String eepHost = _config.getProperty(PROP_EEP_HOST);
|
//String eepHost = _config.getProperty(PROP_EEP_HOST);
|
||||||
@ -332,8 +333,9 @@ public class SnarkManager implements Snark.CompleteListener {
|
|||||||
p.putAll(opts);
|
p.putAll(opts);
|
||||||
_util.setI2CPConfig(i2cpHost, port, p);
|
_util.setI2CPConfig(i2cpHost, port, p);
|
||||||
addMessage(_("I2CP and tunnel changes will take effect after stopping all torrents"));
|
addMessage(_("I2CP and tunnel changes will take effect after stopping all torrents"));
|
||||||
_log.debug("i2cp host [" + i2cpHost + "] i2cp port " + port + " opts [" + opts
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
+ "] oldOpts [" + oldOpts + "]");
|
_log.debug("i2cp host [" + i2cpHost + "] i2cp port " + port + " opts [" + opts
|
||||||
|
+ "] oldOpts [" + oldOpts + "]");
|
||||||
} else {
|
} else {
|
||||||
if (_util.connected()) {
|
if (_util.connected()) {
|
||||||
_util.disconnect();
|
_util.disconnect();
|
||||||
@ -712,7 +714,8 @@ public class SnarkManager implements Snark.CompleteListener {
|
|||||||
getBWLimit();
|
getBWLimit();
|
||||||
while (true) {
|
while (true) {
|
||||||
File dir = getDataDir();
|
File dir = getDataDir();
|
||||||
_log.debug("Directory Monitor loop over " + dir.getAbsolutePath());
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
|
_log.debug("Directory Monitor loop over " + dir.getAbsolutePath());
|
||||||
try {
|
try {
|
||||||
monitorTorrents(dir);
|
monitorTorrents(dir);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
Reference in New Issue
Block a user