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

[tor-commits] [snowflake-mobile/master] Created new package Seriazation and moved SDPSerializer int to it, created RelaySerializatoin file to handle serialization away from service



commit a05bf22b7d6b65e5f810ab51f7bf023b37f67b61
Author: Hashik Donthineni <HashikDonthineni@xxxxxxxxx>
Date:   Fri Jun 26 19:43:44 2020 +0530

    Created new package Seriazation and moved SDPSerializer int to it, created RelaySerializatoin file to handle serialization away from service
---
 .../org/torproject/snowflake/MyPersistentService.java     |  9 +++++----
 .../snowflake/serialization/RelaySerialization.java       | 15 +++++++++++++++
 .../snowflake/{ => serialization}/SDPSerializer.java      |  4 ++--
 3 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/app/src/main/java/org/torproject/snowflake/MyPersistentService.java b/app/src/main/java/org/torproject/snowflake/MyPersistentService.java
index 0b4017c..c02276e 100644
--- a/app/src/main/java/org/torproject/snowflake/MyPersistentService.java
+++ b/app/src/main/java/org/torproject/snowflake/MyPersistentService.java
@@ -25,6 +25,8 @@ import org.torproject.snowflake.pojo.AnswerBody;
 import org.torproject.snowflake.pojo.AnswerBodySDP;
 import org.torproject.snowflake.pojo.OfferRequestBody;
 import org.torproject.snowflake.pojo.SDPOfferResponse;
+import org.torproject.snowflake.serialization.RelaySerialization;
+import org.torproject.snowflake.serialization.SDPSerializer;
 import org.torproject.snowflake.services.GetOfferService;
 import org.torproject.snowflake.services.RetroServiceGenerator;
 import org.torproject.snowflake.services.SendAnswerService;
@@ -290,8 +292,8 @@ public class MyPersistentService extends Service {
             @Override
             public void onMessage(DataChannel.Buffer buffer) {
                 //Relay it to WebSocket
-                Log.d(TAG, "onMessage: ");
-                webSocket.send(ByteString.of(buffer.data.asReadOnlyBuffer()));
+                Log.d(TAG, "onMessage:");
+                webSocket.send(RelaySerialization.clientToTor(buffer));
             }
 
             @Override
@@ -490,8 +492,7 @@ public class MyPersistentService extends Service {
                     @Override
                     public void onMessage(@NotNull WebSocket webSocket, @NotNull ByteString bytes) {
                         Log.d(TAG, "WebSocketListener: onMessage: Bytes");
-                        DataChannel.Buffer buffer = new DataChannel.Buffer(bytes.asByteBuffer(), true);
-                        mainDataChannel.send(buffer);
+                        mainDataChannel.send(RelaySerialization.torToClient(bytes));
                     }
 
                     @Override
diff --git a/app/src/main/java/org/torproject/snowflake/serialization/RelaySerialization.java b/app/src/main/java/org/torproject/snowflake/serialization/RelaySerialization.java
new file mode 100644
index 0000000..8c6277f
--- /dev/null
+++ b/app/src/main/java/org/torproject/snowflake/serialization/RelaySerialization.java
@@ -0,0 +1,15 @@
+package org.torproject.snowflake.serialization;
+
+import org.webrtc.DataChannel;
+
+import okio.ByteString;
+
+public class RelaySerialization {
+    public static ByteString clientToTor(DataChannel.Buffer buffer) {
+        return ByteString.of(buffer.data.asReadOnlyBuffer());
+    }
+
+    public static DataChannel.Buffer torToClient(ByteString byteString) {
+        return new DataChannel.Buffer(byteString.asByteBuffer(), true);
+    }
+}
diff --git a/app/src/main/java/org/torproject/snowflake/SDPSerializer.java b/app/src/main/java/org/torproject/snowflake/serialization/SDPSerializer.java
similarity index 89%
rename from app/src/main/java/org/torproject/snowflake/SDPSerializer.java
rename to app/src/main/java/org/torproject/snowflake/serialization/SDPSerializer.java
index 60bb846..f2e5623 100644
--- a/app/src/main/java/org/torproject/snowflake/SDPSerializer.java
+++ b/app/src/main/java/org/torproject/snowflake/serialization/SDPSerializer.java
@@ -1,4 +1,4 @@
-package org.torproject.snowflake;
+package org.torproject.snowflake.serialization;
 
 import org.json.JSONException;
 import org.json.JSONObject;
@@ -11,7 +11,7 @@ public class SDPSerializer {
                 new JSONObject(SDP).get("sdp").toString());
     }
 
-    public static String serializeAnswer(SessionDescription SDP){
+    public static String serializeAnswer(SessionDescription SDP) {
         return SDP.description;
     }
 }

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