Package org.hive2hive.core.network

Examples of org.hive2hive.core.network.NetworkManager


  }

  private void verifyUpload(File originalFile, int expectedChunks) throws IOException, GetFailedException,
      NoSessionException, NoPeerConnectionException, InvalidProcessStateException {
    // pick new client to test
    NetworkManager client = network.get(1);

    // test if there is something in the user profile
    UserProfile gotProfile = UseCaseTestUtil.getUserProfile(client, userCredentials);
    Assert.assertNotNull(gotProfile);
View Full Code Here


  }

  @Test
  public void testRegisterProcessSuccess() throws InvalidProcessStateException, ClassNotFoundException,
      IOException, GetFailedException, NoPeerConnectionException {
    NetworkManager client = network.get(0);
    NetworkManager otherClient = network.get(1);

    UserCredentials credentials = NetworkTestUtil.generateRandomCredentials();
    UseCaseTestUtil.register(credentials, client);

    // verify put user profile
    UserProfile getUserProfile = UseCaseTestUtil.getUserProfile(otherClient, credentials);

    assertNotNull(getUserProfile);
    assertEquals(credentials.getUserId(), getUserProfile.getUserId());

    // verify put locations
    FutureGet getLocations = otherClient.getDataManager().getUnblocked(
        new Parameters().setLocationKey(credentials.getUserId()).setContentKey(
            H2HConstants.USER_LOCATIONS));
    getLocations.awaitUninterruptibly();
    getLocations.getFutureRequests().awaitUninterruptibly();
    Locations locations = (Locations) getLocations.getData().object();

    assertNotNull(locations);
    assertEquals(credentials.getUserId(), locations.getUserId());
    assertTrue(locations.getPeerAddresses().isEmpty());

    // verify put user public key
    FutureGet getKey = otherClient.getDataManager().getUnblocked(
        new Parameters().setLocationKey(credentials.getUserId()).setContentKey(
            H2HConstants.USER_PUBLIC_KEY));
    getKey.awaitUninterruptibly();
    getKey.getFutureRequests().awaitUninterruptibly();
    UserPublicKey publicKey = (UserPublicKey) getKey.getData().object();
View Full Code Here

  public void testStepSuccessAndRollbackWithChunk() throws InterruptedException, NoPeerConnectionException,
      DataLengthException, InvalidKeyException, IllegalStateException, InvalidCipherTextException,
      IllegalBlockSizeException, BadPaddingException, IOException, SignatureException,
      InvalidProcessStateException {
    // where the process runs
    NetworkManager getter = network.get(0);
    // where the data gets stored
    NetworkManager proxy = network.get(1);

    // generate necessary keys
    KeyPair encryptionKeys = EncryptionUtil.generateRSAKeyPair(H2HConstants.KEYLENGTH_CHUNK);
    KeyPair protectionKeysOld = EncryptionUtil.generateRSAKeyPair();
    KeyPair protectionKeysNew = EncryptionUtil.generateRSAKeyPair();

    // generate a fake chunk
    Chunk chunk = new Chunk(proxy.getNodeId(), NetworkTestUtil.randomString().getBytes(), 0);
    // encrypt the chunk
    HybridEncryptedContent encryptedChunk = H2HEncryptionUtil.encryptHybrid(chunk,
        encryptionKeys.getPublic());

    // initialize put
View Full Code Here

  }

  @Test
  public void testStepSuccessful() throws InterruptedException, ClassNotFoundException, IOException,
      NoPeerConnectionException {
    NetworkManager putter = network.get(0); // where the process runs
    putter.getConnection().getPeer().getPeerBean().storage(new H2HStorageMemory());
    NetworkManager proxy = network.get(1); // where the user profile is stored
    proxy.getConnection().getPeer().getPeerBean().storage(new H2HStorageMemory());

    // create the needed objects
    String userId = proxy.getNodeId();
    Locations newLocations = new Locations(userId);
    newLocations.addPeerAddress(putter.getConnection().getPeer().getPeerAddress());
    KeyPair protectionKeys = EncryptionUtil.generateRSAKeyPair();

    // initialize the process and the one and only step to test
    PutLocationContext context = new PutLocationContext(newLocations, protectionKeys);
    PutUserLocationsStep step = new PutUserLocationsStep(context, context, putter.getDataManager());
    UseCaseTestUtil.executeProcess(step);

    // get the locations
    FutureGet future = proxy.getDataManager().getUnblocked(
        new Parameters().setLocationKey(userId).setContentKey(H2HConstants.USER_LOCATIONS));
    future.awaitUninterruptibly();
    Assert.assertNotNull(future.getData());
    Locations found = (Locations) future.getData().object();
View Full Code Here

  public void testStepSuccessAndRollbackWithMetaFile() throws InterruptedException,
      NoPeerConnectionException, DataLengthException, InvalidKeyException, IllegalStateException,
      InvalidCipherTextException, IllegalBlockSizeException, BadPaddingException, IOException,
      SignatureException, InvalidProcessStateException {
    // where the process runs
    NetworkManager getter = network.get(0);

    // generate necessary keys
    KeyPair chunkEncryptionKeys = EncryptionUtil.generateRSAKeyPair(H2HConstants.KEYLENGTH_CHUNK);
    KeyPair metaFileEncryptionKeys = EncryptionUtil.generateRSAKeyPair(H2HConstants.KEYLENGTH_META_FILE);
    KeyPair protectionKeysOld = EncryptionUtil.generateRSAKeyPair();
    KeyPair protectionKeysNew = EncryptionUtil.generateRSAKeyPair();

    // generate a fake meta file
    List<MetaChunk> metaChunks1 = new ArrayList<MetaChunk>();
    metaChunks1.add(new MetaChunk(NetworkTestUtil.randomString(), NetworkTestUtil.randomString()
        .getBytes(), 0));
    metaChunks1.add(new MetaChunk(NetworkTestUtil.randomString(), NetworkTestUtil.randomString()
        .getBytes(), 1));
    List<MetaChunk> metaChunks2 = new ArrayList<MetaChunk>();
    metaChunks2.add(new MetaChunk(NetworkTestUtil.randomString(), NetworkTestUtil.randomString()
        .getBytes(), 2));
    List<FileVersion> fileVersions = new ArrayList<FileVersion>();
    fileVersions.add(new FileVersion(0, 123, System.currentTimeMillis(), metaChunks1));
    fileVersions.add(new FileVersion(1, 123, System.currentTimeMillis(), metaChunks2));
    MetaFileSmall metaFileSmall = new MetaFileSmall(metaFileEncryptionKeys.getPublic(), fileVersions,
        chunkEncryptionKeys);
    // encrypt the meta file
    HybridEncryptedContent encryptedMetaFile = H2HEncryptionUtil.encryptHybrid(metaFileSmall,
        metaFileEncryptionKeys.getPublic());
    encryptedMetaFile.generateVersionKey();

    // initialize put
    Parameters parameters = new Parameters()
        .setLocationKey(H2HEncryptionUtil.key2String(metaFileSmall.getId()))
        .setContentKey(H2HConstants.META_FILE).setVersionKey(encryptedMetaFile.getVersionKey())
        .setProtectionKeys(protectionKeysOld).setData(encryptedMetaFile);
    // indicate to generate hash
    parameters.setHashFlag(true);
    // put encrypted meta file into network
    getter.getDataManager().putUnblocked(parameters).awaitUninterruptibly();

    // verify put
    Assert.assertNotNull(getter.getDataManager().getUnblocked(parameters).awaitUninterruptibly()
        .getData());

    // initialize a fake process context
    BasePKUpdateContext context = new TestMetaFilePKUpdateContext(protectionKeysOld, protectionKeysNew,
        metaFileSmall, parameters.getHash(), encryptedMetaFile.getVersionKey());
    // create a change protection keys process step
    ChangeProtectionKeysStep step = new ChangeProtectionKeysStep(context, getter.getDataManager());
    // run process, should not fail
    UseCaseTestUtil.executeProcessTillSucceded(step);

    // verify if content protection keys have changed
    Assert.assertEquals(protectionKeysNew.getPublic(), getter.getDataManager().getUnblocked(parameters)
        .awaitUninterruptibly().getData().publicKey());

    // manually trigger roll back
    step.cancel(new RollbackReason("Testing rollback."));

    // verify if content protection keys have changed to old ones
    Assert.assertEquals(protectionKeysOld.getPublic(), getter.getDataManager().getUnblocked(parameters)
        .awaitUninterruptibly().getData().publicKey());
  }
View Full Code Here

    assertNotNull(publicKey);
  }

  @Test
  public void testFailOnExistingLocations() throws InvalidProcessStateException, NoPeerConnectionException {
    NetworkManager client = network.get(0);

    UserCredentials credentials = NetworkTestUtil.generateRandomCredentials();

    // already put a locations map
    FuturePut putLocations = client.getDataManager().putUnblocked(
        new Parameters().setLocationKey(credentials.getUserId())
            .setContentKey(H2HConstants.USER_LOCATIONS)
            .setData(new Locations(credentials.getUserId())));
    putLocations.awaitUninterruptibly();
    putLocations.getFutureRequests().awaitUninterruptibly();
View Full Code Here

  }

  @Test
  public void testLogout() throws ClassNotFoundException, IOException, NoSessionException,
      NoPeerConnectionException {
    NetworkManager client = network.get(0);

    // verify the locations map before logout
    FutureGet futureGet = client.getDataManager().getUnblocked(
        new Parameters().setLocationKey(userCredentials.getUserId()).setContentKey(
            H2HConstants.USER_LOCATIONS));
    futureGet.awaitUninterruptibly();
    futureGet.getFutureRequests().awaitUninterruptibly();
    Locations locations = (Locations) futureGet.getData().object();

    Assert.assertEquals(1, locations.getPeerAddresses().size());

    // logout
    IProcessComponent process = ProcessFactory.instance().createLogoutProcess(client);
    UseCaseTestUtil.executeProcess(process);

    // verify the locations map after logout
    FutureGet futureGet2 = client.getDataManager().getUnblocked(
        new Parameters().setLocationKey(userCredentials.getUserId()).setContentKey(
            H2HConstants.USER_LOCATIONS));
    futureGet2.awaitUninterruptibly();
    futureGet2.getFutureRequests().awaitUninterruptibly();
    Locations locations2 = (Locations) futureGet2.getData().object();
View Full Code Here

   * @throws ProcessExecutionException
   */
  @Test
  public void testNotifyNobody() throws ClassNotFoundException, IOException, InvalidProcessStateException,
      IllegalArgumentException, NoPeerConnectionException, NoSessionException {
    NetworkManager notifier = network.get(0);
    CountingNotificationMessageFactory msgFactory = new CountingNotificationMessageFactory(notifier);
    IProcessComponent process = ProcessFactory.instance().createNotificationProcess(msgFactory,
        new HashSet<String>(0), notifier);
    TestProcessComponentListener listener = new TestProcessComponentListener();
    process.attachListener(listener);
View Full Code Here

  }

  @Test
  public void testStepRollback() throws InterruptedException, NoPeerConnectionException,
      InvalidProcessStateException {
    NetworkManager putter = network.get(0); // where the process runs
    putter.getConnection().getPeer().getPeerBean().storage(new DenyingPutTestStorage());
    NetworkManager proxy = network.get(1); // where the user profile is stored
    proxy.getConnection().getPeer().getPeerBean().storage(new DenyingPutTestStorage());

    // create the needed objects
    String userId = proxy.getNodeId();
    Locations newLocations = new Locations(userId);
    newLocations.addPeerAddress(putter.getConnection().getPeer().getPeerAddress());
    KeyPair protectionKeys = EncryptionUtil.generateRSAKeyPair();

    // initialize the process and the one and only step to test
    PutLocationContext context = new PutLocationContext(newLocations, protectionKeys);
    PutUserLocationsStep step = new PutUserLocationsStep(context, context, putter.getDataManager());
    TestProcessComponentListener listener = new TestProcessComponentListener();
    step.attachListener(listener);
    step.start();

    // wait for the process to finish
    UseCaseTestUtil.waitTillFailed(listener, 10);

    // get the locations which should be stored at the proxy --> they should be null
    FutureGet futureGet = proxy.getDataManager().getUnblocked(
        new Parameters().setLocationKey(userId).setContentKey(H2HConstants.USER_LOCATIONS));
    futureGet.awaitUninterruptibly();
    assertNull(futureGet.getData());
  }
View Full Code Here

   * @throws ProcessExecutionException
   */
  @Test
  public void testNotifyOwnUser() throws ClassNotFoundException, IOException, InvalidProcessStateException,
      IllegalArgumentException, NoPeerConnectionException, NoSessionException {
    NetworkManager notifier = network.get(0);

    // send notification to own peers
    Set<String> users = new HashSet<String>(1);
    users.add(userACredentials.getUserId());
    CountingNotificationMessageFactory msgFactory = new CountingNotificationMessageFactory(notifier);
View Full Code Here

TOP

Related Classes of org.hive2hive.core.network.NetworkManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.