Changeset 8ee660c2


Ignore:
Timestamp:
Aug 27, 2014 4:00:02 PM (7 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
59504de
Parents:
310cd54
Message:

i2psnark:

  • Persist uploaded count (tickets #1034, #1298)
  • Show uploaded count even when stopped
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • apps/i2psnark/java/src/org/klomp/snark/CompleteListener.java

    r310cd54 r8ee660c2  
    5555    public void gotPiece(Snark snark);
    5656
    57     // not really listeners but the easiest way to get back to an optional SnarkManager
     57    /** not really listeners but the easiest way to get back to an optional SnarkManager */
    5858    public long getSavedTorrentTime(Snark snark);
    5959    public BitField getSavedTorrentBitField(Snark snark);
     60    /**
     61     * @since 0.9.15
     62     */
    6063    public boolean getSavedPreserveNamesSetting(Snark snark);
     64    /**
     65     * @since 0.9.15
     66     */
     67    public long getSavedUploaded(Snark snark);
    6168}
  • apps/i2psnark/java/src/org/klomp/snark/PeerCoordinator.java

    r310cd54 r8ee660c2  
    280280  {
    281281    return uploaded;
     282  }
     283
     284  /**
     285   *  Sets the initial total of uploaded bytes of all peers (from a saved status)
     286   *  @since 0.9.15
     287   */
     288  public void setUploaded(long up) {
     289      uploaded = up;
    282290  }
    283291
  • apps/i2psnark/java/src/org/klomp/snark/Snark.java

    r310cd54 r8ee660c2  
    238238  // String indicating main activity
    239239  private volatile String activity = "Not started";
     240  private final long savedUploaded;
    240241
    241242
     
    464465*/
    465466   
     467    savedUploaded = (completeListener != null) ? completeListener.getSavedUploaded(this) : 0;
    466468    if (start)
    467469        startTorrent();
     
    489491    this.additionalTrackerURL = trackerURL;
    490492    this.rootDataDir = rootDir != null ? new File(rootDir) : null;   // null only for FetchAndAdd extension
     493    savedUploaded = 0;
    491494    stopped = true;
    492495    id = generateID();
     
    557560        activity = "Collecting pieces";
    558561        coordinator = new PeerCoordinator(_util, id, infoHash, meta, storage, this, this);
     562        coordinator.setUploaded(savedUploaded);
    559563        if (_peerCoordinatorSet != null) {
    560564            // multitorrent
     
    620624    Storage st = storage;
    621625    if (st != null) {
    622         boolean changed = storage.isChanged();
     626        boolean changed = storage.isChanged() || getUploaded() != savedUploaded;
    623627        try {
    624628            storage.close();
     
    774778        if (coord != null)
    775779            return coord.getUploaded();
    776         return 0;
     780        return savedUploaded;
    777781    }
    778782
  • apps/i2psnark/java/src/org/klomp/snark/SnarkManager.java

    r310cd54 r8ee660c2  
    9393    private static final String PROP_META_PRIORITY = "priority";
    9494    private static final String PROP_META_PRESERVE_NAMES = "preserveFileNames";
     95    private static final String PROP_META_UPLOADED = "uploaded";
    9596    //private static final String PROP_META_BITFIELD_SUFFIX = ".bitfield";
    9697    //private static final String PROP_META_PRIORITY_SUFFIX = ".priority";
     
    13581359            }
    13591360            // so addTorrent won't recheck
    1360             saveTorrentStatus(metainfo, bitfield, null, baseFile, true); // no file priorities
     1361            saveTorrentStatus(metainfo, bitfield, null, baseFile, true, 0); // no file priorities
    13611362            try {
    13621363                locked_writeMetaInfo(metainfo, filename, areFilesPublic());
     
    15231524        return Boolean.parseBoolean(config.getProperty(PROP_META_PRESERVE_NAMES));
    15241525    }
     1526
     1527    /**
     1528     * Get setting for a torrent from the config file.
     1529     * @return setting, 0 if not found
     1530     * @since 0.9.15
     1531     */
     1532    public long getSavedUploaded(Snark snark) {
     1533        Properties config = getConfig(snark);
     1534        if (config != null) {
     1535            try {
     1536                return Long.parseLong(config.getProperty(PROP_META_UPLOADED));
     1537            } catch (NumberFormatException nfe) {}
     1538        }
     1539        return 0;
     1540    }
    15251541   
    15261542    /**
     
    15361552            return;
    15371553        saveTorrentStatus(meta, storage.getBitField(), storage.getFilePriorities(),
    1538                           storage.getBase(), storage.getPreserveFileNames());
     1554                          storage.getBase(), storage.getPreserveFileNames(),
     1555                          snark.getUploaded());
    15391556    }
    15401557
     
    15511568     */
    15521569    private void saveTorrentStatus(MetaInfo metainfo, BitField bitfield, int[] priorities,
    1553                                    File base, boolean preserveNames) {
     1570                                   File base, boolean preserveNames, long uploaded) {
    15541571        synchronized (_configLock) {
    1555             locked_saveTorrentStatus(metainfo, bitfield, priorities, base, preserveNames);
     1572            locked_saveTorrentStatus(metainfo, bitfield, priorities, base, preserveNames, uploaded);
    15561573        }
    15571574    }
    15581575
    15591576    private void locked_saveTorrentStatus(MetaInfo metainfo, BitField bitfield, int[] priorities,
    1560                                           File base, boolean preserveNames) {
     1577                                          File base, boolean preserveNames, long uploaded) {
    15611578        byte[] ih = metainfo.getInfoHash();
    15621579        String bfs;
     
    15711588        config.setProperty(PROP_META_BITFIELD, bfs);
    15721589        config.setProperty(PROP_META_PRESERVE_NAMES, Boolean.toString(preserveNames));
     1590        config.setProperty(PROP_META_UPLOADED, Long.toString(uploaded));
    15731591        if (base != null)
    15741592            config.setProperty(PROP_META_BASE, base.getAbsolutePath());
     
    18271845        if (meta != null && storage != null)
    18281846            saveTorrentStatus(meta, storage.getBitField(), storage.getFilePriorities(),
    1829                               storage.getBase(), storage.getPreserveFileNames());
     1847                              storage.getBase(), storage.getPreserveFileNames(), snark.getUploaded());
    18301848    }
    18311849   
     
    18501868            }
    18511869            saveTorrentStatus(meta, storage.getBitField(), null,
    1852                               storage.getBase(), storage.getPreserveFileNames()); // no file priorities
     1870                              storage.getBase(), storage.getPreserveFileNames(), 0);
    18531871            // temp for addMessage() in case canonical throws
    18541872            String name = storage.getBaseName();
  • apps/i2psnark/java/src/org/klomp/snark/UpdateRunner.java

    r310cd54 r8ee660c2  
    296296    }
    297297
     298    public long getSavedUploaded(Snark snark) {
     299        return _smgr.getSavedUploaded(snark);
     300    }
     301
    298302    //////// end CompleteListener methods
    299303
  • apps/i2psnark/java/src/org/klomp/snark/web/I2PSnarkServlet.java

    r310cd54 r8ee660c2  
    499499        out.write("\">");
    500500        out.write("</th>\n<th align=\"right\">");
    501         if (_manager.util().connected() && !snarks.isEmpty()) {
     501        if (!snarks.isEmpty()) {
    502502            out.write("<img border=\"0\" src=\"" + _imgPath + "head_tx.png\" title=\"");
    503503            out.write(_("Uploaded"));
     
    14661466        out.write("</td>\n\t");
    14671467        out.write("<td align=\"right\" class=\"snarkTorrentUploaded\">");
    1468         if(isRunning && isValid)
     1468        if (isValid && uploaded > 0)
    14691469           out.write(formatSize(uploaded));
    14701470        out.write("</td>\n\t");
    14711471        out.write("<td align=\"right\" class=\"snarkTorrentRateDown\">");
    1472         if(isRunning && needed > 0)
     1472        if (isRunning && needed > 0)
    14731473            out.write(formatSize(downBps) + "ps");
    14741474        out.write("</td>\n\t");
    14751475        out.write("<td align=\"right\" class=\"snarkTorrentRateUp\">");
    1476         if(isRunning && isValid)
     1476        if (isRunning && isValid)
    14771477            out.write(formatSize(upBps) + "ps");
    14781478        out.write("</td>\n\t");
  • history.txt

    r310cd54 r8ee660c2  
     12014-08-27 zzz
     2 * i2psnark: Persist uploaded count (tickets #1034, #1298)
     3
     42014-08-23 zzz
     5 * Console, i2psnark, i2ptunnel: Escape fixes and cleanups
     6 * SSU: Drop peer tests as Bob from unestablished Alices
     7
    182014-08-22 zzz
    29 * SigTypes:
  • router/java/src/net/i2p/router/RouterVersion.java

    r310cd54 r8ee660c2  
    1919    public final static String ID = "Monotone";
    2020    public final static String VERSION = CoreVersion.VERSION;
    21     public final static long BUILD = 9;
     21    public final static long BUILD = 10;
    2222
    2323    /** for example "-test" */
Note: See TracChangeset for help on using the changeset viewer.