Changeset 7a0f384


Ignore:
Timestamp:
Jul 8, 2018 1:13:21 PM (2 years ago)
Author:
meeh <meeh@…>
Branches:
master
Children:
2664c41
Parents:
27a0d4e (diff), dfa1470 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

merge of '6b3a264a4dddd9667ce22ed517fbfccd5d676f9f'

and '95e2b9f35eac4e0ca2160d2f554bb4cdba5c074d'

Files:
1 added
14 edited

Legend:

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

    r27a0d4e r7a0f384  
    519519            }
    520520        }
    521         out.write("</th>\n<th colspan=\"2\" align=\"left\">");
     521        out.write("</th>\n<th colspan=\"3\" align=\"left\">");
    522522        // cycle through sort by name or type
    523523        boolean isTypeSort = false;
     
    711711        if (total == 0) {
    712712            out.write("<tr class=\"snarkTorrentNoneLoaded\">" +
    713                       "<td colspan=\"11\">");
     713                      "<td colspan=\"12\">");
    714714            synchronized(this) {
    715715                File dd = _resourceBase;
     
    729729        } else /** if (snarks.size() > 1) */ {
    730730            out.write("<tfoot><tr>\n" +
    731                       "    <th id=\"snarkTorrentTotals\" align=\"left\" colspan=\"6\">");
     731                      "    <th id=\"snarkTorrentTotals\" align=\"left\" colspan=\"7\">");
    732732            out.write("<span id=\"totals\">");
    733733            out.write(_t("Totals"));
     
    775775                if (showDebug) {
    776776                    out.write("</tr>\n<tr class=\"dhtDebug\">" +
    777                               "<th colspan=\"11\">" +
     777                              "<th colspan=\"12\">" +
    778778                              "<div id=\"dhtDebugPanel\">" +
    779779                              "<input class=\"toggle_input\" id=\"toggle_debug\" type=\"checkbox\"><label class=\"toggleview\" for=\"toggle_debug\">");
     
    17041704        out.write("<tr class=\"" + rowClass + "\" id=\"" + b64Short + "\">" +
    17051705                  "<td class=\"snarkGraphicStatus\" align=\"center\">");
    1706         out.write(statusString + "</td>\n\t");
     1706        out.write(statusString);
    17071707
    17081708        // (i) icon column
    1709         out.write("<td class=\"snarkTrackerDetails\">");
     1709        out.write("</td>\n<td class=\"snarkTrackerDetails\">");
    17101710        if (isValid) {
    17111711            String announce = meta.getAnnounce();
     
    17461746        } else {
    17471747            out.write(toImg(icon));
     1748        }
     1749
     1750        // Comment icon column
     1751        out.write("</td>\n<td class=\"snarkCommentDetails\">");
     1752        if (isValid) {
     1753            CommentSet comments = snark.getComments();
     1754            if (comments != null && !comments.isEmpty()) {
     1755                StringBuilder buf = new StringBuilder(128);
     1756                buf.append("<a href=\"").append(encodedBaseName)
     1757                   .append("/#snarkCommentSection\" title=\"").append(_t("Comments"))
     1758                   .append("\">");
     1759                toThemeImg(buf, "comment", "", "");
     1760                buf.append("</a>");
     1761                out.write(buf.toString());
     1762            }
    17481763        }
    17491764
     
    19131928                out.write("<tr class=\"peerinfo " + rowClass + "\"><td class=\"snarkGraphicStatus\" title=\"");
    19141929                out.write(_t("Peer attached to swarm"));
    1915                 out.write("\"></td><td colspan=\"4\">");
     1930                out.write("\"></td><td colspan=\"5\">");
    19161931                PeerID pid = peer.getPeerID();
    19171932                String ch = pid != null ? pid.toString().substring(0, 4) : "????";
     
    20112026                          "</td></tr>\n\t");
    20122027                if (showDebug)
    2013                     out.write("<tr class=\"debuginfo " + rowClass + "\"><td class=\"snarkGraphicStatus\"></td><td colspan=\"10\">" + peer.getSocket() + "</td></tr>");
     2028                    out.write("<tr class=\"debuginfo " + rowClass + "\"><td class=\"snarkGraphicStatus\"></td><td colspan=\"11\">" + peer.getSocket() + "</td></tr>");
    20142029            }
    20152030        }
  • apps/routerconsole/java/src/net/i2p/router/web/RouterConsoleRunner.java

    r27a0d4e r7a0f384  
    77import java.io.Serializable;
    88import java.io.UnsupportedEncodingException;
    9 import java.net.*;
     9import java.net.InetAddress;
     10import java.net.Inet4Address;
     11import java.net.InetSocketAddress;
     12import java.net.ServerSocket;
    1013import java.util.ArrayList;
    1114import java.util.Collections;
  • history.txt

    r27a0d4e r7a0f384  
     12018-07-08 zzz
     2 * i2psnark: Add comment icon (ticket #2278)
     3 * NTCP2: Avoid possible NPEs (ticket #2286)
     4 * Transport: More efficient caching (ticket #2263)
     5
     62018-07-06 zzz
     7 * NTCP: Read all available data when able (ticket #2243)
     8 * SSU: Change remaining acks from List to Set (ticket #2258)
     9
     102018-07-05 zzz
     11 * i2psnark:
     12   - Fix IOOBE when stopping torrent that is allocating (ticket #2273)
     13   - Fix comments wrapping (ticket #2284)
     14 * NTCP2: Increase max message size
     15
    1162018-07-04 zzz
    217 * NTCP: Don't advertise interface address when configured for force-firewalled
  • installer/resources/themes/snark/classic/snark.css

    r27a0d4e r7a0f384  
    336336}
    337337
    338 .snarkTrackerDetails, .snarkTorrentDetails {
     338.snarkTrackerDetails, .snarkTorrentDetails, .snarkCommentDetails {
    339339     width: 16px !important;
    340340     text-align: center !important;
     
    344344}
    345345
    346 .snarkTrackerDetails img, .snarkTorrentDetails img, .snarkDirInfo td:first-child img {
     346.snarkTrackerDetails img, .snarkTorrentDetails img, .snarkCommentDetails img, .snarkDirInfo td:first-child img {
    347347     padding: 3px !important;
    348348     border: 1px solid transparent !important;
     
    351351.snarkTrackerDetails a:hover img, .snarkTrackerDetails a:focus img,
    352352.snarkTorrentDetails a:hover img, .snarkTorrentDetails a:focus img,
     353.snarkCommentDetails a:hover img, .snarkCommentDetails a:focus img,
    353354.snarkDirInfo td:first-child a:hover img, .snarkDirInfo td:first-child a:focus img {
    354355     border: 1px solid #f60 !important;
     
    359360}
    360361
    361 .snarkTrackerDetails a:active img, .snarkTorrentDetails a:active img, .snarkDirInfo td:first-child a:active img {
     362.snarkTrackerDetails a:active img, .snarkTorrentDetails a:active img, .snarkCommentDetails a:active img, .snarkDirInfo td:first-child a:active img {
    362363     box-shadow: inset 2px 2px 2px #337;
    363364     transform: scale(0.9);
     
    28432844}
    28442845
    2845 .snarkTorrentDetails {
     2846.snarkCommentDetails {
    28462847     padding-left: 10px !important;
    28472848     padding-right: 5px !important;
  • installer/resources/themes/snark/dark/snark.css

    r27a0d4e r7a0f384  
    460460}
    461461
    462 .snarkTrackerDetails, .snarkTorrentDetails {
     462.snarkTrackerDetails, .snarkTorrentDetails, .snarkCommentDetails {
    463463     width: 16px !important;
    464464     text-align: center !important;
     
    468468}
    469469
    470 .snarkTrackerDetails img, .snarkTorrentDetails img, .snarkDirInfo td:first-child img {
     470.snarkTrackerDetails img, .snarkTorrentDetails img, .snarkCommentDetails img, .snarkDirInfo td:first-child img {
    471471     padding: 3px !important;
    472472     border: 1px solid transparent !important;
     
    485485.snarkTrackerDetails a:hover img, .snarkTrackerDetails a:focus img,
    486486.snarkTorrentDetails a:hover img, .snarkTorrentDetails a:focus img,
     487.snarkCommentDetails a:hover img, .snarkCommentDetails a:focus img,
    487488.snarkDirInfo td:first-child a:hover img, .snarkDirInfo td:first-child a:focus img {
    488489     border: 1px solid #f60 !important;
     
    494495}
    495496
    496 .snarkTrackerDetails a:active img, .snarkTorrentDetails a:active img, .snarkDirInfo td:first-child a:active img {
     497.snarkTrackerDetails a:active img, .snarkTorrentDetails a:active img, .snarkCommentDetails a:active img, .snarkDirInfo td:first-child a:active img {
    497498     border: 1px solid #f90 !important;
    498499     box-shadow: inset 2px 2px 3px 3px #000;
     
    28832884}
    28842885
    2885 .snarkTrackerDetails, .SnarkTorrentDetails {
     2886.snarkTrackerDetails, .SnarkTorrentDetails, .snarkCommentDetails {
    28862887     width: 1% !important;
    28872888}
     
    30103011}
    30113012
    3012 .snarkTorrentDetails {
     3013.snarkCommentDetails {
    30133014     padding-left: 8px;
    30143015}
     
    30243025}
    30253026
    3026 .snarkTorrentDetails {
     3027.snarkCommentDetails {
    30273028     padding-left: 3px !important;
    30283029}
  • installer/resources/themes/snark/light/snark.css

    r27a0d4e r7a0f384  
    488488}
    489489
    490 .snarkTorrents thead th:nth-child(3), .snarkTorrents thead th:nth-child(7) {
     490.snarkTorrents thead th:nth-child(3) {
     491     text-align: center !important;
     492}
     493
     494.snarkTorrents thead th:nth-child(7) {
    491495     text-align: right !important;
    492496}
     
    554558}
    555559
    556 .snarkTrackerDetails, .snarkTorrentDetails {
     560.snarkTrackerDetails, .snarkTorrentDetails, .snarkCommentDetails {
    557561     width: 16px !important;
    558562     text-align: center !important;
     
    562566}
    563567
    564 .snarkTrackerDetails img, .snarkTorrentDetails img, .snarkDirInfo td:first-child img {
     568.snarkTrackerDetails img, .snarkTorrentDetails img, .snarkCommentDetails img, .snarkDirInfo td:first-child img {
    565569     margin: 0;
    566570     padding: 3px !important;
     
    572576.snarkTrackerDetails a:hover img, .snarkTrackerDetails a:focus img,
    573577.snarkTorrentDetails a:hover img, .snarkTorrentDetails a:focus img,
     578.snarkCommentDetails a:hover img, .snarkCommentDetails a:focus img,
    574579.snarkDirInfo td:first-child a:hover img, .snarkDirInfo td:first-child a:focus img {
    575580     border: 1px solid #f60 !important;
     
    581586}
    582587
    583 .snarkTrackerDetails a:active img, .snarkTorrentDetails a:active img, .snarkDirInfo td:first-child a:active img {
     588.snarkTrackerDetails a:active img, .snarkTorrentDetails a:active img, .snarkCommentDetails a:active img, .snarkDirInfo td:first-child a:active img {
    584589     box-shadow: inset 2px 2px 2px #99f;
    585590     transform: scale(0.9);
     
    23832388}
    23842389
    2385 .snarkGraphicStatus img, .snarkTrackerDetails img, .snarkTorrentDetails img {
     2390.snarkGraphicStatus img, .snarkTrackerDetails img, .snarkTorrentDetails img, .snarkCommentDetails img {
    23862391     max-height: 14px !important;
    23872392     width: auto;
  • installer/resources/themes/snark/midnight/snark.css

    r27a0d4e r7a0f384  
    411411
    412412.snarkTorrents thead th:nth-child(3) {
    413      text-align: right;
     413     text-align: center;
    414414}
    415415
     
    495495}
    496496
    497 .snarkTrackerDetails, .snarkTorrentDetails {
     497.snarkTrackerDetails, .snarkTorrentDetails, .snarkCommentDetails {
    498498     width: 16px !important;
    499499     text-align: center !important;
     
    503503}
    504504
    505 .snarkTrackerDetails img, .snarkTorrentDetails img, .snarkDirInfo td:first-child img {
     505.snarkTrackerDetails img, .snarkTorrentDetails img, .snarkCommentDetails img, .snarkDirInfo td:first-child img {
    506506     padding: 3px !important;
    507507     border: 1px solid transparent !important;
     
    515515.snarkTrackerDetails a:hover img, .snarkTrackerDetails img:hover, .snarkTrackerDetails a:focus img,
    516516.snarkTorrentDetails a:hover img, .snarkTorrentDetails img:hover, .snarkTorrentDetails a:focus img,
     517.snarkCommentDetails a:hover img, .snarkCommentDetails img:hover, .snarkCommentDetails a:focus img,
    517518.snarkDirInfo td:first-child a:hover img, .snarkDirInfo td:first-child a:focus img {
    518519     border: 1px solid #652787 !important;
     
    524525}
    525526
    526 .snarkTrackerDetails a:active img, .snarkTorrentDetails a:active img, .snarkDirInfo td:first-child a:active img {
     527.snarkTrackerDetails a:active img, .snarkTorrentDetails a:active img, .snarkCommentDetails a:active img, .snarkDirInfo td:first-child a:active img {
    527528     border: 1px solid #f90 !important;
    528529     box-shadow: inset 2px 2px 3px 3px #000;
  • installer/resources/themes/snark/ubergine/snark.css

    r27a0d4e r7a0f384  
    479479}
    480480
    481 .snarkTrackerDetails, .SnarkTorrentDetails {
     481.snarkTrackerDetails, .SnarkTorrentDetails, .snarkCommentDetails {
    482482     width: 1%;
    483483     padding: 2px 0;
     
    657657}
    658658
    659 .snarkTrackerDetails, .snarkTorrentDetails {
     659.snarkTrackerDetails, .snarkTorrentDetails, .snarkCommentDetails {
    660660     width: 16px !important;
    661661     text-align: center !important;
     
    665665}
    666666
    667 .snarkTrackerDetails img, .snarkTorrentDetails img, .snarkDirInfo td:first-child img {
     667.snarkTrackerDetails img, .snarkTorrentDetails img, .snarkCommentDetails img, .snarkDirInfo td:first-child img {
    668668     padding: 3px !important;
    669669     margin: 0 1px !important;
     
    675675.snarkTrackerDetails a:hover img, .snarkTrackerDetails a:focus img,
    676676.snarkTorrentDetails a:hover img, .snarkTorrentDetails a:focus img,
     677.snarkCommentDetails a:hover img, .snarkCommentDetails a:focus img,
    677678.snarkDirInfo td:not(.parentdir):first-child a:hover img, .snarkDirInfo td:not(.parentdir):first-child a:focus img {
    678679     border: 1px solid #f60 !important;
     
    684685}
    685686
    686 .snarkTrackerDetails a:active img, .snarkTorrentDetails a:active img, .snarkDirInfo td:not(.parentdir):first-child a:active img {
     687.snarkTrackerDetails a:active img, .snarkTorrentDetails a:active img, .snarkCommentDetails a:active img, .snarkDirInfo td:not(.parentdir):first-child a:active img {
    687688     border: 1px solid #212 !important;
    688689     box-shadow: inset 3px 3px 2px 1px #202;
     
    32323233}
    32333234
    3234 .snarkTorrentDetails {
     3235.snarkCommentDetails {
    32353236     width: 34px !important;
    32363237     text-align: right !important;
     
    32503251}
    32513252
    3252 .snarkTorrentDetails {
     3253.snarkCommentDetails {
    32533254     padding-left: 8px;
    32543255}
  • installer/resources/themes/snark/vanilla/snark.css

    r27a0d4e r7a0f384  
    546546
    547547.snarkTorrents thead th:nth-child(3) {
    548      text-align: right;
     548     text-align: center;
    549549     padding-right: 0;
    550550}
     
    592592}
    593593
    594 .snarkTrackerDetails, .snarkTorrentDetails {
     594.snarkTrackerDetails, .snarkTorrentDetails, .snarkCommentDetails {
    595595     width: 16px !important;
    596596     text-align: center !important;
     
    600600}
    601601
    602 .snarkTrackerDetails img, .snarkTorrentDetails img, .snarkDirInfo td:first-child img {
     602.snarkTrackerDetails img, .snarkTorrentDetails img, .snarkCommentDetails img, .snarkDirInfo td:first-child img {
    603603     padding: 3px !important;
    604604     border: 1px solid transparent !important;
     
    612612.snarkTrackerDetails a:hover img, .snarkTrackerDetails a:focus img,
    613613.snarkTorrentDetails a:hover img, .snarkTorrentDetails a:focus img,
     614.snarkCommentDetails a:hover img, .snarkCommentDetails a:focus img,
    614615.snarkDirInfo td:first-child a:hover img, .snarkDirInfo td:first-child a:focus img {
    615616     border: 1px solid #f60 !important;
     
    621622}
    622623
    623 .snarkTrackerDetails a:active img, .snarkTorrentDetails a:active img, .snarkDirInfo td:first-child a:active img {
     624.snarkTrackerDetails a:active img, .snarkTorrentDetails a:active img, .snarkCommentDetails a:active img, .snarkDirInfo td:first-child a:active img {
    624625     box-shadow: inset 2px 2px 3px 1px #59513b;
    625626     transform: scale(0.9);
     
    31213122}
    31223123
    3123 .snarkTorrentDetails {
     3124.snarkCommentDetails {
    31243125     padding-left: 5px !important;
    31253126     padding-right: 0 !important;
  • router/java/src/net/i2p/router/RouterVersion.java

    r27a0d4e r7a0f384  
    1919    public final static String ID = "Monotone";
    2020    public final static String VERSION = CoreVersion.VERSION;
    21     public final static long BUILD = 5;
     21    public final static long BUILD = 7;
    2222
    2323    /** for example "-test" */
  • router/java/src/net/i2p/router/transport/ntcp/EventPumper.java

    r27a0d4e r7a0f384  
    2929import net.i2p.router.RouterContext;
    3030import net.i2p.router.transport.FIFOBandwidthLimiter;
     31import net.i2p.util.TryCache;
    3132import net.i2p.util.Addresses;
    3233import net.i2p.util.ConcurrentHashSet;
     
    5455    private final ObjectCounter<ByteArray> _blockedIPs;
    5556    private long _expireIdleWriteTime;
    56     private boolean _useDirect;
     57    private static boolean _useDirect;
    5758   
    5859    /**
     
    6465    private static final int MAX_CACHE_SIZE = 64;
    6566
    66     /**
    67      *  Read buffers. (write buffers use wrap())
    68      *  Shared if there are multiple routers in the JVM
    69      *  Note that if the routers have different PROP_DIRECT settings this will have a mix,
    70      *  so don't do that.
    71      */
    72     private static final LinkedBlockingQueue<ByteBuffer> _bufCache = new LinkedBlockingQueue<ByteBuffer>(MAX_CACHE_SIZE);
     67    private static class BufferFactory implements TryCache.ObjectFactory<ByteBuffer> {
     68        public ByteBuffer newInstance() {
     69            if (_useDirect)
     70                return ByteBuffer.allocateDirect(BUF_SIZE);
     71            else
     72                return ByteBuffer.allocate(BUF_SIZE);
     73        }
     74    }
     75   
    7376
    7477    /**
     
    102105        MIN_BUFS = (int) Math.max(MIN_MINB, Math.min(MAX_MINB, 1 + (maxMemory / (16*1024*1024))));
    103106    }
     107   
     108    private static final TryCache<ByteBuffer> _bufferCache = new TryCache<>(new BufferFactory(), MIN_BUFS);
    104109
    105110    public EventPumper(RouterContext ctx, NTCPTransport transport) {
     
    320325
    321326
    322                 // Clear the cache if the user changes the setting,
    323                 // so we can test the effect.
    324                 boolean newUseDirect = _context.getBooleanProperty(PROP_DIRECT);
    325                 if (_useDirect != newUseDirect) {
    326                     _useDirect = newUseDirect;
    327                     _bufCache.clear();
    328                 }
     327                _useDirect = _context.getBooleanProperty(PROP_DIRECT);
    329328            } catch (RuntimeException re) {
    330329                _log.error("Error in the event pumper", re);
     
    364363        _wantsRegister.clear();
    365364        _wantsWrite.clear();
    366         _bufCache.clear();
    367365    }
    368366   
     
    463461
    464462    /**
    465      *  How many to keep in reserve.
    466      *  Shared if there are multiple routers in the JVM
    467      */
    468     private static int _numBufs = MIN_BUFS;
    469     private static int __consecutiveExtra;
    470 
    471     /**
    472463     *  High-frequency path in thread.
    473464     */
    474465    private ByteBuffer acquireBuf() {
    475         ByteBuffer rv = _bufCache.poll();
    476         // discard buffer if _useDirect setting changes
    477         if (rv == null || rv.isDirect() != _useDirect) {
    478             if (_useDirect)
    479                 rv = ByteBuffer.allocateDirect(BUF_SIZE);
    480             else
    481                 rv = ByteBuffer.allocate(BUF_SIZE);
    482             _numBufs++;
    483         }
    484         return rv;
     466        return _bufferCache.acquire();
    485467    }
    486468   
     
    497479        }
    498480        buf.clear();
    499         int extra = _bufCache.size();
    500         boolean cached = extra < _numBufs;
    501 
    502         // TODO always offer if direct?
    503         if (cached) {
    504             _bufCache.offer(buf);
    505             if (extra > MIN_BUFS) {
    506                 __consecutiveExtra++;
    507                 if (__consecutiveExtra >= 20) {
    508                     if (_numBufs > MIN_BUFS)
    509                         _numBufs--;
    510                     __consecutiveExtra = 0;
    511                 }
    512             }
    513         }
     481        _bufferCache.release(buf);
    514482    }
    515483   
  • router/java/src/net/i2p/router/transport/ntcp/NTCP2Options.java

    r27a0d4e r7a0f384  
    6464    public String toString() {
    6565        return "Padding options: send min/max %: (" + (_sendMin * 100) + ", " + (_sendMax * 100) +
    66                ") recv min/max %: ( " + (_recvMin * 100) + ", " + (_recvMax * 100) +
    67                ") dummy send/recv B/s: ( " + _sendDummy + ", " + _recvDummy +
    68                ") delay send/recv ms: ( " + _sendDelay + ", " + _recvDelay + ')';
     66               ") recv min/max %: (" + (_recvMin * 100) + ", " + (_recvMax * 100) +
     67               ") dummy send/recv B/s: (" + _sendDummy + ", " + _recvDummy +
     68               ") delay send/recv ms: (" + _sendDelay + ", " + _recvDelay + ')';
    6969    }
    7070}
  • router/java/src/net/i2p/router/transport/ntcp/NTCPConnection.java

    r27a0d4e r7a0f384  
    187187    private static final long NTCP2_TERMINATION_CLOSE_DELAY = 50;
    188188    // don't make combined messages too big, to minimize latency
    189     private static final int NTCP2_PREFERRED_PAYLOAD_MAX = 5000;
     189    // Tunnel data msgs are 1024 + 4 + 9 + 3 = 1040, allow 5
     190    private static final int NTCP2_PREFERRED_PAYLOAD_MAX = 5 * 1040;
    190191    static final int REASON_UNSPEC = 0;
    191192    static final int REASON_TERMINATION = 1;
     
    898899        int availForPad = BUFFER_SIZE - (size + NTCP2Payload.BLOCK_HEADER_SIZE);
    899900        if (availForPad > 0) {
    900             // what we want to send, calculated in proportion to data size
    901             int minSend = (int) (size * _paddingConfig.getSendMin());
    902             int maxSend = (int) (size * _paddingConfig.getSendMax());
    903             // the absolute min and max we can send
    904             int min = Math.min(minSend, availForPad);
    905             int max = Math.min(maxSend, availForPad);
    906             int range = max - min;
    907             if (range < MIN_PADDING_RANGE) {
    908                 // reduce min to enforce minimum range if possible
    909                 min = Math.max(0, min - (MIN_PADDING_RANGE - range));
    910                 range = max - min;
    911             } else if (range > MAX_PADDING_RANGE) {
    912                 // Don't send too much, no matter what the config says
    913                 range = MAX_PADDING_RANGE;
    914             }
    915             int padlen = min;
    916             if (range > 0)
    917                 padlen += _context.random().nextInt(1 + range);
    918             if (_log.shouldWarn())
    919                 _log.warn("Padding params:" +
    920                           " data size: " + size +
    921                           " avail: " + availForPad +
    922                           " minSend: " + minSend +
    923                           " maxSend: " + maxSend +
    924                           " min: " + min +
    925                           " max: " + max +
    926                           " range: " + range +
    927                           " padlen: " + padlen);
     901            int padlen = getPaddingSize(size, availForPad);
    928902            // all zeros is fine here
    929903            //Block block = new NTCP2Payload.PaddingBlock(_context, padlen);
     
    938912     *  NTCP2 only
    939913     *
     914     *  @param dataSize the total size of the data we are sending
     915     *  @param availForPad the available size for padding, not including padding block header,
     916     *                     must be greater than zero
     917     *  @return min 0 max availForPad
    940918     *  @since 0.9.36
    941919     */
     920    private int getPaddingSize(int dataSize, int availForPad) {
     921        // what we want to send, calculated in proportion to data size
     922        int minSend = (int) (dataSize * _paddingConfig.getSendMin());
     923        int maxSend = (int) (dataSize * _paddingConfig.getSendMax());
     924        // the absolute min and max we can send
     925        int min = Math.min(minSend, availForPad);
     926        int max = Math.min(maxSend, availForPad);
     927        int range = max - min;
     928        if (range < MIN_PADDING_RANGE) {
     929            // reduce min to enforce minimum range if possible
     930            min = Math.max(0, min - (MIN_PADDING_RANGE - range));
     931            range = max - min;
     932        } else if (range > MAX_PADDING_RANGE) {
     933            // Don't send too much, no matter what the config says
     934            range = MAX_PADDING_RANGE;
     935        }
     936        int padlen = min;
     937        if (range > 0)
     938            padlen += _context.random().nextInt(1 + range);
     939        if (_log.shouldWarn())
     940            _log.warn("Padding params:" +
     941                      " data size: " + dataSize +
     942                      " avail: " + availForPad +
     943                      " minSend: " + minSend +
     944                      " maxSend: " + maxSend +
     945                      " min: " + min +
     946                      " max: " + max +
     947                      " range: " + range +
     948                      " padlen: " + padlen);
     949        return padlen;
     950    }
     951
     952    /**
     953     *  NTCP2 only
     954     *
     955     *  @since 0.9.36
     956     */
    942957    private void sendOurRouterInfo(boolean shouldFlood) {
    943         sendRouterInfo(_context.router().getRouterInfo(), shouldFlood);
     958        RouterInfo ri = _context.router().getRouterInfo();
     959        if (ri == null)
     960            return;
     961        sendRouterInfo(ri, shouldFlood);
    944962    }
    945963
     
    954972            _log.warn("Sending router info for: " + ri.getHash() + " flood? " + shouldFlood);
    955973        List<Block> blocks = new ArrayList<Block>(2);
    956         int plen = 2;
    957974        Block block = new NTCP2Payload.RIBlock(ri, shouldFlood);
    958         plen += block.getTotalLength();
     975        int size = block.getTotalLength();
     976        if (size > BUFFER_SIZE) {
     977            if (_log.shouldWarn())
     978                _log.warn("RI too big: " + ri);
     979            return;
     980        }
    959981        blocks.add(block);
    960         int padlen = 1 + _context.random().nextInt(PADDING_MAX);
    961         // all zeros is fine here
    962         //block = new NTCP2Payload.PaddingBlock(_context, padlen);
    963         block = new NTCP2Payload.PaddingBlock(padlen);
    964         plen += block.getTotalLength();
    965         blocks.add(block);
    966         byte[] tmp = new byte[plen];
    967         sendNTCP2(tmp, blocks);
     982        int availForPad = BUFFER_SIZE - (size + NTCP2Payload.BLOCK_HEADER_SIZE);
     983        if (availForPad > 0) {
     984            int padlen = getPaddingSize(size, availForPad);
     985            // all zeros is fine here
     986            //block = new NTCP2Payload.PaddingBlock(_context, padlen);
     987            block = new NTCP2Payload.PaddingBlock(padlen);
     988            size += block.getTotalLength();
     989            blocks.add(block);
     990        }
     991        // use a "read buf" for the temp array
     992        ByteArray dataBuf = acquireReadBuf();
     993        sendNTCP2(dataBuf.getData(), blocks);
     994        releaseReadBuf(dataBuf);
    968995    }
    969996
     
    9791006            _log.warn("Sending termination, reason: " + reason + ", vaild frames rcvd: " + validFramesRcvd);
    9801007        List<Block> blocks = new ArrayList<Block>(2);
    981         int plen = 2;
    9821008        Block block = new NTCP2Payload.TerminationBlock(reason, validFramesRcvd);
    983         plen += block.getTotalLength();
     1009        int plen = block.getTotalLength();
    9841010        blocks.add(block);
    985         int padlen = 1 + _context.random().nextInt(PADDING_MAX);
    986         // all zeros is fine here
    987         //block = new NTCP2Payload.PaddingBlock(_context, padlen);
    988         block = new NTCP2Payload.PaddingBlock(padlen);
    989         plen += block.getTotalLength();
    990         blocks.add(block);
    991         byte[] tmp = new byte[plen];
    992         sendNTCP2(tmp, blocks);
     1011        int padlen = getPaddingSize(plen, PADDING_MAX);
     1012        if (padlen > 0) {
     1013            // all zeros is fine here
     1014            //block = new NTCP2Payload.PaddingBlock(_context, padlen);
     1015            block = new NTCP2Payload.PaddingBlock(padlen);
     1016            plen += block.getTotalLength();
     1017            blocks.add(block);
     1018        }
     1019        // use a "read buf" for the temp array
     1020        ByteArray dataBuf = acquireReadBuf();
     1021        sendNTCP2(dataBuf.getData(), blocks);
     1022        releaseReadBuf(dataBuf);
    9931023    }
    9941024
     
    9991029     *
    10001030     *  @param tmp to be used for output of NTCP2Payload.writePayload(),
    1001      *         must have room for 2 byte length and block output
     1031     *         must have room for block output. May be released immediately on return.
    10021032     *  @since 0.9.36
    10031033     */
    10041034    private synchronized void sendNTCP2(byte[] tmp, List<Block> blocks) {
     1035        if (_sender == null) {
     1036            if (_log.shouldWarn())
     1037                _log.warn("sender gone", new Exception());
     1038            return;
     1039        }
    10051040        int payloadlen = NTCP2Payload.writePayload(tmp, 0, blocks);
    10061041        int framelen = payloadlen + OutboundNTCP2State.MAC_SIZE;
     
    20402075            _lastReceiveTime = _context.clock().now();
    20412076            _messagesRead.incrementAndGet();
    2042             // TEST send back. null RI for target, not necesary
    2043             //if (_context.getBooleanProperty("i2np.ntcp2.loopback"))
    2044             //  send(new OutNetMessage(_context, msg, _context.clock().now() + 10*1000, OutNetMessage.PRIORITY_MY_DATA, null));
    20452077        }
    20462078
  • router/java/src/net/i2p/router/transport/udp/UDPPacket.java

    r27a0d4e r7a0f384  
    1313import net.i2p.router.transport.FIFOBandwidthLimiter;
    1414import net.i2p.router.util.CDQEntry;
     15import net.i2p.util.TryCache;
    1516import net.i2p.util.Addresses;
    1617import net.i2p.util.Log;
     
    4647    private FIFOBandwidthLimiter.Request _bandwidthRequest;
    4748 
     49    private static class PacketFactory implements TryCache.ObjectFactory<UDPPacket> {
     50        static RouterContext context;
     51        public UDPPacket newInstance() {
     52            return new UDPPacket(context);
     53        }
     54    }
     55   
    4856    //  Warning - this mixes contexts in a multi-router JVM
    49     private static final Queue<UDPPacket> _packetCache;
     57    private static final TryCache<UDPPacket> _packetCache;
     58    private static final TryCache.ObjectFactory<UDPPacket> _packetFactory;
    5059    private static final boolean CACHE = true;
    5160    private static final int MIN_CACHE_SIZE = 64;
     
    5564            long maxMemory = SystemVersion.getMaxMemory();
    5665            int csize = (int) Math.max(MIN_CACHE_SIZE, Math.min(MAX_CACHE_SIZE, maxMemory / (1024*1024)));
    57             _packetCache = new LinkedBlockingQueue<UDPPacket>(csize);
     66            _packetFactory = new PacketFactory();
     67            _packetCache = new TryCache<>(_packetFactory, csize);
    5868        } else {
    5969            _packetCache = null;
     70            _packetFactory = null;
    6071        }
    6172    }
     
    399410        UDPPacket rv = null;
    400411        if (CACHE) {
    401             rv = _packetCache.poll();
    402             if (rv != null) {
    403                 synchronized(rv) {
    404                     if (!rv._released) {
    405                         Log log = rv._context.logManager().getLog(UDPPacket.class);
    406                         log.error("Unreleased cached packet", new Exception());
    407                         rv = null;
    408                     } else {
    409                         rv.init(ctx);
    410                     }
    411                 }
    412             }
     412            PacketFactory.context = ctx;
     413            rv = _packetCache.acquire();
     414            rv.init(ctx);
    413415        }
    414416        if (rv == null)
     
    441443        if (!CACHE)
    442444            return;
    443         _packetCache.offer(this);
     445        _packetCache.release(this);
    444446    }
    445447   
     
    449451     */
    450452    public static void clearCache() {
    451         if (CACHE)
     453        if (CACHE) {
     454            PacketFactory.context = null;
    452455            _packetCache.clear();
     456        }
    453457    }
    454458
Note: See TracChangeset for help on using the changeset viewer.