コード例 #1
0
ファイル: bwdiff.py プロジェクト: fowlslegs/wfpadtools
 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)
コード例 #2
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)
コード例 #3
0
    def relayGapHistogram(self, histo, removeTokens=False, interpolate=True,
                          when="rcv", decay_by=0):
        """Specify histogram that encodes the delay distribution

        The delay distribution represents the probability of sending a
        single additional padding packet after a given delay following
        a padding packet that originated at this hop. In both cases, the
        padding packet is sent in the direction of the client.

        Parameters
        ----------
        histo : list
            Contains delay distribution of sending an IGNORE cell after
            sending an IGNORE cell.
        labels : list
            Millisecond labels for the bins (with "infinity" bin to allow
            encoding the probability of not sending any padding packet in
            response to this packet).
        removeTokens : bool
            If True, follow Adaptive Padding token removal rules.
            If False, histograms are immutable.
        interpolate : bool
            If True, randomize the delay uniformly between bin labels
            If False, use bin labels as exact delay values.
        when : str
            If "rcv", this histogram applies to locally-inserted padding
            packets that were initially sent in response to client-originated
            data.  If "snd", this histogram applies to packets sent in response
            to locally-inserted padding packets sent in response to upstream
            data. Note that this means that implementations must maintain this
            metadata as internal state as the system transitions from
            BURST_HISTOGRAM initiated padding into GAP_HISTOGRAM initiated
            padding.
        decay_by: int
            To add to the "Infinity" bin after each successive padding packet
            is sent. Used to create an increasing likelihood of hitting the
            termination condition with each successive padding packet.
        """
        histo = cast_dictionary_to_type(histo, float)
        self._gapHistoProbdist[when] = hist.new(histo,
                                                interpolate=bool(interpolate),
                                                removeTokens=bool(removeTokens),
                                                decay_by=decay_by)
        self._deferGapCallback[when] = self._gapHistoProbdist[when].removeToken
コード例 #4
0
    def relayBurstHistogram(self, histo, removeTokens=False, interpolate=True,
                            when="rcv", decay_by=0):
        """Specify histogram encoding the delay distribution.

        The delay distribution represents the probability of sending a single
        padding packet after a given delay in response to either an upstream
        cell, or a client-originating cell.

        Parameters
        ----------
        histo : list
            Contains delay distribution of sending an IGNORE cell after
            sending an IGNORE cell.
        labels : list
            Millisecond labels for the bins (with "infinity" bin to allow
            encoding the probability of not sending any padding packet in
            response to this packet).
        removeTokens : bool
            If True, follow Adaptive Padding token removal rules.
            If False, histograms are immutable.
        interpolate : bool
            If True, randomize the delay uniformly between bin labels
            If False, use bin labels as exact delay values.
        when : str
            If set to "rcv", this histogram governs the probability of
            sending a padding packet after some delay in response to a packet
            originating from the other PT end. If set to "snd", this histogram
            governs padding packets that are transmitted after a packet
            arrives from upstream. In both cases, the padding packet is
            sent in the direction of the client.
        """
        histo = cast_dictionary_to_type(histo, float)
        self._burstHistoProbdist[when] = hist.new(histo,
                                                  interpolate=bool(interpolate),
                                                  removeTokens=bool(removeTokens))
        self._deferBurstCallback[when] = self._burstHistoProbdist[when].removeToken
コード例 #5
0
 def test_refill_histo(self):
     h = histo.new({1: 1})
     h.removeToken(1)
     self.assertEqual(h.hist[1], 1)
コード例 #6
0
 def test_remove_tokens_with_only_positive_on_right_with_inf_label(self):
     h = histo.new(TEST_DICT_INF, removeTokens=True)
     h.removeToken(0.1)
     h.removeToken(0.1)
     self.assertEqual(h.hist[0.2], h.template[0.2] - 1)
コード例 #7
0
 def test_remove_tokens_with_gaps_with_inf_label(self):
     h = histo.new(TEST_DICT_INF, removeTokens=True)
     h.removeToken(0.5)
     h.removeToken(0.5)
     self.assertEqual(h.hist[0.4], h.template[0.4] -1)
コード例 #8
0
 def test_remove_tokens_with_interpolation_with_inf_label(self):
     h = histo.new(TEST_DICT_INF, removeTokens=True)
     h.removeToken(const.INF_LABEL)
     self.assertEqual(h.hist[const.INF_LABEL],
                      h.template[const.INF_LABEL] - 1)
コード例 #9
0
 def test_remove_tokens_with_interpolation(self):
     h = histo.new(TEST_DICTIONARY, removeTokens=True)
     x = h.randomSample()
     h.removeToken(x)
     label = h.getLabelFromFloat(x)
     self.assertEqual(h.hist[label], h.template[label] - 1)
コード例 #10
0
 def test_remove_tokens_without_interpolation(self):
     h = histo.new(TEST_DICTIONARY, interpolate=False, removeTokens=True)
     x = h.randomSample()
     h.removeToken(x)
     self.assertEqual(h.hist[x], h.template[x] - 1)
コード例 #11
0
 def test_mean_of_histogram(self):
     h = histo.new(TEST_DICTIONARY, interpolate=False)
     self.assert_mean(h, 0.3)