Changeset 8c7898de for core


Ignore:
Timestamp:
Nov 21, 2017 1:29:31 AM (3 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
b2dcf20
Parents:
07a83bf
Message:

Reseed: Add support for reseeding via outproxy or Orchid (ticket #1841)
InternalSocket?: Add support for some methods needed for reseed to work

Location:
core/java/src/net/i2p/util
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/net/i2p/util/InternalSocket.java

    r07a83bf r8c7898de  
    88import java.net.SocketAddress;
    99import java.nio.channels.SocketChannel;
     10
     11import net.i2p.I2PAppContext;
    1012
    1113/**
     
    1820    private InputStream _is;
    1921    private OutputStream _os;
     22    private final int _port;
    2023
    2124    /** server side */
     
    2326        _is = is;
    2427        _os = os;
     28        _port = 1;
    2529    }
    2630
     
    3236         if (port <= 0)
    3337             throw new IOException("bad port number");
     38         _port = port;
    3439         InternalServerSocket.internalConnect(port, this);
    3540    }
     
    4045     */
    4146    public static Socket getSocket(String host, int port) throws IOException {
    42         if (System.getProperty("router.version") != null &&
     47        if (I2PAppContext.getGlobalContext().isRouterContext() &&
    4348            (host.equals("127.0.0.1") || host.equals("localhost"))) {
    4449            try {
     
    104109    }
    105110
    106     // everything below here unsupported
     111    // everything below here unsupported unless otherwise noted
     112
    107113    /** @deprecated unsupported */
    108114    @Deprecated
     
    147153        throw new UnsupportedOperationException();
    148154    }
    149     /** @deprecated unsupported */
    150     @Deprecated
     155
     156    /**
     157     * Supported as of 0.9.33, prior to that threw UnsupportedOperationException
     158     * @return 1 if connected, -1 if not
     159     */
    151160    @Override
    152161    public int getLocalPort() {
    153         throw new UnsupportedOperationException();
    154     }
     162        return isConnected() ? 1 : -1;
     163    }
     164
    155165    /** @deprecated unsupported */
    156166    @Deprecated
     
    165175        throw new UnsupportedOperationException();
    166176    }
    167     /** @deprecated unsupported */
    168     @Deprecated
     177
     178    /**
     179     * Supported as of 0.9.33, prior to that threw UnsupportedOperationException
     180     * @return if connected: actual port for clients, 1 for servers; -1 if not
     181     */
    169182    @Override
    170183    public int getPort() {
    171         throw new UnsupportedOperationException();
     184        return isConnected() ? _port : 0;
    172185    }
    173186    /** @deprecated unsupported */
     
    195208        throw new UnsupportedOperationException();
    196209    }
    197     /** @deprecated unsupported */
    198     @Deprecated
     210
     211    /**
     212     * Supported as of 0.9.33, prior to that threw UnsupportedOperationException
     213     * @return -1 always
     214     */
    199215    @Override
    200216    public int getSoLinger() {
    201         throw new UnsupportedOperationException();
    202     }
     217        return -1;
     218    }
     219
    203220    /** @deprecated unsupported */
    204221    @Deprecated
     
    219236        throw new UnsupportedOperationException();
    220237    }
    221     /** @deprecated unsupported */
    222     @Deprecated
    223     @Override
    224     public boolean isConnected() {
    225         throw new UnsupportedOperationException();
    226     }
     238
     239    /**
     240     * Supported as of 0.9.33, prior to that threw UnsupportedOperationException
     241     */
     242    @Override
     243    public synchronized boolean isConnected() {
     244        return _is != null || _os != null;
     245    }
     246
    227247    /** @deprecated unsupported */
    228248    @Deprecated
  • core/java/src/net/i2p/util/SSLEepGet.java

    r07a83bf r8c7898de  
    148148     *  Use a proxy.
    149149     *
    150      *  @param proxyPort must be valid, -1 disallowed, no default
     150     *  @param proxyHost Must be valid hostname or literal IPv4/v6.
     151     *                   If type is INTERNAL, set to "localhost".
     152     *  @param proxyPort Must be valid, -1 disallowed, no default.
     153     *                   If type is INTERNAL, set to 4444.
    151154     *  @since 0.9.33
    152155     */
     
    159162     *  Use a proxy.
    160163     *
    161      *  @param proxyPort must be valid, -1 disallowed, no default
     164     *  @param proxyHost Must be valid hostname or literal IPv4/v6.
     165     *                   If type is INTERNAL, set to "localhost".
     166     *  @param proxyPort Must be valid, -1 disallowed, no default.
     167     *                   If type is INTERNAL, set to 4444.
    162168     *  @param state an SSLState retrieved from a previous SSLEepGet with getSSLState(), or null.
    163169     *               This makes repeated fetches from the same host MUCH faster,
     
    184190     *  Use a proxy.
    185191     *
    186      *  @param proxyPort must be valid, -1 disallowed, no default
     192     *  @param proxyHost Must be valid hostname or literal IPv4/v6.
     193     *                   If type is INTERNAL, set to "localhost".
     194     *  @param proxyPort Must be valid, -1 disallowed, no default.
     195     *                   If type is INTERNAL, set to 4444.
    187196     *  @since 0.9.33
    188197     */
     
    195204     *  Use a proxy.
    196205     *
    197      *  @param proxyPort must be valid, -1 disallowed, no default
     206     *  @param proxyHost Must be valid hostname or literal IPv4/v6.
     207     *                   If type is INTERNAL, set to "localhost".
     208     *  @param proxyPort Must be valid, -1 disallowed, no default.
     209     *                   If type is INTERNAL, set to 4444.
    198210     *  @param state an SSLState retrieved from a previous SSLEepGet with getSSLState(), or null.
    199211     *               This makes repeated fetches from the same host MUCH faster,
     
    277289                    } else if (y.equals("SOCKS5")) {
    278290                        ptype = ProxyType.SOCKS5;
     291                    } else if (y.equals("I2P")) {
     292                        ptype = ProxyType.INTERNAL;
     293                        proxyHost = "localhost";
     294                        proxyPort = 4444;
    279295                    } else {
    280296                        error = true;
     
    334350    private static void usage() {
    335351        System.err.println("Usage: SSLEepGet [-psyz] https://url\n" +
    336                            "  -p proxyHost[:proxyPort]    // default port 8080 for HTTPS and 1080 for SOCKS\n" +
    337                            "  -y HTTPS|SOCKS4|SOCKS5      // proxy type, default HTTPS if proxyHost is set\n" +
     352                           "  -p proxyHost[:proxyPort]    // default port 8080 for HTTPS and 1080 for SOCKS; default localhost:4444 for I2P\n" +
     353                           "  -y HTTPS|SOCKS4|SOCKS5|I2P  // proxy type, default HTTPS if proxyHost is set\n" +
    338354                           "  -s save unknown certs\n" +
    339355                           "  -s -s save all certs\n" +
     
    699715                        break;
    700716
     717                      case INTERNAL:
     718                        internalHttpProxyConnect(host, port);
     719                        break;
     720
    701721                      case SOCKS4:
    702722                        socksProxyConnect(false, host, port);
     
    708728
    709729                      case HTTPS:
    710                       case INTERNAL:
    711730                      case TRANSPARENT:
    712731                      default:
     
    804823            _proxy = new Socket(_proxyHost, _proxyPort);
    805824        }
     825        httpProxyConnect(_proxy, host, port);
     826    }
     827
     828    /**
     829     *  Connect to a HTTP proxy.
     830     *  Proxy address must be in _proxyHost and _proxyPort.
     831     *  Side effects: Sets _proxy, _proxyIn, _proxyOut,
     832     *  and other globals via readHeaders()
     833     *
     834     *  @param port what the proxy should connect to, probably 4444
     835     *  @since 0.9.33
     836     */
     837    private void internalHttpProxyConnect(String host, int port) throws IOException {
     838        // connect to the proxy
     839        _proxy = InternalSocket.getSocket(_proxyHost, _proxyPort);
     840        httpProxyConnect(_proxy, host, port);
     841    }
     842
     843    /**
     844     *  Connect to a HTTP proxy.
     845     *  Proxy address must be in _proxyHost and _proxyPort.
     846     *  Side effects: Sets _proxyIn, _proxyOut,
     847     *  and other globals via readHeaders()
     848     *
     849     *  @param host what the proxy should connect to
     850     *  @param port what the proxy should connect to
     851     *  @since 0.9.33
     852     */
     853    private void httpProxyConnect(Socket proxy, String host, int port) throws IOException {
    806854        _proxyIn = _proxy.getInputStream();
    807855        _proxyOut = _proxy.getOutputStream();
Note: See TracChangeset for help on using the changeset viewer.