Changeset 6c3cf9bf


Ignore:
Timestamp:
Jul 15, 2018 1:50:31 PM (2 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
63f4e04
Parents:
4ff62c2
Message:

I2CP: Add option for forcing gzip on/off per-message
Use option in streaming SYN and CLOSE packets

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • apps/streaming/java/src/net/i2p/client/streaming/impl/PacketQueue.java

    r4ff62c2 r6c3cf9bf  
    148148                options.setTagsToSend(sendTags);
    149149                options.setTagThreshold(tagThresh);
     150                // CLOSE, RESET, and PING packets unlikely to have a large payload
     151                // and most of the rest of the packet is
     152                // uncompressible: stream ids, signature
     153                options.setGzip(packet.getPayloadSize() > 50);
    150154            } else if (packet.isFlagSet(FLAGS_INITIAL_TAGS)) {
    151155                if (con != null) {
     
    168172                options.setTagsToSend(sendTags);
    169173                options.setTagThreshold(tagThresh);
     174                // SYN packets are likely to have compressible payload, even if
     175                // conn gzip option is false (e.g. snark bitfield, HTTP headers).
     176                // If they don't have a large payload, most of the rest of the packet
     177                // is uncompressible: stream ids, destination and signature
     178                options.setGzip(packet.getPayloadSize() > 50);
    170179            } else {
    171180                if (con != null) {
  • core/java/src/net/i2p/client/SendMessageOptions.java

    r4ff62c2 r6c3cf9bf  
    1313 *  flags field on the router side.
    1414 *
     15 *  GzipOption flags are as of 0.9.36, are client-side only, and are
     16 *  not included in the flags field or sent to the router.
     17 *
    1518 *  @since 0.9.2
    1619 */
    1720public class SendMessageOptions extends DateAndFlags {
     21
     22    private GzipOption _gzip = GzipOption.DEFAULT;
    1823
    1924    /** all subject to change */
     
    206211        }
    207212    }
     213
     214    /**
     215     *  Overrides i2cp.gzip session option and size threshold
     216     *  for this message only.
     217     *
     218     *  @since 0.9.36
     219     */
     220    public enum GzipOption { DEFAULT, GZIP_OFF, GZIP_ON }
     221
     222    /**
     223     *  Overrides i2cp.gzip session option and size threshold
     224     *  for this message only.
     225     *
     226     *  @return non-null, DEFAULT unless setGzip() was called
     227     *  @since 0.9.36
     228     */
     229    public GzipOption getGzip() {
     230        return _gzip;
     231    }
     232
     233    /**
     234     *  Overrides i2cp.gzip session option and size threshold
     235     *  for this message only.
     236     *
     237     *  @since 0.9.36
     238     */
     239    public void setGzip(boolean yes) {
     240        _gzip = yes? GzipOption.GZIP_ON : GzipOption.GZIP_OFF;
     241    }
    208242}
  • core/java/src/net/i2p/client/impl/I2PSessionMuxedImpl.java

    r4ff62c2 r6c3cf9bf  
    218218                               int proto, int fromPort, int toPort, int flags)
    219219                   throws I2PSessionException {
    220         payload = prepPayload(payload, offset, size, proto, fromPort, toPort);
     220        payload = prepPayload(payload, offset, size, proto, fromPort, toPort, SendMessageOptions.GzipOption.DEFAULT);
    221221        if (_noEffort)
    222222            return sendNoEffort(dest, payload, expires, flags);
     
    243243    public boolean sendMessage(Destination dest, byte[] payload, int offset, int size,
    244244                               int proto, int fromPort, int toPort, SendMessageOptions options) throws I2PSessionException {
    245         payload = prepPayload(payload, offset, size, proto, fromPort, toPort);
     245        payload = prepPayload(payload, offset, size, proto, fromPort, toPort, options.getGzip());
    246246        //if (_noEffort) {
    247247            sendNoEffort(dest, payload, options);
     
    267267                            int proto, int fromPort, int toPort,
    268268                            SendMessageOptions options, SendMessageStatusListener listener) throws I2PSessionException {
    269         payload = prepPayload(payload, offset, size, proto, fromPort, toPort);
     269        payload = prepPayload(payload, offset, size, proto, fromPort, toPort, options.getGzip());
    270270        long nonce = _sendMessageNonce.incrementAndGet();
    271271        long expires = Math.max(_context.clock().now() + 60*1000L, options.getTime());
     
    280280     * @since 0.9.14
    281281     */
    282     private byte[] prepPayload(byte[] payload, int offset, int size, int proto, int fromPort, int toPort) throws I2PSessionException {
     282    private byte[] prepPayload(byte[] payload, int offset, int size, int proto,
     283                               int fromPort, int toPort,
     284                               SendMessageOptions.GzipOption gzo) throws I2PSessionException {
    283285        verifyOpen();
    284286        updateActivity();
    285287
    286         if (shouldCompress(size))
     288        boolean docompress;
     289        if (gzo == SendMessageOptions.GzipOption.DEFAULT)
     290            docompress = shouldCompress(size);
     291        else
     292            docompress = gzo == SendMessageOptions.GzipOption.GZIP_ON;
     293
     294        if (docompress)
    287295            payload = DataHelper.compress(payload, offset, size);
    288296        else
Note: See TracChangeset for help on using the changeset viewer.