aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger
diff options
context:
space:
mode:
authorChristian Schneppe <christian.schneppe@pix-art.de>2019-10-26 16:50:56 +0200
committerChristian Schneppe <christian.schneppe@pix-art.de>2019-10-26 16:50:56 +0200
commit25eb08ae486bb7342632478c4f7c818f178cad76 (patch)
treed6c9973ec026c2fa02867ba7e2a0b97ae80e99a3 /src/main/java/de/pixart/messenger
parentc488121d3822aa72ec22a070121a04bbcfd0c092 (diff)
set shorter timeouts when using direct candidates
Diffstat (limited to 'src/main/java/de/pixart/messenger')
-rw-r--r--src/main/java/de/pixart/messenger/utils/SocksSocketFactory.java6
-rw-r--r--src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnection.java5
-rw-r--r--src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnectionManager.java2
-rw-r--r--src/main/java/de/pixart/messenger/xmpp/jingle/JingleSocks5Transport.java12
4 files changed, 16 insertions, 9 deletions
diff --git a/src/main/java/de/pixart/messenger/utils/SocksSocketFactory.java b/src/main/java/de/pixart/messenger/utils/SocksSocketFactory.java
index 365f77c6c..8a251a6a0 100644
--- a/src/main/java/de/pixart/messenger/utils/SocksSocketFactory.java
+++ b/src/main/java/de/pixart/messenger/utils/SocksSocketFactory.java
@@ -13,8 +13,8 @@ import de.pixart.messenger.Config;
public class SocksSocketFactory {
public static void createSocksConnection(Socket socket, String destination, int port) throws IOException {
- InputStream proxyIs = socket.getInputStream();
- OutputStream proxyOs = socket.getOutputStream();
+ final InputStream proxyIs = socket.getInputStream();
+ final OutputStream proxyOs = socket.getOutputStream();
proxyOs.write(new byte[]{0x05, 0x01, 0x00});
byte[] response = new byte[2];
proxyIs.read(response);
@@ -22,7 +22,7 @@ public class SocksSocketFactory {
throw new SocksConnectionException("Socks 5 handshake failed");
}
byte[] dest = destination.getBytes();
- ByteBuffer request = ByteBuffer.allocate(7 + dest.length);
+ final ByteBuffer request = ByteBuffer.allocate(7 + dest.length);
request.put(new byte[]{0x05, 0x01, 0x00, 0x03});
request.put((byte) dest.length);
request.put(dest);
diff --git a/src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnection.java b/src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnection.java
index d1a523239..561404186 100644
--- a/src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnection.java
+++ b/src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnection.java
@@ -568,8 +568,11 @@ public class JingleConnection implements Transferable {
content.setTransportId(this.transportId);
if (this.initialTransport == Transport.IBB) {
content.ibbTransport().setAttribute("block-size", Integer.toString(this.ibbBlockSize));
+ Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": sending IBB offer");
} else {
- content.socks5transport().setChildren(getCandidatesAsElements());
+ final List<Element> candidates = getCandidatesAsElements();
+ Log.d(Config.LOGTAG, String.format("%s: sending S5B offer with %d candidates", account.getJid().asBareJid(), candidates.size()));
+ content.socks5transport().setChildren(candidates);
}
packet.setContent(content);
this.sendJinglePacket(packet, (account, response) -> {
diff --git a/src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnectionManager.java b/src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnectionManager.java
index 068924bca..addd350d2 100644
--- a/src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnectionManager.java
+++ b/src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnectionManager.java
@@ -106,7 +106,7 @@ public class JingleConnectionManager extends AbstractConnectionManager {
candidate.setPort(Integer.parseInt(port));
candidate.setType(JingleCandidate.TYPE_PROXY);
candidate.setJid(proxy);
- candidate.setPriority(655360 + (initiator ? 10 : 20));
+ candidate.setPriority(655360 + (initiator ? 30 : 0));
primaryCandidates.put(account.getJid().asBareJid(), candidate);
listener.onPrimaryCandidateFound(true, candidate);
} catch (final NumberFormatException e) {
diff --git a/src/main/java/de/pixart/messenger/xmpp/jingle/JingleSocks5Transport.java b/src/main/java/de/pixart/messenger/xmpp/jingle/JingleSocks5Transport.java
index b3f56bba5..1fc69ec6f 100644
--- a/src/main/java/de/pixart/messenger/xmpp/jingle/JingleSocks5Transport.java
+++ b/src/main/java/de/pixart/messenger/xmpp/jingle/JingleSocks5Transport.java
@@ -26,7 +26,8 @@ import de.pixart.messenger.utils.WakeLockHelper;
import de.pixart.messenger.xmpp.jingle.stanzas.Content;
public class JingleSocks5Transport extends JingleTransport {
-
+ private static final int SOCKET_TIMEOUT_DIRECT = 3000;
+ private static final int SOCKET_TIMEOUT_PROXY = 5000;
private final JingleCandidate candidate;
private final JingleConnection connection;
private final String destination;
@@ -93,8 +94,9 @@ public class JingleSocks5Transport extends JingleTransport {
}
}
- private void acceptIncomingSocketConnection(Socket socket) throws IOException {
+ private void acceptIncomingSocketConnection(final Socket socket) throws IOException {
Log.d(Config.LOGTAG, "accepted connection from " + socket.getInetAddress().getHostAddress());
+ socket.setSoTimeout(SOCKET_TIMEOUT_DIRECT);
final byte[] authBegin = new byte[2];
final InputStream inputStream = socket.getInputStream();
final OutputStream outputStream = socket.getOutputStream();
@@ -137,6 +139,7 @@ public class JingleSocks5Transport extends JingleTransport {
outputStream.flush();
if (success) {
Log.d(Config.LOGTAG, connection.getAccount().getJid().asBareJid() + ": successfully processed connection to candidate " + candidate.getHost() + ":" + candidate.getPort());
+ socket.setSoTimeout(0);
this.socket = socket;
this.inputStream = inputStream;
this.outputStream = outputStream;
@@ -152,6 +155,7 @@ public class JingleSocks5Transport extends JingleTransport {
public void connect(final OnTransportConnected callback) {
new Thread(() -> {
+ final int timeout = candidate.getType() == JingleCandidate.TYPE_DIRECT ? SOCKET_TIMEOUT_DIRECT : SOCKET_TIMEOUT_PROXY;
try {
final boolean useTor = connection.getAccount().isOnion() || connection.getConnectionManager().getXmppConnectionService().useTorToConnect();
if (useTor) {
@@ -159,11 +163,11 @@ public class JingleSocks5Transport extends JingleTransport {
} else {
socket = new Socket();
SocketAddress address = new InetSocketAddress(candidate.getHost(), candidate.getPort());
- socket.connect(address, 5000);
+ socket.connect(address, timeout);
}
inputStream = socket.getInputStream();
outputStream = socket.getOutputStream();
- socket.setSoTimeout(5000);
+ socket.setSoTimeout(timeout);
SocksSocketFactory.createSocksConnection(socket, destination, 0);
socket.setSoTimeout(0);
isEstablished = true;