diff options
author | Daniel Gultsch <daniel@gultsch.de> | 2015-11-28 20:11:38 +0100 |
---|---|---|
committer | Christian S <christian@pix-art.de> | 2015-12-04 20:02:05 +0100 |
commit | c1677af5b1872846c39514e5c488381de67be63c (patch) | |
tree | 8d87764082c000b998ff4b57cc739ac0790cad66 /src/main/java/eu/siacs/conversations/xmpp | |
parent | 45e961f02b1f60859741af16f6d278b0cfdfb121 (diff) |
initial tor support
Diffstat (limited to 'src/main/java/eu/siacs/conversations/xmpp')
-rw-r--r-- | src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java | 18 | ||||
-rw-r--r-- | src/main/java/eu/siacs/conversations/xmpp/jingle/JingleSocks5Transport.java | 6 |
2 files changed, 18 insertions, 6 deletions
diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java index 16b3f78b4..dec3cad6d 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java @@ -27,6 +27,7 @@ import java.net.ConnectException; import java.net.IDN; import java.net.InetAddress; import java.net.InetSocketAddress; +import java.net.Proxy; import java.net.Socket; import java.net.UnknownHostException; import java.net.URL; @@ -233,16 +234,23 @@ public class XmppConnection implements Runnable { tagReader = new XmlReader(wakeLock); tagWriter = new TagWriter(); this.changeStatus(Account.State.CONNECTING); + final boolean useTor = mXmppConnectionService.useTorToConnect(); + final Proxy TOR_PROXY = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress(InetAddress.getLocalHost(), 9050)); if (DNSHelper.isIp(account.getServer().toString())) { - socket = new Socket(); + socket = useTor ? new Socket(TOR_PROXY) : new Socket(); try { socket.connect(new InetSocketAddress(account.getServer().toString(), 5222), Config.SOCKET_TIMEOUT * 1000); } catch (IOException e) { throw new UnknownHostException(); } } else { - final Bundle result = DNSHelper.getSRVRecord(account.getServer(),mXmppConnectionService); - final ArrayList<Parcelable> values = result.getParcelableArrayList("values"); + final ArrayList<Parcelable> values; + if (useTor) { + values = account.getHostnamePortBundles(); + } else { + final Bundle result = DNSHelper.getSRVRecord(account.getServer(),mXmppConnectionService); + values = result.getParcelableArrayList("values"); + } int i = 0; boolean socketError = true; while (socketError && values.size() > i) { @@ -269,11 +277,11 @@ public class XmppConnection implements Runnable { + ": using values from dns " + srvRecordServer + ":" + srvRecordPort); } - socket = new Socket(); + socket = useTor ? new Socket(TOR_PROXY) : new Socket(); socket.connect(addr, Config.SOCKET_TIMEOUT * 1000); socketError = false; } catch (final Throwable e) { - Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": " + e.getMessage()); + Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": " + e.getMessage() +"("+e.getClass().getName()+")"); i++; } } diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleSocks5Transport.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleSocks5Transport.java index 556395aef..74306ce3d 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleSocks5Transport.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleSocks5Transport.java @@ -7,7 +7,9 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.net.InetAddress; import java.net.InetSocketAddress; +import java.net.Proxy; import java.net.Socket; import java.net.SocketAddress; import java.net.UnknownHostException; @@ -59,7 +61,9 @@ public class JingleSocks5Transport extends JingleTransport { @Override public void run() { try { - socket = new Socket(); + final boolean useTor = connection.getConnectionManager().getXmppConnectionService().useTorToConnect(); + final Proxy TOR_PROXY = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress(InetAddress.getLocalHost(), 9050)); + socket = useTor ? new Socket(TOR_PROXY) : new Socket(); SocketAddress address = new InetSocketAddress(candidate.getHost(),candidate.getPort()); socket.connect(address,Config.SOCKET_TIMEOUT * 1000); inputStream = socket.getInputStream(); |