@Test public void testAllMixed() throws GetFailedException, NoPeerConnectionException { Map<String, PublicKey> publicKeys = new HashMap<String, PublicKey>(); for (int i = 0; i < 5; i++) { String userId = randomString(); KeyPair key = generateRSAKeyPair(H2HConstants.KEYLENGTH_USER_KEYS); UserPublicKey userPublicKey = new UserPublicKey(key.getPublic()); Parameters parameters = new Parameters().setLocationKey(userId).setContentKey(H2HConstants.USER_PUBLIC_KEY) .setNetworkContent(userPublicKey); Assert.assertEquals(H2HPutStatus.OK, NetworkTestUtil.getRandomNode(network).getDataManager().put(parameters)); publicKeys.put(userId, key.getPublic()); } List<String> userIds = new ArrayList<String>(publicKeys.keySet()); List<String> gettingList = new ArrayList<String>(); for (int i = 0; i < 20; i++) { gettingList.add(userIds.get(random.nextInt(userIds.size()))); } for (String userId : gettingList) { assertEquals(publicKeys.get(userId), publicKeyManager.getPublicKey(userId)); } }
public PublicKey getPublicKey(String userId) throws GetFailedException { logger.debug("Requested to get the public key of user '{}'.", userId); if (this.userId.equals(userId)) { return usersKeyPair.getPublic(); } if (publicKeyCache.containsKey(userId)) { return publicKeyCache.get(userId); } IParameters parameters = new Parameters().setLocationKey(userId).setContentKey(H2HConstants.USER_PUBLIC_KEY); BaseNetworkContent content = dataManager.get(parameters); return evaluateResult(content, userId); }
PublicKeyManager { public PublicKey getPublicKey(String userId) throws GetFailedException { logger.debug("Requested to get the public key of user '{}'.", userId); if (this.userId.equals(userId)) { return usersKeyPair.getPublic(); } if (publicKeyCache.containsKey(userId)) { return publicKeyCache.get(userId); } IParameters parameters = new Parameters().setLocationKey(userId).setContentKey(H2HConstants.USER_PUBLIC_KEY); BaseNetworkContent content = dataManager.get(parameters); return evaluateResult(content, userId); } }
PublicKeyManager { public PublicKey getPublicKey(String userId) throws GetFailedException { logger.debug("Requested to get the public key of user '{}'.", userId); if (this.userId.equals(userId)) { return usersKeyPair.getPublic(); } if (publicKeyCache.containsKey(userId)) { return publicKeyCache.get(userId); } IParameters parameters = new Parameters().setLocationKey(userId).setContentKey(H2HConstants.USER_PUBLIC_KEY); BaseNetworkContent content = dataManager.get(parameters); return evaluateResult(content, userId); } PublicKeyManager(String userId, KeyPair usersKeyPair, KeyPair defaultProtectionKeyPair, DataManager dataManager); }
PublicKeyManager { public PublicKey getPublicKey(String userId) throws GetFailedException { logger.debug("Requested to get the public key of user '{}'.", userId); if (this.userId.equals(userId)) { return usersKeyPair.getPublic(); } if (publicKeyCache.containsKey(userId)) { return publicKeyCache.get(userId); } IParameters parameters = new Parameters().setLocationKey(userId).setContentKey(H2HConstants.USER_PUBLIC_KEY); BaseNetworkContent content = dataManager.get(parameters); return evaluateResult(content, userId); } PublicKeyManager(String userId, KeyPair usersKeyPair, KeyPair defaultProtectionKeyPair, DataManager dataManager); PublicKey getOwnPublicKey(); PrivateKey getOwnPrivateKey(); KeyPair getOwnKeyPair(); KeyPair getDefaultProtectionKeyPair(); Map<String, PublicKey> getCachedPublicKeys(); void putPublicKey(String userId, PublicKey publicKey); boolean containsPublicKey(String userId); PublicKey getPublicKey(String userId); }
PublicKeyManager { public PublicKey getPublicKey(String userId) throws GetFailedException { logger.debug("Requested to get the public key of user '{}'.", userId); if (this.userId.equals(userId)) { return usersKeyPair.getPublic(); } if (publicKeyCache.containsKey(userId)) { return publicKeyCache.get(userId); } IParameters parameters = new Parameters().setLocationKey(userId).setContentKey(H2HConstants.USER_PUBLIC_KEY); BaseNetworkContent content = dataManager.get(parameters); return evaluateResult(content, userId); } PublicKeyManager(String userId, KeyPair usersKeyPair, KeyPair defaultProtectionKeyPair, DataManager dataManager); PublicKey getOwnPublicKey(); PrivateKey getOwnPrivateKey(); KeyPair getOwnKeyPair(); KeyPair getDefaultProtectionKeyPair(); Map<String, PublicKey> getCachedPublicKeys(); void putPublicKey(String userId, PublicKey publicKey); boolean containsPublicKey(String userId); PublicKey getPublicKey(String userId);  }