Changeset d1a2e24


Ignore:
Timestamp:
Aug 6, 2014 4:35:08 PM (6 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
9655e79
Parents:
086381d9
Message:

SSU: Speed up introductions by responding to HolePunch? (ticket #1333)

Location:
router/java/src/net/i2p/router/transport/udp
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • router/java/src/net/i2p/router/transport/udp/EstablishmentManager.java

    r086381d9 rd1a2e24  
    969969
    970970    /**
     971     *  Called from UDPReceiver.
     972     *  Accelerate response to RelayResponse if we haven't sent it yet.
     973     *
     974     *  @since 0.9.15
     975     */
     976    void receiveHolePunch(InetAddress from, int fromPort) {
     977        RemoteHostId id = new RemoteHostId(from.getAddress(), fromPort);
     978        OutboundEstablishState state = _outboundStates.get(id);
     979        if (state != null) {
     980            boolean sendNow = state.receiveHolePunch();
     981            if (sendNow) {
     982                if (_log.shouldLog(Log.WARN))
     983                    _log.warn("Hole punch from " + state + ", sending SessionRequest now");
     984                notifyActivity();
     985            } else {
     986                if (_log.shouldLog(Log.WARN))
     987                    _log.warn("Hole punch from " + state + ", already sent SessionRequest");
     988            }
     989        } else {
     990            // HolePunch received before RelayResponse, and we didn't know the IP/port, or it changed
     991            if (_log.shouldLog(Log.WARN))
     992                _log.warn("No state found for hole punch from " + from + " port " + fromPort);
     993        }
     994    }
     995
     996    /**
    971997     *  Are IP and port valid? This is only for checking the relay response.
    972998     *  Reject all IPv6, for now, even if we are configured for it.
  • router/java/src/net/i2p/router/transport/udp/OutboundEstablishState.java

    r086381d9 rd1a2e24  
    100100    private static final long MAX_DELAY = 15*1000;
    101101
     102    private static final long WAIT_FOR_HOLE_PUNCH_DELAY = 500;
     103
    102104    /**
    103105     *  @param claimedAddress an IP/port based RemoteHostId, or null if unknown
     
    557559        if (_currentState != OutboundState.OB_STATE_PENDING_INTRO)
    558560            return; // we've already successfully been introduced, so don't overwrite old settings
    559         _nextSend = _context.clock().now() + 500; // wait briefly for the hole punching
     561        _nextSend = _context.clock().now() + WAIT_FOR_HOLE_PUNCH_DELAY; // wait briefly for the hole punching
    560562        _currentState = OutboundState.OB_STATE_INTRODUCED;
    561563        if (_claimedAddress != null && bobPort == _bobPort && DataHelper.eq(bobIP, _bobIP)) {
     
    571573            _log.info("Introduced to " + _remoteHostId + ", now lets get on with establishing");
    572574    }
     575
     576    /**
     577     *  Accelerate response to RelayResponse if we haven't sent it yet.
     578     *
     579     *  @return true if we should send the SessionRequest now
     580     *  @since 0.9.15
     581     */
     582    synchronized boolean receiveHolePunch() {
     583        if (_currentState != OutboundState.OB_STATE_INTRODUCED)
     584            return false;
     585        if (_requestSentCount > 0)
     586            return false;
     587        long now = _context.clock().now();
     588        if (_log.shouldLog(Log.WARN))
     589            _log.warn(toString() + " accelerating SessionRequest by " + (_nextSend - now) + " ms");
     590        _nextSend = now;
     591        return true;
     592    }
    573593   
    574594    /** how long have we been trying to establish this session? */
  • router/java/src/net/i2p/router/transport/udp/UDPReceiver.java

    r086381d9 rd1a2e24  
    22
    33import java.io.IOException;
     4import java.net.DatagramPacket;
    45import java.net.DatagramSocket;
    56import java.util.Arrays;
     
    221222                //}
    222223                UDPPacket packet = UDPPacket.acquire(_context, true);
     224                DatagramPacket dpacket = packet.getPacket();
    223225
    224226                // Android ICS bug
    225227                // http://code.google.com/p/android/issues/detail?id=24748
    226228                if (_isAndroid)
    227                     packet.getPacket().setLength(UDPPacket.MAX_PACKET_SIZE);
     229                    dpacket.setLength(UDPPacket.MAX_PACKET_SIZE);
    228230               
    229231                // block before we read...
     
    237239                    //    _log.info("Before blocking socket.receive on " + System.identityHashCode(packet));
    238240                    //synchronized (Runner.this) {
    239                         _socket.receive(packet.getPacket());
     241                        _socket.receive(dpacket);
    240242                    //}
    241                     int size = packet.getPacket().getLength();
     243                    int size = dpacket.getLength();
    242244                    if (_log.shouldLog(Log.INFO))
    243245                        _log.info("After blocking socket.receive: packet is " + size + " bytes on " + System.identityHashCode(packet));
     
    267269                        // nat hole punch packets are 0 bytes
    268270                        if (_log.shouldLog(Log.INFO))
    269                             _log.info("Received a 0 byte udp packet from " + packet.getPacket().getAddress() + ":" + packet.getPacket().getPort());
     271                            _log.info("Received a 0 byte udp packet from " + dpacket.getAddress() + ":" + dpacket.getPort());
     272                        _transport.getEstablisher().receiveHolePunch(dpacket.getAddress(), dpacket.getPort());
    270273                        packet.release();
    271274                    }
Note: See TracChangeset for help on using the changeset viewer.