Browse Source

Comments and Signatures for realistic Timestamps updated

Updated Signature of addDelay(...) and modified comments in the realistic Timestamps section
Marcel Juschak 7 years ago
parent
commit
6e7cc754a3
1 changed files with 17 additions and 14 deletions
  1. 17 14
      code/Attack/MembersMgmtCommAttack.py

+ 17 - 14
code/Attack/MembersMgmtCommAttack.py

@@ -305,11 +305,11 @@ class MembersMgmtCommAttack(BaseAttack.BaseAttack):
                          bot_configs[bot]["TTL"] = self.statistics.process_db_query("most_used(ttlValue)")
 
 
-        def add_delay(timestamp, minDelay, delay):
+        def add_delay(timestamp: float, minDelay: float, delay: float):
             '''
             Adds delay to a timestamp, with a minimum value of minDelay. But usually a value close to delay
             :param timestamp: the timestamp that is to be increased
-            :param minDelay: the minimum value that is to add to the timestamp
+            :param minDelay: the minimum value that is to be added to the timestamp
             :param delay: The general size of the delay. Statistically speaking: the expected value
             :return: the updated timestamp
             '''
@@ -319,6 +319,8 @@ class MembersMgmtCommAttack(BaseAttack.BaseAttack):
             if 0.1*delay < minDelay:
                 print("Warning: minDelay probably too big when computing time_stamps")
 
+            # updated timestamps consist of the sum of the minimum delay, the magnitude of the delay
+            # and a deviation by up to 10% in order to guarantee uniqueness
             general_offset = randomdelay.random()
             unique_offset = uniform(-0.1*general_offset, 0.1*general_offset)
             return timestamp + minDelay + general_offset + unique_offset
@@ -396,24 +398,24 @@ class MembersMgmtCommAttack(BaseAttack.BaseAttack):
         #### Set realistic timestamps for messages ####
 
         most_used_ip_address = self.statistics.get_most_used_ip_address()
-        minDelay, maxDelay = self.get_reply_delay(most_used_ip_address)
+        minDelay = self.get_reply_delay(most_used_ip_address)[0]
         next_timestamp = self.get_param_value(Param.INJECT_AT_TIMESTAMP)
         pcap_duration = float(self._get_capture_duration())
         equi_timeslice = pcap_duration/len(messages)
 
-        # Dict, takes a tuple of 2 Bots as a key (IP with lower number first), returns the time when the Hello_reply came in
-        Hello_times = {}
+        # Dict, takes a tuple of 2 Bot_IDs as a key (ID with lower number first), returns the time when the Hello_reply came in
+        hello_times = {}
         # msg_IDs with already updated timestamps
         updated_msgs = []
 
         for req_msg in messages:
             updated = 0
             if(req_msg.msg_id in updated_msgs):
-                #message already updated
+                # message already updated
                 continue
 
             if(req_msg.msg_id == -1):
-                #message has no corresponding request/response
+                # message has no corresponding request/response
                 req_msg.time = next_timestamp
                 next_timestamp = add_delay(next_timestamp, minDelay, equi_timeslice)
                 updated_msgs.append(req_msg.msg_id)
@@ -421,14 +423,14 @@ class MembersMgmtCommAttack(BaseAttack.BaseAttack):
 
 
             elif req_msg.type != MessageType.SALITY_HELLO:
-                #Hello msg must have preceded, so make sure the timestamp of this msg is after the HELLO_REPLY
+                # Hello messages must have preceded, so make sure the timestamp of this msg is after the HELLO_REPLY
                 if int(req_msg.src) < int(req_msg.dst):
-                    hello_time = Hello_times[(req_msg.src, req_msg.dst)]
+                    hello_time = hello_times[(req_msg.src, req_msg.dst)]
                 else:
-                    hello_time = Hello_times[(req_msg.dst, req_msg.src)] 
+                    hello_time = hello_times[(req_msg.dst, req_msg.src)] 
                 
                 if next_timestamp < hello_time:
-                    #use the time of the hello_reply instead of next_timestamp to update this pair of messages
+                    # use the time of the hello_reply instead of next_timestamp to update this pair of messages
                     post_hello = add_delay(hello_time, minDelay, equi_timeslice)
                     respns_msg = messages[req_msg.refer_msg_id]
                     respns_msg.time = add_delay(post_hello, minDelay, equi_timeslice)
@@ -436,7 +438,7 @@ class MembersMgmtCommAttack(BaseAttack.BaseAttack):
                     updated = 1
 
             if not updated:
-                #update normally
+                # update normally
                 respns_msg = messages[req_msg.refer_msg_id]
                 respns_msg.time = add_delay(next_timestamp, minDelay, equi_timeslice)
                 req_msg.time = next_timestamp
@@ -446,10 +448,11 @@ class MembersMgmtCommAttack(BaseAttack.BaseAttack):
             updated_msgs.append(req_msg.refer_msg_id)
 
             if req_msg.type == MessageType.SALITY_HELLO:
+                # if hello messages have been exchanged, save timestamp of the HELLO_REPLY
                 if int(req_msg.src) < int(req_msg.dst):
-                    Hello_times[(req_msg.src, req_msg.dst)] = respns_msg.time
+                    hello_times[(req_msg.src, req_msg.dst)] = respns_msg.time
                 else:
-                    Hello_times[(req_msg.dst, req_msg.src)] = respns_msg.time
+                    hello_times[(req_msg.dst, req_msg.src)] = respns_msg.time
                     
         # create port configurations for the bots
         for bot in bot_configs: