@Test public void testContentProtectionRemove() throws Exception { NetworkManager node = NetworkTestUtil.getRandomNode(network); String locationKey = randomString(); String contentKey = randomString(); VersionManager<H2HTestData> versionManager = new VersionManager<H2HTestData>(node.getDataManager(), locationKey, contentKey); KeyPair otherProtectionKeys = generateRSAKeyPair(H2HConstants.KEYLENGTH_PROTECTION); H2HTestData version0 = new H2HTestData("version0"); versionManager.put(version0, protectionKeys); H2HTestData version1 = new H2HTestData("version1"); version1.setVersionKey(version0.getVersionKey()); versionManager.put(version1, protectionKeys); Parameters parameters0 = new Parameters().setLocationKey(locationKey).setContentKey(contentKey) .setVersionKey(version0.getVersionKey()); Parameters parameters1 = new Parameters().setLocationKey(locationKey).setContentKey(contentKey) .setVersionKey(version1.getVersionKey()); Assert.assertFalse(node.getDataManager().remove( new Parameters().setLocationKey(locationKey).setContentKey(contentKey))); Assert.assertEquals(version0.getTestString(), ((H2HTestData) node.getDataManager().getVersion(parameters0)).getTestString()); Assert.assertEquals(version1.getTestString(), ((H2HTestData) node.getDataManager().getVersion(parameters1)).getTestString()); Assert.assertFalse(node.getDataManager().remove( new Parameters().setLocationKey(locationKey).setContentKey(contentKey) .setProtectionKeys(otherProtectionKeys))); Assert.assertEquals(version0.getTestString(), ((H2HTestData) node.getDataManager().getVersion(parameters0)).getTestString()); Assert.assertEquals(version1.getTestString(), ((H2HTestData) node.getDataManager().getVersion(parameters1)).getTestString()); Assert.assertTrue(node.getDataManager().remove( new Parameters().setLocationKey(locationKey).setContentKey(contentKey).setProtectionKeys(protectionKeys))); Assert.assertNull(node.getDataManager().getVersion(parameters0)); Assert.assertNull(node.getDataManager().getVersion(parameters1)); }
public void put(T networkContent, KeyPair protectionKeys) throws PutFailedException { networkContent.generateVersionKey(); IParameters parameters = new Parameters().setLocationKey(this.parameters.getLocationKey()) .setContentKey(this.parameters.getContentKey()).setVersionKey(networkContent.getVersionKey()) .setBasedOnKey(networkContent.getBasedOnKey()).setNetworkContent(networkContent) .setProtectionKeys(protectionKeys).setTTL(networkContent.getTimeToLive()).setPrepareFlag(true); H2HPutStatus status = dataManager.put(parameters); if (status.equals(H2HPutStatus.FAILED)) { throw new PutFailedException("Put failed."); } else if (status.equals(H2HPutStatus.VERSION_FORK)) { logger.warn("Version fork after put detected. Rejecting put"); if (!dataManager.remove(parameters)) { logger.warn("Removing of conflicting version failed."); } throw new VersionForkAfterPutException(); } else { digestCache.put(parameters.getVersionKey(), new HashSet<Number160>(parameters.getData().basedOnSet())); contentCache.put(parameters.getVersionKey(), networkContent); } }
VersionManager extends BaseVersionManager<T> { public void put(T networkContent, KeyPair protectionKeys) throws PutFailedException { networkContent.generateVersionKey(); IParameters parameters = new Parameters().setLocationKey(this.parameters.getLocationKey()) .setContentKey(this.parameters.getContentKey()).setVersionKey(networkContent.getVersionKey()) .setBasedOnKey(networkContent.getBasedOnKey()).setNetworkContent(networkContent) .setProtectionKeys(protectionKeys).setTTL(networkContent.getTimeToLive()).setPrepareFlag(true); H2HPutStatus status = dataManager.put(parameters); if (status.equals(H2HPutStatus.FAILED)) { throw new PutFailedException("Put failed."); } else if (status.equals(H2HPutStatus.VERSION_FORK)) { logger.warn("Version fork after put detected. Rejecting put"); if (!dataManager.remove(parameters)) { logger.warn("Removing of conflicting version failed."); } throw new VersionForkAfterPutException(); } else { digestCache.put(parameters.getVersionKey(), new HashSet<Number160>(parameters.getData().basedOnSet())); contentCache.put(parameters.getVersionKey(), networkContent); } } }
VersionManager extends BaseVersionManager<T> { public void put(T networkContent, KeyPair protectionKeys) throws PutFailedException { networkContent.generateVersionKey(); IParameters parameters = new Parameters().setLocationKey(this.parameters.getLocationKey()) .setContentKey(this.parameters.getContentKey()).setVersionKey(networkContent.getVersionKey()) .setBasedOnKey(networkContent.getBasedOnKey()).setNetworkContent(networkContent) .setProtectionKeys(protectionKeys).setTTL(networkContent.getTimeToLive()).setPrepareFlag(true); H2HPutStatus status = dataManager.put(parameters); if (status.equals(H2HPutStatus.FAILED)) { throw new PutFailedException("Put failed."); } else if (status.equals(H2HPutStatus.VERSION_FORK)) { logger.warn("Version fork after put detected. Rejecting put"); if (!dataManager.remove(parameters)) { logger.warn("Removing of conflicting version failed."); } throw new VersionForkAfterPutException(); } else { digestCache.put(parameters.getVersionKey(), new HashSet<Number160>(parameters.getData().basedOnSet())); contentCache.put(parameters.getVersionKey(), networkContent); } } VersionManager(DataManager dataManager, String locationKey, String contentKey); }
VersionManager extends BaseVersionManager<T> { public void put(T networkContent, KeyPair protectionKeys) throws PutFailedException { networkContent.generateVersionKey(); IParameters parameters = new Parameters().setLocationKey(this.parameters.getLocationKey()) .setContentKey(this.parameters.getContentKey()).setVersionKey(networkContent.getVersionKey()) .setBasedOnKey(networkContent.getBasedOnKey()).setNetworkContent(networkContent) .setProtectionKeys(protectionKeys).setTTL(networkContent.getTimeToLive()).setPrepareFlag(true); H2HPutStatus status = dataManager.put(parameters); if (status.equals(H2HPutStatus.FAILED)) { throw new PutFailedException("Put failed."); } else if (status.equals(H2HPutStatus.VERSION_FORK)) { logger.warn("Version fork after put detected. Rejecting put"); if (!dataManager.remove(parameters)) { logger.warn("Removing of conflicting version failed."); } throw new VersionForkAfterPutException(); } else { digestCache.put(parameters.getVersionKey(), new HashSet<Number160>(parameters.getData().basedOnSet())); contentCache.put(parameters.getVersionKey(), networkContent); } } VersionManager(DataManager dataManager, String locationKey, String contentKey); T get(); void put(T networkContent, KeyPair protectionKeys); }
VersionManager extends BaseVersionManager<T> { public void put(T networkContent, KeyPair protectionKeys) throws PutFailedException { networkContent.generateVersionKey(); IParameters parameters = new Parameters().setLocationKey(this.parameters.getLocationKey()) .setContentKey(this.parameters.getContentKey()).setVersionKey(networkContent.getVersionKey()) .setBasedOnKey(networkContent.getBasedOnKey()).setNetworkContent(networkContent) .setProtectionKeys(protectionKeys).setTTL(networkContent.getTimeToLive()).setPrepareFlag(true); H2HPutStatus status = dataManager.put(parameters); if (status.equals(H2HPutStatus.FAILED)) { throw new PutFailedException("Put failed."); } else if (status.equals(H2HPutStatus.VERSION_FORK)) { logger.warn("Version fork after put detected. Rejecting put"); if (!dataManager.remove(parameters)) { logger.warn("Removing of conflicting version failed."); } throw new VersionForkAfterPutException(); } else { digestCache.put(parameters.getVersionKey(), new HashSet<Number160>(parameters.getData().basedOnSet())); contentCache.put(parameters.getVersionKey(), networkContent); } } VersionManager(DataManager dataManager, String locationKey, String contentKey); T get(); void put(T networkContent, KeyPair protectionKeys);  }