Changeset 8633ef9


Ignore:
Timestamp:
Sep 12, 2012 9:52:12 PM (8 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
b9aceb8
Parents:
4666454
Message:
  • Streaming: Don't send a RST to an hour/day limited peer, or blacklisted, or non-whitelisted, to not waste outbound bandwidth
Location:
apps/streaming/java/src/net/i2p/client/streaming
Files:
2 edited

Legend:

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

    r4666454 r8633ef9  
    3939    }
    4040
    41     /** increments before checking */
     41    /**
     42     *  Checks both individual and total. Increments before checking.
     43     */
    4244    boolean shouldThrottle(Hash h) {
    4345        if (_totalMax > 0 && _currentTotal.incrementAndGet() > _totalMax)
     
    4547        if (_max > 0)
    4648            return this.counter.increment(h) > _max;
     49        return false;
     50    }
     51
     52    /**
     53     *  Checks individual count only. Does not increment.
     54     *  @since 0.9.3
     55     */
     56    boolean isThrottled(Hash h) {
     57        if (_max > 0)
     58            return this.counter.count(h) > _max;
    4759        return false;
    4860    }
  • apps/streaming/java/src/net/i2p/client/streaming/ConnectionManager.java

    r4666454 r8633ef9  
    203203       
    204204        if (reject) {
    205             PacketLocal reply = new PacketLocal(_context, synPacket.getOptionalFrom());
     205            Destination from = synPacket.getOptionalFrom();
     206            if (from == null)
     207                return null;
     208            if (_dayThrottler != null || _hourThrottler != null) {
     209                Hash h = from.calculateHash();
     210                if ((_hourThrottler != null && _hourThrottler.isThrottled(h)) ||
     211                    (_dayThrottler != null && _dayThrottler.isThrottled(h)) ||
     212                    (_defaultOptions.isAccessListEnabled() && !_defaultOptions.getAccessList().contains(h)) ||
     213                    (_defaultOptions.isBlacklistEnabled() && _defaultOptions.getBlacklist().contains(h))) {
     214                    // A signed RST packet + ElGamal + session tags is fairly expensive, so
     215                    // once the hour/day limit is hit for a particular peer, don't even send it.
     216                    // Ditto for blacklist / whitelist
     217                    // This is a tradeoff, because it will keep retransmitting the SYN for a while,
     218                    // thus more inbound, but let's not spend several KB on the outbound.
     219                    if (_log.shouldLog(Log.INFO))
     220                        _log.info("Dropping RST to " + h);
     221                    return null;
     222                }
     223            }
     224            PacketLocal reply = new PacketLocal(_context, from);
    206225            reply.setFlag(Packet.FLAG_RESET);
    207226            reply.setFlag(Packet.FLAG_SIGNATURE_INCLUDED);
Note: See TracChangeset for help on using the changeset viewer.