Changeset 757df8c


Ignore:
Timestamp:
May 3, 2013 4:34:02 PM (8 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
368c207
Parents:
c6121cb
Message:

prep for multiple address discovery

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

Legend:

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

    rc6121cb r757df8c  
    530530     *  This may be from a local interface, UPnP, a config change, etc.
    531531     *  This should not be called if the ip didn't change
    532      *  (from that source's point of view), or is a local address,
    533      *  or if the ip is IPv6, but the transport should check anyway.
     532     *  (from that source's point of view), or is a local address.
     533     *  May be called multiple times for IPv4 or IPv6.
    534534     *  The transport should also do its own checking on whether to accept
    535535     *  notifications from this source.
     
    538538     *  or after the transport is running.
    539539     *
     540     *  This implementation does nothing. Transports should override if they want notification.
     541     *
    540542     *  @param source defined in Transport.java
    541      *  @param ip typ. IPv4 non-local
     543     *  @param ip typ. IPv4 or IPv6 non-local
    542544     *  @param port 0 for unknown or unchanged
    543545     */
     
    546548    /**
    547549     *  Notify a transport of the results of trying to forward a port.
     550     *
     551     *  This implementation does nothing. Transports should override if they want notification.
     552     *
    548553     *  @param port the internal port
    549554     *  @param externalPort the external port, which for now should always be the same as
  • router/java/src/net/i2p/router/transport/TransportManager.java

    rc6121cb r757df8c  
    102102    }
    103103   
     104    /**
     105     *  Notify transport of ALL routable local addresses, including IPv6.
     106     *  It's the transport's job to ignore what it can't handle.
     107     */
    104108    private void initializeAddress(Transport t) {
    105         String ips = Addresses.getAnyAddress();
    106         if (ips == null)
    107             return;
    108         InetAddress ia;
    109         try {
    110             ia = InetAddress.getByName(ips);
    111         } catch (UnknownHostException e) {
    112             _log.error("UDP failed to bind to local address", e);
    113             return;
    114         }
    115         byte[] ip = ia.getAddress();
    116         t.externalAddressReceived(Transport.SOURCE_INTERFACE, ip, 0);
     109        Set<String> ipset = Addresses.getAddresses(false, true);  // non-local, include IPv6
     110        for (String ips : ipset) {
     111            try {
     112                InetAddress ia = InetAddress.getByName(ips);
     113                byte[] ip = ia.getAddress();
     114                t.externalAddressReceived(Transport.SOURCE_INTERFACE, ip, 0);
     115            } catch (UnknownHostException e) {
     116                _log.error("UDP failed to bind to local address", e);
     117            }
     118        }
    117119    }
    118120
  • router/java/src/net/i2p/router/transport/udp/UDPTransport.java

    rc6121cb r757df8c  
    512512    }
    513513   
     514    // temp prevent multiples
     515    private boolean gotIPv4Addr = false;
     516    private boolean gotIPv6Addr = false;
     517
    514518    /**
    515519     * From config, UPnP, local i/f, ...
    516520     *
    517521     * @param source used for logging only
    518      * @param ip publicly routable IPv4 only
     522     * @param ip publicly routable IPv4 or IPv6
    519523     * @param port 0 if unknown
    520524     */
     
    528532        if (!sources.contains(source))
    529533            return;
     534        if (!isValid(ip))
     535            return;
     536        if (source.equals(Transport.SOURCE_INTERFACE)) {
     537            // temp prevent multiples
     538            if (ip.length == 4 && !gotIPv4Addr) {
     539                gotIPv4Addr = true;
     540                return;
     541            } else if (ip.length == 16 && !gotIPv6Addr) {
     542                gotIPv6Addr = true;
     543                return;
     544            }
     545        }
    530546        boolean changed = changeAddress(ip, port);
    531547        // Assume if we have an interface with a public IP that we aren't firewalled.
    532548        // If this is wrong, the peer test will figure it out and change the status.
    533         if (changed && source.equals(Transport.SOURCE_INTERFACE))
     549        if (changed && ip.length == 4 && source.equals(Transport.SOURCE_INTERFACE))
    534550            setReachabilityStatus(CommSystemFacade.STATUS_OK);
    535551    }
     
    621637   
    622638    /**
     639     * @param ourIP MUST have been previously validated with isValid()
    623640     * @param ourPort >= 1024 or 0 for no change
    624641     */
Note: See TracChangeset for help on using the changeset viewer.