Changeset 4c72c08


Ignore:
Timestamp:
Nov 18, 2015 1:43:14 PM (5 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
1e89fac
Parents:
679fe9b
Message:

i2psnark: Add skipped length on details page
reorder some logging
volatile

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

Legend:

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

    r679fe9b r4c72c08  
    6363  // Keeps state for in/out connections.  Non-null when the handshake
    6464  // was successful, the connection setup and runs
    65   PeerState state;
     65  volatile PeerState state;
    6666
    6767  /** shared across all peers on this torrent */
  • apps/i2psnark/java/src/org/klomp/snark/PeerConnectionIn.java

    r679fe9b r4c72c08  
    4040                                                   MagnetState.CHUNK_SIZE + 100);  // 100 for the ext msg dictionary
    4141
    42   private Thread thread;
     42  private volatile Thread thread;
    4343  private volatile boolean quit;
    4444
     
    7676    try
    7777      {
    78         PeerState ps = peer.state;
    79         while (!quit && ps != null)
     78        while (!quit)
    8079          {
     80            final PeerState ps = peer.state;
     81            if (ps == null)
     82                break;
     83
    8184            // Common variables used for some messages.
    8285            int piece;
     
    9295            if (i == 0)
    9396              {
     97                if (_log.shouldLog(Log.DEBUG))
     98                    _log.debug("Received keepalive from " + peer);
    9499                ps.keepAliveMessage();
    95                 if (_log.shouldLog(Log.DEBUG))
    96                     _log.debug("Received keepalive from " + peer);
    97100                continue;
    98101              }
     
    102105              {
    103106              case Message.CHOKE:
     107                if (_log.shouldLog(Log.DEBUG))
     108                    _log.debug("Received choke from " + peer);
    104109                ps.chokeMessage(true);
    105                 if (_log.shouldLog(Log.DEBUG))
    106                     _log.debug("Received choke from " + peer);
    107110                break;
    108111
    109112              case Message.UNCHOKE:
     113                if (_log.shouldLog(Log.DEBUG))
     114                    _log.debug("Received unchoke from " + peer);
    110115                ps.chokeMessage(false);
    111                 if (_log.shouldLog(Log.DEBUG))
    112                     _log.debug("Received unchoke from " + peer);
    113116                break;
    114117
    115118              case Message.INTERESTED:
     119                if (_log.shouldLog(Log.DEBUG))
     120                    _log.debug("Received interested from " + peer);
    116121                ps.interestedMessage(true);
    117                 if (_log.shouldLog(Log.DEBUG))
    118                     _log.debug("Received interested from " + peer);
    119122                break;
    120123
    121124              case Message.UNINTERESTED:
     125                if (_log.shouldLog(Log.DEBUG))
     126                    _log.debug("Received not interested from " + peer);
    122127                ps.interestedMessage(false);
    123                 if (_log.shouldLog(Log.DEBUG))
    124                     _log.debug("Received not interested from " + peer);
    125128                break;
    126129
    127130              case Message.HAVE:
    128131                piece = din.readInt();
     132                if (_log.shouldLog(Log.DEBUG))
     133                    _log.debug("Received havePiece(" + piece + ") from " + peer);
    129134                ps.haveMessage(piece);
    130                 if (_log.shouldLog(Log.DEBUG))
    131                     _log.debug("Received havePiece(" + piece + ") from " + peer);
    132135                break;
    133136
     
    135138                byte[] bitmap = new byte[i-1];
    136139                din.readFully(bitmap);
     140                if (_log.shouldLog(Log.DEBUG))
     141                    _log.debug("Received bitmap from " + peer  + ": size=" + (i-1) /* + ": " + ps.bitfield */ );
    137142                ps.bitfieldMessage(bitmap);
    138                 if (_log.shouldLog(Log.DEBUG))
    139                     _log.debug("Received bitmap from " + peer  + ": size=" + (i-1) /* + ": " + ps.bitfield */ );
    140143                break;
    141144
     
    144147                begin = din.readInt();
    145148                len = din.readInt();
     149                if (_log.shouldLog(Log.DEBUG))
     150                    _log.debug("Received request(" + piece + "," + begin + ") from " + peer);
    146151                ps.requestMessage(piece, begin, len);
    147                 if (_log.shouldLog(Log.DEBUG))
    148                     _log.debug("Received request(" + piece + "," + begin + ") from " + peer);
    149152                break;
    150153
     
    157160                  {
    158161                    req.read(din);
    159                     ps.pieceMessage(req);
    160162                    if (_log.shouldLog(Log.DEBUG))
    161163                        _log.debug("Received data(" + piece + "," + begin + ") from " + peer);
     164                    ps.pieceMessage(req);
    162165                  }
    163166                else
     
    176179                begin = din.readInt();
    177180                len = din.readInt();
     181                if (_log.shouldLog(Log.DEBUG))
     182                    _log.debug("Received cancel(" + piece + "," + begin + ") from " + peer);
    178183                ps.cancelMessage(piece, begin, len);
    179                 if (_log.shouldLog(Log.DEBUG))
    180                     _log.debug("Received cancel(" + piece + "," + begin + ") from " + peer);
    181184                break;
    182185
    183186              case Message.PORT:
    184187                int port = din.readUnsignedShort();
     188                if (_log.shouldLog(Log.DEBUG))
     189                    _log.debug("Received port message from " + peer);
    185190                ps.portMessage(port);
    186                 if (_log.shouldLog(Log.DEBUG))
    187                     _log.debug("Received port message from " + peer);
    188191                break;
    189192
     
    248251            _log.info("IOError talking with " + peer, ioe);
    249252      }
    250     catch (Throwable t)
     253    catch (RuntimeException t)
    251254      {
    252255        _log.error("Error talking with " + peer, t);
    253         if (t instanceof OutOfMemoryError)
    254             throw (OutOfMemoryError)t;
    255256      }
    256257    finally
  • apps/i2psnark/java/src/org/klomp/snark/Snark.java

    r679fe9b r4c72c08  
    913913
    914914    /**
     915     *  Bytes not received and set to skipped.
     916     *  This is not the same as the total of all skipped files,
     917     *  since pieces may span multiple files.
     918     *
     919     *  @return exact value. or 0 if no storage yet.
     920     *  @since 0.9.24
     921     */
     922    public long getSkippedLength() {
     923        PeerCoordinator coord = coordinator;
     924        if (coord != null) {
     925            // fast way
     926            long r = getRemainingLength();
     927            if (r <= 0)
     928                return 0;
     929            long n = coord.getNeededLength();
     930            return r - n;
     931        } else if (storage != null) {
     932            // slow way
     933            return storage.getSkippedLength();
     934        }
     935        return 0;
     936    }
     937
     938    /**
    915939     *  Does not account (i.e. includes) for skipped files.
    916940     *  @return number of pieces still needed (magnet mode or not), or -1 if unknown
  • apps/i2psnark/java/src/org/klomp/snark/Storage.java

    r679fe9b r4c72c08  
    515515          }
    516516          rv[i] = pri;
     517      }
     518      return rv;
     519  }
     520
     521  /**
     522   *  Call setPriority() for all changed files first,
     523   *  then call this.
     524   *  The length of all the pieces that are not yet downloaded,
     525   *  and are set to skipped.
     526   *  This is not the same as the total of all skipped files,
     527   *  since pieces may span multiple files.
     528   *
     529   *  @return 0 on error, if complete, or if only one file
     530   *  @since 0.9.24
     531   */
     532  public long getSkippedLength() {
     533      int[] pri = getPiecePriorities();
     534      if (pri == null)
     535          return 0;
     536      long rv = 0;
     537      final int end = pri.length - 1;
     538      for (int i = 0; i <= end; i++) {
     539          if (pri[i] <= -9 && !bitfield.get(i)) {
     540              rv += (i != end) ? piece_size : metainfo.getPieceLength(i);
     541          }
    517542      }
    518543      return rv;
  • apps/i2psnark/java/src/org/klomp/snark/web/I2PSnarkServlet.java

    r679fe9b r4c72c08  
    29172917                   .append(formatSize(needed));
    29182918            }
     2919            long skipped = snark.getSkippedLength();
     2920            if (skipped > 0) {
     2921                buf.append("&nbsp;");
     2922                toThemeImg(buf, "head_rx");
     2923                buf.append("&nbsp;<b>")
     2924                   .append(_t("Skipped"))
     2925                   .append(":</b> ")
     2926                   .append(formatSize(skipped));
     2927            }
    29192928            if (meta != null) {
    29202929                List<List<String>> files = meta.getFiles();
Note: See TracChangeset for help on using the changeset viewer.