forked from I2P_Developers/i2p.i2p
i2psnark: Add skipped length on details page
reorder some logging volatile
This commit is contained in:
@ -62,7 +62,7 @@ public class Peer implements Comparable<Peer>
|
|||||||
|
|
||||||
// Keeps state for in/out connections. Non-null when the handshake
|
// Keeps state for in/out connections. Non-null when the handshake
|
||||||
// was successful, the connection setup and runs
|
// was successful, the connection setup and runs
|
||||||
PeerState state;
|
volatile PeerState state;
|
||||||
|
|
||||||
/** shared across all peers on this torrent */
|
/** shared across all peers on this torrent */
|
||||||
MagnetState magnetState;
|
MagnetState magnetState;
|
||||||
|
@ -39,7 +39,7 @@ class PeerConnectionIn implements Runnable
|
|||||||
private static final int MAX_MSG_SIZE = Math.max(PeerState.PARTSIZE + 9,
|
private static final int MAX_MSG_SIZE = Math.max(PeerState.PARTSIZE + 9,
|
||||||
MagnetState.CHUNK_SIZE + 100); // 100 for the ext msg dictionary
|
MagnetState.CHUNK_SIZE + 100); // 100 for the ext msg dictionary
|
||||||
|
|
||||||
private Thread thread;
|
private volatile Thread thread;
|
||||||
private volatile boolean quit;
|
private volatile boolean quit;
|
||||||
|
|
||||||
long lastRcvd;
|
long lastRcvd;
|
||||||
@ -75,9 +75,12 @@ class PeerConnectionIn implements Runnable
|
|||||||
thread = Thread.currentThread();
|
thread = Thread.currentThread();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
PeerState ps = peer.state;
|
while (!quit)
|
||||||
while (!quit && ps != null)
|
|
||||||
{
|
{
|
||||||
|
final PeerState ps = peer.state;
|
||||||
|
if (ps == null)
|
||||||
|
break;
|
||||||
|
|
||||||
// Common variables used for some messages.
|
// Common variables used for some messages.
|
||||||
int piece;
|
int piece;
|
||||||
int begin;
|
int begin;
|
||||||
@ -91,9 +94,9 @@ class PeerConnectionIn implements Runnable
|
|||||||
|
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
{
|
{
|
||||||
ps.keepAliveMessage();
|
|
||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
_log.debug("Received keepalive from " + peer);
|
_log.debug("Received keepalive from " + peer);
|
||||||
|
ps.keepAliveMessage();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,51 +104,51 @@ class PeerConnectionIn implements Runnable
|
|||||||
switch (b)
|
switch (b)
|
||||||
{
|
{
|
||||||
case Message.CHOKE:
|
case Message.CHOKE:
|
||||||
ps.chokeMessage(true);
|
|
||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
_log.debug("Received choke from " + peer);
|
_log.debug("Received choke from " + peer);
|
||||||
|
ps.chokeMessage(true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Message.UNCHOKE:
|
case Message.UNCHOKE:
|
||||||
ps.chokeMessage(false);
|
|
||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
_log.debug("Received unchoke from " + peer);
|
_log.debug("Received unchoke from " + peer);
|
||||||
|
ps.chokeMessage(false);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Message.INTERESTED:
|
case Message.INTERESTED:
|
||||||
ps.interestedMessage(true);
|
|
||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
_log.debug("Received interested from " + peer);
|
_log.debug("Received interested from " + peer);
|
||||||
|
ps.interestedMessage(true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Message.UNINTERESTED:
|
case Message.UNINTERESTED:
|
||||||
ps.interestedMessage(false);
|
|
||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
_log.debug("Received not interested from " + peer);
|
_log.debug("Received not interested from " + peer);
|
||||||
|
ps.interestedMessage(false);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Message.HAVE:
|
case Message.HAVE:
|
||||||
piece = din.readInt();
|
piece = din.readInt();
|
||||||
ps.haveMessage(piece);
|
|
||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
_log.debug("Received havePiece(" + piece + ") from " + peer);
|
_log.debug("Received havePiece(" + piece + ") from " + peer);
|
||||||
|
ps.haveMessage(piece);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Message.BITFIELD:
|
case Message.BITFIELD:
|
||||||
byte[] bitmap = new byte[i-1];
|
byte[] bitmap = new byte[i-1];
|
||||||
din.readFully(bitmap);
|
din.readFully(bitmap);
|
||||||
ps.bitfieldMessage(bitmap);
|
|
||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
_log.debug("Received bitmap from " + peer + ": size=" + (i-1) /* + ": " + ps.bitfield */ );
|
_log.debug("Received bitmap from " + peer + ": size=" + (i-1) /* + ": " + ps.bitfield */ );
|
||||||
|
ps.bitfieldMessage(bitmap);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Message.REQUEST:
|
case Message.REQUEST:
|
||||||
piece = din.readInt();
|
piece = din.readInt();
|
||||||
begin = din.readInt();
|
begin = din.readInt();
|
||||||
len = din.readInt();
|
len = din.readInt();
|
||||||
ps.requestMessage(piece, begin, len);
|
|
||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
_log.debug("Received request(" + piece + "," + begin + ") from " + peer);
|
_log.debug("Received request(" + piece + "," + begin + ") from " + peer);
|
||||||
|
ps.requestMessage(piece, begin, len);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Message.PIECE:
|
case Message.PIECE:
|
||||||
@ -156,9 +159,9 @@ class PeerConnectionIn implements Runnable
|
|||||||
if (req != null)
|
if (req != null)
|
||||||
{
|
{
|
||||||
req.read(din);
|
req.read(din);
|
||||||
ps.pieceMessage(req);
|
|
||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
_log.debug("Received data(" + piece + "," + begin + ") from " + peer);
|
_log.debug("Received data(" + piece + "," + begin + ") from " + peer);
|
||||||
|
ps.pieceMessage(req);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -175,16 +178,16 @@ class PeerConnectionIn implements Runnable
|
|||||||
piece = din.readInt();
|
piece = din.readInt();
|
||||||
begin = din.readInt();
|
begin = din.readInt();
|
||||||
len = din.readInt();
|
len = din.readInt();
|
||||||
ps.cancelMessage(piece, begin, len);
|
|
||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
_log.debug("Received cancel(" + piece + "," + begin + ") from " + peer);
|
_log.debug("Received cancel(" + piece + "," + begin + ") from " + peer);
|
||||||
|
ps.cancelMessage(piece, begin, len);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Message.PORT:
|
case Message.PORT:
|
||||||
int port = din.readUnsignedShort();
|
int port = din.readUnsignedShort();
|
||||||
ps.portMessage(port);
|
|
||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
_log.debug("Received port message from " + peer);
|
_log.debug("Received port message from " + peer);
|
||||||
|
ps.portMessage(port);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Message.EXTENSION:
|
case Message.EXTENSION:
|
||||||
@ -247,11 +250,9 @@ class PeerConnectionIn implements Runnable
|
|||||||
if (_log.shouldLog(Log.INFO))
|
if (_log.shouldLog(Log.INFO))
|
||||||
_log.info("IOError talking with " + peer, ioe);
|
_log.info("IOError talking with " + peer, ioe);
|
||||||
}
|
}
|
||||||
catch (Throwable t)
|
catch (RuntimeException t)
|
||||||
{
|
{
|
||||||
_log.error("Error talking with " + peer, t);
|
_log.error("Error talking with " + peer, t);
|
||||||
if (t instanceof OutOfMemoryError)
|
|
||||||
throw (OutOfMemoryError)t;
|
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
@ -911,6 +911,30 @@ public class Snark
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bytes not received and set to skipped.
|
||||||
|
* This is not the same as the total of all skipped files,
|
||||||
|
* since pieces may span multiple files.
|
||||||
|
*
|
||||||
|
* @return exact value. or 0 if no storage yet.
|
||||||
|
* @since 0.9.24
|
||||||
|
*/
|
||||||
|
public long getSkippedLength() {
|
||||||
|
PeerCoordinator coord = coordinator;
|
||||||
|
if (coord != null) {
|
||||||
|
// fast way
|
||||||
|
long r = getRemainingLength();
|
||||||
|
if (r <= 0)
|
||||||
|
return 0;
|
||||||
|
long n = coord.getNeededLength();
|
||||||
|
return r - n;
|
||||||
|
} else if (storage != null) {
|
||||||
|
// slow way
|
||||||
|
return storage.getSkippedLength();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Does not account (i.e. includes) for skipped files.
|
* Does not account (i.e. includes) for skipped files.
|
||||||
* @return number of pieces still needed (magnet mode or not), or -1 if unknown
|
* @return number of pieces still needed (magnet mode or not), or -1 if unknown
|
||||||
|
@ -518,6 +518,31 @@ public class Storage implements Closeable
|
|||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Call setPriority() for all changed files first,
|
||||||
|
* then call this.
|
||||||
|
* The length of all the pieces that are not yet downloaded,
|
||||||
|
* and are set to skipped.
|
||||||
|
* This is not the same as the total of all skipped files,
|
||||||
|
* since pieces may span multiple files.
|
||||||
|
*
|
||||||
|
* @return 0 on error, if complete, or if only one file
|
||||||
|
* @since 0.9.24
|
||||||
|
*/
|
||||||
|
public long getSkippedLength() {
|
||||||
|
int[] pri = getPiecePriorities();
|
||||||
|
if (pri == null)
|
||||||
|
return 0;
|
||||||
|
long rv = 0;
|
||||||
|
final int end = pri.length - 1;
|
||||||
|
for (int i = 0; i <= end; i++) {
|
||||||
|
if (pri[i] <= -9 && !bitfield.get(i)) {
|
||||||
|
rv += (i != end) ? piece_size : metainfo.getPieceLength(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The BitField that tells which pieces this storage contains.
|
* The BitField that tells which pieces this storage contains.
|
||||||
* Do not change this since this is the current state of the storage.
|
* Do not change this since this is the current state of the storage.
|
||||||
|
@ -2916,6 +2916,15 @@ public class I2PSnarkServlet extends BasicServlet {
|
|||||||
.append(":</b> ")
|
.append(":</b> ")
|
||||||
.append(formatSize(needed));
|
.append(formatSize(needed));
|
||||||
}
|
}
|
||||||
|
long skipped = snark.getSkippedLength();
|
||||||
|
if (skipped > 0) {
|
||||||
|
buf.append(" ");
|
||||||
|
toThemeImg(buf, "head_rx");
|
||||||
|
buf.append(" <b>")
|
||||||
|
.append(_t("Skipped"))
|
||||||
|
.append(":</b> ")
|
||||||
|
.append(formatSize(skipped));
|
||||||
|
}
|
||||||
if (meta != null) {
|
if (meta != null) {
|
||||||
List<List<String>> files = meta.getFiles();
|
List<List<String>> files = meta.getFiles();
|
||||||
int fileCount = files != null ? files.size() : 1;
|
int fileCount = files != null ? files.size() : 1;
|
||||||
|
Reference in New Issue
Block a user