Package net.tomp2p.peers

Examples of net.tomp2p.peers.PeerAddress


      //if I have conetnt and I see the removed peer as a responsible, push it.
      if(isInReplicationRange(entry.getKey().locationKey(), remotePeer, replicationFactor)) {
        //limit the pushing peer to those that are responsible
        if(isInReplicationRange(entry.getKey().locationKey(), self, replicationFactor)) {
          NavigableSet<PeerAddress> closePeers = peerMap.closePeers(entry.getKey().locationKey(), replicationFactor);
          PeerAddress newResponsible = closePeers.headSet(remotePeer).last();
          peerExchange.peerExchange(newResponsible, entry.getKey(), entry.getValue());
        }
      }
    }
  }
View Full Code Here


      peerOffline.remove(remotePeer.peerId());
      Number320 keyToRemove = null;
      PeerStatistic statToRemove = null;
      for (Map.Entry<Number320, TrackerData> entry : dataMapUnverified.entrySet()) {
        for (Map.Entry<PeerStatistic, Data> entry2 : entry.getValue().peerAddresses().entrySet()) {
          PeerAddress tmp = entry2.getKey().peerAddress();
          if (tmp.equals(remotePeer)) {
            if (add(entry.getKey(), entry2.getKey(), dataMap, entry2.getValue())) {
              // only remove from unverified if we could store to
              // verified
              keyToRemove = entry.getKey();
              statToRemove = entry2.getKey();
View Full Code Here

   * Remove recently failed relays, peers that are relayed themselves and
   * peers that are already relays
   */
  private void filterRelayCandidates(Collection<PeerAddress> relayCandidates) {
    for (Iterator<PeerAddress> iterator = relayCandidates.iterator(); iterator.hasNext();) {
      PeerAddress pa = iterator.next();

      // filter peers that are relayed themselves
      if (pa.isRelayed()) {
        iterator.remove();
        continue;
      }

      // filter relays that are already connected
View Full Code Here

      final List<PeerAddress> relayCandidates, final int numberOfRelays, final FutureRelay futureRelay,
      final int fail, final int maxFail, final StringBuilder status) {
    int active = 0;
    for (int i = 0; i < numberOfRelays; i++) {
      if (futures.get(i) == null) {
        PeerAddress candidate = null;
        synchronized (relayCandidates) {
          if (!relayCandidates.isEmpty()) {
            candidate = relayCandidates.remove(0);
          }
        }
View Full Code Here

    boolean hasRelays = !relays.isEmpty();

    Collection<PeerSocketAddress> socketAddresses = new ArrayList<PeerSocketAddress>(relays.size());
    synchronized (relays) {
      for (BaseRelayConnection relay : relays) {
        PeerAddress pa = relay.relayAddress();
        socketAddresses.add(new PeerSocketAddress(pa.inetAddress(), pa.tcpPort(), pa.udpPort()));
      }
    }

    // update firewalled and isRelayed flags
    PeerAddress newAddress = peer.peerAddress().changeFirewalledTCP(!hasRelays).changeFirewalledUDP(!hasRelays)
        .changeRelayed(hasRelays).changePeerSocketAddresses(socketAddresses).changeSlow(hasRelays && relayType.isSlow());
    peer.peerBean().serverPeerAddress(newAddress);
    LOG.debug("Updated peer address {}, isrelay = {}", newAddress, hasRelays);
  }
View Full Code Here

    public void dataInserted(final Number160 locationKey) {
        if (!isReplication()) {
            return;
        }
        if (!nRootReplication) {
            PeerAddress closest = closest(locationKey);
            if (closest.peerId().equals(selfAddress.peerId())) {
                if (backend.updateResponsibilities(locationKey, closest.peerId())) {
                    // I am responsible for this content
                    notifyMeResponsible(locationKey);
                }
            } else {
                if (backend.updateResponsibilities(locationKey, closest.peerId())) {
                    // notify that someone else is now responsible for the
                    // content with key responsibleLocations
                    notifyOtherResponsible(locationKey, closest);
                }
            }
        } else {
      if (isInReplicationRange(locationKey, selfAddress, replicationFactor)) {
        if (backend.updateResponsibilities(locationKey, selfAddress.peerId())) {
          LOG.debug("I {} am now responsible for key {}.", selfAddress, locationKey);
          notifyMeResponsible(locationKey);
        }
      } else {
        LOG.debug("I {} am not responsible for key {}.", selfAddress, locationKey);
        final PeerAddress closest = closest(locationKey);
        // Try to notify another replica node.
        FutureForkJoin<FutureDone<Void>> futureForkJoin = notifyOtherResponsible(
            locationKey, closest);
        // Remove responsibility after successful notifying.
        futureForkJoin
View Full Code Here

        LOG.debug("I {} have to check replication responsibilities for {}.", selfAddress, myResponsibleLocations);
       
        for (final Number160 myResponsibleLocation : myResponsibleLocations) {
      if (!nRootReplication) {
        // use 0-root replication strategy
        PeerAddress closest = closest(myResponsibleLocation);
        if (!closest.peerId().equals(selfAddress.peerId())) {
          if (isInReplicationRange(myResponsibleLocation, selfAddress, replicationFactor)) {
              if (backend.updateResponsibilities(myResponsibleLocation, closest.peerId())) {
                LOG.debug("I {} didn't know that {} is responsible for {}.", selfAddress, closest,
                    myResponsibleLocation);
                // notify that someone else is now responsible for the
                // content with key responsibleLocations
                notifyOtherResponsible(myResponsibleLocation, closest);
                // cancel any pending notifyMeResponsible*, as we are
                // not responsible anymore.
              } else {
                LOG.debug("I {} know already that {} is responsible for {}.", selfAddress, closest,
                    myResponsibleLocation);
              }
          } else {
            // notify closest replica node about responsibility
            notifyOtherResponsible(myResponsibleLocation, closest);
            LOG.debug("I {} am no more in the replica set of {}.", selfAddress, myResponsibleLocation);
            backend.removeResponsibility(myResponsibleLocation, keepData);
          }
        } else if (isInReplicationRange(myResponsibleLocation, peerAddress, replicationFactor)) {
          LOG.debug("{} is in the replica set for {}.", peerAddress, myResponsibleLocation);
          // we are still responsible, but a new peer joined and if it
          // is within the x close peers, we need to
          // replicate
          if (backend.updateResponsibilities(myResponsibleLocation,
              selfAddress.peerId())) {
            LOG.debug("I {} didn't know that I'm responsible for {}.", selfAddress,
                myResponsibleLocation);
            // I figured out I'm the new responsible, so check all
            // my peer in the replication range
            notifyMeResponsible(myResponsibleLocation);
          } else {
            LOG.debug("I {} already know that I'm responsible for {}.", selfAddress,
                myResponsibleLocation);
            // new peer joined, I'm responsible, so replicate to
            // that peer
            notifyMeResponsible(myResponsibleLocation, peerAddress);
          }
        }
      } else {
        // check if newly joined peer has duty to replicate
        if (isInReplicationRange(myResponsibleLocation, peerAddress, replicationFactor)) {
          // check if I still have to replicate
          if (isInReplicationRange(myResponsibleLocation, selfAddress, replicationFactor)) {
            LOG.debug("I {} and newly joined peer {} have replication responibility for {}.",
                selfAddress, peerAddress, myResponsibleLocation);
            // newly joined peer has to get notified
            notifyMeResponsible(myResponsibleLocation, peerAddress);
          } else {
            LOG.debug("I {} lose and newly joined peer {} gets replication responsibility for {}.",
                selfAddress, peerAddress, myResponsibleLocation);
            // newly joined peer has to get notified
            FutureForkJoin<FutureDone<Void>> futureForkJoin = notifyOtherResponsible(
                myResponsibleLocation, peerAddress);
            // I'm not in replication range, I don't need to know
            // about all responsibility entries to the given key.
            // Remove responsibility after notifying newly joined peer.
            futureForkJoin.addListener(new BaseFutureListener<BaseFuture>() {
              @Override
              public void operationComplete(BaseFuture future)
                  throws Exception {
                    if (future.isSuccess()) {
                      backend.removeResponsibility(
                          myResponsibleLocation,
                          keepData);
                    } else {
                      LOG.debug(
                          "I {} couldn't notify newly joined peer {} about responsibility for {}."
                              + " I keep responsibility.",
                          selfAddress, peerAddress,
                          myResponsibleLocation);
                    }
              }
              @Override
              public void exceptionCaught(Throwable t)
                  throws Exception {
                LOG.error("Unexcepted exception ocurred.", t);
              }
            });
          }
        } else {
          // check if I still have to replicate
          if (!isInReplicationRange(myResponsibleLocation,
              selfAddress, replicationFactor)) {
            LOG.debug(
                "I {} and newly joined peer {} don't have to replicate {}.",
                selfAddress, peerAddress, myResponsibleLocation);
            // I'm not in replication range, I don't need to know
            // about all responsibility entries to the given key
            final PeerAddress closest = closest(myResponsibleLocation);
            // Try to notify another replica node.
            FutureForkJoin<FutureDone<Void>> futureForkJoin = notifyOtherResponsible(
                myResponsibleLocation, closest);
            // Remove responsibility after successful notifying.
            futureForkJoin
View Full Code Here

        LOG.debug("I {} have to replicate {}.", selfAddress, myResponsibleLocations);
    if (!nRootReplication) {
      // check if we are now responsible for content where the other peer
      // was responsible
      for (Number160 otherResponsibleLocation : otherResponsibleLocations) {
        PeerAddress closest = closest(otherResponsibleLocation);
        if (closest.peerId().equals(selfAddress.peerId())) {
          if (backend.updateResponsibilities(otherResponsibleLocation,
              closest.peerId())) {
            LOG.debug("I {} am responsible for {} after leaving of {}.", selfAddress,
                otherResponsibleLocations, peerAddress);
            notifyMeResponsible(otherResponsibleLocation);
            // we don't need to check this again, so remove it from
            // the list if present
            myResponsibleLocations.remove(otherResponsibleLocation);
          } else {
            LOG.debug("I {} already know that I'm responsible for {} after leaving of {}.",
                selfAddress, otherResponsibleLocations, peerAddress);
          }
        } else {
          if (backend.updateResponsibilities(otherResponsibleLocation,
              closest.peerId())) {
            LOG.debug("We should check if the closer peer has the content");
            notifyOtherResponsible(otherResponsibleLocation, closest);
            // we don't need to check this again, so remove it from
            // the list if present
            myResponsibleLocations.remove(otherResponsibleLocation);
View Full Code Here

      sender.peer().bootstrap().peerAddress(receiver.peerAddress()).start().awaitUninterruptibly();

      FutureChannelCreator futureChannelCreator = sender.peer().connectionBean().reservation().create(0, 1);

      final CountDownLatch latch = new CountDownLatch(1);
      final PeerAddress receiverAddress = receiver.peerAddress();

      futureChannelCreator.addListener(new BaseFutureAdapter<FutureChannelCreator>() {
        @Override
        public void operationComplete(final FutureChannelCreator future2) throws Exception {
          if (future2.isSuccess()) {
View Full Code Here

      sender.put(locationKey).data(new Data(value)).start().awaitUninterruptibly();

      sender.peer().bootstrap().peerAddress(receiver.peerAddress()).start().awaitUninterruptibly();
      final CountDownLatch latch = new CountDownLatch(1);
      final PeerAddress receiverAddress = receiver.peerAddress();
      FutureChannelCreator futureChannelCreator = sender.peer().connectionBean().reservation().create(0, 1);
      futureChannelCreator.addListener(new BaseFutureAdapter<FutureChannelCreator>() {
        @Override
        public void operationComplete(final FutureChannelCreator future2) throws Exception {
          if (future2.isSuccess()) {
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.