Changeset 05b17e5


Ignore:
Timestamp:
Nov 9, 2009 5:09:53 PM (11 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
e3d9452
Parents:
13b3edfb
Message:
  • i2psnark:
    • Reject torrents with too many pieces
    • Reject torrents with a single file named *.torrent
    • Increase max piece size to 2MB (was 1MB), but reduce max number of connections to lessen ooms
Location:
apps/i2psnark/java/src/org/klomp/snark
Files:
3 edited

Legend:

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

    r13b3edfb r05b17e5  
    237237    synchronized(peers)
    238238      {
    239         return !halted && peers.size() < _util.getMaxConnections();
     239        return !halted && peers.size() < getMaxConnections();
    240240      }
    241241  }
    242242 
     243  /** reduce max if huge pieces to keep from ooming */
     244  private int getMaxConnections() {
     245    int size = metainfo.getPieceLength(0);
     246    int max = _util.getMaxConnections();
     247    if (size <= 1024*1024)
     248      return max;
     249    if (size <= 2*1024*1024)
     250      return (max + 1) / 2;
     251    return (max + 3) / 4;
     252  }
     253
    243254  public boolean halted() { return halted; }
    244255
     
    295306          }
    296307        // This is already checked in addPeer() but we could have gone over the limit since then
    297         else if (peers.size() >= _util.getMaxConnections())
     308        else if (peers.size() >= getMaxConnections())
    298309          {
    299310            if (_log.shouldLog(Log.WARN))
     
    351362        // This isn't a strict limit, as we may have several pending connections;
    352363        // thus there is an additional check in connected()
    353         need_more = (!peer.isConnected()) && peersize < _util.getMaxConnections();
     364        need_more = (!peer.isConnected()) && peersize < getMaxConnections();
    354365        // Check if we already have this peer before we build the connection
    355366        Peer old = peerIDInList(peer.getPeerID(), peers);
     
    379390        _log.info("Add peer already connected: " + peer);
    380391      else
    381         _log.info("Connections: " + peersize + "/" + _util.getMaxConnections()
     392        _log.info("Connections: " + peersize + "/" + getMaxConnections()
    382393                  + " not accepting extra peer: " + peer);
    383394    }
  • apps/i2psnark/java/src/org/klomp/snark/SnarkManager.java

    r13b3edfb r05b17e5  
    553553        if ( (files != null) && (files.size() > MAX_FILES_PER_TORRENT) ) {
    554554            return "Too many files in " + info.getName() + " (" + files.size() + "), deleting it!";
     555        } else if ( (files == null) && (info.getName().endsWith(".torrent")) ) {
     556            return "Torrent file " + info.getName() + " cannot end in '.torrent', deleting it!";
    555557        } else if (info.getPieces() <= 0) {
    556558            return "No pieces in " + info.getName() + "?  deleting it!";
     559        } else if (info.getPieces() > Storage.MAX_PIECES) {
     560            return "Too many pieces in " + info.getName() + ", limit is " + Storage.MAX_PIECES + ", deleting it!";
    557561        } else if (info.getPieceLength(0) > Storage.MAX_PIECE_SIZE) {
    558562            return "Pieces are too large in " + info.getName() + " (" + DataHelper.formatSize(info.getPieceLength(0)) +
    559                    "B), deleting it.";
     563                   "B, limit is " + DataHelper.formatSize(Storage.MAX_PIECE_SIZE) + "B), deleting it.";
    560564        } else if (info.getTotalLength() > Storage.MAX_TOTAL_SIZE) {
    561565            System.out.println("torrent info: " + info.toString());
  • apps/i2psnark/java/src/org/klomp/snark/Storage.java

    r13b3edfb r05b17e5  
    5858  /** The default piece size. */
    5959  private static final int MIN_PIECE_SIZE = 256*1024;
    60   public static final int MAX_PIECE_SIZE = 1024*1024;
     60  /** note that we start reducing max number of peer connections above 1MB */
     61  public static final int MAX_PIECE_SIZE = 2*1024*1024;
    6162  /** The maximum number of pieces in a torrent. */
    6263  public static final int MAX_PIECES = 10*1024;
Note: See TracChangeset for help on using the changeset viewer.