Package org.hive2hive.core.network.data.parameters

Examples of org.hive2hive.core.network.data.parameters.Parameters


    process.add(new GetUserProfileTaskStep(context, node));
    process.add(new RemoveUserProfileTaskStep(context, node));

    UseCaseTestUtil.executeProcess(process);

    Parameters parameters = new Parameters().setLocationKey(userId).setDomainKey(H2HConstants.USER_PROFILE_TASK_DOMAIN)
        .setContentKey(userProfileTask.getContentKey());
    FutureGet futureGet = node.getDataManager().getUnblocked(parameters);
    futureGet.awaitUninterruptibly();

    assertNull(futureGet.getData());
View Full Code Here


        // encrypt the chunk prior to put such that nobody can read it
        HybridEncryptedContent encryptedContent = H2HEncryptionUtil.encryptHybrid(chunk, context
            .consumeChunkKeys().getPublic());

        logger.debug("Uploading chunk {} of file {}.", chunk.getOrder(), file.getName());
        Parameters parameters = new Parameters().setLocationKey(chunk.getId())
            .setContentKey(H2HConstants.FILE_CHUNK).setData(encryptedContent)
            .setProtectionKeys(context.consumeProtectionKeys()).setTTL(chunk.getTimeToLive());

        // data manager has to produce the hash, which gets used for signing
        parameters.setHashFlag(true);
        // put the encrypted chunk into the network
        put(parameters);

        // store the hash in the index of the meta file
        context.getMetaChunks().add(new MetaChunk(chunkId, parameters.getHash(), index));
      } catch (IOException | DataLengthException | InvalidKeyException | IllegalStateException
          | InvalidCipherTextException | IllegalBlockSizeException | BadPaddingException
          | PutFailedException e) {
        logger.error("Could not encrypt and put the chunk.", e);
        throw new ProcessExecutionException("Could not encrypt and put the chunk.", e);
View Full Code Here

      logger.trace("Encrypting meta file of file '{}' in a hybrid manner.", context.getFile().getName());
      HybridEncryptedContent encrypted = H2HEncryptionUtil.encryptHybrid(metaFile, metaFile.getId());
      encrypted.setBasedOnKey(metaFile.getVersionKey());
      encrypted.generateVersionKey();

      Parameters parameters = new Parameters()
          .setLocationKey(H2HEncryptionUtil.key2String(metaFile.getId()))
          .setContentKey(H2HConstants.META_FILE).setVersionKey(encrypted.getVersionKey())
          .setData(encrypted).setProtectionKeys(protectionKeys).setTTL(metaFile.getTimeToLive());
      // data manager has to produce the hash, which gets used for signing
      parameters.setHashFlag(true);
      // put the encrypted meta file into the network
      put(parameters);
      // store the hash
      context.provideHash(parameters.getHash());

    } catch (IOException | DataLengthException | InvalidKeyException | IllegalStateException
        | InvalidCipherTextException | IllegalBlockSizeException | BadPaddingException e) {
      throw new ProcessExecutionException("Meta file could not be encrypted.", e);
    } catch (PutFailedException e) {
View Full Code Here

    NetworkManager node = network.get(random.nextInt(networkSize));

    // initial put
    H2HTestData data1 = new H2HTestData("bla1");
    Parameters parameters1 = new Parameters().setLocationKey(locationKey).setDomainKey(domainKey)
        .setContentKey(contentKey).setData(data1).setProtectionKeys(protectionKey);
    FuturePut futurePut = node.getDataManager().putUnblocked(parameters1);
    futurePut.awaitUninterruptibly();

    // verify initial put
    FutureGet futureGet = node.getDataManager().getUnblocked(parameters1);
    futureGet.awaitUninterruptibly();
    assertEquals(data1.getTestString(), ((H2HTestData) futureGet.getData().object()).getTestString());

    // try to put without a protection key
    H2HTestData data2 = new H2HTestData("bla2");
    Parameters parameters2 = new Parameters().setLocationKey(locationKey).setDomainKey(domainKey)
        .setContentKey(contentKey).setData(data2);
    futurePut = node.getDataManager().putUnblocked(parameters2);
    futurePut.awaitUninterruptibly();

    // should have been not modified
View Full Code Here

    NetworkManager node = network.get(random.nextInt(networkSize));

    // initial put
    H2HTestData data1 = new H2HTestData("bla1");
    Parameters parameters1 = new Parameters().setLocationKey(locationKey).setDomainKey(domainKey)
        .setContentKey(contentKey).setData(data1).setProtectionKeys(protectionKey);
    FuturePut futurePut = node.getDataManager().putUnblocked(parameters1);
    futurePut.awaitUninterruptibly();

    // verify initial put
    FutureGet futureGet = node.getDataManager().getUnblocked(parameters1);
    futureGet.awaitUninterruptibly();
    assertEquals(data1.getTestString(), ((H2HTestData) futureGet.getData().object()).getTestString());

    // overwrite with correct protection key
    H2HTestData data2 = new H2HTestData("bla2");
    Parameters parameters2 = new Parameters().setLocationKey(locationKey).setDomainKey(domainKey)
        .setContentKey(contentKey).setData(data2).setProtectionKeys(protectionKey);
    futurePut = node.getDataManager().putUnblocked(parameters2);
    futurePut.awaitUninterruptibly();

    // verify overwrite
    futureGet = node.getDataManager().getUnblocked(parameters2);
    futureGet.awaitUninterruptibly();
    assertEquals(data2.getTestString(), ((H2HTestData) futureGet.getData().object()).getTestString());

    // try to overwrite without protection key
    H2HTestData data3 = new H2HTestData("bla3");
    Parameters parameters3 = new Parameters().setLocationKey(locationKey).setDomainKey(domainKey)
        .setContentKey(contentKey).setData(data3);
    futurePut = node.getDataManager().putUnblocked(parameters3);
    futurePut.awaitUninterruptibly();

    // should have been not changed
View Full Code Here

    NetworkManager node = network.get(random.nextInt(networkSize));

    // initial put
    H2HTestData data1 = new H2HTestData("bla1");
    Parameters parameters1 = new Parameters().setLocationKey(locationKey).setDomainKey(domainKey)
        .setContentKey(contentKey).setData(data1).setProtectionKeys(protectionKey1);
    FuturePut futurePut = node.getDataManager().putUnblocked(parameters1);
    futurePut.awaitUninterruptibly();

    // verify initial put
    FutureGet futureGet = node.getDataManager().getUnblocked(parameters1);
    futureGet.awaitUninterruptibly();
    assertEquals(data1.getTestString(), ((H2HTestData) futureGet.getData().object()).getTestString());

    // try to overwrite with wrong protection key
    H2HTestData data2 = new H2HTestData("bla2");
    Parameters parameters2 = new Parameters().setLocationKey(locationKey).setDomainKey(domainKey)
        .setContentKey(contentKey).setData(data2).setProtectionKeys(protectionKey2);
    futurePut = node.getDataManager().putUnblocked(parameters2);
    futurePut.awaitUninterruptibly();

    // should have been not changed;
View Full Code Here

    NetworkManager node = network.get(random.nextInt(networkSize));

    // initial put
    H2HTestData data1 = new H2HTestData("bla1");
    Parameters parameters1 = new Parameters().setLocationKey(locationKey).setDomainKey(domainKey)
        .setContentKey(contentKey).setData(data1).setProtectionKeys(protectionKey1);
    FuturePut futurePut = node.getDataManager().putUnblocked(parameters1);
    futurePut.awaitUninterruptibly();

    // verify initial put
    FutureGet futureGet = node.getDataManager().getUnblocked(parameters1);
    futureGet.awaitUninterruptibly();
    assertEquals(data1.getTestString(), ((H2HTestData) futureGet.getData().object()).getTestString());

    // try to remove without protection keys
    Parameters parameters2 = new Parameters().setLocationKey(locationKey).setDomainKey(domainKey)
        .setContentKey(contentKey);
    FutureRemove futureRemove = node.getDataManager().removeUnblocked(parameters2);
    futureRemove.awaitUninterruptibly();

    // should have been not changed
    futureGet = node.getDataManager().getUnblocked(parameters2);
    futureGet.awaitUninterruptibly();
    assertEquals(data1.getTestString(), ((H2HTestData) futureGet.getData().object()).getTestString());

    // try to remove with wrong protection keys
    Parameters parameters3 = new Parameters().setLocationKey(locationKey).setDomainKey(domainKey)
        .setContentKey(contentKey).setProtectionKeys(protectionKey2);
    futureRemove = node.getDataManager().removeUnblocked(parameters3);
    futureRemove.awaitUninterruptibly();

    // should have been not changed
View Full Code Here

    NetworkManager node = network.get(random.nextInt(networkSize));

    H2HTestData data1 = new H2HTestData("bla1");
    data1.generateVersionKey();
    Parameters parameters1 = new Parameters().setLocationKey(locationKey).setDomainKey(domainKey)
        .setContentKey(contentKey).setVersionKey(data1.getVersionKey()).setData(data1)
        .setProtectionKeys(protectionKey1);

    // initial put
    FuturePut futurePut = node.getDataManager().putUnblocked(parameters1);
    futurePut.awaitUninterruptibly();

    // check if put was ok
    FutureGet futureGet = node.getDataManager().getVersionUnblocked(parameters1);
    futureGet.awaitUninterruptibly();
    assertEquals(data1.getTestString(), ((H2HTestData) futureGet.getData().object()).getTestString());

    // try to remove without a protection key
    Parameters parameters2 = new Parameters().setLocationKey(locationKey).setDomainKey(domainKey)
        .setContentKey(contentKey).setVersionKey(data1.getVersionKey()).setData(data1);
    FutureRemove futureRemove = node.getDataManager().removeVersionUnblocked(parameters2);
    futureRemove.awaitUninterruptibly();

    // should have been not modified
    futureGet = node.getDataManager().getVersionUnblocked(parameters1);
    futureGet.awaitUninterruptibly();
    assertEquals(data1.getTestString(), ((H2HTestData) futureGet.getData().object()).getTestString());

    // try to remove with wrong protection key
    Parameters parameters3 = new Parameters().setLocationKey(locationKey).setDomainKey(domainKey)
        .setContentKey(contentKey).setVersionKey(data1.getVersionKey())
        .setProtectionKeys(protectionKey2);
    futureRemove = node.getDataManager().removeVersionUnblocked(parameters3);
    futureRemove.awaitUninterruptibly();

    // should have been not modified
    futureGet = node.getDataManager().getVersionUnblocked(parameters1);
    futureGet.awaitUninterruptibly();
    assertEquals(data1.getTestString(), ((H2HTestData) futureGet.getData().object()).getTestString());

    // remove with correct content protection key
    Parameters parameters4 = new Parameters().setLocationKey(locationKey).setDomainKey(domainKey)
        .setContentKey(contentKey).setVersionKey(data1.getVersionKey()).setData(data1)
        .setProtectionKeys(protectionKey1);
    futureRemove = node.getDataManager().removeVersionUnblocked(parameters4);
    futureRemove.awaitUninterruptibly();
View Full Code Here

  @Test
  public void testCleanUpOutdatedVersion() throws InterruptedException, IOException,
      NoPeerConnectionException {
    NetworkManager node = network.get(random.nextInt(networkSize));

    Parameters parameters = new Parameters().setLocationKey(NetworkTestUtil.randomString())
        .setDomainKey(NetworkTestUtil.randomString()).setContentKey(NetworkTestUtil.randomString())
        .setProtectionKeys(EncryptionUtil.generateRSAKeyPair());

    int numVersions = H2HConstants.MAX_VERSIONS_HISTORY + random.nextInt(5) + 1;
    List<H2HTestData> versions = new ArrayList<H2HTestData>();
    List<H2HTestData> newerVersions = new ArrayList<H2HTestData>();

    H2HTestData last = null;
    for (int i = 0; i < numVersions; i++) {
      long timeStamp = new Date().getTime();
      timeStamp += 2 * H2HConstants.MIN_VERSION_AGE_BEFORE_REMOVAL_MS;
      H2HTestData testData = generateTestData(timeStamp);
      if (last != null)
        testData.setBasedOnKey(last.getVersionKey());
      last = testData;
      versions.add(testData);
      if (i >= numVersions - H2HConstants.MAX_VERSIONS_HISTORY - 1)
        newerVersions.add(testData);
      synchronized (this) {
        Thread.sleep(10);
      }
    }

    long timeDiff = versions.get(numVersions - 1).getVersionKey().timestamp()
        - versions.get(0).getVersionKey().timestamp();
    if (timeDiff < H2HConstants.MIN_VERSION_AGE_BEFORE_REMOVAL_MS)
      Assert.fail("H2H constant is too low to generate appropriate time stamps.");

    for (H2HTestData testData : versions) {
      parameters.setVersionKey(testData.getVersionKey()).setData(testData);
      node.getDataManager().putUnblocked(parameters).awaitUninterruptibly();
    }

    FutureDigest futureDigest = node.getDataManager().getDigestUnblocked(parameters);
    futureDigest.awaitUninterruptibly();
View Full Code Here

  public void testRemove() throws NoPeerConnectionException {
    NetworkManager nodeA = network.get(random.nextInt(networkSize));
    NetworkManager nodeB = network.get(random.nextInt(networkSize));

    H2HTestData data = new H2HTestData(NetworkTestUtil.randomString());
    Parameters parameters = new Parameters().setLocationKey(nodeA.getNodeId())
        .setContentKey(NetworkTestUtil.randomString()).setData(data);

    nodeA.getDataManager().putUnblocked(parameters).awaitUninterruptibly();

    boolean success = nodeB.getDataManager().remove(parameters);
View Full Code Here

TOP

Related Classes of org.hive2hive.core.network.data.parameters.Parameters

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.