Smack 4.1.8 needs improvement to handle Sock5BytestreamRequest.accept() with multiple <streamhost/>

File transfer between Pidgin client and an xmpp client uses smack 4.1.3 (and latest 4.1.8) failed. From a debug log of SMACK communication:

With reference to the method Socks5BytestreaRequest.accept()

When the two xmpp clients are on different network, if the multiple parameters from Pidgin client contains a local ip e.g:

09-10 11:21:20.029: D/SMACK(12093): RECV (0): <iq from='swan@example.com/pidgin’to=‘leopard@example.com/atalk’ type=‘set’ id=‘purple3bc5d7be’>

The whole file transfer process aborted with exceptions when the first connection cannot be established.

On tracing into socks5Client.getSocket(timeout) ===> res = establish(socket);

It is found that (res = false) when it tries to establish(socket) with a local ip but unavailable , it executes

              socket.close();

              throw new SmackException("SOCKS5 negotiation failed");

and no socket is being returned.

Since the SmackException is not being catched within the accept() method; but throwing upstream to the application. Under this case, the application will never succeed in staring up the file transfer using Sock5Bytestream, as any retry will always return the same effect.

I have captured the below log with the modified added catch (SmackException e) in the accept() method:

09-10 11:21:20.129: E/Jitsi(12093): [10] org.jivesoftware.smackx.bytestreams.socks5.Socks5BytestreamRequest.accept().246

SmackException while transfering file with failure Count: 0 at addrees: 192.168.1.109:51006 Exception:

09-10 11:21:20.129: E/Jitsi(12093): org.jivesoftware.smack.SmackException: SOCKS5 negotiation failed

09-10 11:21:20.129: E/Jitsi(12093): at org.jivesoftware.smackx.bytestreams.socks5.Socks5Client$1.call(Socks5Client.jav a:105)

09-10 11:21:20.129: E/Jitsi(12093): at org.jivesoftware.smackx.bytestreams.socks5.Socks5Client$1.call(Socks5Client.jav a:80)

09-10 11:21:20.129: E/Jitsi(12093): at java.util.concurrent.FutureTask.run(FutureTask.java:237)

09-10 11:21:20.129: E/Jitsi(12093): at java.lang.Thread.run(Thread.java:818)

To allow application to implement Sock5Bytestrem file transfer using Smack Library, the accept() must include an additional ‘catch’ statement as below. This is to disallow throwing the SmackException upstream as this will cause the application to abort the sock5 file transfer process.

     catch (SmackException e) {

            incrementConnectionFailures(address);

      }

I have actually successfully implement the sock5 file transfer between pidgin and the xmpp client atalk application (ported from Jitsi-android) with smack 4.1.8 with the above solution to resolve the issue.

You may try to install both pidgin and gajim client on a system, and then send a file from pidgin to gajim (with xmpp console turned on).

The file transfer failed in my earlier test (not sure if gajim has found a way to resolve this in the latest release). I believe gajim is also using a version of asmack or smack but personally did not verify this.

Also all current Jitsi client supports only ibb file transfer, with sock5Bytestream option disabled. Not sure if the above problem has prevent them from implementing it.

Please kindly consider my proposed implementation to the Smack Sock5BytestreamReques.accept() method.

Please kindly consider my proposed implementation to the Smack Sock5BytestreamReques.accept() method.

Please show us a patch or a github pull request based on the current ‘master’ branch of Smack, so that we can review your changes. Thank you.

Please see below for the patch based on the latest master branch (Oct 25, 2016) for file:

smack-extensions\src\main\java\org\jivesoftware\smackx\bytestreams\socks5\Socks5 BytestreamRequest.java


Index: Socks5BytestreamRequest.java

===================================================================

— Socks5BytestreamRequest.java (revision 5460)

+++ Socks5BytestreamRequest.java (working copy)

@@ -242,6 +242,9 @@

catch (TimeoutException e) {

incrementConnectionFailures(address);

}

  •        catch (SmackException e) {
    
  •            incrementConnectionFailures(address);
    
  •        }
    

catch (IOException e) {

incrementConnectionFailures(address);

}

Thanks. Fixed with Also catch SmackException in Socks5BytestreamRequest · Flowdalic/Smack@095b5c8 · GitHub