mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 04:39:54 +01:00
Include description of SOCKS error in exception.
This commit is contained in:
@@ -12,6 +12,18 @@ import java.net.SocketAddress;
|
|||||||
|
|
||||||
class SocksSocket extends Socket {
|
class SocksSocket extends Socket {
|
||||||
|
|
||||||
|
private static final String[] ERRORS = {
|
||||||
|
"Succeeded",
|
||||||
|
"General SOCKS server failure",
|
||||||
|
"Connection not allowed by ruleset",
|
||||||
|
"Network unreachable",
|
||||||
|
"Host unreachable",
|
||||||
|
"Connection refused",
|
||||||
|
"TTL expired",
|
||||||
|
"Command not supported",
|
||||||
|
"Address type not supported"
|
||||||
|
};
|
||||||
|
|
||||||
private final SocketAddress proxy;
|
private final SocketAddress proxy;
|
||||||
private final int connectToProxyTimeout;
|
private final int connectToProxyTimeout;
|
||||||
|
|
||||||
@@ -93,13 +105,16 @@ class SocksSocket extends Socket {
|
|||||||
private void receiveConnectResponse(InputStream in) throws IOException {
|
private void receiveConnectResponse(InputStream in) throws IOException {
|
||||||
byte[] connectResponse = new byte[4];
|
byte[] connectResponse = new byte[4];
|
||||||
IoUtils.read(in, connectResponse);
|
IoUtils.read(in, connectResponse);
|
||||||
byte version = connectResponse[0];
|
int version = connectResponse[0] & 0xFF;
|
||||||
byte reply = connectResponse[1];
|
int reply = connectResponse[1] & 0xFF;
|
||||||
byte addressType = connectResponse[3];
|
int addressType = connectResponse[3] & 0xFF;
|
||||||
if (version != 5)
|
if (version != 5)
|
||||||
throw new IOException("Unsupported SOCKS version: " + version);
|
throw new IOException("Unsupported SOCKS version: " + version);
|
||||||
if (reply != 0)
|
if (reply != 0) {
|
||||||
throw new IOException("Connection failed: " + reply);
|
if (reply < ERRORS.length)
|
||||||
|
throw new IOException("Connection failed: " + ERRORS[reply]);
|
||||||
|
else throw new IOException("Connection failed: " + reply);
|
||||||
|
}
|
||||||
if (addressType == 1) IoUtils.read(in, new byte[4]); // IPv4
|
if (addressType == 1) IoUtils.read(in, new byte[4]); // IPv4
|
||||||
else if (addressType == 4) IoUtils.read(in, new byte[16]); // IPv6
|
else if (addressType == 4) IoUtils.read(in, new byte[16]); // IPv6
|
||||||
else throw new IOException("Unsupported address type: " + addressType);
|
else throw new IOException("Unsupported address type: " + addressType);
|
||||||
|
|||||||
Reference in New Issue
Block a user