Changeset d34087f for apps


Ignore:
Timestamp:
Jul 12, 2018 11:19:56 AM (2 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
e24ebf4
Parents:
b78870d
Message:

i2psnark: Stub out support for sequential download (ticket #2234)

Location:
apps/i2psnark/java/src/org/klomp/snark
Files:
2 edited

Legend:

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

    rb78870d rd34087f  
    106106    private static final String PROP_META_ADDED = "added";
    107107    private static final String PROP_META_COMPLETED = "completed";
     108    private static final String PROP_META_INORDER = "inOrder";
    108109    private static final String PROP_META_MAGNET = "magnet";
    109110    private static final String PROP_META_MAGNET_DN = "magnet_dn";
     
    17601761                return false;
    17611762            } else if (bitfield != null) {
    1762                 saveTorrentStatus(metainfo, bitfield, null, baseFile, true, 0, true); // no file priorities
     1763                saveTorrentStatus(metainfo, bitfield, null, false, baseFile, true, 0, true); // no file priorities
    17631764            }
    17641765            // so addTorrent won't recheck           
     
    18991900        Properties config = getConfig(snark);
    19001901        String pri = config.getProperty(PROP_META_PRIORITY);
    1901         if (pri == null)
    1902             return;
    1903         int filecount = metainfo.getFiles().size();
    1904         int[] rv = new int[filecount];
    1905         String[] arr = DataHelper.split(pri, ",");
    1906         for (int i = 0; i < filecount && i < arr.length; i++) {
    1907             if (arr[i].length() > 0) {
    1908                 try {
    1909                     rv[i] = Integer.parseInt(arr[i]);
    1910                 } catch (Throwable t) {}
    1911             }
    1912         }
    1913         storage.setFilePriorities(rv);
     1902        if (pri != null) {
     1903            int filecount = metainfo.getFiles().size();
     1904            int[] rv = new int[filecount];
     1905            String[] arr = DataHelper.split(pri, ",");
     1906            for (int i = 0; i < filecount && i < arr.length; i++) {
     1907                if (arr[i].length() > 0) {
     1908                    try {
     1909                        rv[i] = Integer.parseInt(arr[i]);
     1910                    } catch (Throwable t) {}
     1911                }
     1912            }
     1913            storage.setFilePriorities(rv);
     1914        }
     1915        boolean inOrder = Boolean.parseBoolean(config.getProperty(PROP_META_INORDER));
     1916        storage.setInOrder(inOrder);
    19141917    }
    19151918
     
    20182021        if (meta == null || storage == null)
    20192022            return;
    2020         saveTorrentStatus(meta, storage.getBitField(), storage.getFilePriorities(),
     2023        saveTorrentStatus(meta, storage.getBitField(), storage.getFilePriorities(), storage.getInOrder(),
    20212024                          storage.getBase(), storage.getPreserveFileNames(),
    20222025                          snark.getUploaded(), snark.isStopped(), comments);
     
    20352038     * @param base may be null
    20362039     */
    2037     private void saveTorrentStatus(MetaInfo metainfo, BitField bitfield, int[] priorities,
     2040    private void saveTorrentStatus(MetaInfo metainfo, BitField bitfield, int[] priorities, boolean inOrder,
    20382041                                   File base, boolean preserveNames, long uploaded, boolean stopped) {
    2039         saveTorrentStatus(metainfo, bitfield, priorities, base, preserveNames, uploaded, stopped, null);
     2042        saveTorrentStatus(metainfo, bitfield, priorities, inOrder, base, preserveNames, uploaded, stopped, null);
    20402043    }
    20412044
     
    20442047     * @since 0.9.31
    20452048     */
    2046     private void saveTorrentStatus(MetaInfo metainfo, BitField bitfield, int[] priorities,
     2049    private void saveTorrentStatus(MetaInfo metainfo, BitField bitfield, int[] priorities, boolean inOrder,
    20472050                                   File base, boolean preserveNames, long uploaded, boolean stopped,
    20482051                                   Boolean comments) {
    20492052        synchronized (_configLock) {
    2050             locked_saveTorrentStatus(metainfo, bitfield, priorities, base, preserveNames, uploaded, stopped, comments);
    2051         }
    2052     }
    2053 
    2054     private void locked_saveTorrentStatus(MetaInfo metainfo, BitField bitfield, int[] priorities,
     2053            locked_saveTorrentStatus(metainfo, bitfield, priorities, inOrder, base, preserveNames, uploaded, stopped, comments);
     2054        }
     2055    }
     2056
     2057    private void locked_saveTorrentStatus(MetaInfo metainfo, BitField bitfield, int[] priorities, boolean inOrder,
    20552058                                          File base, boolean preserveNames, long uploaded, boolean stopped,
    20562059                                          Boolean comments) {
     
    20782081        boolean running = !stopped;
    20792082        config.setProperty(PROP_META_RUNNING, Boolean.toString(running));
     2083        config.setProperty(PROP_META_INORDER, Boolean.toString(inOrder));
    20802084        if (base != null)
    20812085            config.setProperty(PROP_META_BASE, base.getAbsolutePath());
     
    20962100                StringBuilder buf = new StringBuilder(2 * priorities.length);
    20972101                for (int i = 0; i < priorities.length; i++) {
    2098                     if (priorities[i] != 0)
     2102                    // only output if !inOrder || !skipped so the string isn't too long
     2103                    if (priorities[i] != 0 &&
     2104                        (!inOrder || priorities[i] < 0))
    20992105                        buf.append(Integer.toString(priorities[i]));
    21002106                    if (i != priorities.length - 1)
     
    24442450        Storage storage = snark.getStorage();
    24452451        if (meta != null && storage != null)
    2446             saveTorrentStatus(meta, storage.getBitField(), storage.getFilePriorities(),
     2452            saveTorrentStatus(meta, storage.getBitField(), storage.getFilePriorities(), storage.getInOrder(),
    24472453                              storage.getBase(), storage.getPreserveFileNames(), snark.getUploaded(),
    24482454                              snark.isStopped());
     
    24682474                return null;
    24692475            }
    2470             saveTorrentStatus(meta, storage.getBitField(), null,
     2476            saveTorrentStatus(meta, storage.getBitField(), null, false,
    24712477                              storage.getBase(), storage.getPreserveFileNames(), 0,
    24722478                              snark.isStopped());
  • apps/i2psnark/java/src/org/klomp/snark/Storage.java

    rb78870d rd34087f  
    7373  private boolean changed;
    7474  private volatile boolean _isChecking;
     75  private boolean _inOrder;
    7576  private final AtomicInteger _allocateCount = new AtomicInteger();
    7677  private final AtomicInteger _checkProgress = new AtomicInteger();
     
    8384  public static final int MAX_PIECES = 32*1024;
    8485  public static final long MAX_TOTAL_SIZE = MAX_PIECE_SIZE * (long) MAX_PIECES;
     86  public static final int PRIORITY_SKIP = -9;
     87  public static final int PRIORITY_NORMAL = 0;
    8588
    8689  private static final Map<String, String> _filterNameCache = new ConcurrentHashMap<String, String>();
     
    146149   
    147150    long total = 0;
    148     ArrayList<Long> lengthsList = new ArrayList<Long>();
     151    ArrayList<Long> lengthsList = new ArrayList<Long>(_torrentFiles.size());
    149152    for (TorrentFile tf : _torrentFiles)
    150153      {
     
    179182    needed = 0;
    180183
    181     List<List<String>> files = new ArrayList<List<String>>();
     184    List<List<String>> files = new ArrayList<List<String>>(_torrentFiles.size());
    182185    for (TorrentFile tf : _torrentFiles)
    183186      {
     
    496499
    497500  /**
     501   *  @return as last set, default false
     502   *  @since 0.9.36
     503   */
     504  public boolean getInOrder() {
     505      return _inOrder;
     506  }
     507
     508  /**
     509   *  Call AFTER setFilePriorites() so we know what's skipped
     510   *  @param yes enable or not
     511   *  @since 0.9.36
     512   */
     513  public void setInOrder(boolean yes) {
     514      if (yes == _inOrder)
     515          return;
     516      _inOrder = yes;
     517      if (complete() || metainfo.getFiles() == null)
     518          return;
     519      if (yes) {
     520          int sz = _torrentFiles.size();
     521          for (int i = 0; i < sz; i++) {
     522              _torrentFiles.get(i).priority = sz - i;
     523          }
     524      } else {
     525          for (TorrentFile tf : _torrentFiles) {
     526              if (tf.priority > PRIORITY_NORMAL)
     527                  tf.priority = PRIORITY_NORMAL;
     528          }
     529      }
     530  }
     531
     532  /**
    498533   *  Call setPriority() for all changed files first,
    499534   *  then call this.
     
    514549          pcEnd += piece_size;
    515550          int pri = _torrentFiles.get(file).priority;
     551          // TODO if (_inOrder) ...
    516552          while (fileEnd <= pcEnd && file < _torrentFiles.size() - 1) {
    517553              file++;
     
    545581      final int end = pri.length - 1;
    546582      for (int i = 0; i <= end; i++) {
    547           if (pri[i] <= -9 && !bitfield.get(i)) {
     583          if (pri[i] <= PRIORITY_SKIP && !bitfield.get(i)) {
    548584              rv += (i != end) ? piece_size : metainfo.getPieceLength(i);
    549585          }
Note: See TracChangeset for help on using the changeset viewer.