Exemple #1
0
 def getBwDifferential(self):
     self.iat_length_tuples = [l for l in self.iat_length_tuples if len(l) > 0]
     if time.time() - self.session.startTime > 0.2 and len(self.iat_length_tuples) > 1:
         lengths0 = [t[1] for t in self.iat_length_tuples[-2]]
         lengths1 = [t[1] for t in self.iat_length_tuples[-1]]
         bw0 = sum(lengths0) / self._period
         bw1 = sum(lengths1) / self._period
         bw_diff = (bw1 - bw0) / self._period
         self.session.bw_diffs.append(bw_diff)
         log.debug("[bwdiff %s] - bw diffs: %s", self.end, self.session.bw_diffs)
         log.debug("[bwdiff %s] -  abs bwdiff (%s) > threshold (%s)",
                   self.end, abs(bw_diff), self._threshold)
         if abs(bw_diff) > self._threshold:
             # we should sample uniformly from the passed iats
             # convert self.iat_length_tuples to distribution
             # and pass it to wfpad iat distribution as dict.
             iats = gu.get_iats([t[0] for t in gu.flatten_list(self.iat_length_tuples)])
             h = {iat: 1 for iat in iats}
             self._burstHistoProbdist['snd'] = hs.new(h)
             self._gapHistoProbdist['snd'] = hs.new(h)
         else:
             self._burstHistoProbdist['snd'] = hs.uniform(const.INF_LABEL)
             self._gapHistoProbdist['snd'] = hs.uniform(const.INF_LABEL)
     self.iat_length_tuples.append([])
     log.debug("[bwdiff %s] A period has passed: %s", self.end, self.iat_length_tuples[-3:-1])
     if self.isVisiting():
         log.debug("[bwdiff %s] Calling next period (visiting = %s, padding = %s)",
                   self.end, self.isVisiting(), self.session.is_padding)
         cm.deferLater(self._period, self.getBwDifferential)
    def whenBurstEnds(self):
        """BurstEnd packets are sent by the cooperating node during tail-padding
        When such a packet is received, the receiving node should switch to Talkie mode and begin
        sending the next padding burst"""
        self._pad_count = 0
        self._active = True
        log.info('[walkietalkie - %s] ready to send next burst.', self.end)

        pad_target = self.getBurstTarget()
        if pad_target <= 0 and self.session.is_padding:
            log.debug("[walkietalkie - %s] no more bursts left in decoy!",
                      self.end)
            self.onEndPadding()

        if self.weAreClient:
            delay = CLIENT_DELAY_TIME * 10
        else:
            delay = RELAY_DELAY_TIME * 10
        #if not self._deferData or (self._deferData and self._deferData.called):
        if self._deferData and self._deferData.called:
            self._deferData.cancel()
        self._deferData = deferLater(delay,
                                     self.flushBuffer,
                                     id=self.flushbuf_id + 1)
        self.flushbuf_id += 1
    def pushData(self, data):
        """Overwrite WFPadTransport pushData to schedule flushBuffer based on custom timings.
        """
        log.debug("[walkietalkie - %s] Pushing %d bytes of outgoing data.",
                  self.end, len(data))
        if len(data) <= 0:
            log.debug(
                "[walkietalkie - %s] pushData() was called without a reason!",
                self.end)
            return

        # Cancel existing deferred calls to padding methods to prevent
        # callbacks that remove tokens from histograms
        #deferBurstCancelled, deferGapCancelled = self.cancelDeferrers('snd')

        # Draw delay for data message
        #delay = self._burstTimeoutHisto.randomSample()
        if self.weAreClient:
            delay = CLIENT_DELAY_TIME
        else:
            delay = RELAY_DELAY_TIME

        # Update delay according to elapsed time since last message
        # was sent. In case elapsed time is greater than current
        # delay, we sent the data message as soon as possible.
        #if deferBurstCancelled or deferGapCancelled:
        #    elapsed = self.elapsedSinceLastMsg()
        #    newDelay = delay - elapsed
        #    delay = 0 if newDelay < 0 else newDelay
        #    log.debug("[wfpad - %s] New delay is %s", self.end, delay)
        #
        #    if deferBurstCancelled and hasattr(self._burstHistoProbdist['snd'], "histo"):
        #        self._burstHistoProbdist['snd'].removeToken(elapsed, False)
        #    if deferGapCancelled and hasattr(self._gapHistoProbdist['snd'], "histo"):
        #        self._gapHistoProbdist['snd'].removeToken(elapsed, False)

        # Push data message to data buffer
        self._buffer.write(data)
        log.debug(
            "[walkietalkie - %s] Buffered %d bytes of outgoing data w/ delay %sms",
            self.end, len(self._buffer), delay)

        # if there is a scheduled flush buffer, cancel and re-schedule
        if self._deferData and self._deferData.called:
            self._deferData.cancel()
        self._deferData = deferLater(delay,
                                     self.flushBuffer,
                                     id=self.flushbuf_id + 1)
        self.flushbuf_id += 1
        log.debug("[walkietalkie - %s] Delay buffer flush %s ms delay",
                  self.end, delay)
    def relaySendPadding(self, N, t):
        """Send the requested number of padding cells in response.

        Parameters
        ----------
        N : int
            Number of padding cells to send in response to this cell.
        t : int
            Number of milliseconds delay before sending.
        """
        millisec = t
        deferreds = []
        for _ in xrange(N):
            deferreds.append(deferLater(millisec, self.sendIgnore))
        return defer.DeferredList(deferreds, consumeErrors=True)
Exemple #5
0
 def getBwDifferential(self):
     self.iat_length_tuples = [
         l for l in self.iat_length_tuples if len(l) > 0
     ]
     if time.time() - self.session.startTime > 0.2 and len(
             self.iat_length_tuples) > 1:
         lengths0 = [t[1] for t in self.iat_length_tuples[-2]]
         lengths1 = [t[1] for t in self.iat_length_tuples[-1]]
         bw0 = sum(lengths0) / self._period
         bw1 = sum(lengths1) / self._period
         bw_diff = (bw1 - bw0) / self._period
         self.session.bw_diffs.append(bw_diff)
         log.debug("[bwdiff %s] - bw diffs: %s", self.end,
                   self.session.bw_diffs)
         log.debug("[bwdiff %s] -  abs bwdiff (%s) > threshold (%s)",
                   self.end, abs(bw_diff), self._threshold)
         if abs(bw_diff) > self._threshold:
             # we should sample uniformly from the passed iats
             # convert self.iat_length_tuples to distribution
             # and pass it to wfpad iat distribution as dict.
             iats = gu.get_iats(
                 [t[0] for t in gu.flatten_list(self.iat_length_tuples)])
             h = {iat: 1 for iat in iats}
             self._burstHistoProbdist['snd'] = hs.new(h)
             self._gapHistoProbdist['snd'] = hs.new(h)
         else:
             self._burstHistoProbdist['snd'] = hs.uniform(const.INF_LABEL)
             self._gapHistoProbdist['snd'] = hs.uniform(const.INF_LABEL)
     self.iat_length_tuples.append([])
     log.debug("[bwdiff %s] A period has passed: %s", self.end,
               self.iat_length_tuples[-3:-1])
     if self.isVisiting():
         log.debug(
             "[bwdiff %s] Calling next period (visiting = %s, padding = %s)",
             self.end, self.isVisiting(), self.session.is_padding)
         cm.deferLater(self._period, self.getBwDifferential)