Use a simple check to verify proxies during registration.

fork-5.53.8
Greyson Parrelli 2021-02-03 14:55:05 -05:00
rodzic 51879a9c46
commit af7e736de9
4 zmienionych plików z 39 dodań i 2 usunięć

Wyświetl plik

@ -148,6 +148,7 @@ public class EditProxyFragment extends Fragment {
requireActivity().onBackPressed(); requireActivity().onBackPressed();
}) })
.show(); .show();
requireActivity().onBackPressed();
break; break;
case PROXY_FAILURE: case PROXY_FAILURE:
proxyStatus.setVisibility(View.INVISIBLE); proxyStatus.setVisibility(View.INVISIBLE);

Wyświetl plik

@ -6,12 +6,16 @@ import androidx.annotation.WorkerThread;
import androidx.lifecycle.Observer; import androidx.lifecycle.Observer;
import org.conscrypt.Conscrypt; import org.conscrypt.Conscrypt;
import org.signal.core.util.concurrent.SignalExecutors;
import org.signal.core.util.logging.Log; import org.signal.core.util.logging.Log;
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies; import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
import org.thoughtcrime.securesms.keyvalue.SignalStore; import org.thoughtcrime.securesms.keyvalue.SignalStore;
import org.thoughtcrime.securesms.net.PipeConnectivityListener; import org.thoughtcrime.securesms.net.PipeConnectivityListener;
import org.thoughtcrime.securesms.push.AccountManagerFactory;
import org.whispersystems.signalservice.api.SignalServiceAccountManager;
import org.whispersystems.signalservice.internal.configuration.SignalProxy; import org.whispersystems.signalservice.internal.configuration.SignalProxy;
import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
@ -69,8 +73,8 @@ public final class SignalProxyUtil {
startListeningToWebsocket(); startListeningToWebsocket();
if (TextSecurePreferences.getLocalNumber(ApplicationDependencies.getApplication()) == null) { if (TextSecurePreferences.getLocalNumber(ApplicationDependencies.getApplication()) == null) {
Log.i(TAG, "User is unregistered! Assuming success."); Log.i(TAG, "User is unregistered! Doing simple check.");
return true; return testWebsocketConnectionUnregistered(timeout);
} }
CountDownLatch latch = new CountDownLatch(1); CountDownLatch latch = new CountDownLatch(1);
@ -156,4 +160,28 @@ public final class SignalProxyUtil {
return "https://" + PROXY_LINK_HOST + "/#" + host; return "https://" + PROXY_LINK_HOST + "/#" + host;
} }
private static boolean testWebsocketConnectionUnregistered(long timeout) {
CountDownLatch latch = new CountDownLatch(1);
AtomicBoolean success = new AtomicBoolean(false);
SignalServiceAccountManager accountManager = AccountManagerFactory.createUnauthenticated(ApplicationDependencies.getApplication(), "", "");
SignalExecutors.UNBOUNDED.execute(() -> {
try {
accountManager.checkNetworkConnection();
success.set(true);
latch.countDown();
} catch (IOException e) {
latch.countDown();
}
});
try {
latch.await(timeout, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
Log.w(TAG, "Interrupted!", e);
}
return success.get();
}
} }

Wyświetl plik

@ -632,6 +632,10 @@ public class SignalServiceAccountManager {
return this.pushServiceSocket.getTurnServerInfo(); return this.pushServiceSocket.getTurnServerInfo();
} }
public void checkNetworkConnection() throws IOException {
this.pushServiceSocket.pingStorageService();
}
/** /**
* @return The avatar URL path, if one was written. * @return The avatar URL path, if one was written.
*/ */

Wyświetl plik

@ -885,6 +885,10 @@ public class PushServiceSocket {
} }
} }
public void pingStorageService() throws IOException {
makeStorageRequest(null, "/ping", "GET", null);
}
public RemoteConfigResponse getRemoteConfig() throws IOException { public RemoteConfigResponse getRemoteConfig() throws IOException {
String response = makeServiceRequest("/v1/config", "GET", null); String response = makeServiceRequest("/v1/config", "GET", null);
return JsonUtil.fromJson(response, RemoteConfigResponse.class); return JsonUtil.fromJson(response, RemoteConfigResponse.class);