From 6b755c7a6a2e523b599cfebb12421213bc8a4cf8 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Mon, 17 Jun 2019 21:21:25 +0200 Subject: use socks instead of http proxy for http upload MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit http proxy doesn’t seem to work with onion v3 --- src/main/java/de/pixart/messenger/http/HttpConnectionManager.java | 2 +- .../java/de/pixart/messenger/http/HttpDownloadConnection.java | 8 +++----- src/main/java/de/pixart/messenger/http/HttpUploadConnection.java | 4 +++- 3 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src/main/java/de') diff --git a/src/main/java/de/pixart/messenger/http/HttpConnectionManager.java b/src/main/java/de/pixart/messenger/http/HttpConnectionManager.java index 84c4aa1bb..e6e1a3df5 100644 --- a/src/main/java/de/pixart/messenger/http/HttpConnectionManager.java +++ b/src/main/java/de/pixart/messenger/http/HttpConnectionManager.java @@ -36,7 +36,7 @@ public class HttpConnectionManager extends AbstractConnectionManager { } public static Proxy getProxy() throws IOException { - return new Proxy(Proxy.Type.HTTP, new InetSocketAddress(InetAddress.getByAddress(new byte[]{127, 0, 0, 1}), 8118)); + return new Proxy(Proxy.Type.SOCKS, new InetSocketAddress(InetAddress.getByAddress(new byte[]{127, 0, 0, 1}), 9050)); } public void createNewDownloadConnection(Message message) { diff --git a/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java b/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java index e5f5d878a..969ea1611 100644 --- a/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java +++ b/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java @@ -280,13 +280,13 @@ public class HttpDownloadConnection implements Transferable { } private long retrieveFileSize() throws IOException { - PowerManager.WakeLock wakeLock = mHttpConnectionManager.createWakeLock("http_download_filesize" + message.getUuid()); try { - wakeLock.acquire(); Log.d(Config.LOGTAG, "retrieve file size. interactive:" + String.valueOf(interactive)); changeStatus(STATUS_CHECKING); HttpURLConnection connection; - if (mUseTor || message.getConversation().getAccount().isOnion()) { + final String hostname = mUrl.getHost(); + final boolean onion = hostname != null && hostname.endsWith(".onion"); + if (mUseTor || message.getConversation().getAccount().isOnion() || onion) { connection = (HttpURLConnection) mUrl.openConnection(HttpConnectionManager.getProxy()); } else { connection = (HttpURLConnection) mUrl.openConnection(); @@ -329,8 +329,6 @@ public class HttpDownloadConnection implements Transferable { throw e; } catch (NumberFormatException e) { throw new IOException(); - } finally { - WakeLockHelper.release(wakeLock); } } diff --git a/src/main/java/de/pixart/messenger/http/HttpUploadConnection.java b/src/main/java/de/pixart/messenger/http/HttpUploadConnection.java index 609ad65d3..0fa79ff8f 100644 --- a/src/main/java/de/pixart/messenger/http/HttpUploadConnection.java +++ b/src/main/java/de/pixart/messenger/http/HttpUploadConnection.java @@ -155,11 +155,13 @@ public class HttpUploadConnection implements Transferable { PowerManager.WakeLock wakeLock = mHttpConnectionManager.createWakeLock("http_upload_" + message.getUuid()); try { fileInputStream = new FileInputStream(file); + final String slotHostname = slot.getPutUrl().getHost(); + final boolean onionSlot = slotHostname != null && slotHostname.endsWith(".onion"); final int expectedFileSize = (int) file.getExpectedSize(); final int readTimeout = ((expectedFileSize / 2048) + Config.SOCKET_TIMEOUT) * 1000; //assuming a minimum transfer speed of 16kbit/s wakeLock.acquire(readTimeout); Log.d(Config.LOGTAG, "uploading to " + slot.getPutUrl().toString() + " w/ read timeout of " + readTimeout / 1000 + "s"); - if (mUseTor || message.getConversation().getAccount().isOnion()) { + if (mUseTor || message.getConversation().getAccount().isOnion() || onionSlot) { connection = (HttpURLConnection) slot.getPutUrl().openConnection(HttpConnectionManager.getProxy()); } else { connection = (HttpURLConnection) slot.getPutUrl().openConnection(); -- cgit v1.2.3