mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-22 14:22:05 +01:00
Improve exceptions of Socks5Proxy
This commit is contained in:
parent
818ee8a727
commit
92b02afbff
1 changed files with 13 additions and 22 deletions
|
@ -435,33 +435,23 @@ public class Socks5Proxy {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
while (true) {
|
while (true) {
|
||||||
|
ServerSocket serverSocket = Socks5Proxy.this.serverSocket;
|
||||||
|
if (serverSocket == null || serverSocket.isClosed() || Thread.currentThread().isInterrupted()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// accept connection
|
||||||
Socket socket = null;
|
Socket socket = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
socket = serverSocket.accept();
|
||||||
if (Socks5Proxy.this.serverSocket == null || Socks5Proxy.this.serverSocket.isClosed()
|
|
||||||
|| Thread.currentThread().isInterrupted()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// accept connection
|
|
||||||
socket = Socks5Proxy.this.serverSocket.accept();
|
|
||||||
|
|
||||||
// initialize connection
|
// initialize connection
|
||||||
establishConnection(socket);
|
establishConnection(socket);
|
||||||
|
} catch (SmackException | IOException e) {
|
||||||
}
|
// Do nothing, if caused by closing the server socket, thread will terminate in next loop.
|
||||||
catch (SocketException e) {
|
LOGGER.log(Level.FINE, "Exception while " + Socks5Proxy.this + " was handling connection", e);
|
||||||
/*
|
|
||||||
* do nothing, if caused by closing the server socket, thread will terminate in
|
|
||||||
* next loop
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
CloseableUtil.maybeClose(socket, LOGGER);
|
CloseableUtil.maybeClose(socket, LOGGER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -478,7 +468,7 @@ public class Socks5Proxy {
|
||||||
// first byte is version should be 5
|
// first byte is version should be 5
|
||||||
int b = in.read();
|
int b = in.read();
|
||||||
if (b != 5) {
|
if (b != 5) {
|
||||||
throw new SmackException.SmackMessageException("Only SOCKS5 supported");
|
throw new SmackException.SmackMessageException("Only SOCKS5 supported: Peer send " + b + " but we expect 5");
|
||||||
}
|
}
|
||||||
|
|
||||||
// second byte number of authentication methods supported
|
// second byte number of authentication methods supported
|
||||||
|
@ -523,7 +513,8 @@ public class Socks5Proxy {
|
||||||
out.write(connectionRequest);
|
out.write(connectionRequest);
|
||||||
out.flush();
|
out.flush();
|
||||||
|
|
||||||
throw new SmackException.SmackMessageException("Connection is not allowed");
|
throw new SmackException.SmackMessageException(
|
||||||
|
"Connection with digest '" + responseDigest + "' is not allowed");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store the connection before we send the return status.
|
// Store the connection before we send the return status.
|
||||||
|
|
Loading…
Reference in a new issue