Changeset 5a2975b


Ignore:
Timestamp:
Apr 13, 2016 1:40:46 PM (5 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
25fe886e
Parents:
094cf14
Message:

SOCKS: Fix NPE on lookup failure in SOCKS 4a
Remove duplicate lookups in SOCKS 5
Log tweaks
Streaming, i2ptunnel: Catch null destination in connect() calls
Synchronize Connection.setRemotePeer(); remove _remotePeerSet field

Files:
9 edited

Legend:

Unmodified
Added
Removed
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelClientBase.java

    r094cf14 r5a2975b  
    627627     * tunnel.
    628628     *
    629      * @param dest The destination to connect to
     629     * @param dest The destination to connect to, non-null
    630630     * @return a new I2PSocket
    631631     */
     
    639639     * tunnel.
    640640     *
    641      * @param dest The destination to connect to
     641     * @param dest The destination to connect to, non-null
    642642     * @param port The destination port to connect to 0 - 65535
    643643     * @return a new I2PSocket
     
    657657     * tunnel.
    658658     *
    659      * @param dest The destination to connect to
     659     * @param dest The destination to connect to, non-null
    660660     * @param opt Option to be used to open when opening the socket
    661661     * @return a new I2PSocket
     
    667667     */
    668668    public I2PSocket createI2PSocket(Destination dest, I2PSocketOptions opt) throws I2PException, ConnectException, NoRouteToHostException, InterruptedIOException {
     669        if (dest == null)
     670            throw new NullPointerException();
    669671        I2PSocket i2ps;
    670672
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/socks/SOCKS4aServer.java

    r094cf14 r5a2975b  
    2323import net.i2p.client.streaming.I2PSocketOptions;
    2424import net.i2p.data.DataFormatException;
     25import net.i2p.data.Destination;
    2526import net.i2p.util.HexDump;
    2627import net.i2p.util.Log;
     
    213214            if (connHostName.toLowerCase(Locale.US).endsWith(".i2p") ||
    214215                connHostName.toLowerCase(Locale.US).endsWith(".onion")) {
    215                 _log.debug("connecting to " + connHostName + "...");
    216                 // Let's not due a new Dest for every request, huh?
     216                // Let's not do a new Dest for every request, huh?
    217217                //I2PSocketManager sm = I2PSocketManagerFactory.createManager();
    218218                //destSock = sm.connect(I2PTunnel.destFromName(connHostName), null);
     219                Destination dest = I2PAppContext.getGlobalContext().namingService().lookup(connHostName);
     220                if (dest == null) {
     221                    try {
     222                        sendRequestReply(Reply.CONNECTION_REFUSED, InetAddress.getByName("127.0.0.1"), 0, out);
     223                    } catch (IOException ioe) {}
     224                    throw new SOCKSException("Host not found");
     225                }
     226                if (_log.shouldDebug())
     227                    _log.debug("connecting to " + connHostName + "...");
    219228                Properties overrides = new Properties();
    220229                I2PSocketOptions sktOpts = t.buildOptions(overrides);
    221230                sktOpts.setPort(connPort);
    222                 destSock = t.createI2PSocket(I2PAppContext.getGlobalContext().namingService().lookup(connHostName), sktOpts);
     231                destSock = t.createI2PSocket(dest, sktOpts);
    223232            } else if ("localhost".equals(connHostName) || "127.0.0.1".equals(connHostName)) {
    224233                String err = "No localhost accesses allowed through the Socks Proxy";
     
    250259                int p = I2PAppContext.getGlobalContext().random().nextInt(proxies.size());
    251260                String proxy = proxies.get(p);
    252                 _log.debug("connecting to port " + connPort + " proxy " + proxy + " for " + connHostName + "...");
     261                Destination dest = I2PAppContext.getGlobalContext().namingService().lookup(proxy);
     262                if (dest == null) {
     263                    try {
     264                        sendRequestReply(Reply.CONNECTION_REFUSED, InetAddress.getByName("127.0.0.1"), 0, out);
     265                    } catch (IOException ioe) {}
     266                    throw new SOCKSException("Outproxy not found");
     267                }
     268                if (_log.shouldDebug())
     269                    _log.debug("connecting to port " + connPort + " proxy " + proxy + " for " + connHostName + "...");
    253270                // this isn't going to work, these need to be socks outproxies so we need
    254271                // to do a socks session to them?
    255                 destSock = t.createI2PSocket(I2PAppContext.getGlobalContext().namingService().lookup(proxy));
     272                destSock = t.createI2PSocket(dest);
    256273            }
    257274            confirmConnection();
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/socks/SOCKS5Server.java

    r094cf14 r5a2975b  
    364364        try {
    365365            if (connHostName.toLowerCase(Locale.US).endsWith(".i2p")) {
    366                 _log.debug("connecting to " + connHostName + "...");
    367                 // Let's not due a new Dest for every request, huh?
     366                // Let's not do a new Dest for every request, huh?
    368367                //I2PSocketManager sm = I2PSocketManagerFactory.createManager();
    369368                //destSock = sm.connect(I2PTunnel.destFromName(connHostName), null);
     
    375374                    throw new SOCKSException("Host not found");
    376375                }
     376                if (_log.shouldDebug())
     377                    _log.debug("connecting to " + connHostName + "...");
    377378                Properties overrides = new Properties();
    378379                I2PSocketOptions sktOpts = t.buildOptions(overrides);
    379380                sktOpts.setPort(connPort);
    380                 destSock = t.createI2PSocket(I2PAppContext.getGlobalContext().namingService().lookup(connHostName), sktOpts);
     381                destSock = t.createI2PSocket(dest, sktOpts);
    381382            } else if ("localhost".equals(connHostName) || "127.0.0.1".equals(connHostName)) {
    382383                String err = "No localhost accesses allowed through the Socks Proxy";
     
    469470        if (dest == null)
    470471            throw new SOCKSException("Outproxy not found");
    471         I2PSocket destSock = tun.createI2PSocket(I2PAppContext.getGlobalContext().namingService().lookup(proxy), proxyOpts);
     472        I2PSocket destSock = tun.createI2PSocket(dest, proxyOpts);
    472473        DataOutputStream out = null;
    473474        DataInputStream in = null;
  • apps/streaming/java/src/net/i2p/client/streaming/impl/Connection.java

    r094cf14 r5a2975b  
    826826        _timer.addEvent(event, msToWait);
    827827    }
    828    
    829     private boolean _remotePeerSet = false;
     828
    830829    /** who are we talking with
    831      * @return peer Destination
    832      */
    833     public Destination getRemotePeer() { return _remotePeer; }
     830     * @return peer Destination or null if unset
     831     */
     832    public synchronized Destination getRemotePeer() { return _remotePeer; }
     833
     834    /**
     835     *  @param peer non-null
     836     */
    834837    public void setRemotePeer(Destination peer) {
    835         if (_remotePeerSet) throw new RuntimeException("Remote peer already set [" + _remotePeer + ", " + peer + "]");
    836         _remotePeerSet = true;
    837         _remotePeer = peer;
     838        if (peer == null)
     839            throw new NullPointerException();
     840        synchronized(this) {
     841            if (_remotePeer != null)
     842                throw new RuntimeException("Remote peer already set [" + _remotePeer + ", " + peer + "]");
     843            _remotePeer = peer;
     844        }
    838845        // now that we know who the other end is, get the rtt etc. from the cache
    839846        _connectionManager.updateOptsFromShare(this);
     
    12211228        else
    12221229            buf.append(" to ");
    1223         if (_remotePeerSet)
     1230        if (_remotePeer != null)
    12241231            buf.append(_remotePeer.calculateHash().toBase64().substring(0,4));
    12251232        else
  • apps/streaming/java/src/net/i2p/client/streaming/impl/ConnectionManager.java

    r094cf14 r5a2975b  
    396396     * connection delay, otherwise it returns immediately.
    397397     *
    398      * @param peer Destination to contact
     398     * @param peer Destination to contact, non-null
    399399     * @param opts Connection's options
    400400     * @param session generally the session from the constructor, but could be a subsession
     
    402402     */
    403403    public Connection connect(Destination peer, ConnectionOptions opts, I2PSession session) {
     404        if (peer == null)
     405            throw new NullPointerException();
    404406        Connection con = null;
    405407        long expiration = _context.clock().now();
  • apps/streaming/java/src/net/i2p/client/streaming/impl/ConnectionPacketHandler.java

    r094cf14 r5a2975b  
    480480                if (packet.isFlagSet(Packet.FLAG_SYNCHRONIZE)) {
    481481                    con.setSendStreamId(packet.getReceiveStreamId());
    482                     con.setRemotePeer(packet.getOptionalFrom());
     482                    Destination dest = packet.getOptionalFrom();
     483                    if (dest == null) {
     484                        if (_log.shouldWarn())
     485                            _log.warn("SYN Packet without FROM");
     486                        return false;
     487                    }
     488                    con.setRemotePeer(dest);
    483489                    return true;
    484490                } else {
  • apps/streaming/java/src/net/i2p/client/streaming/impl/I2PSocketManagerFull.java

    r094cf14 r5a2975b  
    525525    public I2PSocket connect(Destination peer, I2PSocketOptions options)
    526526                             throws I2PException, NoRouteToHostException {
     527        if (peer == null)
     528            throw new NullPointerException();
    527529        if (options == null)
    528530            options = _defaultOptions;
  • history.txt

    r094cf14 r5a2975b  
     12016-04-13 zzz
     2 * SOCKS: Fix NPE on lookup failure in SOCKS 4a
     3
    142016-04-07 zzz
    25 * Debian builds:
  • router/java/src/net/i2p/router/RouterVersion.java

    r094cf14 r5a2975b  
    1919    public final static String ID = "Monotone";
    2020    public final static String VERSION = CoreVersion.VERSION;
    21     public final static long BUILD = 1;
     21    public final static long BUILD = 2;
    2222
    2323    /** for example "-test" */
Note: See TracChangeset for help on using the changeset viewer.