i2psnark:

- Persist uploaded count (tickets #1034, #1298)
 - Show uploaded count even when stopped
This commit is contained in:
zzz
2014-08-27 16:00:02 +00:00
parent 310cd54aa0
commit 8ee660c238
8 changed files with 63 additions and 15 deletions

View File

@ -54,8 +54,15 @@ public interface CompleteListener {
*/
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 BitField getSavedTorrentBitField(Snark snark);
/**
* @since 0.9.15
*/
public boolean getSavedPreserveNamesSetting(Snark snark);
/**
* @since 0.9.15
*/
public long getSavedUploaded(Snark snark);
}

View File

@ -281,6 +281,14 @@ class PeerCoordinator implements PeerListener
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.
*/

View File

@ -237,6 +237,7 @@ public class Snark
private volatile boolean _autoStoppable;
// String indicating main activity
private volatile String activity = "Not started";
private final long savedUploaded;
/**
@ -463,6 +464,7 @@ public class Snark
trackerclient = new TrackerClient(meta, coordinator);
*/
savedUploaded = (completeListener != null) ? completeListener.getSavedUploaded(this) : 0;
if (start)
startTorrent();
}
@ -488,6 +490,7 @@ public class Snark
this.infoHash = ih;
this.additionalTrackerURL = trackerURL;
this.rootDataDir = rootDir != null ? new File(rootDir) : null; // null only for FetchAndAdd extension
savedUploaded = 0;
stopped = true;
id = generateID();
@ -556,6 +559,7 @@ public class Snark
_log.info("Starting PeerCoordinator, ConnectionAcceptor, and TrackerClient");
activity = "Collecting pieces";
coordinator = new PeerCoordinator(_util, id, infoHash, meta, storage, this, this);
coordinator.setUploaded(savedUploaded);
if (_peerCoordinatorSet != null) {
// multitorrent
_peerCoordinatorSet.add(coordinator);
@ -619,7 +623,7 @@ public class Snark
pc.halt();
Storage st = storage;
if (st != null) {
boolean changed = storage.isChanged();
boolean changed = storage.isChanged() || getUploaded() != savedUploaded;
try {
storage.close();
} catch (IOException ioe) {
@ -773,7 +777,7 @@ public class Snark
PeerCoordinator coord = coordinator;
if (coord != null)
return coord.getUploaded();
return 0;
return savedUploaded;
}
/**

View File

@ -92,6 +92,7 @@ public class SnarkManager implements CompleteListener {
private static final String PROP_META_BITFIELD = "bitfield";
private static final String PROP_META_PRIORITY = "priority";
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_PRIORITY_SUFFIX = ".priority";
private static final String PROP_META_MAGNET_PREFIX = "i2psnark.magnet.";
@ -1357,7 +1358,7 @@ public class SnarkManager implements CompleteListener {
return false;
}
// 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 {
locked_writeMetaInfo(metainfo, filename, areFilesPublic());
// hold the lock for a long time
@ -1523,6 +1524,21 @@ public class SnarkManager implements CompleteListener {
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
* for that torrent. Does nothing for magnets.
@ -1535,7 +1551,8 @@ public class SnarkManager implements CompleteListener {
if (meta == null || storage == null)
return;
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
*/
private void saveTorrentStatus(MetaInfo metainfo, BitField bitfield, int[] priorities,
File base, boolean preserveNames) {
File base, boolean preserveNames, long uploaded) {
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,
File base, boolean preserveNames) {
File base, boolean preserveNames, long uploaded) {
byte[] ih = metainfo.getInfoHash();
String bfs;
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_BITFIELD, bfs);
config.setProperty(PROP_META_PRESERVE_NAMES, Boolean.toString(preserveNames));
config.setProperty(PROP_META_UPLOADED, Long.toString(uploaded));
if (base != null)
config.setProperty(PROP_META_BASE, base.getAbsolutePath());
@ -1826,7 +1844,7 @@ public class SnarkManager implements CompleteListener {
Storage storage = snark.getStorage();
if (meta != null && storage != null)
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;
}
saveTorrentStatus(meta, storage.getBitField(), null,
storage.getBase(), storage.getPreserveFileNames()); // no file priorities
storage.getBase(), storage.getPreserveFileNames(), 0);
// temp for addMessage() in case canonical throws
String name = storage.getBaseName();
try {

View File

@ -295,6 +295,10 @@ class UpdateRunner implements UpdateTask, CompleteListener {
return _smgr.getSavedPreserveNamesSetting(snark);
}
public long getSavedUploaded(Snark snark) {
return _smgr.getSavedUploaded(snark);
}
//////// end CompleteListener methods
private static String linkify(String url) {

View File

@ -498,7 +498,7 @@ public class I2PSnarkServlet extends BasicServlet {
out.write(_("RX"));
out.write("\">");
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(_("Uploaded"));
out.write("\" alt=\"");
@ -1465,15 +1465,15 @@ public class I2PSnarkServlet extends BasicServlet {
// out.write("??"); // no meta size yet
out.write("</td>\n\t");
out.write("<td align=\"right\" class=\"snarkTorrentUploaded\">");
if(isRunning && isValid)
if (isValid && uploaded > 0)
out.write(formatSize(uploaded));
out.write("</td>\n\t");
out.write("<td align=\"right\" class=\"snarkTorrentRateDown\">");
if(isRunning && needed > 0)
if (isRunning && needed > 0)
out.write(formatSize(downBps) + "ps");
out.write("</td>\n\t");
out.write("<td align=\"right\" class=\"snarkTorrentRateUp\">");
if(isRunning && isValid)
if (isRunning && isValid)
out.write(formatSize(upBps) + "ps");
out.write("</td>\n\t");
out.write("<td align=\"center\" class=\"snarkTorrentAction\">");

View File

@ -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
* SigTypes:
- Add isSupportedSince(), use in floodfill selection

View File

@ -18,7 +18,7 @@ public class RouterVersion {
/** deprecated */
public final static String ID = "Monotone";
public final static String VERSION = CoreVersion.VERSION;
public final static long BUILD = 9;
public final static long BUILD = 10;
/** for example "-test" */
public final static String EXTRA = "";