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 test_control_and_data_have_same_length(self): testData = "a message padded to MPU" dataMsgs = self.msgFactory.encapsulate(data=testData, lenProbdist=histo.uniform(const.MPU)) ctrlMsgs = self.msgFactory.encapsulate( data=testData, opcode=const.OP_APP_HINT, lenProbdist=histo.uniform(const.MPU) ) dataMsg, ctrlMsg = dataMsgs[0], ctrlMsgs[0] self.assertTrue( len(dataMsg) == len(ctrlMsg) == const.MTU, msg="The length of the data message is %s," " the length of the control msg is %s and" " the expected length is: %s)" % (len(dataMsg), len(ctrlMsg), const.MTU), )
def onSessionStarts(self, sessId): self._delayDataProbdist = histo.uniform(0) if self._histograms: self.relayBurstHistogram( **dict(self._histograms["burst"]["snd"], **{"when": "snd"})) self.relayBurstHistogram( **dict(self._histograms["burst"]["rcv"], **{"when": "rcv"})) self.relayGapHistogram( **dict(self._histograms["gap"]["snd"], **{"when": "snd"})) self.relayGapHistogram( **dict(self._histograms["gap"]["rcv"], **{"when": "rcv"})) else: if self.weAreClient: # parameters have been estimated from real web traffic hist_dict_incoming = self.getHistoFromDistrParams("weibull", 0.406831232, scale=0.002465967) hist_dict_outgoing = self.getHistoFromDistrParams("beta", (0.1620305, 35.3933556)) low_bins_inc, high_bins_inc = self.divideHistogram(hist_dict_incoming) low_bins_out, high_bins_out = self.divideHistogram(hist_dict_outgoing) self.relayBurstHistogram(low_bins_inc, "rcv") self.relayBurstHistogram(low_bins_inc, "snd") self.relayGapHistogram(high_bins_inc, "rcv") self.relayGapHistogram(high_bins_inc, "snd") self.sendControlMessage(const.OP_BURST_HISTO, [low_bins_out, True, True, "rcv"]) self.sendControlMessage(const.OP_BURST_HISTO, [low_bins_out, True, True, "snd"]) self.sendControlMessage(const.OP_GAP_HISTO, [high_bins_out, True, True, "rcv"]) self.sendControlMessage(const.OP_GAP_HISTO, [high_bins_out, True, True, "snd"]) WFPadTransport.onSessionStarts(self, sessId)
def test_control_and_data_have_same_length(self): testData = "a message padded to MPU" dataMsgs = self.msgFactory.encapsulate(data=testData, lenProbdist=histo.uniform( const.MPU)) ctrlMsgs = self.msgFactory.encapsulate(data=testData, opcode=const.OP_APP_HINT, lenProbdist=histo.uniform( const.MPU)) dataMsg, ctrlMsg = dataMsgs[0], ctrlMsgs[0] self.assertTrue(len(dataMsg) == len(ctrlMsg) == const.MTU, msg="The length of the data message is %s," " the length of the control msg is %s and" " the expected length is: %s)" % (len(dataMsg), len(ctrlMsg), const.MTU))
def onSessionStarts(self, sessId): self._lengthDataProbdist = hs.uniform(self._length) self._delayDataProbdist = hs.uniform(0) WFPadTransport.onSessionStarts(self, sessId) # if self._padding_mode == const.TOTAL_PADDING: # self.relayTotalPad(sessId, self._period, False) # elif self._padding_mode == const.PAYLOAD_PADDING: # self.relayPayloadPad(sessId, self._period, False) # else: # raise RuntimeError("Value passed for padding mode is not valid: %s" % self._padding_mode) if self._early_termination and self.weAreServer: stopCond = self.stopCondition def earlyTermination(self): return not self.session.is_peer_padding or stopCond() self.stopCondition = earlyTermination self.iat_length_tuples = [[]] self.getBwDifferential()
def __init__(self): super(TamarawTransport, self).__init__() # Defaults for BuFLO specifications. self._period = 10 self._length = const.MPU self._batch = 20 # Set constant length for messages self._lengthDataProbdist = histo.uniform(self._length)
def __init__(self): super(WalkieTalkieTransport, self).__init__() self._decoy_directory = const.WT_DECOY_DIR if "DECOY_DIR" not in os.environ else os.environ[ "DECOY_DIR"] self._decoy_sequence = [] #[10 for _ in range(20)] # Set constant length for messages self._length = const.MPU self._lengthDataProbdist = histo.uniform(self._length) self._burstTimeoutHisto = histo.uniform(0.5) self._time_of_last_pkt = 0 # Start listening for URL signals self._port = const.WT_PORT self._initializeWTListener() self._initializeWTState()
def __init__(self): super(AdaptiveTransport, self).__init__() # Set constant length for messages self._lengthDataProbdist = histo.uniform(self._length) # The stop condition in Adaptive: # Adaptive stops padding if the visit has finished and the # elapsed time has exceeded the minimum padding time. def stopConditionHandler(s): elapsed = s.getElapsed() log.debug("[adaptive {}] - elapsed = {}, mintime = {}, visiting = {}" .format(self.end, elapsed, ADAPTIVE_MAX_VISIT_TIME, s.isVisiting())) return elapsed >= ADAPTIVE_MAX_VISIT_TIME and not s.isVisiting() self.stopCondition = stopConditionHandler
def __init__(self): super(BuFLOTransport, self).__init__() # Set constant length for messages self._lengthDataProbdist = histo.uniform(self._length) # The stop condition in BuFLO: # BuFLO stops padding if the visit has finished and the # elapsed time has exceeded the minimum padding time. def stopConditionHandler(s): elapsed = s.getElapsed() log.debug("[buflo {}] - elapsed = {}, mintime = {}, visiting = {}" .format(self.end, elapsed, s._mintime, s.isVisiting())) return elapsed > s._mintime and not s.isVisiting() self.stopCondition = stopConditionHandler
def test_uniform_length(self): # Test payload is padded to specified length testData = "a message padded to MPU" dataMsgs = self.msgFactory.encapsulate(data=testData, lenProbdist=histo.uniform(const.MPU)) self.assertEqual(len(dataMsgs), 1, "More than one message for control without args " "was created.") dataMsg = dataMsgs[0] obsLength = len(dataMsg) expLength = const.MTU self.assertEqual( obsLength, expLength, "Observed length (%s) and " "expected length (%s) do not match" % (obsLength, expLength), )
def test_uniform_length(self): # Test payload is padded to specified length testData = "a message padded to MPU" dataMsgs = self.msgFactory.encapsulate(data=testData, lenProbdist=histo.uniform( const.MPU)) self.assertEqual( len(dataMsgs), 1, "More than one message for control without args " "was created.") dataMsg = dataMsgs[0] obsLength = len(dataMsg) expLength = const.MTU self.assertEqual( obsLength, expLength, "Observed length (%s) and " "expected length (%s) do not match" % (obsLength, expLength))
def __init__(self): super(CSBuFLOTransport, self).__init__() # Defaults for BuFLO specifications. self._initial_rho = const.INIT_RHO self._period = const.INIT_RHO self._length = const.MPU self._padding_mode = const.TOTAL_PADDING self._early_termination = False self._rho_stats = [[]] self._rho_star = self._initial_rho # Set constant length for messages self._lengthDataProbdist = histo.uniform(self._length)
def __init__(self): super(BuFLOTransport, self).__init__() # Set constant length for messages self._lengthDataProbdist = histo.uniform(self._length) # The stop condition in BuFLO: # BuFLO stops padding if the visit has finished and the # elapsed time has exceeded the minimum padding time. def stopConditionHandler(s): elapsed = s.getElapsed() log.debug("[buflo {}] - elapsed = {}, mintime = {}, visiting = {}". format(self.end, elapsed, s._mintime, s.isVisiting())) return elapsed > s._mintime and not s.isVisiting() self.stopCondition = stopConditionHandler
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 __init__(self): super(AdaptiveTransport, self).__init__() # Set constant length for messages self._lengthDataProbdist = histo.uniform(self._length) # The stop condition in Adaptive: # Adaptive stops padding if the visit has finished and the # elapsed time has exceeded the minimum padding time. def stopConditionHandler(s): elapsed = s.getElapsed() log.debug( "[adaptive {}] - elapsed = {}, mintime = {}, visiting = {}". format(self.end, elapsed, ADAPTIVE_MAX_VISIT_TIME, s.isVisiting())) return elapsed >= ADAPTIVE_MAX_VISIT_TIME and not s.isVisiting() self.stopCondition = stopConditionHandler
def assert_uniform(self, x): NUM_SAMPLES = 100 u = histo.uniform(x) for _ in xrange(NUM_SAMPLES): s = u.randomSample() self.assertEquals(s, x)
def __init__(self): super(CSBuFLOTransport, self).__init__() self._rho_stats = [[]] self._rho_star = self._initial_rho # Set constant length for messages self._lengthDataProbdist = histo.uniform(self._length)
def __init__(self): super(TamarawTransport, self).__init__() # Set constant length for messages self._lengthDataProbdist = histo.uniform(self._length)