@Test public void testStoreExisting() { assertEquals(0, folder.getNumElements()); folder.store(contact1); assertEquals(1, folder.getNumElements()); folder.store(contact2); assertEquals(1, folder.getNumElements()); assertTrue("Contact in the folder was overwritten!", folder.iterator().next().getDestination().toBase64().equals(contact1.getDestination().toBase64())); assertTrue("Contact in the folder was overwritten!", !folder.iterator().next().getDestination().toBase64().equals(contact2.getDestination().toBase64())); folder.store(contact3); assertEquals(2, folder.getNumElements()); }
@Override public void store(DhtStorablePacket packetToStore) { File packetFile = findPacketFile(packetToStore.getDhtKey()); if (packetFile != null) log.debug("Not storing directory packet with DHT key " + packetToStore.getDhtKey() + " because file exists."); else { if (!(packetToStore instanceof Contact)) log.error("Expected class Contact, got " + packetToStore.getClass()); else { Contact contact = (Contact)packetToStore; try { if (!contact.verify()) log.debug("Not storing Contact because verification failed."); else super.store(packetToStore); } catch (GeneralSecurityException e) { log.error("Can't verify Contact", e); } } } }
DirectoryEntryFolder extends DhtPacketFolder<Contact> { @Override public void store(DhtStorablePacket packetToStore) { File packetFile = findPacketFile(packetToStore.getDhtKey()); if (packetFile != null) log.debug("Not storing directory packet with DHT key " + packetToStore.getDhtKey() + " because file exists."); else { if (!(packetToStore instanceof Contact)) log.error("Expected class Contact, got " + packetToStore.getClass()); else { Contact contact = (Contact)packetToStore; try { if (!contact.verify()) log.debug("Not storing Contact because verification failed."); else super.store(packetToStore); } catch (GeneralSecurityException e) { log.error("Can't verify Contact", e); } } } } }
DirectoryEntryFolder extends DhtPacketFolder<Contact> { @Override public void store(DhtStorablePacket packetToStore) { File packetFile = findPacketFile(packetToStore.getDhtKey()); if (packetFile != null) log.debug("Not storing directory packet with DHT key " + packetToStore.getDhtKey() + " because file exists."); else { if (!(packetToStore instanceof Contact)) log.error("Expected class Contact, got " + packetToStore.getClass()); else { Contact contact = (Contact)packetToStore; try { if (!contact.verify()) log.debug("Not storing Contact because verification failed."); else super.store(packetToStore); } catch (GeneralSecurityException e) { log.error("Can't verify Contact", e); } } } } DirectoryEntryFolder(File storageDir); }
DirectoryEntryFolder extends DhtPacketFolder<Contact> { @Override public void store(DhtStorablePacket packetToStore) { File packetFile = findPacketFile(packetToStore.getDhtKey()); if (packetFile != null) log.debug("Not storing directory packet with DHT key " + packetToStore.getDhtKey() + " because file exists."); else { if (!(packetToStore instanceof Contact)) log.error("Expected class Contact, got " + packetToStore.getClass()); else { Contact contact = (Contact)packetToStore; try { if (!contact.verify()) log.debug("Not storing Contact because verification failed."); else super.store(packetToStore); } catch (GeneralSecurityException e) { log.error("Can't verify Contact", e); } } } } DirectoryEntryFolder(File storageDir); @Override void store(DhtStorablePacket packetToStore); }
DirectoryEntryFolder extends DhtPacketFolder<Contact> { @Override public void store(DhtStorablePacket packetToStore) { File packetFile = findPacketFile(packetToStore.getDhtKey()); if (packetFile != null) log.debug("Not storing directory packet with DHT key " + packetToStore.getDhtKey() + " because file exists."); else { if (!(packetToStore instanceof Contact)) log.error("Expected class Contact, got " + packetToStore.getClass()); else { Contact contact = (Contact)packetToStore; try { if (!contact.verify()) log.debug("Not storing Contact because verification failed."); else super.store(packetToStore); } catch (GeneralSecurityException e) { log.error("Can't verify Contact", e); } } } } DirectoryEntryFolder(File storageDir); @Override void store(DhtStorablePacket packetToStore);  }