Changeset 6670209


Ignore:
Timestamp:
Jan 10, 2011 5:14:34 PM (9 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
1ae6c28
Parents:
1580636
Message:

i2psnark:

  • Update session options when max bandwidth changes
  • BufferedStream? cleanup and comments
  • torrent name display tweak
  • findbugs
Location:
apps/i2psnark/java/src/org/klomp/snark
Files:
11 edited

Legend:

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

    r1580636 r6670209  
    180180              InputStream in = _socket.getInputStream();
    181181              OutputStream out = _socket.getOutputStream();
    182 
    183               if (true) {
    184                   in = new BufferedInputStream(in);
    185                   //out = new BufferedOutputStream(out);
    186               }
     182              // this is for the readahead in PeerAcceptor.connection()
     183              in = new BufferedInputStream(in);
    187184              if (_log.shouldLog(Log.DEBUG))
    188185                  _log.debug("Handling socket from " + _socket.getPeerDestination().calculateHash().toBase64());
  • apps/i2psnark/java/src/org/klomp/snark/I2PSnarkUtil.java

    r1580636 r6670209  
    7272    public static final int DEFAULT_MAX_UP_BW = 8;  //KBps
    7373    public static final int MAX_CONNECTIONS = 16; // per torrent
     74    private static final String PROP_MAX_BW = "i2cp.outboundBytesPerSecond";
    7475    private static final boolean ENABLE_DHT = true;
    7576
     
    133134    }
    134135   
     136    /**
     137     *  @param KBps
     138     */
    135139    public void setMaxUpBW(int limit) {
    136140        _maxUpBW = limit;
     141        _opts.put(PROP_MAX_BW, Integer.toString(limit * (1024 * 6 / 5)));   // add a little for overhead
    137142        _configured = true;
     143        if (_manager != null) {
     144            I2PSession sess = _manager.getSession();
     145            if (sess != null) {
     146                Properties newProps = new Properties();
     147                newProps.putAll(_opts);
     148                sess.updateOptions(newProps);
     149            }
     150        }
    138151    }
    139152   
     
    155168    public boolean getEepProxySet() { return _shouldProxy; }
    156169    public int getMaxUploaders() { return _maxUploaders; }
     170
     171    /**
     172     *  @return KBps
     173     */
    157174    public int getMaxUpBW() { return _maxUpBW; }
    158175    public int getMaxConnections() { return _maxConnections; }
     
    167184            if (_log.shouldLog(Log.DEBUG))
    168185                _log.debug("Connecting to I2P", new Exception("I did it"));
    169             Properties opts = new Properties();
     186            Properties opts = _context.getProperties();
    170187            if (_opts != null) {
    171188                for (Iterator iter = _opts.keySet().iterator(); iter.hasNext(); ) {
  • apps/i2psnark/java/src/org/klomp/snark/MetaInfo.java

    r1580636 r6670209  
    190190              throw new InvalidBEncodingException("Missing length number");
    191191            long len = val.getLong();
    192             m_lengths.add(new Long(len));
     192            m_lengths.add(Long.valueOf(len));
    193193            l += len;
    194194
     
    439439    info.put("pieces", piece_hashes);
    440440    if (files == null)
    441       info.put("length", new Long(length));
     441      info.put("length", Long.valueOf(length));
    442442    else
    443443      {
  • apps/i2psnark/java/src/org/klomp/snark/Peer.java

    r1580636 r6670209  
    2121package org.klomp.snark;
    2222
    23 import java.io.BufferedInputStream;
    2423import java.io.DataInputStream;
    2524import java.io.DataOutputStream;
     
    232231            }
    233232            InputStream in = sock.getInputStream();
    234             OutputStream out = sock.getOutputStream(); //new BufferedOutputStream(sock.getOutputStream());
    235             if (true) {
    236                 // buffered output streams are internally synchronized, so we can't get through to the underlying
    237                 // I2PSocket's MessageOutputStream to close() it if we are blocking on a write(...).  Oh, and the
    238                 // buffer is unnecessary anyway, as unbuffered access lets the streaming lib do the 'right thing'.
    239                 //out = new BufferedOutputStream(out);
    240                 in = new BufferedInputStream(sock.getInputStream());
    241             }
    242             //BufferedInputStream bis
    243             //  = new BufferedInputStream(sock.getInputStream());
    244             //BufferedOutputStream bos
    245             //  = new BufferedOutputStream(sock.getOutputStream());
    246             byte [] id = handshake(in, out); //handshake(bis, bos);
     233            OutputStream out = sock.getOutputStream();
     234            byte [] id = handshake(in, out);
    247235            byte [] expected_id = peerID.getID();
    248236            if (expected_id == null) {
     
    329317   * reported by the other side.
    330318   */
    331   private byte[] handshake(InputStream in, OutputStream out) //BufferedInputStream bis, BufferedOutputStream bos)
     319  private byte[] handshake(InputStream in, OutputStream out)
    332320    throws IOException
    333321  {
  • apps/i2psnark/java/src/org/klomp/snark/PeerCheckerTask.java

    r1580636 r6670209  
    211211                _util.getDHT().announce(coordinator.getInfoHash(), peer.getPeerID().getDestHash());
    212212            }
     213            // send PEX
    213214          }
    214215
  • apps/i2psnark/java/src/org/klomp/snark/PeerCoordinator.java

    r1580636 r6670209  
    11861186   */
    11871187  public void gotPeers(Peer peer, List<PeerID> peers) {
    1188 
     1188      // spin off thread or timer task to do a new Peer() and an addPeer() for each one
    11891189  }
    11901190
  • apps/i2psnark/java/src/org/klomp/snark/Piece.java

    r1580636 r6670209  
    3636    @Override
    3737    public boolean equals(Object o) {
     38        if (o == null) return false;
    3839        if (o instanceof Piece) {
    39             if (o == null) return false;
    4040            return this.id == ((Piece)o).id;
    4141        }
  • apps/i2psnark/java/src/org/klomp/snark/Snark.java

    r1580636 r6670209  
    109109              System.out.println("OOM in the OOM");
    110110          }
    111           System.exit(0);
     111          //System.exit(0);
    112112      }
    113113     
     
    981981    System.out.println
    982982      ("         \tor (with --share) a file to share.");
    983     System.exit(-1);
    984983  }
    985984
     
    11181117  }
    11191118
     1119  /** SnarkSnutdown callback unused */
    11201120  public void shutdown()
    11211121  {
    11221122    // Should not be necessary since all non-deamon threads should
    11231123    // have died. But in reality this does not always happen.
    1124     System.exit(0);
     1124    //System.exit(0);
    11251125  }
    11261126 
  • apps/i2psnark/java/src/org/klomp/snark/SnarkManager.java

    r1580636 r6670209  
    248248            }
    249249        }
    250         if (i2cpHost != null) {
    251             _util.setI2CPConfig(i2cpHost, i2cpPort, i2cpOpts);
    252             if (_log.shouldLog(Log.DEBUG))
    253                 _log.debug("Configuring with I2CP options " + i2cpOpts);
    254         }
     250        _util.setI2CPConfig(i2cpHost, i2cpPort, i2cpOpts);
     251        if (_log.shouldLog(Log.DEBUG))
     252            _log.debug("Configuring with I2CP options " + i2cpOpts);
    255253        //I2PSnarkUtil.instance().setI2CPConfig("66.111.51.110", 7654, new Properties());
    256254        //String eepHost = _config.getProperty(PROP_EEP_HOST);
     
    339337
    340338        }
     339        // FIXME do this even if == null
    341340        if (i2cpHost != null) {
    342341            int oldI2CPPort = _util.getI2CPPort();
     
    384383                    p.putAll(opts);
    385384                    _util.setI2CPConfig(i2cpHost, port, p);
     385                    _util.setMaxUpBW(getInt(PROP_UPBW_MAX, DEFAULT_MAX_UP_BW));
    386386                    addMessage(_("I2CP and tunnel changes will take effect after stopping all torrents"));
    387387                    if (_log.shouldLog(Log.DEBUG))
     
    397397                    addMessage(_("I2CP settings changed to {0}", i2cpHost + ":" + port + " (" + i2cpOpts.trim() + ")"));
    398398                    _util.setI2CPConfig(i2cpHost, port, p);
     399                    _util.setMaxUpBW(getInt(PROP_UPBW_MAX, DEFAULT_MAX_UP_BW));
    399400                    boolean ok = _util.connect();
    400401                    if (!ok) {
  • apps/i2psnark/java/src/org/klomp/snark/Storage.java

    r1580636 r6670209  
    106106        long length = lengths[i];
    107107        total += length;
    108         lengthsList.add(new Long(length));
     108        lengthsList.add(Long.valueOf(length));
    109109      }
    110110
     
    754754    // XXX - Is this the best way to make sure we have enough space for
    755755    // the whole file?
    756     listener.storageCreateFile(this, names[nr], lengths[nr]);
     756    if (listener != null)
     757        listener.storageCreateFile(this, names[nr], lengths[nr]);
    757758    final int ZEROBLOCKSIZE = metainfo.getPieceLength(0);
    758759    byte[] zeros;
  • apps/i2psnark/java/src/org/klomp/snark/web/I2PSnarkServlet.java

    r1580636 r6670209  
    756756        String fullFilename = filename;
    757757        if (filename.length() > MAX_DISPLAYED_FILENAME_LENGTH) {
    758             fullFilename = new String(filename);
    759             filename = filename.substring(0, MAX_DISPLAYED_FILENAME_LENGTH) + "&hellip;";
     758            String start = filename.substring(0, MAX_DISPLAYED_FILENAME_LENGTH);
     759            if (start.indexOf(" ") < 0 && start.indexOf("-") < 0) {
     760                // browser has nowhere to break it
     761                fullFilename = filename;
     762                filename = start + "&hellip;";
     763            }
    760764        }
    761765        long total = snark.getTotalLength();
     
    10361040                    pct = (float) 101.0;
    10371041                    // until we get the metainfo we don't know how many pieces there are
    1038                     out.write("??");
     1042                    //out.write("??");
    10391043                }
    10401044                out.write("</td>\n\t");
     
    11351139
    11361140    private void writeAddForm(PrintWriter out, HttpServletRequest req) throws IOException {
    1137         String uri = req.getRequestURI();
    11381141        String newURL = req.getParameter("newURL");
    11391142        if ( (newURL == null) || (newURL.trim().length() <= 0) )
     
    11761179   
    11771180    private void writeSeedForm(PrintWriter out, HttpServletRequest req) throws IOException {
    1178         String uri = req.getRequestURI();
    11791181        String baseFile = req.getParameter("baseFile");
    11801182        if (baseFile == null || baseFile.trim().length() <= 0)
     
    12361238   
    12371239    private void writeConfigForm(PrintWriter out, HttpServletRequest req) throws IOException {
    1238         String uri = req.getRequestURI();
    12391240        String dataDir = _manager.getDataDir().getAbsolutePath();
    12401241        boolean autoStart = _manager.shouldAutoStart();
     
    19151916                    }
    19161917
    1917                     // don't hold object from this MetaInfo
    1918                     String name = new String(info.getName());
     1918                    String name = info.getName();
    19191919                    name = Storage.filterName(name);
    19201920                    name = name + ".torrent";
Note: See TracChangeset for help on using the changeset viewer.