Package net.tomp2p.message

Examples of net.tomp2p.message.TrackerData


    tmp.add(self);
    return tmp.headSet(peerAddress).size() < replicationFactor;
  }

  private boolean add(Number320 key, PeerStatistic stat, Map<Number320, TrackerData> map, Data attachement) {
    TrackerData trackerData = map.get(key);
    if (trackerData == null) {
      trackerData = new TrackerData(new ConcurrentCacheMap<PeerStatistic, Data>(trackerTimoutSeconds,
              TRACKER_CACHE_SIZE, true));
      map.put(key, trackerData);
    }
    if (trackerData.size() < TRACKER_CACHE_SIZE) {
      trackerData.put(stat, attachement);
      return true;
    } else {
      return false;
    }
  }
View Full Code Here


      return false;
    }
  }

  private boolean remove(Number320 key, PeerStatistic stat, Map<Number320, TrackerData> map) {
    TrackerData trackerData = map.get(key);
    if (trackerData != null) {
      boolean retVal = trackerData.remove(stat.peerAddress().peerId()) != null;
      if(trackerData.peerAddresses().size() == 0) {
        map.remove(key);
      }
      return retVal;
    }
    return false;
View Full Code Here

  @Override
    public DigestInfo digest(Number160 locationKey, Number160 domainKey, Number160 contentKey) {
    Number160 contentDigest = Number160.ZERO;
    int counter = 0;
    TrackerData trackerData = dataMap.get(new Number320(locationKey, domainKey));
    if(trackerData!=null) {
      if(contentKey!=null) {
        Map.Entry<PeerStatistic, Data> entry = trackerData.get(contentKey);
        if(entry!=null) {
          return new DigestInfo(Number160.ZERO, contentKey, 1);
        }
      } else {
        for(PeerStatistic peerStatatistic: trackerData.peerAddresses().keySet()) {
          contentDigest = contentDigest.xor(peerStatatistic.peerAddress().peerId());
          counter++;
        }
      }
    }
View Full Code Here

    addTrackerDataListener(futureResponse, new Number320(builder.locationKey(), builder.domainKey()));
    RequestHandler<FutureResponse> requestHandler = new RequestHandler<FutureResponse>(futureResponse, peerBean(),
            connectionBean(), builder);

    TrackerData trackerData = new TrackerData(new HashMap<PeerStatistic, Data>());
    PeerAddress peerAddressToAnnounce = builder.peerAddressToAnnounce();
    if (peerAddressToAnnounce == null) {
      peerAddressToAnnounce = peerBean().serverPeerAddress();
    }
    trackerData.put(new PeerStatistic(peerAddressToAnnounce), builder.attachement());
    trackerData = UtilsTracker.limit(trackerData, TrackerRPC.MAX_MSG_SIZE_UDP);
    message.trackerData(trackerData);

    if (builder.isForceTCP()) {
      return requestHandler.sendTCP(channelCreator);
View Full Code Here

        if (future.isSuccess()) {
          // Since I might become a tracker as well, we keep this
          // information
          // about those trackers.
          Message message = future.responseMessage();
          TrackerData tmp = message.trackerData(0);
          // no data found
          if (tmp == null || tmp.size() == 0) {
            return;
          }

          for (Map.Entry<PeerStatistic, Data> trackerData : tmp.peerAddresses().entrySet()) {
            // we don't know the public key, since this is not first
            // hand information. TTL will be set in tracker storage,
            // so don't worry about it here.
            trackerStorage.put(key, trackerData.getKey().peerAddress(), null, trackerData.getValue());
          }
View Full Code Here

    Number160 domainKey = message.key(1);
    SimpleBloomFilter<Number160> knownPeers = message.bloomFilter(0);

    PublicKey publicKey = message.publicKey(0);
    //
    TrackerData meshPeers = trackerStorage.peers(new Number320(locationKey, domainKey));
   
    LOG.debug("found peers on tracker: {}", meshPeers == null ? "null " : meshPeers.peerAddresses());

    boolean couldProvideMoreData = false;
    if (meshPeers != null) {
      if (knownPeers != null) {
        meshPeers = UtilsTracker.disjunction(meshPeers, knownPeers);
      }
      int size = meshPeers.size();

      meshPeers = UtilsTracker.limit(meshPeers, TrackerRPC.MAX_MSG_SIZE_UDP);
      couldProvideMoreData = size > meshPeers.size();
      responseMessage.trackerData(meshPeers);
    }

    if (couldProvideMoreData) {
      responseMessage.type(Message.Type.PARTIALLY_OK);
    }

    if (message.command() == RPC.Commands.TRACKER_ADD.getNr()) {
      TrackerData trackerData = message.trackerData(0);
      if (trackerData.size() != 1) {
        responseMessage.type(Message.Type.EXCEPTION);
      } else {
        Map.Entry<PeerStatistic, Data> entry = trackerData.peerAddresses().entrySet().iterator().next();
        if (!trackerStorage.put(new Number320(locationKey, domainKey), entry.getKey().peerAddress(), publicKey,
                entry.getValue())) {
          responseMessage.type(Message.Type.DENIED);
          LOG.debug("tracker NOT put on({}) locationKey:{}, domainKey:{}, address:{}", peerBean()
                  .serverPeerAddress(), locationKey, domainKey, entry.getKey());
View Full Code Here

    Number320 n320 = new Number320(Number160.ZERO, Number160.ZERO);

    boolean retVal = trackerStorage.put(n320, selfAddress, null, new Data("test"));
    Assert.assertTrue(retVal);
    //
    TrackerData td = trackerStorage.peers(n320);
    Object o = td.peerAddresses().values().iterator().next().object();
    Assert.assertEquals(o, "test");
  }
View Full Code Here

    Number320 n320 = new Number320(Number160.ZERO, Number160.ZERO);

    boolean retVal = trackerStorage.put(n320, selfAddress, null, new Data("test"));
    Assert.assertTrue(retVal);
    //
    TrackerData td = trackerStorage.peers(n320);
    Assert.assertNull(td);
  }
View Full Code Here

    Number320 n320 = new Number320(Number160.ZERO, Number160.ZERO);

    trackerStorage.put(n320, selfAddress, null, new Data("test"));
    trackerStorage.peerFound(selfAddress, null, null);
   
    TrackerData td = trackerStorage.peers(n320);
    Object o = td.peerAddresses().values().iterator().next().object();
    Assert.assertEquals(o, "test");
  }
View Full Code Here

   
    trackerStorage.put(n320, selfAddress, pair1.getPublic(), new Data("test"));
    trackerStorage.peerFound(selfAddress, null, null);
    trackerStorage.put(n320, selfAddress, pair1.getPublic(), new Data("test1"));
   
    TrackerData td = trackerStorage.peers(n320);
    Object o = td.peerAddresses().values().iterator().next().object();
    Assert.assertEquals(o, "test1");
  }
View Full Code Here

TOP

Related Classes of net.tomp2p.message.TrackerData

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.