aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/utils/SocksSocketFactory.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de/pixart/messenger/utils/SocksSocketFactory.java')
-rw-r--r--src/main/java/de/pixart/messenger/utils/SocksSocketFactory.java24
1 files changed, 19 insertions, 5 deletions
diff --git a/src/main/java/de/pixart/messenger/utils/SocksSocketFactory.java b/src/main/java/de/pixart/messenger/utils/SocksSocketFactory.java
index 0bc27749a..365f77c6c 100644
--- a/src/main/java/de/pixart/messenger/utils/SocksSocketFactory.java
+++ b/src/main/java/de/pixart/messenger/utils/SocksSocketFactory.java
@@ -19,7 +19,7 @@ public class SocksSocketFactory {
byte[] response = new byte[2];
proxyIs.read(response);
if (response[0] != 0x05 || response[1] != 0x00) {
- throw new SocksConnectionException();
+ throw new SocksConnectionException("Socks 5 handshake failed");
}
byte[] dest = destination.getBytes();
ByteBuffer request = ByteBuffer.allocate(7 + dest.length);
@@ -31,12 +31,18 @@ public class SocksSocketFactory {
response = new byte[7 + dest.length];
proxyIs.read(response);
if (response[1] != 0x00) {
- throw new SocksConnectionException();
+ if (response[1] == 0x04) {
+ throw new HostNotFoundException("Host unreachable");
+ }
+ if (response[1] == 0x05) {
+ throw new HostNotFoundException("Connection refused");
+ }
+ throw new SocksConnectionException("Unable to connect to destination " + (int) (response[1]));
}
}
public static boolean contains(byte needle, byte[] haystack) {
- for(byte hay : haystack) {
+ for (byte hay : haystack) {
if (hay == needle) {
return true;
}
@@ -59,11 +65,19 @@ public class SocksSocketFactory {
return createSocket(new InetSocketAddress(InetAddress.getLocalHost(), 9050), destination, port);
}
- static class SocksConnectionException extends IOException {
-
+ private static class SocksConnectionException extends IOException {
+ SocksConnectionException(String message) {
+ super(message);
+ }
}
public static class SocksProxyNotFoundException extends IOException {
}
+
+ public static class HostNotFoundException extends SocksConnectionException {
+ HostNotFoundException(String message) {
+ super(message);
+ }
+ }
}