1
0
Fork 0
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:
Florian Schmaus 2019-06-11 12:33:57 +02:00
parent 818ee8a727
commit 92b02afbff

View file

@ -435,33 +435,23 @@ public class Socks5Proxy {
@Override @Override
public void run() { public void run() {
while (true) { while (true) {
Socket socket = null; ServerSocket serverSocket = Socks5Proxy.this.serverSocket;
if (serverSocket == null || serverSocket.isClosed() || Thread.currentThread().isInterrupted()) {
try {
if (Socks5Proxy.this.serverSocket == null || Socks5Proxy.this.serverSocket.isClosed()
|| Thread.currentThread().isInterrupted()) {
return; return;
} }
// accept connection // accept connection
socket = Socks5Proxy.this.serverSocket.accept(); Socket socket = null;
try {
socket = 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.