diff options
author | Christian Schneppe <christian@pix-art.de> | 2019-04-28 14:45:36 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2019-04-28 14:45:36 +0200 |
commit | b563d5a8118006f967b153a0aafca81b54b88f2f (patch) | |
tree | 134962d1ea74311ae999cafeb189815124b6caa3 /src/main/java/de/pixart/messenger/services | |
parent | da896e202d1d286b60fa1f950d76dfdb403b0176 (diff) |
added Tor support to channel search
Diffstat (limited to 'src/main/java/de/pixart/messenger/services')
-rw-r--r-- | src/main/java/de/pixart/messenger/services/ChannelDiscoveryService.java | 26 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/services/XmppConnectionService.java | 5 |
2 files changed, 27 insertions, 4 deletions
diff --git a/src/main/java/de/pixart/messenger/services/ChannelDiscoveryService.java b/src/main/java/de/pixart/messenger/services/ChannelDiscoveryService.java index 21711c647..ac790b10f 100644 --- a/src/main/java/de/pixart/messenger/services/ChannelDiscoveryService.java +++ b/src/main/java/de/pixart/messenger/services/ChannelDiscoveryService.java @@ -5,12 +5,16 @@ import android.util.Log; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; +import java.io.IOException; +import java.util.Collections; import java.util.List; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import de.pixart.messenger.Config; +import de.pixart.messenger.http.HttpConnectionManager; import de.pixart.messenger.http.services.MuclumbusService; +import okhttp3.OkHttpClient; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; @@ -21,19 +25,31 @@ public class ChannelDiscoveryService { private final XmppConnectionService service; - private final MuclumbusService muclumbusService; + private MuclumbusService muclumbusService; private final Cache<String, List<MuclumbusService.Room>> cache; public ChannelDiscoveryService(XmppConnectionService service) { this.service = service; + this.cache = CacheBuilder.newBuilder().expireAfterWrite(5, TimeUnit.MINUTES).build(); + } + + public void initializeMuclumbusService() { + OkHttpClient.Builder builder = new OkHttpClient.Builder(); + if (service.useTorToConnect()) { + try { + builder.proxy(HttpConnectionManager.getProxy()); + } catch (IOException e) { + throw new RuntimeException("Unable to use Tor proxy", e); + } + } Retrofit retrofit = new Retrofit.Builder() + .client(builder.build()) .baseUrl(Config.CHANNEL_DISCOVERY) .addConverterFactory(GsonConverterFactory.create()) .callbackExecutor(Executors.newSingleThreadExecutor()) .build(); this.muclumbusService = retrofit.create(MuclumbusService.class); - this.cache = CacheBuilder.newBuilder().expireAfterWrite(5, TimeUnit.MINUTES).build(); } public void discover(String query, OnChannelSearchResultsFound onChannelSearchResultsFound) { @@ -67,7 +83,8 @@ public class ChannelDiscoveryService { @Override public void onFailure(Call<MuclumbusService.Rooms> call, Throwable throwable) { - + Log.d(Config.LOGTAG, "Unable to query muclumbus on " + Config.CHANNEL_DISCOVERY, throwable); + listener.onChannelSearchResultsFound(Collections.emptyList()); } }); } catch (Exception e) { @@ -92,7 +109,8 @@ public class ChannelDiscoveryService { @Override public void onFailure(Call<MuclumbusService.SearchResult> call, Throwable throwable) { - throwable.printStackTrace(); + Log.d(Config.LOGTAG, "Unable to query muclumbus on " + Config.CHANNEL_DISCOVERY, throwable); + listener.onChannelSearchResultsFound(Collections.emptyList()); } }); } diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index 1456d5a8e..5917cc725 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -839,6 +839,10 @@ public class XmppConnectionService extends Service { editor.commit(); } + public void reinitializeMuclumbusService() { + mChannelDiscoveryService.initializeMuclumbusService(); + } + public void discoverChannels(String query, ChannelDiscoveryService.OnChannelSearchResultsFound onChannelSearchResultsFound) { mChannelDiscoveryService.discover(query, onChannelSearchResultsFound); } @@ -1153,6 +1157,7 @@ public class XmppConnectionService extends Service { if (Compatibility.runsTwentySix()) { mNotificationService.initializeChannels(); } + mChannelDiscoveryService.initializeMuclumbusService(); mForceDuringOnCreate.set(Compatibility.runsAndTargetsTwentySix(this)); final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024); final int cacheSize = maxMemory / 8; |