forked from I2P_Developers/i2p.i2p
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
This commit is contained in:
@ -626,7 +626,7 @@ public abstract class I2PTunnelClientBase extends I2PTunnelTask implements Runna
|
||||
* adding it to the list of connections actually managed by this
|
||||
* tunnel.
|
||||
*
|
||||
* @param dest The destination to connect to
|
||||
* @param dest The destination to connect to, non-null
|
||||
* @return a new I2PSocket
|
||||
*/
|
||||
public I2PSocket createI2PSocket(Destination dest) throws I2PException, ConnectException, NoRouteToHostException, InterruptedIOException {
|
||||
@ -638,7 +638,7 @@ public abstract class I2PTunnelClientBase extends I2PTunnelTask implements Runna
|
||||
* adding it to the list of connections actually managed by this
|
||||
* tunnel.
|
||||
*
|
||||
* @param dest The destination to connect to
|
||||
* @param dest The destination to connect to, non-null
|
||||
* @param port The destination port to connect to 0 - 65535
|
||||
* @return a new I2PSocket
|
||||
* @since 0.9.9
|
||||
@ -656,7 +656,7 @@ public abstract class I2PTunnelClientBase extends I2PTunnelTask implements Runna
|
||||
* adding it to the list of connections actually managed by this
|
||||
* tunnel.
|
||||
*
|
||||
* @param dest The destination to connect to
|
||||
* @param dest The destination to connect to, non-null
|
||||
* @param opt Option to be used to open when opening the socket
|
||||
* @return a new I2PSocket
|
||||
*
|
||||
@ -666,6 +666,8 @@ public abstract class I2PTunnelClientBase extends I2PTunnelTask implements Runna
|
||||
* @throws I2PException if there is some other I2P-related problem
|
||||
*/
|
||||
public I2PSocket createI2PSocket(Destination dest, I2PSocketOptions opt) throws I2PException, ConnectException, NoRouteToHostException, InterruptedIOException {
|
||||
if (dest == null)
|
||||
throw new NullPointerException();
|
||||
I2PSocket i2ps;
|
||||
|
||||
verifySocketManager();
|
||||
|
@ -22,6 +22,7 @@ import net.i2p.I2PException;
|
||||
import net.i2p.client.streaming.I2PSocket;
|
||||
import net.i2p.client.streaming.I2PSocketOptions;
|
||||
import net.i2p.data.DataFormatException;
|
||||
import net.i2p.data.Destination;
|
||||
import net.i2p.util.HexDump;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
@ -212,14 +213,22 @@ public class SOCKS4aServer extends SOCKSServer {
|
||||
try {
|
||||
if (connHostName.toLowerCase(Locale.US).endsWith(".i2p") ||
|
||||
connHostName.toLowerCase(Locale.US).endsWith(".onion")) {
|
||||
_log.debug("connecting to " + connHostName + "...");
|
||||
// Let's not due a new Dest for every request, huh?
|
||||
// Let's not do a new Dest for every request, huh?
|
||||
//I2PSocketManager sm = I2PSocketManagerFactory.createManager();
|
||||
//destSock = sm.connect(I2PTunnel.destFromName(connHostName), null);
|
||||
Destination dest = I2PAppContext.getGlobalContext().namingService().lookup(connHostName);
|
||||
if (dest == null) {
|
||||
try {
|
||||
sendRequestReply(Reply.CONNECTION_REFUSED, InetAddress.getByName("127.0.0.1"), 0, out);
|
||||
} catch (IOException ioe) {}
|
||||
throw new SOCKSException("Host not found");
|
||||
}
|
||||
if (_log.shouldDebug())
|
||||
_log.debug("connecting to " + connHostName + "...");
|
||||
Properties overrides = new Properties();
|
||||
I2PSocketOptions sktOpts = t.buildOptions(overrides);
|
||||
sktOpts.setPort(connPort);
|
||||
destSock = t.createI2PSocket(I2PAppContext.getGlobalContext().namingService().lookup(connHostName), sktOpts);
|
||||
destSock = t.createI2PSocket(dest, sktOpts);
|
||||
} else if ("localhost".equals(connHostName) || "127.0.0.1".equals(connHostName)) {
|
||||
String err = "No localhost accesses allowed through the Socks Proxy";
|
||||
_log.error(err);
|
||||
@ -249,10 +258,18 @@ public class SOCKS4aServer extends SOCKSServer {
|
||||
}
|
||||
int p = I2PAppContext.getGlobalContext().random().nextInt(proxies.size());
|
||||
String proxy = proxies.get(p);
|
||||
_log.debug("connecting to port " + connPort + " proxy " + proxy + " for " + connHostName + "...");
|
||||
Destination dest = I2PAppContext.getGlobalContext().namingService().lookup(proxy);
|
||||
if (dest == null) {
|
||||
try {
|
||||
sendRequestReply(Reply.CONNECTION_REFUSED, InetAddress.getByName("127.0.0.1"), 0, out);
|
||||
} catch (IOException ioe) {}
|
||||
throw new SOCKSException("Outproxy not found");
|
||||
}
|
||||
if (_log.shouldDebug())
|
||||
_log.debug("connecting to port " + connPort + " proxy " + proxy + " for " + connHostName + "...");
|
||||
// this isn't going to work, these need to be socks outproxies so we need
|
||||
// to do a socks session to them?
|
||||
destSock = t.createI2PSocket(I2PAppContext.getGlobalContext().namingService().lookup(proxy));
|
||||
destSock = t.createI2PSocket(dest);
|
||||
}
|
||||
confirmConnection();
|
||||
_log.debug("connection confirmed - exchanging data...");
|
||||
|
@ -363,8 +363,7 @@ public class SOCKS5Server extends SOCKSServer {
|
||||
|
||||
try {
|
||||
if (connHostName.toLowerCase(Locale.US).endsWith(".i2p")) {
|
||||
_log.debug("connecting to " + connHostName + "...");
|
||||
// Let's not due a new Dest for every request, huh?
|
||||
// Let's not do a new Dest for every request, huh?
|
||||
//I2PSocketManager sm = I2PSocketManagerFactory.createManager();
|
||||
//destSock = sm.connect(I2PTunnel.destFromName(connHostName), null);
|
||||
Destination dest = I2PAppContext.getGlobalContext().namingService().lookup(connHostName);
|
||||
@ -374,10 +373,12 @@ public class SOCKS5Server extends SOCKSServer {
|
||||
} catch (IOException ioe) {}
|
||||
throw new SOCKSException("Host not found");
|
||||
}
|
||||
if (_log.shouldDebug())
|
||||
_log.debug("connecting to " + connHostName + "...");
|
||||
Properties overrides = new Properties();
|
||||
I2PSocketOptions sktOpts = t.buildOptions(overrides);
|
||||
sktOpts.setPort(connPort);
|
||||
destSock = t.createI2PSocket(I2PAppContext.getGlobalContext().namingService().lookup(connHostName), sktOpts);
|
||||
destSock = t.createI2PSocket(dest, sktOpts);
|
||||
} else if ("localhost".equals(connHostName) || "127.0.0.1".equals(connHostName)) {
|
||||
String err = "No localhost accesses allowed through the Socks Proxy";
|
||||
_log.error(err);
|
||||
@ -468,7 +469,7 @@ public class SOCKS5Server extends SOCKSServer {
|
||||
Destination dest = I2PAppContext.getGlobalContext().namingService().lookup(proxy);
|
||||
if (dest == null)
|
||||
throw new SOCKSException("Outproxy not found");
|
||||
I2PSocket destSock = tun.createI2PSocket(I2PAppContext.getGlobalContext().namingService().lookup(proxy), proxyOpts);
|
||||
I2PSocket destSock = tun.createI2PSocket(dest, proxyOpts);
|
||||
DataOutputStream out = null;
|
||||
DataInputStream in = null;
|
||||
try {
|
||||
|
Reference in New Issue
Block a user