123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- package de.tudarmstadt.informatik.hostage.sync;
- /**
- * Created by Julien on 08.12.2014.
- */
- import java.net.ServerSocket;
- import java.util.ArrayList;
- 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;
- public class Synchronizer {
- private HostageDBOpenHelper dbh;
- public Synchronizer(HostageDBOpenHelper dbh){
- super();
- this.dbh = dbh;
- }
- /**
- *
- * Update Idea:
- * PullDevices
- * PullNetworks
- * PullAttacks
- *
- * Commit Idea:
- * PushDevice
- * PushNetworks
- * PushAttacks
- *
- */
- /**
- * 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
- *
- *
- */
- /**
- * Inserts a list of networks
- * @param others all missing networks
- */
- public void updateNewNetworks(ArrayList<NetworkRecord> others){
- if (others != null && others.size() > 0){
- this.dbh.updateNetworkInformation(others);
- }
- }
- /**
- * Updates new inserted devices.
- * @param otherDeviceIds ArrayList<String> other device ids
- */
- public void updateNewDevices(ArrayList<String> otherDeviceIds){
- if (otherDeviceIds != null){
- ArrayList<SyncDevice> otherDevices = new ArrayList<SyncDevice>();
- for (String deviceId : otherDeviceIds){
- SyncDevice device = new SyncDevice();
- device.setDeviceID(deviceId);
- device.setHighest_attack_id(-1);
- device.setLast_sync_timestamp(0);
- otherDevices.add(device);
- }
- if (otherDevices.size() > 0)
- this.dbh.updateSyncDevices(otherDevices);
- }
- }
- /**
- * Get all missing sync records from the other device.
- * @param updates list of new attack information
- */
- public void updateNewAttacks(ArrayList<SyncRecord> updates){
- if (updates != null && updates.size() > 0)
- this.dbh.insertSyncRecords(updates);
- }
- /**
- *
- * PUSH METHODS
- *
- *
- * */
- /**
- * Parses an array of device id strings and sends all missing sync devices ids.
- * @param otherIDs other device ids
- * @return missing device ids
- */
- public ArrayList<String> pushDeviceIds(ArrayList<String> otherIDs){
- if (otherIDs != null){
- return this.dbh.getMissingDeviceIds(otherIDs);
- //this.sendMissingDeviceIds(serverSocket, missingIds);
- }
- return new ArrayList<String>();
- }
- /**
- * Returns list of unsynced records.
- * @param si other states {@link de.tudarmstadt.informatik.hostage.logging.SyncInfo}
- * @return unsynced sync records
- */
- public ArrayList<SyncRecord> pushUnsyncedRecords(SyncInfo si){
- if (si.deviceMap != null){
- return this.dbh.getUnsyncedAttacksFor(si.deviceMap, false);
- }
- return new ArrayList<SyncRecord>();
- }
- /**
- * Returns list of missing network records.
- * @param otherBSSIDs list of other bssids
- * @return array list of network records to push.
- */
- public ArrayList<NetworkRecord> pushNetworkInformation(ArrayList<String> otherBSSIDs){
- if (otherBSSIDs != null){
- return this.dbh.getMissingNetworkRecords(otherBSSIDs);
- }
- return new ArrayList<NetworkRecord>();
- }
- }
|