Changeset 8f7b31a for apps/ministreaming


Ignore:
Timestamp:
Oct 23, 2013 8:20:54 PM (7 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
35a86e60
Parents:
0f5a0b6
Message:
  • I2PTunnel standard and IRC clients:
    • Allow host:port targets; set defaults in i2ptunnel.config (ticket #1066)
    • Don't fail start if hostname is unresolvable; retry at connect time (ticket #946)
    • Output IRC message on connect fail
    • Update target list on-the-fly when configuration changes
File:
1 edited

Legend:

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

    r0f5a0b6 r8f7b31a  
    1212 *  See InetSocketAddress for javadocs.
    1313 *
    14  *  Warning, this interface and implementation is preliminary and subject to change without notice.
    15  *
    1614 *  @since 0.9.1
    1715 */
     
    1917
    2018    private final int _port;
    21     private final Destination _dest;
     19    private Destination _dest;
    2220    private final String _host;
    2321
    24     // no constructor for port-only "wildcard" address
     22    /**
     23     *  Convenience constructor that parses host:port.
     24     *
     25     *  Does a naming service lookup to resolve the dest.
     26     *  May take several seconds for b32.
     27     *  @param host hostname or b64 dest or b32, may have :port appended
     28     *  @throws IllegalArgumentException for port < 0 or port > 65535 or invalid port
     29     *  @since 0.9.9
     30     */
     31    public I2PSocketAddress(String host) {
     32        int port = 0;
     33        int colon = host.indexOf(":");
     34        if (colon > 0) {
     35            try {
     36                port = Integer.parseInt(host.substring(colon + 1));
     37                host = host.substring(0, colon);
     38                if (port < 0 || port > 65535)
     39                    throw new IllegalArgumentException("bad port " + port);
     40            } catch (IndexOutOfBoundsException ioobe) {
     41                throw new IllegalArgumentException("bad port " + host);
     42            } catch (NumberFormatException nfe) {
     43                throw new IllegalArgumentException("bad port " + host);
     44            }
     45        }
     46        _port = port;
     47        _dest = I2PAppContext.getGlobalContext().namingService().lookup(host);
     48        _host = host;
     49    }
    2550
    2651    /**
    2752     *  Does not do a reverse lookup. Host will be null.
     53     *  @throws IllegalArgumentException for port < 0 or port > 65535
    2854     */
    2955    public I2PSocketAddress(Destination dest, int port) {
     56        if (dest == null)
     57            throw new NullPointerException();
     58        if (port < 0 || port > 65535)
     59            throw new IllegalArgumentException("bad port " + port);
    3060        _port = port;
    3161        _dest = dest;
     
    3666     *  Does a naming service lookup to resolve the dest.
    3767     *  May take several seconds for b32.
     68     *  @throws IllegalArgumentException for port < 0 or port > 65535
    3869     */
    3970    public I2PSocketAddress(String host, int port) {
     71        if (port < 0 || port > 65535)
     72            throw new IllegalArgumentException("bad port " + port);
    4073        _port = port;
    4174        _dest = I2PAppContext.getGlobalContext().namingService().lookup(host);
     
    4376    }
    4477
     78    /**
     79     *  @throws IllegalArgumentException for port < 0 or port > 65535
     80     */
    4581    public static I2PSocketAddress createUnresolved(String host, int port) {
    4682        return new I2PSocketAddress(port, host);
     
    4985    /** unresolved */
    5086    private I2PSocketAddress(int port, String host) {
     87        if (port < 0 || port > 65535)
     88            throw new IllegalArgumentException("bad port " + port);
    5189        _port = port;
    5290        _dest = null;
     
    5896    }
    5997
    60     public Destination getAddress() {
     98    /**
     99     *  Does a naming service lookup to resolve the dest if this was created unresolved
     100     *  or if the resolution failed in the constructor.
     101     *  If unresolved, this may take several seconds for b32.
     102     */
     103    public synchronized Destination getAddress() {
     104        if (_dest == null)
     105            _dest = I2PAppContext.getGlobalContext().namingService().lookup(_host);
    61106        return _dest;
    62107    }
Note: See TracChangeset for help on using the changeset viewer.