Changeset 0b94d86


Ignore:
Timestamp:
Dec 19, 2015 10:17:33 PM (4 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
c60f397, d5990cc
Parents:
fa6643c
Message:

BuildHandler?: Improve handling of null 'from' value
when not IBGW (ticket #1738)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • router/java/src/net/i2p/router/tunnel/pool/BuildHandler.java

    rfa6643c r0b94d86  
    630630        boolean isOutEnd = req.readIsOutboundEndpoint();
    631631
     632        Hash from = state.fromHash;
     633        if (from == null && state.from != null)
     634            from = state.from.calculateHash();
     635        // warning, from could be null, but it should only
     636        // happen if we will be a IBGW and it came from us as a OBEP
     637
    632638        if (isInGW && isOutEnd) {
    633639            _context.statManager().addRateData("tunnel.rejectHostile", 1);
     
    646652            return;
    647653        }
    648         // previous test should be sufficient to keep it from getting here but maybe not?
    649654        if (!isInGW) {
    650             Hash from = state.fromHash;
    651             if (from == null && state.from != null)
    652                 from = state.from.calculateHash();
    653             if (_context.routerHash().equals(from)) {
     655            // if from is null, it came via OutboundMessageDistributor.distribute(),
     656            // i.e. we were the OBEP, which is fine if we're going to be an IBGW
     657            // but if not, something is seriously wrong here.
     658            if (from == null || _context.routerHash().equals(from)) {
    654659                _context.statManager().addRateData("tunnel.rejectHostile", 1);
    655660                _log.error("Dropping build request, we are the previous hop");
     
    658663        }
    659664        if ((!isOutEnd) && (!isInGW)) {
    660             Hash from = state.fromHash;
    661             if (from == null && state.from != null)
    662                 from = state.from.calculateHash();
    663665            // Previous and next hop the same? Don't help somebody be evil. Drop it without a reply.
    664666            // A-B-C-A is not preventable
     
    762764        // We may need another counter above for requests.
    763765        if (response == 0 && !isInGW) {
    764             Hash from = state.fromHash;
    765             if (from == null && state.from != null)
    766                 from = state.from.calculateHash();
    767766            if (from != null && _throttler.shouldThrottle(from)) {
    768767                if (_log.shouldLog(Log.WARN))
     
    785784            _log.debug("Responding to " + state.msg.getUniqueId() + "/" + ourId
    786785                       + " after " + recvDelay + " with " + response
    787                        + " from " + (state.fromHash != null ? state.fromHash :
    788                                      state.from != null ? state.from.calculateHash() : "tunnel"));
     786                       + " from " + (from != null ? from : "tunnel"));
    789787
    790788        HopConfig cfg = null;
     
    799797                //cfg.setReceiveFrom(null);
    800798            } else {
    801                 if (state.fromHash != null) {
    802                     cfg.setReceiveFrom(state.fromHash);
    803                 } else if (state.from != null) {
    804                     cfg.setReceiveFrom(state.from.calculateHash());
     799                if (from != null) {
     800                    cfg.setReceiveFrom(from);
    805801                } else {
    806802                    // b0rk
     
    839835            }
    840836        }
     837
     838        // determination of response is now complete
     839
    841840        if (response != 0) {
    842841            _context.statManager().addRateData("tunnel.reject." + response, 1);
    843             _context.messageHistory().tunnelRejected(state.fromHash, new TunnelId(ourId), nextPeer,
     842            _context.messageHistory().tunnelRejected(from, new TunnelId(ourId), nextPeer,
    844843                                                     "rejecting for " + response + ": " +
    845844                                                     state.msg.getUniqueId() + "/" + ourId + "/" + req.readNextTunnelId() + " delay " +
    846845                                                     recvDelay + " as " +
    847846                                                     (isOutEnd ? "outbound endpoint" : isInGW ? "inbound gw" : "participant"));
    848         }
    849 
    850         // Connection congestion control:
    851         // If we rejected the request, are near our conn limits, and aren't connected to the next hop,
    852         // just drop it.
    853         // 81% = between 75% control measures in Transports and 87% rejection above
    854         if (response != 0 &&
    855             (! _context.routerHash().equals(nextPeer)) &&
    856             (! _context.commSystem().haveOutboundCapacity(81)) &&
    857             (! _context.commSystem().isEstablished(nextPeer))) {
    858             _context.statManager().addRateData("tunnel.dropConnLimits", 1);
    859             if (_log.shouldLog(Log.WARN))
    860                 _log.warn("Not sending rejection due to conn limits");
    861             return;
     847            // Connection congestion control:
     848            // If we rejected the request, are near our conn limits, and aren't connected to the next hop,
     849            // just drop it.
     850            // 81% = between 75% control measures in Transports and 87% rejection above
     851            if ((! _context.routerHash().equals(nextPeer)) &&
     852                (! _context.commSystem().haveOutboundCapacity(81)) &&
     853                (! _context.commSystem().isEstablished(nextPeer))) {
     854                _context.statManager().addRateData("tunnel.dropConnLimits", 1);
     855                if (_log.shouldLog(Log.WARN))
     856                    _log.warn("Not sending rejection due to conn limits");
     857                return;
     858            }
    862859        }
    863860
     
    935932     */
    936933    private class TunnelBuildMessageHandlerJobBuilder implements HandlerJobBuilder {
     934
     935        /**
     936         *  Either from or fromHash may be null, but both should be null only if
     937         *  we're to be a IBGW and it came from us as a OBEP.
     938         */
    937939        public Job createJob(I2NPMessage receivedMessage, RouterIdentity from, Hash fromHash) {
    938940            // need to figure out if this is a reply to an inbound tunnel request (where we are the
     
    10611063        final long recvTime;
    10621064
     1065        /**
     1066         *  Either f or h may be null, but both should be null only if
     1067         *  we're to be a IBGW and it came from us as a OBEP.
     1068         */
    10631069        public BuildMessageState(RouterContext ctx, I2NPMessage m, RouterIdentity f, Hash h) {
    10641070            _ctx = ctx;
Note: See TracChangeset for help on using the changeset viewer.