Ejemplo n.º 1
0
 private NatedAddress selectPeerToShuffleWith(double temperature) {
   if (!bootstrapNodes.isEmpty()) {
     return bootstrapNodes.remove(0);
   }
   NatedAddress node = null;
   if (!publicView.isEmpty()) {
     node = publicView.selectPeerToShuffleWith(croupierConfig.policy, true, temperature);
   } else if (!privateView.isEmpty()) {
     node = privateView.selectPeerToShuffleWith(croupierConfig.policy, true, temperature);
   }
   return node;
 }
Ejemplo n.º 2
0
        @Override
        public void handle(ShuffleCycle event) {
          log.trace("{} {}", logPrefix, event);
          log.debug(
              "{} public view size:{}, private view size:{}, bootstrap nodes size:{}",
              new Object[] {
                logPrefix, publicView.size(), privateView.size(), bootstrapNodes.size()
              });

          if (!haveShufflePartners()) {
            log.warn("{} no shuffle partners - disconnected", logPrefix);
            stopShuffle();
            return;
          }

          if (!publicView.isEmpty() || !privateView.isEmpty()) {
            CroupierSample cs =
                new CroupierSample(overlayId, publicView.getAllCopy(), privateView.getAllCopy());
            log.info(
                "{} publishing sample \n public nodes:{} \n private nodes:{}",
                new Object[] {logPrefix, cs.publicSample, cs.privateSample});
            trigger(cs, croupierPort);
          }

          NatedAddress peer = selectPeerToShuffleWith(croupierConfig.softMaxTemperature);
          if (peer == null || peer.getBaseAdr().equals(self.getBaseAdr())) {
            log.error("{} this should not happen - logic error selecting peer", logPrefix);
            // throw new RuntimeException("Error selecting peer");
            return;
          }

          if (!peer.isOpen()) {
            log.debug(
                "{} did not pick a public node for shuffling - public view size:{}",
                new Object[] {logPrefix, publicView.getAllCopy().size()});
          }

          // NOTE:
          publicView.incrementDescriptorAges();
          privateView.incrementDescriptorAges();

          Set<CroupierContainer> publicDescCopy =
              publicView.initiatorCopySet(croupierConfig.shuffleSize, peer);
          Set<CroupierContainer> privateDescCopy =
              privateView.initiatorCopySet(croupierConfig.shuffleSize, peer);

          if (self.isOpen()) {
            publicDescCopy.add(new CroupierContainer(self, selfView));
          } else {
            privateDescCopy.add(new CroupierContainer(self, selfView));
          }

          OverlayHeaderImpl<NatedAddress> requestHeader =
              new OverlayHeaderImpl(new BasicHeader(self, peer, Transport.UDP), overlayId);
          CroupierShuffle.Request requestContent =
              new CroupierShuffle.Request(UUID.randomUUID(), publicDescCopy, privateDescCopy);
          CroupierShuffleNet.Request request =
              new CroupierShuffleNet.Request(requestHeader, requestContent);
          log.trace("{} sending:{} to:{}", new Object[] {logPrefix, requestContent, peer});
          trigger(request, network);
          scheduleShuffleTimeout(peer);
        }
Ejemplo n.º 3
0
 private boolean haveShufflePartners() {
   return !bootstrapNodes.isEmpty() || !publicView.isEmpty() || !privateView.isEmpty();
 }