Package org.hive2hive.core.model

Examples of org.hive2hive.core.model.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));
View Full Code Here


    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();

    // verify if both objects are the same
    Assert.assertEquals(userId, found.getUserId());

    List<PeerAddress> onlinePeers = new ArrayList<PeerAddress>(found.getPeerAddresses());
    Assert.assertEquals(putter.getConnection().getPeer().getPeerAddress(), onlinePeers.get(0));
  }
View Full Code Here

    // 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();

    assertTrue(putLocations.isSuccess());
View Full Code Here

    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());
View Full Code Here

    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();

    Assert.assertEquals(0, locations2.getPeerAddresses().size());
  }
View Full Code Here

    // wait until all messages are sent
    UseCaseTestUtil.waitTillSucceded(listener, 20);

    // check the locations map; should have 2 entries only
    Locations locations = UseCaseTestUtil.getLocations(network.get(0), userACredentials.getUserId());
    Assert.assertEquals(2, locations.getPeerAddresses().size());
  }
View Full Code Here

    }

    // if own peer is not possible, take a foreign sharer
    Random rnd = new Random();
    while (!locations.isEmpty()) {
      Locations randomLocation = locations.get(rnd.nextInt(locations.size()));
      List<PeerAddress> addresses = new ArrayList<PeerAddress>(randomLocation.getPeerAddresses());
      if (addresses.isEmpty()) {
        // does not contain any addresses, kick it
        locations.remove(randomLocation);
      } else {
        logger.debug("Found peer of foreign user to contact for the file {}", task.getDestinationName());
        PeerAddress rndAddress = addresses.get(rnd.nextInt(addresses.size()));
        context.setSelectedPeer(rndAddress, randomLocation.getUserId());
        return;
      }
    }

    logger.warn("No online peer found that could be contacted to get the file {}", task.getDestinationName());
View Full Code Here

      keyManager = networkManager.getSession().getKeyManager();
    } catch (NoSessionException e) {
      throw new ProcessExecutionException("No session yet");
    }

    Locations locations = context.consumeLocations();
    waitForResponses = new CountDownLatch(locations.getPeerAddresses().size());
    if (!locations.getPeerAddresses().isEmpty()) {
      for (PeerAddress address : locations.getPeerAddresses()) {
        // contact all other clients (exclude self)
        if (!address.equals(networkManager.getConnection().getPeer().getPeerAddress())) {
          String evidence = UUID.randomUUID().toString();
          evidences.put(address, evidence);
View Full Code Here

  }

  private void updateLocations() {
    isUpdated = true;

    Locations updatedLocations = new Locations(context.consumeLocations().getUserId());
    updatedLocations.setBasedOnKey(context.consumeLocations().getBasedOnKey());
    updatedLocations.setVersionKey(context.consumeLocations().getVersionKey());

    // add addresses that responded and self
    for (PeerAddress address : responses.keySet()) {
      if (responses.get(address)) {
        updatedLocations.addPeerAddress(address);
      }
    }
    updatedLocations.addPeerAddress(networkManager.getConnection().getPeer().getPeerAddress());
    context.provideLocations(updatedLocations);

    // evaluate if initial
    List<PeerAddress> clientAddresses = new ArrayList<PeerAddress>(updatedLocations.getPeerAddresses());

    if (NetworkUtils.choseFirstPeerAddress(clientAddresses).equals(
        networkManager.getConnection().getPeer().getPeerAddress())) {
      context.setIsInitial(true);
    } else {
View Full Code Here

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

    locationsContext.provideLocations(new Locations(userId));
  }
View Full Code Here

TOP

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

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.