@Before public void setup() throws NoPeerConnectionException, IOException, GeneralSecurityException { userCredentials = generateRandomCredentials(); client = NetworkTestUtil.getRandomNode(network); root = FileTestUtil.getTempDirectory(); // create an user profile UserProfile userProfile = new UserProfile( userCredentials.getUserId(), generateRSAKeyPair(H2HConstants.KEYLENGTH_USER_KEYS), generateRSAKeyPair(H2HConstants.KEYLENGTH_PROTECTION)); // encrypt it (fake encryption) EncryptedNetworkContent encrypted = client.getDataManager().getEncryption().encryptAES(userProfile, null); encrypted.setVersionKey(userProfile.getVersionKey()); encrypted.generateVersionKey(); // upload user profile, avoids register step IParameters parameters = new Parameters() .setLocationKey(userCredentials.getProfileLocationKey()) .setContentKey(H2HConstants.USER_PROFILE) .setVersionKey(encrypted.getVersionKey()) .setNetworkContent(encrypted) .setProtectionKeys(userProfile.getProtectionKeys()) .setTTL(userProfile.getTimeToLive()); client.getDataManager().put(parameters); }
@Override public void run() { logger.debug("Update file notification message received."); H2HSession session; try { session = networkManager.getSession(); } catch (NoSessionException e) { logger.error("No user seems to be logged in."); return; } UserProfileManager profileManager = session.getProfileManager(); UserProfile userProfile; try { userProfile = profileManager.readUserProfile(); } catch (GetFailedException e) { logger.error("Couldn't load user profile.", e); return; } Index updatedFile = userProfile.getFileById(fileKey); if (updatedFile == null) { logger.error("Got notified about a file we don't know."); return; } // trigger event getEventBus() .publish( new FileUpdateEvent(updatedFile.asFile(session.getRootFile()), updatedFile.isFile())); }