[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [snowflake-mobile/master] Closing the websocket when necessary



commit 416041b857f14cb9211838e54721e343ce654908
Author: Hashik Donthineni <HashikDonthineni@xxxxxxxxx>
Date:   Fri Jun 26 18:49:18 2020 +0530

    Closing the websocket when necessary
---
 app/src/main/java/org/torproject/snowflake/MyPersistentService.java | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/app/src/main/java/org/torproject/snowflake/MyPersistentService.java b/app/src/main/java/org/torproject/snowflake/MyPersistentService.java
index d532412..0b4017c 100644
--- a/app/src/main/java/org/torproject/snowflake/MyPersistentService.java
+++ b/app/src/main/java/org/torproject/snowflake/MyPersistentService.java
@@ -122,6 +122,7 @@ public class MyPersistentService extends Service {
             mainPeerConnection.dispose();
         }
 
+        webSocket.close(1000, "Normal closure");
         mNotificationManager.cancel(ForegroundServiceConstants.DEF_NOTIFICATION_ID);
         Log.d(TAG, "onDestroy: Service Destroyed");
         super.onDestroy();
@@ -352,6 +353,10 @@ public class MyPersistentService extends Service {
     private void fetchOffer() {
         //Fetch offer only when the connection is not alive/active and only when the service is on.
         if (isServiceStarted && !isConnectionAlive) {
+            if (isWebSocketOpen) {
+                //If the WebSocket is still open while a new offer is getting sent, it's old connection's WebSocket. So we can close it and re-open a new one.
+                webSocket.close(1000, "Normal Closure");
+            }
             isConnectionAlive = true; //Considering connection is alive from now on, until it is set to false.
             Log.d(TAG, "fetchOffer: Fetching offer from broker.");
             ///Retrofit call



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits