@Test public void testRepair() throws Exception { NetworkManager node = NetworkTestUtil.getRandomNode(network); UseCaseTestUtil.registerAndLogin(generateRandomCredentials(), node, tempFolder.newFolder()); Locations repaired = node.getSession().getLocationsManager().repairLocations(); Assert.assertNotNull(repaired); Assert.assertEquals(0, repaired.getPeerAddresses().size()); }
public Locations repairLocations() { Parameters removeParams = new Parameters().setContentKey(H2HConstants.USER_LOCATIONS).setLocationKey(userId) .setProtectionKeys(protectionKeys); logger.info("Start repairing the locations of user {}", userId); if (dataManager.remove(removeParams)) { logger.debug("Removed old locations of user {}", userId); } else { logger.warn("Failed to remove the old locations of user {}", userId); } Locations locations = new Locations(userId); locations.generateVersionKey(); Parameters addParams = new Parameters().setLocationKey(userId).setContentKey(H2HConstants.USER_LOCATIONS) .setVersionKey(locations.getVersionKey()).setBasedOnKey(locations.getBasedOnKey()) .setNetworkContent(locations).setProtectionKeys(protectionKeys).setTTL(locations.getTimeToLive()); if (dataManager.put(addParams) == H2HPutStatus.OK) { logger.debug("Successfully repaired the locations of user {}", userId); return locations; } else { logger.warn("Could not put the repaired locations of user {}", userId); return null; } }
LocationsManager { public Locations repairLocations() { Parameters removeParams = new Parameters().setContentKey(H2HConstants.USER_LOCATIONS).setLocationKey(userId) .setProtectionKeys(protectionKeys); logger.info("Start repairing the locations of user {}", userId); if (dataManager.remove(removeParams)) { logger.debug("Removed old locations of user {}", userId); } else { logger.warn("Failed to remove the old locations of user {}", userId); } Locations locations = new Locations(userId); locations.generateVersionKey(); Parameters addParams = new Parameters().setLocationKey(userId).setContentKey(H2HConstants.USER_LOCATIONS) .setVersionKey(locations.getVersionKey()).setBasedOnKey(locations.getBasedOnKey()) .setNetworkContent(locations).setProtectionKeys(protectionKeys).setTTL(locations.getTimeToLive()); if (dataManager.put(addParams) == H2HPutStatus.OK) { logger.debug("Successfully repaired the locations of user {}", userId); return locations; } else { logger.warn("Could not put the repaired locations of user {}", userId); return null; } } }
LocationsManager { public Locations repairLocations() { Parameters removeParams = new Parameters().setContentKey(H2HConstants.USER_LOCATIONS).setLocationKey(userId) .setProtectionKeys(protectionKeys); logger.info("Start repairing the locations of user {}", userId); if (dataManager.remove(removeParams)) { logger.debug("Removed old locations of user {}", userId); } else { logger.warn("Failed to remove the old locations of user {}", userId); } Locations locations = new Locations(userId); locations.generateVersionKey(); Parameters addParams = new Parameters().setLocationKey(userId).setContentKey(H2HConstants.USER_LOCATIONS) .setVersionKey(locations.getVersionKey()).setBasedOnKey(locations.getBasedOnKey()) .setNetworkContent(locations).setProtectionKeys(protectionKeys).setTTL(locations.getTimeToLive()); if (dataManager.put(addParams) == H2HPutStatus.OK) { logger.debug("Successfully repaired the locations of user {}", userId); return locations; } else { logger.warn("Could not put the repaired locations of user {}", userId); return null; } } LocationsManager(DataManager dataManager, String userId, KeyPair protectionKeys); }
LocationsManager { public Locations repairLocations() { Parameters removeParams = new Parameters().setContentKey(H2HConstants.USER_LOCATIONS).setLocationKey(userId) .setProtectionKeys(protectionKeys); logger.info("Start repairing the locations of user {}", userId); if (dataManager.remove(removeParams)) { logger.debug("Removed old locations of user {}", userId); } else { logger.warn("Failed to remove the old locations of user {}", userId); } Locations locations = new Locations(userId); locations.generateVersionKey(); Parameters addParams = new Parameters().setLocationKey(userId).setContentKey(H2HConstants.USER_LOCATIONS) .setVersionKey(locations.getVersionKey()).setBasedOnKey(locations.getBasedOnKey()) .setNetworkContent(locations).setProtectionKeys(protectionKeys).setTTL(locations.getTimeToLive()); if (dataManager.put(addParams) == H2HPutStatus.OK) { logger.debug("Successfully repaired the locations of user {}", userId); return locations; } else { logger.warn("Could not put the repaired locations of user {}", userId); return null; } } LocationsManager(DataManager dataManager, String userId, KeyPair protectionKeys); void put(Locations locations); Locations get(); Locations repairLocations(); }
LocationsManager { public Locations repairLocations() { Parameters removeParams = new Parameters().setContentKey(H2HConstants.USER_LOCATIONS).setLocationKey(userId) .setProtectionKeys(protectionKeys); logger.info("Start repairing the locations of user {}", userId); if (dataManager.remove(removeParams)) { logger.debug("Removed old locations of user {}", userId); } else { logger.warn("Failed to remove the old locations of user {}", userId); } Locations locations = new Locations(userId); locations.generateVersionKey(); Parameters addParams = new Parameters().setLocationKey(userId).setContentKey(H2HConstants.USER_LOCATIONS) .setVersionKey(locations.getVersionKey()).setBasedOnKey(locations.getBasedOnKey()) .setNetworkContent(locations).setProtectionKeys(protectionKeys).setTTL(locations.getTimeToLive()); if (dataManager.put(addParams) == H2HPutStatus.OK) { logger.debug("Successfully repaired the locations of user {}", userId); return locations; } else { logger.warn("Could not put the repaired locations of user {}", userId); return null; } } LocationsManager(DataManager dataManager, String userId, KeyPair protectionKeys); void put(Locations locations); Locations get(); Locations repairLocations();  }