Package org.hive2hive.core.model

Examples of org.hive2hive.core.model.NetworkContent


    this.context = context;
  }

  @Override
  protected void doExecute() throws InvalidProcessStateException, ProcessExecutionException {
    NetworkContent loadedContent = get(userId, H2HConstants.USER_LOCATIONS);

    if (loadedContent == null) {
      context.provideLocations(null);
    } else {
      Locations locations = (Locations) loadedContent;
View Full Code Here


  }

  @Override
  protected void doExecute() throws InvalidProcessStateException, ProcessExecutionException {

    NetworkContent loadedContent = get(credentials.getProfileLocationKey(), H2HConstants.USER_PROFILE);

    if (loadedContent == null) {
      throw new ProcessExecutionException("User profile not found.");
    } else {
      // decrypt user profile
      EncryptedNetworkContent encryptedContent = (EncryptedNetworkContent) loadedContent;

      SecretKey decryptionKey = PasswordUtil.generateAESKeyFromPassword(credentials.getPassword(),
          credentials.getPin(), H2HConstants.KEYLENGTH_USER_PROFILE);

      NetworkContent decryptedContent = null;
      try {
        decryptedContent = H2HEncryptionUtil.decryptAES(encryptedContent, decryptionKey);
      } catch (DataLengthException | IllegalStateException | InvalidCipherTextException
          | ClassNotFoundException | IOException e) {
        throw new ProcessExecutionException("User profile could not be decrypted.");
View Full Code Here

    } catch (NoPeerConnectionException e) {
      throw new ProcessExecutionException(e);
    }

    logger.debug("Get the next user profile task of user '{}'.", userId);
    NetworkContent content = dataManager.getUserProfileTask(userId);

    if (content == null) {
      logger.warn("Did not get an user profile task. User ID = '{}'.", userId);
      context.provideUserProfileTask(null);
    } else {
      logger.debug("Got encrypted user profile task. User ID = '{}'", userId);

      HybridEncryptedContent encrypted = (HybridEncryptedContent) content;
      PrivateKey key = null;
      try {
        key = networkManager.getSession().getKeyPair().getPrivate();
      } catch (NoSessionException e) {
        throw new ProcessExecutionException(e);
      }
      NetworkContent decrypted = null;
      try {
        decrypted = H2HEncryptionUtil.decryptHybrid(encrypted, key);
      } catch (InvalidKeyException | DataLengthException | IllegalBlockSizeException
          | BadPaddingException | IllegalStateException | InvalidCipherTextException
          | ClassNotFoundException | IOException e) {
View Full Code Here

        && digest.firstEntry().getKey().getVersionKey().equals(cachedUserProfile.getVersionKey())) {
      // no need for fetching user profile from network
      entry.setUserProfile(cachedUserProfile);
    } else {
      // load latest user profile from network
      NetworkContent content = dataManager.get(parameters);
      if (content == null) {
        logger.warn("Did not find user profile. user id = '{}'", credentials.getUserId());
        entry.setGetError(new GetFailedException("User profile not found. Got null."));
      } else {
        try {
          logger.trace("Decrypting user profile with 256-bit AES key from password. user id = '{}'",
              credentials.getUserId());
          EncryptedNetworkContent encrypted = (EncryptedNetworkContent) content;
          NetworkContent decrypted = H2HEncryptionUtil.decryptAES(encrypted, userProfileEncryptionKey);
          UserProfile userProfile = (UserProfile) decrypted;
          userProfile.setVersionKey(content.getVersionKey());
          userProfile.setBasedOnKey(content.getBasedOnKey());

          // cache user profile
View Full Code Here

      // check the cache
      return publicKeyCache.get(userId);

    IParameters parameters = new Parameters().setLocationKey(userId).setContentKey(
        H2HConstants.USER_PUBLIC_KEY);
    NetworkContent content = dataManager.get(parameters);
    return evaluateResult(content, userId);
  }
View Full Code Here

      this.contentKey = contentKey;
    }

    @Override
    protected void doExecute() throws InvalidProcessStateException, ProcessExecutionException {
      NetworkContent content = get(locationKey, contentKey);
      this.content = content;
      if (content == null)
        throw new ProcessExecutionException("Content is null.");
    }
View Full Code Here

  }

  @Override
  protected void doExecute() throws InvalidProcessStateException, ProcessExecutionException {
    KeyPair keyPair = keyContext.consumeKeyPair();
    NetworkContent loadedContent = get(keyPair.getPublic(), H2HConstants.META_FILE);

    if (loadedContent == null) {
      logger.warn("Meta file not found.");
      throw new ProcessExecutionException("Meta file not found.");
    } else {

      // decrypt meta document
      HybridEncryptedContent encryptedContent = (HybridEncryptedContent) loadedContent;

      NetworkContent decryptedContent = null;
      try {
        decryptedContent = H2HEncryptionUtil.decryptHybrid(encryptedContent, keyPair.getPrivate());
      } catch (InvalidKeyException | DataLengthException | IllegalBlockSizeException
          | BadPaddingException | IllegalStateException | InvalidCipherTextException
          | ClassNotFoundException | IOException e) {
View Full Code Here

    logger.debug("Starting to get all locations from the users to be notified.");
    Map<String, List<PeerAddress>> allLocations = new HashMap<String, List<PeerAddress>>();

    // iterate over all users and get the locations of them
    for (String userId : context.consumeUsersToNotify()) {
      NetworkContent content = get(userId, H2HConstants.USER_LOCATIONS);
      if (content == null) {
        allLocations.put(userId, new ArrayList<PeerAddress>());
      } else {
        Locations currentLoc = (Locations) content;
        List<PeerAddress> addresses = new ArrayList<PeerAddress>(currentLoc.getPeerAddresses());
View Full Code Here

    logger.debug("Downloading chunk {} of file {} from the DHT", metaChunk.getIndex(),
        task.getDestinationName());
    IParameters parameters = new Parameters().setLocationKey(metaChunk.getChunkId()).setContentKey(
        H2HConstants.FILE_CHUNK);
    NetworkContent content = dataManager.get(parameters);
    if (content == null) {
      task.abortDownload("Chunk not found in the DHT");
      return;
    }

    HybridEncryptedContent encrypted = (HybridEncryptedContent) content;
    Chunk chunk;

    try {
      NetworkContent decrypted = H2HEncryptionUtil.decryptHybrid(encrypted, task.getDecryptionKey());
      chunk = (Chunk) decrypted;
    } catch (ClassNotFoundException | InvalidKeyException | DataLengthException
        | IllegalBlockSizeException | BadPaddingException | IllegalStateException
        | InvalidCipherTextException | IllegalArgumentException | IOException e) {
      task.abortDownload("Decryption of the chunk failed");
View Full Code Here

TOP

Related Classes of org.hive2hive.core.model.NetworkContent

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.