forked from I2P_Developers/i2p.i2p
i2psnark:
- Persist uploaded count (tickets #1034, #1298) - Show uploaded count even when stopped
This commit is contained in:
@ -54,8 +54,15 @@ public interface CompleteListener {
|
|||||||
*/
|
*/
|
||||||
public void gotPiece(Snark snark);
|
public void gotPiece(Snark snark);
|
||||||
|
|
||||||
// not really listeners but the easiest way to get back to an optional SnarkManager
|
/** not really listeners but the easiest way to get back to an optional SnarkManager */
|
||||||
public long getSavedTorrentTime(Snark snark);
|
public long getSavedTorrentTime(Snark snark);
|
||||||
public BitField getSavedTorrentBitField(Snark snark);
|
public BitField getSavedTorrentBitField(Snark snark);
|
||||||
|
/**
|
||||||
|
* @since 0.9.15
|
||||||
|
*/
|
||||||
public boolean getSavedPreserveNamesSetting(Snark snark);
|
public boolean getSavedPreserveNamesSetting(Snark snark);
|
||||||
|
/**
|
||||||
|
* @since 0.9.15
|
||||||
|
*/
|
||||||
|
public long getSavedUploaded(Snark snark);
|
||||||
}
|
}
|
||||||
|
@ -281,6 +281,14 @@ class PeerCoordinator implements PeerListener
|
|||||||
return uploaded;
|
return uploaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the initial total of uploaded bytes of all peers (from a saved status)
|
||||||
|
* @since 0.9.15
|
||||||
|
*/
|
||||||
|
public void setUploaded(long up) {
|
||||||
|
uploaded = up;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the total number of downloaded bytes of all peers.
|
* Returns the total number of downloaded bytes of all peers.
|
||||||
*/
|
*/
|
||||||
|
@ -237,6 +237,7 @@ public class Snark
|
|||||||
private volatile boolean _autoStoppable;
|
private volatile boolean _autoStoppable;
|
||||||
// String indicating main activity
|
// String indicating main activity
|
||||||
private volatile String activity = "Not started";
|
private volatile String activity = "Not started";
|
||||||
|
private final long savedUploaded;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -463,6 +464,7 @@ public class Snark
|
|||||||
trackerclient = new TrackerClient(meta, coordinator);
|
trackerclient = new TrackerClient(meta, coordinator);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
savedUploaded = (completeListener != null) ? completeListener.getSavedUploaded(this) : 0;
|
||||||
if (start)
|
if (start)
|
||||||
startTorrent();
|
startTorrent();
|
||||||
}
|
}
|
||||||
@ -488,6 +490,7 @@ public class Snark
|
|||||||
this.infoHash = ih;
|
this.infoHash = ih;
|
||||||
this.additionalTrackerURL = trackerURL;
|
this.additionalTrackerURL = trackerURL;
|
||||||
this.rootDataDir = rootDir != null ? new File(rootDir) : null; // null only for FetchAndAdd extension
|
this.rootDataDir = rootDir != null ? new File(rootDir) : null; // null only for FetchAndAdd extension
|
||||||
|
savedUploaded = 0;
|
||||||
stopped = true;
|
stopped = true;
|
||||||
id = generateID();
|
id = generateID();
|
||||||
|
|
||||||
@ -556,6 +559,7 @@ public class Snark
|
|||||||
_log.info("Starting PeerCoordinator, ConnectionAcceptor, and TrackerClient");
|
_log.info("Starting PeerCoordinator, ConnectionAcceptor, and TrackerClient");
|
||||||
activity = "Collecting pieces";
|
activity = "Collecting pieces";
|
||||||
coordinator = new PeerCoordinator(_util, id, infoHash, meta, storage, this, this);
|
coordinator = new PeerCoordinator(_util, id, infoHash, meta, storage, this, this);
|
||||||
|
coordinator.setUploaded(savedUploaded);
|
||||||
if (_peerCoordinatorSet != null) {
|
if (_peerCoordinatorSet != null) {
|
||||||
// multitorrent
|
// multitorrent
|
||||||
_peerCoordinatorSet.add(coordinator);
|
_peerCoordinatorSet.add(coordinator);
|
||||||
@ -619,7 +623,7 @@ public class Snark
|
|||||||
pc.halt();
|
pc.halt();
|
||||||
Storage st = storage;
|
Storage st = storage;
|
||||||
if (st != null) {
|
if (st != null) {
|
||||||
boolean changed = storage.isChanged();
|
boolean changed = storage.isChanged() || getUploaded() != savedUploaded;
|
||||||
try {
|
try {
|
||||||
storage.close();
|
storage.close();
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
@ -773,7 +777,7 @@ public class Snark
|
|||||||
PeerCoordinator coord = coordinator;
|
PeerCoordinator coord = coordinator;
|
||||||
if (coord != null)
|
if (coord != null)
|
||||||
return coord.getUploaded();
|
return coord.getUploaded();
|
||||||
return 0;
|
return savedUploaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -92,6 +92,7 @@ public class SnarkManager implements CompleteListener {
|
|||||||
private static final String PROP_META_BITFIELD = "bitfield";
|
private static final String PROP_META_BITFIELD = "bitfield";
|
||||||
private static final String PROP_META_PRIORITY = "priority";
|
private static final String PROP_META_PRIORITY = "priority";
|
||||||
private static final String PROP_META_PRESERVE_NAMES = "preserveFileNames";
|
private static final String PROP_META_PRESERVE_NAMES = "preserveFileNames";
|
||||||
|
private static final String PROP_META_UPLOADED = "uploaded";
|
||||||
//private static final String PROP_META_BITFIELD_SUFFIX = ".bitfield";
|
//private static final String PROP_META_BITFIELD_SUFFIX = ".bitfield";
|
||||||
//private static final String PROP_META_PRIORITY_SUFFIX = ".priority";
|
//private static final String PROP_META_PRIORITY_SUFFIX = ".priority";
|
||||||
private static final String PROP_META_MAGNET_PREFIX = "i2psnark.magnet.";
|
private static final String PROP_META_MAGNET_PREFIX = "i2psnark.magnet.";
|
||||||
@ -1357,7 +1358,7 @@ public class SnarkManager implements CompleteListener {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// so addTorrent won't recheck
|
// so addTorrent won't recheck
|
||||||
saveTorrentStatus(metainfo, bitfield, null, baseFile, true); // no file priorities
|
saveTorrentStatus(metainfo, bitfield, null, baseFile, true, 0); // no file priorities
|
||||||
try {
|
try {
|
||||||
locked_writeMetaInfo(metainfo, filename, areFilesPublic());
|
locked_writeMetaInfo(metainfo, filename, areFilesPublic());
|
||||||
// hold the lock for a long time
|
// hold the lock for a long time
|
||||||
@ -1522,6 +1523,21 @@ public class SnarkManager implements CompleteListener {
|
|||||||
Properties config = getConfig(snark);
|
Properties config = getConfig(snark);
|
||||||
return Boolean.parseBoolean(config.getProperty(PROP_META_PRESERVE_NAMES));
|
return Boolean.parseBoolean(config.getProperty(PROP_META_PRESERVE_NAMES));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get setting for a torrent from the config file.
|
||||||
|
* @return setting, 0 if not found
|
||||||
|
* @since 0.9.15
|
||||||
|
*/
|
||||||
|
public long getSavedUploaded(Snark snark) {
|
||||||
|
Properties config = getConfig(snark);
|
||||||
|
if (config != null) {
|
||||||
|
try {
|
||||||
|
return Long.parseLong(config.getProperty(PROP_META_UPLOADED));
|
||||||
|
} catch (NumberFormatException nfe) {}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save the completion status of a torrent and other data in the config file
|
* Save the completion status of a torrent and other data in the config file
|
||||||
@ -1535,7 +1551,8 @@ public class SnarkManager implements CompleteListener {
|
|||||||
if (meta == null || storage == null)
|
if (meta == null || storage == null)
|
||||||
return;
|
return;
|
||||||
saveTorrentStatus(meta, storage.getBitField(), storage.getFilePriorities(),
|
saveTorrentStatus(meta, storage.getBitField(), storage.getFilePriorities(),
|
||||||
storage.getBase(), storage.getPreserveFileNames());
|
storage.getBase(), storage.getPreserveFileNames(),
|
||||||
|
snark.getUploaded());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1550,14 +1567,14 @@ public class SnarkManager implements CompleteListener {
|
|||||||
* @param base may be null
|
* @param base may be null
|
||||||
*/
|
*/
|
||||||
private void saveTorrentStatus(MetaInfo metainfo, BitField bitfield, int[] priorities,
|
private void saveTorrentStatus(MetaInfo metainfo, BitField bitfield, int[] priorities,
|
||||||
File base, boolean preserveNames) {
|
File base, boolean preserveNames, long uploaded) {
|
||||||
synchronized (_configLock) {
|
synchronized (_configLock) {
|
||||||
locked_saveTorrentStatus(metainfo, bitfield, priorities, base, preserveNames);
|
locked_saveTorrentStatus(metainfo, bitfield, priorities, base, preserveNames, uploaded);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void locked_saveTorrentStatus(MetaInfo metainfo, BitField bitfield, int[] priorities,
|
private void locked_saveTorrentStatus(MetaInfo metainfo, BitField bitfield, int[] priorities,
|
||||||
File base, boolean preserveNames) {
|
File base, boolean preserveNames, long uploaded) {
|
||||||
byte[] ih = metainfo.getInfoHash();
|
byte[] ih = metainfo.getInfoHash();
|
||||||
String bfs;
|
String bfs;
|
||||||
if (bitfield.complete()) {
|
if (bitfield.complete()) {
|
||||||
@ -1570,6 +1587,7 @@ public class SnarkManager implements CompleteListener {
|
|||||||
config.setProperty(PROP_META_STAMP, Long.toString(System.currentTimeMillis()));
|
config.setProperty(PROP_META_STAMP, Long.toString(System.currentTimeMillis()));
|
||||||
config.setProperty(PROP_META_BITFIELD, bfs);
|
config.setProperty(PROP_META_BITFIELD, bfs);
|
||||||
config.setProperty(PROP_META_PRESERVE_NAMES, Boolean.toString(preserveNames));
|
config.setProperty(PROP_META_PRESERVE_NAMES, Boolean.toString(preserveNames));
|
||||||
|
config.setProperty(PROP_META_UPLOADED, Long.toString(uploaded));
|
||||||
if (base != null)
|
if (base != null)
|
||||||
config.setProperty(PROP_META_BASE, base.getAbsolutePath());
|
config.setProperty(PROP_META_BASE, base.getAbsolutePath());
|
||||||
|
|
||||||
@ -1826,7 +1844,7 @@ public class SnarkManager implements CompleteListener {
|
|||||||
Storage storage = snark.getStorage();
|
Storage storage = snark.getStorage();
|
||||||
if (meta != null && storage != null)
|
if (meta != null && storage != null)
|
||||||
saveTorrentStatus(meta, storage.getBitField(), storage.getFilePriorities(),
|
saveTorrentStatus(meta, storage.getBitField(), storage.getFilePriorities(),
|
||||||
storage.getBase(), storage.getPreserveFileNames());
|
storage.getBase(), storage.getPreserveFileNames(), snark.getUploaded());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1849,7 +1867,7 @@ public class SnarkManager implements CompleteListener {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
saveTorrentStatus(meta, storage.getBitField(), null,
|
saveTorrentStatus(meta, storage.getBitField(), null,
|
||||||
storage.getBase(), storage.getPreserveFileNames()); // no file priorities
|
storage.getBase(), storage.getPreserveFileNames(), 0);
|
||||||
// temp for addMessage() in case canonical throws
|
// temp for addMessage() in case canonical throws
|
||||||
String name = storage.getBaseName();
|
String name = storage.getBaseName();
|
||||||
try {
|
try {
|
||||||
|
@ -295,6 +295,10 @@ class UpdateRunner implements UpdateTask, CompleteListener {
|
|||||||
return _smgr.getSavedPreserveNamesSetting(snark);
|
return _smgr.getSavedPreserveNamesSetting(snark);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getSavedUploaded(Snark snark) {
|
||||||
|
return _smgr.getSavedUploaded(snark);
|
||||||
|
}
|
||||||
|
|
||||||
//////// end CompleteListener methods
|
//////// end CompleteListener methods
|
||||||
|
|
||||||
private static String linkify(String url) {
|
private static String linkify(String url) {
|
||||||
|
@ -498,7 +498,7 @@ public class I2PSnarkServlet extends BasicServlet {
|
|||||||
out.write(_("RX"));
|
out.write(_("RX"));
|
||||||
out.write("\">");
|
out.write("\">");
|
||||||
out.write("</th>\n<th align=\"right\">");
|
out.write("</th>\n<th align=\"right\">");
|
||||||
if (_manager.util().connected() && !snarks.isEmpty()) {
|
if (!snarks.isEmpty()) {
|
||||||
out.write("<img border=\"0\" src=\"" + _imgPath + "head_tx.png\" title=\"");
|
out.write("<img border=\"0\" src=\"" + _imgPath + "head_tx.png\" title=\"");
|
||||||
out.write(_("Uploaded"));
|
out.write(_("Uploaded"));
|
||||||
out.write("\" alt=\"");
|
out.write("\" alt=\"");
|
||||||
@ -1465,15 +1465,15 @@ public class I2PSnarkServlet extends BasicServlet {
|
|||||||
// out.write("??"); // no meta size yet
|
// out.write("??"); // no meta size yet
|
||||||
out.write("</td>\n\t");
|
out.write("</td>\n\t");
|
||||||
out.write("<td align=\"right\" class=\"snarkTorrentUploaded\">");
|
out.write("<td align=\"right\" class=\"snarkTorrentUploaded\">");
|
||||||
if(isRunning && isValid)
|
if (isValid && uploaded > 0)
|
||||||
out.write(formatSize(uploaded));
|
out.write(formatSize(uploaded));
|
||||||
out.write("</td>\n\t");
|
out.write("</td>\n\t");
|
||||||
out.write("<td align=\"right\" class=\"snarkTorrentRateDown\">");
|
out.write("<td align=\"right\" class=\"snarkTorrentRateDown\">");
|
||||||
if(isRunning && needed > 0)
|
if (isRunning && needed > 0)
|
||||||
out.write(formatSize(downBps) + "ps");
|
out.write(formatSize(downBps) + "ps");
|
||||||
out.write("</td>\n\t");
|
out.write("</td>\n\t");
|
||||||
out.write("<td align=\"right\" class=\"snarkTorrentRateUp\">");
|
out.write("<td align=\"right\" class=\"snarkTorrentRateUp\">");
|
||||||
if(isRunning && isValid)
|
if (isRunning && isValid)
|
||||||
out.write(formatSize(upBps) + "ps");
|
out.write(formatSize(upBps) + "ps");
|
||||||
out.write("</td>\n\t");
|
out.write("</td>\n\t");
|
||||||
out.write("<td align=\"center\" class=\"snarkTorrentAction\">");
|
out.write("<td align=\"center\" class=\"snarkTorrentAction\">");
|
||||||
|
@ -1,3 +1,10 @@
|
|||||||
|
2014-08-27 zzz
|
||||||
|
* i2psnark: Persist uploaded count (tickets #1034, #1298)
|
||||||
|
|
||||||
|
2014-08-23 zzz
|
||||||
|
* Console, i2psnark, i2ptunnel: Escape fixes and cleanups
|
||||||
|
* SSU: Drop peer tests as Bob from unestablished Alices
|
||||||
|
|
||||||
2014-08-22 zzz
|
2014-08-22 zzz
|
||||||
* SigTypes:
|
* SigTypes:
|
||||||
- Add isSupportedSince(), use in floodfill selection
|
- Add isSupportedSince(), use in floodfill selection
|
||||||
|
@ -18,7 +18,7 @@ public class RouterVersion {
|
|||||||
/** deprecated */
|
/** deprecated */
|
||||||
public final static String ID = "Monotone";
|
public final static String ID = "Monotone";
|
||||||
public final static String VERSION = CoreVersion.VERSION;
|
public final static String VERSION = CoreVersion.VERSION;
|
||||||
public final static long BUILD = 9;
|
public final static long BUILD = 10;
|
||||||
|
|
||||||
/** for example "-test" */
|
/** for example "-test" */
|
||||||
public final static String EXTRA = "";
|
public final static String EXTRA = "";
|
||||||
|
Reference in New Issue
Block a user