Package org.hive2hive.core.network.data

Examples of org.hive2hive.core.network.data.UserProfileManager


    String userId = NetworkTestUtil.randomString();
    TestUserProfileTask userProfileTask = new TestUserProfileTask();
    KeyPair key = EncryptionUtil.generateRSAKeyPair(H2HConstants.KEYLENGTH_USER_KEYS);
    NetworkManager node = network.get(random.nextInt(networkSize));
    PublicKeyManager publicKeyManager = new PublicKeyManager(userId, key, node.getDataManager());
    node.setSession(new H2HSession(new UserProfileManager(node.getDataManager(), new UserCredentials(userId, "password",
        "pin")), publicKeyManager, new DownloadManager(node.getDataManager(), node.getMessageManager(),
        publicKeyManager, config), config, FileTestUtil.getTempDirectory().toPath()));

    // IGetUserProfileTaskContext context = new SimpleGetUserProfileTaskContext();
    // HybridEncryptedContent encrypted = H2HEncryptionUtil.encryptHybrid(userProfileTask,
View Full Code Here


      NoPeerConnectionException {
    String userId = NetworkTestUtil.randomString();
    NetworkManager node = network.get(random.nextInt(networkSize));
    KeyPair key = EncryptionUtil.generateRSAKeyPair(H2HConstants.KEYLENGTH_USER_KEYS);
    PublicKeyManager publicKeyManager = new PublicKeyManager(userId, key, node.getDataManager());
    node.setSession(new H2HSession(new UserProfileManager(node.getDataManager(), new UserCredentials(userId, "password",
        "pin")), publicKeyManager, new DownloadManager(node.getDataManager(), node.getMessageManager(),
        publicKeyManager, config), config, FileTestUtil.getTempDirectory().toPath()));

    // create some tasks
    List<TestUserProfileTask> tasks = new ArrayList<TestUserProfileTask>();
View Full Code Here

  @Override
  public IProcessComponent login(UserCredentials credentials, Path rootPath) throws NoPeerConnectionException {
    // TODO refactor
    SessionParameters params = new SessionParameters();
    params.setProfileManager(new UserProfileManager(networkManager.getDataManager(), credentials));
    params.setRoot(rootPath);
    params.setFileConfig(fileConfiguration);

    IProcessComponent loginProcess = ProcessFactory.instance().createLoginProcess(credentials, params, networkManager);
View Full Code Here

      return;
    }

    UserProfile userProfile;
    try {
      UserProfileManager profileManager = session.getProfileManager();
      userProfile = profileManager.getUserProfile(messageID, false);
    } catch (GetFailedException e) {
      logger.error("Cannot get the user profile", e);
      sendDirectResponse(createResponse(null));
      return;
    }
View Full Code Here

    this.networkManager = networkManager;
  }

  @Override
  protected void doExecute() throws InvalidProcessStateException, ProcessExecutionException {
    UserProfileManager profileManager;
    try {
      profileManager = networkManager.getSession().getProfileManager();
    } catch (NoSessionException e) {
      throw new ProcessExecutionException(e);
    }

    UserProfile profile = null;
    try {
      profile = profileManager.getUserProfile(getID(), false);
    } catch (GetFailedException e) {
      throw new ProcessExecutionException("User profile could not be loaded.");
    }

    FileSynchronizer synchronizer;
View Full Code Here

    // - file moved from root to other destination
    // - file moved from other source to root
    // - file moved from other source to other destination
    // Additionally, the file can be renamed (within any directory)
    try {
      UserProfileManager profileManager = networkManager.getSession().getProfileManager();
      UserProfile userProfile = profileManager.getUserProfile(getID(), true);

      logger.debug("Start relinking the moved file in the user profile.");
      Index movedNode = userProfile.getFileById(context.getFileNodeKeys().getPublic());

      // consider renaming
      movedNode.setName(context.getDestination().getName());

      FolderIndex oldParent = movedNode.getParent();
      oldParentKey = oldParent.getFileKeys().getPublic();

      // source's parent needs to be updated, no matter if it's root or not
      oldParent.removeChild(movedNode);

      // add to the new parent
      FolderIndex newParent = (FolderIndex) userProfile.getFileByPath(context.getDestination()
          .getParentFile(), networkManager.getSession().getRoot());
      movedNode.setParent(newParent);
      newParent.addChild(movedNode);

      // validate
      if (!oldParent.canWrite()) {
        throw new ProcessExecutionException("No write access to the source directory");
      } else if (!newParent.canWrite()) {
        throw new ProcessExecutionException("No write access to the destination directory");
      }

      // update in DHT
      profileManager.readyToPut(userProfile, getID());
      profileUpdated = true;
      logger.debug("Successfully relinked the moved file in the user profile.");

      // check if the protection key needs to be updated
      if (!H2HEncryptionUtil.compare(oldParent.getProtectionKeys(), newParent.getProtectionKeys())) {
View Full Code Here

  @Override
  public void start() {
    try {
      // get the user profile first
      String randomPID = UUID.randomUUID().toString();
      UserProfileManager profileManager = networkManager.getSession().getProfileManager();
      UserProfile userProfile = profileManager.getUserProfile(randomPID, true);
      FolderIndex parentNode = (FolderIndex) userProfile.getFileById(parentKey);
      if (parentNode == null) {
        logger.error("Could not process the task because the parent node has not been found.");
        return;
      }

      // validate if the other sharer has the right to share
      if (parentNode.canWrite(sender)) {
        logger.debug("Rights of user '{}' checked. User is allowed to modify.", sender);
      } else {
        logger.error("Permission of user '{}' not found. Deny to apply this user's changes.", sender);
        return;
      }

      // this task is sent when the file has been added or updated, make the difference between them.
      // When it's been added, add the index to the user profile, else, simply upldate it's md5 hash
      // there.
      if (parentNode.getChildByName(index.getName()) == null) {
        logger.debug("Newly shared file '{}' received.", index.getName());
        // file is new, link parent and new child
        parentNode.addChild(index);
        index.setParent(parentNode);
      } else {
        // copy the md5 parameter of the received file
        Index existing = parentNode.getChildByName(index.getName());
        if (existing.isFile() && index.isFile()) {
          logger.debug("File update in a shared folder received: '{}'.", index.getName());
          FileIndex existingFile = (FileIndex) existing;
          FileIndex newFile = (FileIndex) index;
          existingFile.setMD5(newFile.getMD5());
        }
      }

      // upload the changes
      profileManager.readyToPut(userProfile, randomPID);
      logger.debug("Successfully updated the index '{}' in the own user profile.", index.getName());
    } catch (Hive2HiveException e) {
      logger.error("Could not add the filenode to the own user profile.", e);
      return;
    }
View Full Code Here

  @Override
  protected void doRollback(RollbackReason reason) throws InvalidProcessStateException {
    // only when user profile has been updated
    if (profileUpdated) {
      try {
        UserProfileManager profileManager = networkManager.getSession().getProfileManager();
        UserProfile userProfile = profileManager.getUserProfile(getID(), true);

        // relink them
        Index movedNode = userProfile.getFileById(context.getFileNodeKeys().getPublic());
        userProfile.getRoot().removeChild(movedNode);
        FolderIndex oldParent = (FolderIndex) userProfile.getFileById(oldParentKey);
        movedNode.setParent(oldParent);
        oldParent.addChild(movedNode);

        // update in DHT
        profileManager.readyToPut(userProfile, getID());
      } catch (NoSessionException | GetFailedException | PutFailedException e) {
        // ignore
      }
    }
  }
View Full Code Here

  }

  private void move() {
    try {
      H2HSession session = networkManager.getSession();
      UserProfileManager profileManager = session.getProfileManager();
      UserProfile userProfile = profileManager.getUserProfile(UUID.randomUUID().toString(), false);

      Index oldParent = userProfile.getFileById(oldParentKey);
      Index newParent = userProfile.getFileById(newParentKey);
      FileUtil.moveFile(session.getRoot(), sourceFileName, destFileName, oldParent, newParent);
    } catch (NoSessionException | GetFailedException | IOException e) {
View Full Code Here

  @Override
  protected void doExecute() throws InvalidProcessStateException, ProcessExecutionException {
    UserProfile userProfile = null;
    try {
      UserProfileManager profileManager = networkManager.getSession().getProfileManager();
      userProfile = profileManager.getUserProfile(getID(), false);
    } catch (GetFailedException | NoSessionException e) {
      throw new ProcessExecutionException(e);
    }

    Index index = userProfile.getFileById(context.getFileKey());
View Full Code Here

TOP

Related Classes of org.hive2hive.core.network.data.UserProfileManager

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.