Exemplo n.º 1
0
        @Override
        public void handle(CroupierShuffleNet.Response response) {
          OverlayHeaderImpl<NatedAddress> header = (OverlayHeaderImpl) response.getHeader();
          if (header.getOverlayId() != overlayId) {
            log.error(
                "{} message with header:{} not belonging to croupier overlay:{}",
                new Object[] {logPrefix, header, overlayId});
            throw new RuntimeException("message not belonging to croupier overlay");
          }
          NatedAddress respSrc = response.getHeader().getSource();
          if (self.getBaseAdr().equals(respSrc.getBaseAdr())) {
            log.error("{} Tried to shuffle with myself", logPrefix);
            throw new RuntimeException("tried to shuffle with myself");
          }
          log.trace("{} received:{} from:{}", new Object[] {logPrefix, response, respSrc});

          if (shuffleTimeoutId == null) {
            log.debug(
                "{} req:{}  already timed out",
                new Object[] {logPrefix, response.getContent().getId(), respSrc});
            return;
          }

          publicView.selectToKeep(respSrc, response.getContent().publicNodes);
          privateView.selectToKeep(respSrc, response.getContent().privateNodes);
          cancelShuffleTimeout();
        }
Exemplo n.º 2
0
        @Override
        public void handle(CroupierShuffleNet.Request request) {
          OverlayHeaderImpl<NatedAddress> header = (OverlayHeaderImpl) request.getHeader();
          if (header.getOverlayId() != overlayId) {
            log.error(
                "{} message with header:{} not belonging to croupier overlay:{}",
                new Object[] {logPrefix, header, overlayId});
            throw new RuntimeException("message not belonging to croupier overlay");
          }
          NatedAddress reqSrc = request.getHeader().getSource();
          if (self.getBaseAdr().equals(reqSrc.getBaseAdr())) {
            log.error("{} Tried to shuffle with myself", logPrefix);
            throw new RuntimeException("tried to shuffle with myself");
          }
          log.trace("{} received:{} from:{}", new Object[] {logPrefix, request, reqSrc});
          if (selfView == null) {
            log.warn(
                "{} not ready to shuffle - no self view available - {} tried to shuffle with me",
                logPrefix,
                reqSrc);
            return;
          }

          log.debug(
              "{} received from:{} \n public nodes:{} \n private nodes:{}",
              new Object[] {
                logPrefix,
                request.getHeader().getSource(),
                request.getContent().publicNodes,
                request.getContent().privateNodes
              });

          publicView.incrementDescriptorAges();
          privateView.incrementDescriptorAges();

          Set<CroupierContainer> publicDescCopy =
              publicView.receiverCopySet(croupierConfig.shuffleSize, reqSrc);
          Set<CroupierContainer> privateDescCopy =
              privateView.receiverCopySet(croupierConfig.shuffleSize, reqSrc);
          if (self.isOpen()) {
            publicDescCopy.add(new CroupierContainer(self, selfView));
          } else {
            privateDescCopy.add(new CroupierContainer(self, selfView));
          }

          OverlayHeaderImpl<NatedAddress> responseHeader =
              new OverlayHeaderImpl(new BasicHeader(self, reqSrc, Transport.UDP), overlayId);
          CroupierShuffle.Response responseContent =
              new CroupierShuffle.Response(
                  request.getContent().getId(), publicDescCopy, privateDescCopy);
          CroupierShuffleNet.Response response =
              new CroupierShuffleNet.Response(responseHeader, responseContent);

          log.trace("{} sending:{} to:{}", new Object[] {logPrefix, responseContent, reqSrc});
          trigger(response, network);

          publicView.selectToKeep(reqSrc, request.getContent().publicNodes);
          privateView.selectToKeep(reqSrc, request.getContent().privateNodes);
          if (!connected() && haveShufflePartners()) {
            startShuffle();
          }
        }