|
@@ -10,6 +10,7 @@ import java.util.List;
|
|
|
|
|
|
import de.tudarmstadt.informatik.hostage.logging.NetworkRecord;
|
|
|
import de.tudarmstadt.informatik.hostage.logging.SyncDevice;
|
|
|
+import de.tudarmstadt.informatik.hostage.logging.SyncInfo;
|
|
|
import de.tudarmstadt.informatik.hostage.logging.SyncRecord;
|
|
|
import de.tudarmstadt.informatik.hostage.persistence.HostageDBOpenHelper;
|
|
|
import de.tudarmstadt.informatik.hostage.system.Device;
|
|
@@ -38,6 +39,30 @@ public class Synchronizer {
|
|
|
*
|
|
|
*/
|
|
|
|
|
|
+ /**
|
|
|
+ * Returns all recorded BSSIDs.
|
|
|
+ * @return array list of bssids
|
|
|
+ */
|
|
|
+ public ArrayList<String> getAllBSSIDs(){
|
|
|
+ return this.dbh.getAllBSSIDS();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Returns all devices ids.
|
|
|
+ * @return ArrayList<String>
|
|
|
+ */
|
|
|
+ public ArrayList<String> getAllDeviceIDs(){
|
|
|
+ return this.dbh.getAllDevicesIds();
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * Returns own state of all registered devices.
|
|
|
+ * @return ArrayList<SyncDevice>
|
|
|
+ */
|
|
|
+ public SyncInfo getOwnState(){
|
|
|
+ return this.dbh.getOwnState();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/***
|
|
|
*
|
|
|
* PULL METHODS
|
|
@@ -46,25 +71,20 @@ public class Synchronizer {
|
|
|
*/
|
|
|
|
|
|
/**
|
|
|
- * Get a list of missing network records from the other device.
|
|
|
- * @param serverSocket server socket
|
|
|
+ * Inserts a list of networks
|
|
|
+ * @param others all missing networks
|
|
|
*/
|
|
|
- public void pullNetworks(ServerSocket serverSocket){
|
|
|
- ArrayList<String> myNetworks = this.dbh.getAllBSSIDS();
|
|
|
-
|
|
|
- ArrayList<NetworkRecord> others = this.getOtherNetworkInformation(serverSocket, myNetworks);
|
|
|
+ public void updateNewNetworks(ArrayList<NetworkRecord> others){
|
|
|
if (others != null && others.size() > 0){
|
|
|
this.dbh.updateNetworkInformation(others);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Get a list of missing devices from the other device.
|
|
|
- * @param serverSocket server socket
|
|
|
+ * Updates new inserted devices.
|
|
|
+ * @param otherDeviceIds ArrayList<String> other device ids
|
|
|
*/
|
|
|
- public void pullNewDevices(ServerSocket serverSocket){
|
|
|
- ArrayList<String> myDevices = this.dbh.getAllDevicesIds();
|
|
|
- ArrayList<String> otherDeviceIds = this.getOtherDevices(serverSocket, myDevices);
|
|
|
+ public void updateNewDevices(ArrayList<String> otherDeviceIds){
|
|
|
|
|
|
if (otherDeviceIds != null){
|
|
|
ArrayList<SyncDevice> otherDevices = new ArrayList<SyncDevice>();
|
|
@@ -84,49 +104,13 @@ public class Synchronizer {
|
|
|
|
|
|
/**
|
|
|
* Get all missing sync records from the other device.
|
|
|
- * @param serverSocket server socket
|
|
|
+ * @param updates list of new attack information
|
|
|
*/
|
|
|
- public void pullAttacks(ServerSocket serverSocket){
|
|
|
- ArrayList<SyncDevice> myState = this.dbh.getSyncDevices();
|
|
|
-
|
|
|
- ArrayList<SyncRecord> updates = this.getChanges(serverSocket, myState);
|
|
|
-
|
|
|
+ public void updateNewAttacks(ArrayList<SyncRecord> updates){
|
|
|
if (updates != null && updates.size() > 0)
|
|
|
this.dbh.insertSyncRecords(updates);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Sends own devices ids and parses a list of missing device ids.
|
|
|
- * @param serverSocket server socket
|
|
|
- * @param ownDevices own device ids
|
|
|
- * @return list of missing device ids
|
|
|
- */
|
|
|
- private ArrayList<String> getOtherDevices(ServerSocket serverSocket, ArrayList<String> ownDevices){
|
|
|
- // TODO parse other device ids from in put stream here
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Sends all network bssids to the other devices and parses all missing network records.
|
|
|
- * @param serverSocket server socket
|
|
|
- * @param records network bssids
|
|
|
- * @return list of missing networks
|
|
|
- */
|
|
|
- private ArrayList<NetworkRecord> getOtherNetworkInformation(ServerSocket serverSocket, List<String> records){
|
|
|
- // TODO Parse missing network records from input stream here
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Sends the own state to the other device and parses the answer.
|
|
|
- * @param serverSocket server socket
|
|
|
- * @param ownState our state
|
|
|
- * @return list of unsynced sync records
|
|
|
- */
|
|
|
- private ArrayList<SyncRecord> getChanges(ServerSocket serverSocket, ArrayList<SyncDevice> ownState){
|
|
|
- // TODO Parse unsynced sync records from in put stream here
|
|
|
- return null;
|
|
|
- }
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -138,77 +122,42 @@ public class Synchronizer {
|
|
|
|
|
|
/**
|
|
|
* Parses an array of device id strings and sends all missing sync devices ids.
|
|
|
- * @param serverSocket server socket
|
|
|
+ * @param otherIDs other device ids
|
|
|
+ * @return missing device ids
|
|
|
*/
|
|
|
- public void pushDeviceIds(ServerSocket serverSocket){
|
|
|
-
|
|
|
- // TODO parse other device ids from input stream here
|
|
|
- ArrayList<String> otherIDs = null;
|
|
|
-
|
|
|
+ public ArrayList<String> pushDeviceIds(ArrayList<String> otherIDs){
|
|
|
|
|
|
if (otherIDs != null){
|
|
|
- ArrayList<String> missingIds = this.dbh.getMissingDeviceIds(otherIDs);
|
|
|
- this.sendMissingDeviceIds(serverSocket, missingIds);
|
|
|
+ return this.dbh.getMissingDeviceIds(otherIDs);
|
|
|
+ //this.sendMissingDeviceIds(serverSocket, missingIds);
|
|
|
}
|
|
|
+ return new ArrayList<String>();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Parses an array of sync devices and sends the all unsynced records.
|
|
|
- * @param serverSocket server socket
|
|
|
+ * Returns list of unsynced records.
|
|
|
+ * @param si other states {@link de.tudarmstadt.informatik.hostage.logging.SyncInfo}
|
|
|
+ * @return unsynced sync records
|
|
|
*/
|
|
|
- public void pushUnsyncedRecords(ServerSocket serverSocket){
|
|
|
+ public ArrayList<SyncRecord> pushUnsyncedRecords(SyncInfo si){
|
|
|
|
|
|
- // TODO parse other sync devices from input stream here
|
|
|
- ArrayList<SyncDevice> otherDeviceState = null;
|
|
|
-
|
|
|
- if (otherDeviceState != null){
|
|
|
- ArrayList<SyncRecord> unsynced = this.dbh.getUnsyncedAttacksFor(otherDeviceState, false);
|
|
|
- this.sendUnsyncedRecords(serverSocket, unsynced);
|
|
|
+ if (si.deviceMap != null){
|
|
|
+ return this.dbh.getUnsyncedAttacksFor(si.deviceMap, false);
|
|
|
}
|
|
|
+ return new ArrayList<SyncRecord>();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Parses an array of bssid strings and sends all missing network records.
|
|
|
- * @param serverSocket server socket
|
|
|
+ * Returns list of missing network records.
|
|
|
+ * @param otherBSSIDs list of other bssids
|
|
|
+ * @return array list of network records to push.
|
|
|
*/
|
|
|
- public void pushNetworkInformation(ServerSocket serverSocket){
|
|
|
-
|
|
|
- // TODO parse other bssids from input stream
|
|
|
- ArrayList<String> otherBSSIDs = null;
|
|
|
-
|
|
|
+ public ArrayList<NetworkRecord> pushNetworkInformation(ArrayList<String> otherBSSIDs){
|
|
|
|
|
|
if (otherBSSIDs != null){
|
|
|
- ArrayList<NetworkRecord> missings = this.dbh.getMissingNetworkRecords(otherBSSIDs);
|
|
|
- this.sendMissingNetworkRecords(serverSocket, missings);
|
|
|
+ return this.dbh.getMissingNetworkRecords(otherBSSIDs);
|
|
|
}
|
|
|
+ return new ArrayList<NetworkRecord>();
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Sends all missing network records over an object output stream.
|
|
|
- * @param serverSocket server socket
|
|
|
- * @param n missing network information
|
|
|
- */
|
|
|
- private void sendMissingNetworkRecords(ServerSocket serverSocket, ArrayList<NetworkRecord> n){
|
|
|
- // TODO make output stream here
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Sends all missing device ids over an object output stream
|
|
|
- * @param serverSocket server socket
|
|
|
- * @param missingIds all missing device ids
|
|
|
- */
|
|
|
- private void sendMissingDeviceIds(ServerSocket serverSocket, ArrayList<String> missingIds){
|
|
|
- // TODO make output stream here
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Sends all unsynced sync records over an object output stream
|
|
|
- * @param serverSocket server socket
|
|
|
- * @param unsynced array of unsynced sync records
|
|
|
- */
|
|
|
- private void sendUnsyncedRecords(ServerSocket serverSocket, ArrayList<SyncRecord> unsynced){
|
|
|
- // TODO make output stream here
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
}
|