[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [snowflake-mobile/master] Added 'fetch offer' to fetch offer from broker
commit 78334a91237dee8e8dba16f2dd06e1c17fb2b042
Author: Hashik Donthineni <HashikDonthineni@xxxxxxxxx>
Date: Tue Jun 9 14:42:36 2020 +0530
Added 'fetch offer' to fetch offer from broker
---
.../torproject/snowflake/MyPersistentService.java | 42 ++++++++++++++++++++++
.../snowflake/constants/BrokerConstants.java | 11 ++++++
2 files changed, 53 insertions(+)
diff --git a/app/src/main/java/org/torproject/snowflake/MyPersistentService.java b/app/src/main/java/org/torproject/snowflake/MyPersistentService.java
index 4484a72..8a045a6 100644
--- a/app/src/main/java/org/torproject/snowflake/MyPersistentService.java
+++ b/app/src/main/java/org/torproject/snowflake/MyPersistentService.java
@@ -12,13 +12,18 @@ import android.util.Log;
import androidx.annotation.Nullable;
+import org.json.JSONException;
+import org.torproject.snowflake.constants.BrokerConstants;
import org.torproject.snowflake.constants.ForegroundServiceConstants;
import org.torproject.snowflake.interfaces.PeerConnectionObserverCallback;
import org.torproject.snowflake.pojo.OfferRequestBody;
import org.torproject.snowflake.pojo.SDPOfferResponse;
+import org.torproject.snowflake.services.GetOfferService;
+import org.torproject.snowflake.services.RetroServiceGenerator;
import org.webrtc.DataChannel;
import org.webrtc.PeerConnection;
import org.webrtc.PeerConnectionFactory;
+import org.webrtc.SessionDescription;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
@@ -27,6 +32,7 @@ import java.util.List;
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.core.Observable;
+import io.reactivex.rxjava3.disposables.Disposable;
import io.reactivex.rxjava3.schedulers.Schedulers;
/**
@@ -41,6 +47,8 @@ public class MyPersistentService extends Service {
private SharedPreferences sharedPreferences;
private boolean isServiceStarted;
private PowerManager.WakeLock wakeLock;
+ private Disposable serviceDisposable;
+
@Nullable
@Override
@@ -258,4 +266,38 @@ public class MyPersistentService extends Service {
return factory.createPeerConnection(rtcConfiguration, pcObserver);
}
/////////////// Network Calls ////////////////////////
+ /**
+ * Sending post request to get offer from the broker.
+ */
+ private void fetchOffer() {
+ Log.d(TAG, "fetchOffer: Fetching offer from broker.");
+ ///Retrofit call
+ final GetOfferService getOfferService = RetroServiceGenerator.createService(GetOfferService.class);
+ Observable<SDPOfferResponse> offer = getOfferService.getOffer(new OfferRequestBody("555"));
+ serviceDisposable = offer.subscribeOn(Schedulers.io())
+ .observeOn(AndroidSchedulers.mainThread()).subscribe(this::offerRequestSuccess, this::offerRequestFailure);
+ }
+
+ /**
+ * Fetching offer is a success.
+ * @param sdpOfferResponse
+ */
+ public void offerRequestSuccess(SDPOfferResponse sdpOfferResponse) {
+ if (sdpOfferResponse.getStatus().equals(BrokerConstants.CLIENT_MATCH)) {
+ Log.d(TAG, "requestSuccess: CLIENT MATCH");
+ //TODO:Serialize SDP, SetRemote Description, Send Answer.
+
+ } else {
+ Log.d(TAG, "requestSuccess: NO CLIENT MATCH");
+// if (isServiceStarted)
+ //fetchOffer(); //Sending request for offer again.
+ }
+ }
+
+ public void offerRequestFailure(Throwable t){
+ Log.d(TAG, "requestFailure: " + t.getMessage());
+ createPersistentNotification(true,"Failed getting offer. Retrying.");
+ //TODO:Set a time out to resending offer.
+ fetchOffer(); //Sending request for offer again.
+ }
}
diff --git a/app/src/main/java/org/torproject/snowflake/constants/BrokerConstants.java b/app/src/main/java/org/torproject/snowflake/constants/BrokerConstants.java
new file mode 100644
index 0000000..11a7bcf
--- /dev/null
+++ b/app/src/main/java/org/torproject/snowflake/constants/BrokerConstants.java
@@ -0,0 +1,11 @@
+package org.torproject.snowflake.constants;
+
+public class BrokerConstants {
+ //Getting Offer
+ public static final String CLIENT_MATCH = "client match";
+ public static final String CLIENT_NO_MATCH = "no match";
+
+ //Sending Answer
+ public static final String SENDING_SUCCESS = "success";
+ public static final String CLIENT_GONE = "client gone";
+}
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits