i2ptunnel: Return error code from SOCKS client on failure to build tunnels

previously just closed the socket
This commit is contained in:
zzz
2023-01-15 11:18:00 -05:00
parent acec9b5275
commit 19e3122f48
2 changed files with 20 additions and 1 deletions

View File

@@ -164,6 +164,8 @@ public class I2PSOCKSTunnel extends I2PTunnelClientBase {
/**
* Because getDefaultOptions() in super() is protected
* @since 0.8.2
*
* This will throw IAE on tunnel build failure
*/
public I2PSocketOptions buildOptions(Properties overrides) {
Properties defaultOpts = getTunnel().getClientOptions();

View File

@@ -473,7 +473,17 @@ class SOCKS5Server extends SOCKSServer {
if (_log.shouldDebug())
_log.debug("connecting to " + connHostName + "...");
Properties overrides = new Properties();
I2PSocketOptions sktOpts = t.buildOptions(overrides);
I2PSocketOptions sktOpts;
try {
sktOpts = t.buildOptions(overrides);
} catch (RuntimeException re) {
// tunnel build failure
_log.error("socks error", re);
try {
sendRequestReply(Reply.GENERAL_SOCKS_SERVER_FAILURE, AddressType.DOMAINNAME, null, "0.0.0.0", 0, out);
} catch (IOException ioe) {}
throw re;
}
sktOpts.setPort(connPort);
destSock = t.createI2PSocket(dest, sktOpts);
} else if (hostLowerCase.equals("localhost") || connHostName.equals("127.0.0.1") ||
@@ -525,6 +535,13 @@ class SOCKS5Server extends SOCKSServer {
String proxy = proxies.get(p);
try {
destSock = outproxyConnect(t, proxy);
} catch (RuntimeException re) {
// tunnel build failure
_log.error("socks error", re);
try {
sendRequestReply(Reply.GENERAL_SOCKS_SERVER_FAILURE, AddressType.DOMAINNAME, null, "0.0.0.0", 0, out);
} catch (IOException ioe) {}
throw re;
} catch (SOCKSException se) {
try {
sendRequestReply(Reply.HOST_UNREACHABLE, AddressType.DOMAINNAME, null, "0.0.0.0", 0, out);