Browse Source

Changes in documentation and method signatures

christof 6 năm trước cách đây
mục cha
commit
2b18061cc0
2 tập tin đã thay đổi với 18 bổ sung17 xóa
  1. 2 3
      code/Attack/MembersMgmtCommAttack.py
  2. 16 14
      code/ID2TLib/Generator.py

+ 2 - 3
code/Attack/MembersMgmtCommAttack.py

@@ -295,12 +295,11 @@ class MembersMgmtCommAttack(BaseAttack.BaseAttack):
             else:
                 return 0
 
-        def assign_realistic_ttls(bot_configs):
+        def assign_realistic_ttls(bot_configs:list):
             '''
             Assigns a realisitic ttl to each bot from @param: bot_configs. Uses statistics and distribution to be able
             to calculate a realisitc ttl.
-            :param bot_configs:
-            :return:
+            :param bot_configs: List that contains all bots that should be assigned with realistic ttls.
             '''
             ids = sorted(bot_configs.keys())
             for pos,bot in enumerate(ids):

+ 16 - 14
code/ID2TLib/Generator.py

@@ -17,18 +17,18 @@ from . import IPv4 as ip
 '''PaddingGenerator
 '''
 
-def add_padding(packet, bytes_padding = 0, user_padding=True, rnd = False):
+def add_padding(packet, bytes_padding:int = 0, user_padding:bool=True, rnd:bool = False):
     '''
-    Adds padding to a packet with the given amount of bytes, but a maximum of 100 bytes.
+    Adds padding to a packet with the given amount of bytes, but a maximum of 100 bytes, if called by the user.
     :param packet: the packet that will be extended with the additional payload
-    :param bytes_padding: the amount of bytes that will be appended to the packet
-    :param user_padding: true, if the function add_padding is called from another class and the user
-    sets the padding manually
-    :param rnd: adds a random padding betwing 0 and bytes_adding, if true
+    :param bytes_padding: the amount of bytes that will be appended to the packet. Capped to 100,
+    if called by the user.
+    :param user_padding: true, if the function add_padding by the user and not within the code
+    :param rnd: adds a random padding between 0 and bytes_padding, if true
     :return: the initial packet, extended with the wanted amount of bytes of padding
     '''
 
-    if(user_padding and bytes_padding > 100):
+    if(user_padding == True and bytes_padding > 100):
         bytes_padding = 100
 
     if (rnd is True):
@@ -38,13 +38,15 @@ def add_padding(packet, bytes_padding = 0, user_padding=True, rnd = False):
     packet[Raw].load += Raw(load=payload).load
     return packet
 
-def equal_length(list_of_packets, length = 0, padding = 0):
+def equal_length(list_of_packets:list, length:int = 0, padding:int = 0):
     '''
-    Equals the length of a given set of packets on the given length. If the given length is smaller than the largest
-    packet, all the other packets are extended to the largest packet's length.
+    Equals the length of a given list of packets on the given length. If the given length is smaller than the largest
+    packet, all the other packets are extended to the largest packet's length. Add additional padding
+    afterwards to create realism.
     :param list_of_packets: The given set of packet.
-    :param length: The length each packet should have.
-    :return: The set of extended packets.
+    :param length: The length each packet should have. Can be redundant, if the largest packet has more bytes
+    than length.
+    :return: The list of extended packets.
     '''
 
     largest_packet = length
@@ -56,8 +58,8 @@ def equal_length(list_of_packets, length = 0, padding = 0):
     for packet in list_of_packets:
         bytes_padding = largest_packet - len(packet)
         if(bytes_padding > 0):
-            add_padding(packet, bytes_padding, False, False)
-            add_padding(packet, padding, False, True)
+            add_padding(packet, bytes_padding, False, False) #Add padding to extend to param:length
+            add_padding(packet, padding, False, True) #Add random additional padding to create realism
 
     return list_of_packets