Browse Source

Added sync docs;
Changed debug log tag for wifi p2p

julien.clauter 7 years ago
parent
commit
67b93b0b18

BIN
docs/sync/hostage_sync_uml.png


+ 19 - 0
docs/sync/hostage_sync_uml_desc.txt

@@ -0,0 +1,19 @@
+title Synchronisation Protocol
+
+DeviceA->+DeviceB: Send Sync Info
+note right of DeviceB: The Sync Info is a tuple (otherDevices, ssids) where\notherDevices ∈ ℘(DeviceIds x ℕ)\nand ssids ∈ ℘(NetworkSSIDs)
+
+
+DeviceB->-DeviceA: Send Sync Info
+note right of DeviceB: Compare own Sync Info with the other\nSync Info to create a Sync Data object.
+
+
+note over DeviceA,DeviceB: If we received unknown Device Ids create new Sync Devices.\nSet the max sync id for each new device to 0.
+
+
+DeviceA->+DeviceB: Send Sync Data
+note right of DeviceB: Sync Data is a tuple (n , a) where\nn ∈ ℘(NetworkRecords) and a ∈ ℘(AttackRecords)
+DeviceB->-DeviceA: Send Sync Data
+
+
+note over DeviceA,DeviceB: Save received network and attack records.\nActualise the max sync id if of all Sync Devices.

+ 6 - 6
src/de/tudarmstadt/informatik/hostage/sync/wifi_direct/WiFiP2pBroadcastReceiver.java

@@ -91,7 +91,7 @@ public class WiFiP2pBroadcastReceiver extends BroadcastReceiver implements WifiP
         } else if (WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION.equals(action)) {
             // THE DEVICE LIST CHANGED
             // REQUEST THE LIST OF DEVICES
-            Log.d("DEBUG_WiFiP2pBroadcastReceiver", "P2P peers changed.");
+            Log.d("DEBUG_WiFiP2p", "BroadcastReceiver - P2P peers changed.");
             if (manager != null) {
                 manager.requestPeers(channel, this);
             }
@@ -121,7 +121,7 @@ public class WiFiP2pBroadcastReceiver extends BroadcastReceiver implements WifiP
                 }
             }
             if (this.networkState != networkInfo.getDetailedState()){
-                Log.d("DEBUG_WiFiP2pBroadcastReceiver", "P2P device network state changed to " + this.getDeviceNetworkStatus(networkInfo.getDetailedState()) + ".");
+                Log.d("DEBUG_WiFiP2p", "BroadcastReceiver - P2P device network state changed to " + this.getDeviceNetworkStatus(networkInfo.getDetailedState()) + ".");
             }
             this.networkState = networkInfo.getDetailedState();
         } else if (WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION.equals(action)) {
@@ -162,7 +162,7 @@ public class WiFiP2pBroadcastReceiver extends BroadcastReceiver implements WifiP
         peers.addAll(peerList.getDeviceList());
 
         if (peers.size() == 0) {
-            Log.d("DEBUG_WiFiP2pBroadcastReceiver", "No devices found");
+            Log.d("DEBUG_WiFiP2p", "BroadcastReceiver - No devices found");
         }
 
         this.eventListener.discoveredDevices(peers);
@@ -205,7 +205,7 @@ public class WiFiP2pBroadcastReceiver extends BroadcastReceiver implements WifiP
                 public void didSucceed() {
                     if (this.receiver.getOwnDevice().status != WifiP2pDevice.CONNECTED && isConnecting){
                         this.receiver.disconnect();
-                        Log.d("DEBUG_WiFiP2pBroadcastReceiver", "Cancel connection process.");
+                        Log.d("DEBUG_WiFiP2p", "BroadcastReceiver - Cancel connection process.");
                         isConnecting = false;
                     }
                 }
@@ -282,11 +282,11 @@ public class WiFiP2pBroadcastReceiver extends BroadcastReceiver implements WifiP
         manager.discoverPeers(channel, new WifiP2pManager.ActionListener() {
             @Override
             public void onSuccess() {
-                Log.d("DEBUG_WiFiP2pBroadcastReceiver", " Discovering Peers initiated.");
+                Log.d("DEBUG_WiFiP2p", "BroadcastReceiver - Discovering Peers initiated.");
             }
             @Override
             public void onFailure(int reasonCode) {
-                Log.d("DEBUG_WiFiP2pBroadcastReceiver", " Discovering Peers failed. c="+reasonCode);
+                Log.d("DEBUG_WiFiP2p", "BroadcastReceiver - Discovering Peers failed. c="+reasonCode);
             }
         });
     }

+ 8 - 8
src/de/tudarmstadt/informatik/hostage/sync/wifi_direct/WiFiP2pClientTask.java

@@ -66,7 +66,7 @@ public abstract class WiFiP2pClientTask extends BackgroundTask {
             try {
                 this.socket.close();
             } catch (IOException e) {
-                Log.e("DEBUG_WiFiP2pClientTask", e.getMessage());
+                Log.e("DEBUG_WiFiP2p", e.getMessage());
             }
         }
     }
@@ -82,22 +82,22 @@ public abstract class WiFiP2pClientTask extends BackgroundTask {
             this.socket = new Socket();
 
             try {
-                Log.d("DEBUG_WiFiP2pClientTask", "Opening client socket - ");
+                Log.d("DEBUG_WiFiP2p", "ClientTask - Opening client socket - ");
                 socket.bind(null);
                 socket.connect((new InetSocketAddress(hostIP, port())), time_out());
 
-                Log.d("DEBUG_WiFiP2pClientTask", "Client socket - " + socket.isConnected());
+                Log.d("DEBUG_WiFiP2p", "ClientTask socket - " + socket.isConnected());
                 this.handleConnection(socket);
 
-                Log.d("DEBUG_WiFiP2pClientTask", "Client: Data written");
+                Log.d("DEBUG_WiFiP2p", "ClientTask - Data written");
             } catch (ClassNotFoundException e){
-                Log.e("DEBUG_WiFiP2pClientTask", e.getMessage());
+                Log.e("DEBUG_WiFiP2p", e.getMessage());
                 e_message =  e.getLocalizedMessage();
                 if (e_message == null){
                     e_message = WiFiP2pServerTask.ERROR_COMMUNICATION_FAILED;// COMMUNICATION_ERROR
                 }
                 return e_message;            } catch (IOException e) {
-                Log.e("DEBUG_WiFiP2pClientTask", e.getMessage());
+                Log.e("DEBUG_WiFiP2p", e.getMessage());
 
                 if(this.isInterrupted()) {
                     this.interrupt(true);
@@ -106,7 +106,7 @@ public abstract class WiFiP2pClientTask extends BackgroundTask {
 
                 long seconds_to_wait = (long) Math.min(60, Math.pow(2, 1));
                 tryNum++;
-                Log.i("DEBUG_WiFiP2pClientTask", "could not connect to server. Will try again in " + 1 + "s");
+                Log.i("DEBUG_WiFiP2p", "ClientTaskError - could not connect to server. Will try again in " + 1 + "s");
                 try {
                     Thread.sleep(seconds_to_wait * time_out());
                 } catch (InterruptedException ie){
@@ -120,7 +120,7 @@ public abstract class WiFiP2pClientTask extends BackgroundTask {
                         } catch (IOException e) {
                             // Give up
                             e.printStackTrace();
-                            Log.d("DEBUG_WiFiP2p_Error"," Failed to close socket - "+ e.getLocalizedMessage());
+                            Log.d("DEBUG_WiFiP2p","ClientTaskError - Failed to close socket - "+ e.getLocalizedMessage());
                             e_message =  e.getLocalizedMessage();
                             if (e_message == null){
                                 e_message = WiFiP2pServerTask.ERROR_CONNECTION_FAILED;// FAILED TO CONNECT

+ 6 - 6
src/de/tudarmstadt/informatik/hostage/sync/wifi_direct/WiFiP2pServerTask.java

@@ -75,7 +75,7 @@ public abstract class WiFiP2pServerTask extends BackgroundTask {
                 this.serverSocket.close();
             } catch (IOException e) {
                 String message = e.getLocalizedMessage() != null? e.getLocalizedMessage() : ERROR_MESSAGE_UNKNOWN;
-                Log.e("DEBUG_WiFiP2pServerTask", "" + message);
+                Log.e("DEBUG_WiFiP2p", "ServerTask - " + message);
             }
         }
     }
@@ -93,10 +93,10 @@ public abstract class WiFiP2pServerTask extends BackgroundTask {
                 this.serverSocket = new ServerSocket(WiFiP2pClientTask.port());
                 //serverSocket.setReuseAddress(true);
                 //serverSocket.bind(new InetSocketAddress(WiFiP2pClientTask.port()));
-                Log.d("DEBUG_WiFiP2pServerTask", "Server: Socket opened");
+                Log.d("DEBUG_WiFiP2p", "ServerTask - Socket opened");
                 this.serverSocket.setSoTimeout(this.getTimeoutSeconds() * 1000);
                 Socket client = this.serverSocket.accept();
-                Log.d("DEBUG_WiFiP2pServerTask", "Server: connection done");
+                Log.d("DEBUG_WiFiP2p", "ServerTask - connection done");
 
                 this.handleConnection(client, this.serverSocket);
 
@@ -106,7 +106,7 @@ public abstract class WiFiP2pServerTask extends BackgroundTask {
                 return BACKGROUND_TASK_MESSAGE_SUCCESS;
             } catch (ClassNotFoundException e){
                 e.printStackTrace();
-                Log.e("DEBUG_WiFiP2pServerTask", "" + e.getMessage());
+                Log.e("DEBUG_WiFiP2p", "ServerTask - " + e.getMessage());
                 String e_message =  null;
                 e_message = e.getLocalizedMessage();
                 if (e_message == null){
@@ -117,10 +117,10 @@ public abstract class WiFiP2pServerTask extends BackgroundTask {
                 try {
                     if (!this.serverSocket.isClosed()) this.serverSocket.close();
                 }catch (IOException ec){
-                    Log.e("DEBUG_WiFiP2pServerTask", "Could not close server socket.");
+                    Log.e("DEBUG_WiFiP2p", "ServerTask - Could not close server socket.");
                 }
                 e.printStackTrace();
-                Log.e("DEBUG_WiFiP2pServerTask", "" + e.getMessage());
+                Log.e("DEBUG_WiFiP2p", "ServerTask - " + e.getMessage());
                 String e_message = e.getLocalizedMessage();
                 if (e_message == null){
                     e_message = ERROR_MESSAGE_UNKNOWN;// UNKNOWN_ERROR

+ 13 - 13
src/de/tudarmstadt/informatik/hostage/sync/wifi_direct/ui/WiFiP2pSyncActivity.java

@@ -207,20 +207,20 @@ public class WiFiP2pSyncActivity extends Activity implements AdapterView.OnItemC
 
                 @Override
                 public void discoveredDevices(List<WifiP2pDevice> peers) {
-                    Log.d("DEBUG_WiFiP2pSyncActivity", "Actualise devices list");
+                    Log.d("DEBUG_WiFiP2p", "Activity - Actualise devices list");
                     this.activity.updateDeviceListView(peers);
                 }
 
                 @Override
                 public void wifiP2pIsEnabled(boolean enabled) {
                     String tmp = enabled? "enabled" : "disabled";
-                    Log.d("DEBUG_WiFiP2pSyncActivity", "Peer to peer is " + tmp + ".");
+                    Log.d("DEBUG_WiFiP2p", "Activity - Peer to peer is " + tmp + ".");
                     this.activity.setWifiDirectAvailable(enabled);
                 }
 
                 @Override
                 public void didConnect(boolean isHost, WifiP2pInfo connectionInfo) {
-                    Log.d("DEBUG_WiFiP2pSyncActivity", "Did connect");
+                    Log.d("DEBUG_WiFiP2p", "Activity - Did connect");
 
                     this.activity.progressDialog.setMessage(PROGRESS_MESSAGE_LOADING);
                     if (!this.activity.progressDialog.isShowing()){
@@ -229,17 +229,17 @@ public class WiFiP2pSyncActivity extends Activity implements AdapterView.OnItemC
 
                     this.activity.setHost(isHost);
                     if (isHost){
-                        Log.d("DEBUG_WiFiP2pSyncActivity", "Connected as HOST");
+                        Log.d("DEBUG_WiFiP2p", "Activity - Connected as HOST");
                         this.activity.startHost();
                     } else {
-                        Log.d("DEBUG_WiFiP2pSyncActivity", "Connected as Client");
+                        Log.d("DEBUG_WiFiP2p", "Activity - Connected as Client");
                         this.activity.startClient(connectionInfo);
                     }
                 }
 
                 @Override
                 public void failedToConnect() {
-                    Log.d("DEBUG_WiFiP2pSyncActivity", "Failed to connect");
+                    Log.d("DEBUG_WiFiP2p", "Activity - Failed to connect");
                     Toast.makeText(this.activity, COULD_NOT_CONNECT_MESSAGE , Toast.LENGTH_LONG).show();
                     if (this.activity.progressDialog != null){
                         this.activity.progressDialog.dismiss();
@@ -248,7 +248,7 @@ public class WiFiP2pSyncActivity extends Activity implements AdapterView.OnItemC
 
                 @Override
                 public void didDisconnect() {
-                    Log.d("DEBUG_WiFiP2pSyncActivity", "Did disconnect");
+                    Log.d("DEBUG_WiFiP2p", "Activity - Did disconnect");
                     if (this.activity.progressDialog != null){
                         this.activity.progressDialog.dismiss();
                     }
@@ -256,7 +256,7 @@ public class WiFiP2pSyncActivity extends Activity implements AdapterView.OnItemC
 
                 @Override
                 public void failedToDisconnect() {
-                    Log.d("DEBUG_WiFiP2pSyncActivity", "Failed to disconnect");
+                    Log.d("DEBUG_WiFiP2p", "Activity - Failed to disconnect");
                     //Toast.makeText(this.activity, "Could not disconnect with device. Retry.", Toast.LENGTH_LONG).show();
                     // Other device did disconnect a while before.
                     if (this.activity.progressDialog != null &&
@@ -271,7 +271,7 @@ public class WiFiP2pSyncActivity extends Activity implements AdapterView.OnItemC
 
                 @Override
                 public void ownDeviceInformationIsUpdated(WifiP2pDevice device) {
-                    Log.d("DEBUG_WiFiP2pSyncActivity", "Updated device " + device.deviceName + " " + device.deviceAddress + ".");
+                    Log.d("DEBUG_WiFiP2p", "Activity - Updated device " + device.deviceName + " " + device.deviceAddress + ".");
                     this.activity.updateOwnDeviceInformation(device);
                     this.activity.searchForDevices();
                 }
@@ -372,7 +372,7 @@ public class WiFiP2pSyncActivity extends Activity implements AdapterView.OnItemC
                 return this;
             }
         }.init(this.mLstP2PDevices));
-        Log.d("DEBUG_WiFiP2pSyncActivity", " Discovered "+peers.size()+" devices.");
+        Log.d("DEBUG_WiFiP2p", "Activity - Discovered "+peers.size()+" devices.");
 
         if (peers.size() == 0){
             this.searchForDevices();
@@ -386,13 +386,13 @@ public class WiFiP2pSyncActivity extends Activity implements AdapterView.OnItemC
     {
 
         //if (this.hostTask == null || this.hostTask.isInterrupted()){
-            Log.d("DEBUG_WiFiP2pSyncActivity", "Starting HOST Task");
+            Log.d("DEBUG_WiFiP2p", "Activity - Starting HOST Task");
             //Toast.makeText(this, PERFORMING_TASK_AS_HOST , Toast.LENGTH_SHORT).show();
             this.hostTask = new SyncHostTask(this.ownDevice, this.syncCompletionListener(), getApplicationContext());
             this.executingTask = this.hostTask;
             this.hostTask.execute();
         //} else {
-        //    Log.d("DEBUG_WiFiP2pSyncActivity", "Preventing third device for any syncing.");
+        //    Log.d("DEBUG_WiFiP2p", "Activity - Preventing third device for any syncing.");
         //}
     }
 
@@ -402,7 +402,7 @@ public class WiFiP2pSyncActivity extends Activity implements AdapterView.OnItemC
      */
     private void startClient(WifiP2pInfo info)
     {
-           Log.d("DEBUG_WiFiP2pSyncActivity", "Starting CLIENT Task");
+           Log.d("DEBUG_WiFiP2p", "Activity - Starting CLIENT Task");
            this.clientTask = new SyncClientTask( info.groupOwnerAddress.getHostAddress(),this.ownDevice, this.syncCompletionListener(), getApplicationContext() );
            this.executingTask = this.clientTask;
            this.clientTask.execute();