From 92b02afbff60e807920db548eec6d0d2f2af8f65 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Tue, 11 Jun 2019 12:33:57 +0200 Subject: [PATCH] Improve exceptions of Socks5Proxy --- .../bytestreams/socks5/Socks5Proxy.java | 35 +++++++------------ 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5Proxy.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5Proxy.java index bff8d6fac..fec1bd113 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5Proxy.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5Proxy.java @@ -435,33 +435,23 @@ public class Socks5Proxy { @Override public void run() { while (true) { + ServerSocket serverSocket = Socks5Proxy.this.serverSocket; + if (serverSocket == null || serverSocket.isClosed() || Thread.currentThread().isInterrupted()) { + return; + } + + // accept connection Socket socket = null; - try { - - if (Socks5Proxy.this.serverSocket == null || Socks5Proxy.this.serverSocket.isClosed() - || Thread.currentThread().isInterrupted()) { - return; - } - - // accept connection - socket = Socks5Proxy.this.serverSocket.accept(); - + socket = serverSocket.accept(); // initialize connection establishConnection(socket); - - } - catch (SocketException e) { - /* - * do nothing, if caused by closing the server socket, thread will terminate in - * next loop - */ - } - catch (Exception e) { + } catch (SmackException | IOException e) { + // Do nothing, if caused by closing the server socket, thread will terminate in next loop. + LOGGER.log(Level.FINE, "Exception while " + Socks5Proxy.this + " was handling connection", e); CloseableUtil.maybeClose(socket, LOGGER); } } - } /** @@ -478,7 +468,7 @@ public class Socks5Proxy { // first byte is version should be 5 int b = in.read(); 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 @@ -523,7 +513,8 @@ public class Socks5Proxy { out.write(connectionRequest); 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.