Package net.tomp2p.peers

Examples of net.tomp2p.peers.PeerAddress


    final Peer peer;
    try {
      peer = new PeerMaker(new Number160(r)).setPorts(port)
          .makeAndListen();

      PeerAddress pa = new PeerAddress(Number160.ZERO, masterPeerAddress,
          masterPeerPort, masterPeerPort);
      logger.info(String.format("Client-Node connecting to master: %s",
          pa));

      // Future Discover
View Full Code Here


  @Override
  public void sendMessageTo(String peer, String message) {
    l.log(TYPE_SEND, String.format("Peer %s sends message: %s to peer %s",
        p, message, peer), 10);
    byte[] recipient = toByteArray(peer);
    p.sendDirect(new PeerAddress(recipient)).setObject(message).start();
  }
View Full Code Here

  }

  private boolean isInitialClient(Locations locations, PeerAddress client) {
    ArrayList<PeerAddress> list = new ArrayList<PeerAddress>();
    list.addAll(locations.getPeerAddresses());
    PeerAddress initial = NetworkUtils.choseFirstPeerAddress(list);
    return (initial.equals(client));
  }
View Full Code Here

    Locations result = runProcessStep(fakedLocations,
        isInitialClient(fakedLocations, network.get(0).getConnection().getPeer().getPeerAddress()));

    assertEquals(4, result.getPeerAddresses().size());
    PeerAddress newClientsEntry = null;
    for (PeerAddress address : result.getPeerAddresses()) {
      if (address.equals(network.get(0).getConnection().getPeer().getPeerAddress())) {
        newClientsEntry = address;
        break;
      }
View Full Code Here

    Locations result = runProcessStep(fakedLocations,
        isInitialClient(fakedLocations, network.get(0).getConnection().getPeer().getPeerAddress()));

    assertEquals(2, result.getPeerAddresses().size());
    PeerAddress newClientsEntry = null;
    for (PeerAddress address : result.getPeerAddresses()) {
      if (address.equals(network.get(0).getConnection().getPeer().getPeerAddress())) {
        newClientsEntry = address;
        break;
      }
View Full Code Here

    Locations result = runProcessStep(fakedLocations,
        isInitialClient(fakedLocations, network.get(0).getConnection().getPeer().getPeerAddress()));

    assertEquals(2, result.getPeerAddresses().size());
    PeerAddress newClientsEntry = null;
    for (PeerAddress address : result.getPeerAddresses()) {
      if (address.equals(network.get(0).getConnection().getPeer().getPeerAddress())) {
        newClientsEntry = address;
        break;
      }
View Full Code Here

      logger.warn("Not executing step because task is aborted");
      return;
    }

    // prefer own user name
    PeerAddress selectedOwnPeer = null;
    for (Locations location : locations) {
      if (location.getUserId().equals(task.getOwnUserName())) {
        selectedOwnPeer = selectAddressOwnUser(location.getPeerAddresses());
        break;
      }
    }

    if (selectedOwnPeer != null) {
      logger.debug("Found peer of own user to contact for the file {}", task.getDestinationName());
      context.setSelectedPeer(selectedOwnPeer, task.getOwnUserName());
      return;
    }

    // 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;
      }
    }
View Full Code Here

    } else {
      logger.info("Initalize the process for downloading file '{}'.", index.getFullPath());
      try {
        IDataManager dataManager = networkManager.getDataManager();
        getParent().add(new GetMetaFileStep(context, context, dataManager));
        PeerAddress ownPeerAddress = networkManager.getConnection().getPeer().getPeerAddress();
        getParent().add(
            new InitDownloadChunksStep(context, networkManager.getSession(), ownPeerAddress));
      } catch (NoPeerConnectionException | NoSessionException e) {
        throw new ProcessExecutionException(e);
      }
View Full Code Here

  private void notifyMasterPeer(List<PeerAddress> peerList, BaseNotificationMessageFactory messageFactory, String userId,
      PublicKey publicKey) {
    boolean success = false;
    while (!success && !peerList.isEmpty()) {
      PeerAddress initial = NetworkUtils.choseFirstPeerAddress(peerList);
      BaseDirectMessage msg = messageFactory.createHintNotificationMessage(initial, userId);
      try {
        sendDirect(msg, publicKey);
        success = true;
      } catch (SendFailedException e) {
View Full Code Here

     */
    public void progress(FutureAsyncTask futureAsyncTask) {
        synchronized (lock) {
            if (futureAsyncTask.isSuccess()) {
                resultSuccess++;
                PeerAddress peerAddress = futureAsyncTask.remotePeer();
                Map<Number160, Data> tmp = dataMap.get(peerAddress);
                if (tmp == null) {
                    tmp = new HashMap<Number160, Data>();
                    dataMap.put(peerAddress, tmp);
                }
View Full Code Here

TOP

Related Classes of net.tomp2p.peers.PeerAddress

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.