[tor-commits] [oonib/master] clearer logic by eliminating checking_first_packet and bringing assignments to the same variable closer together

art at torproject.org art at torproject.org
Wed Apr 23 14:31:51 UTC 2014


commit 6ce07ebd9c2261d4dc069c52baa02bad965564a6
Author: Darius Bacon <darius at wry.me>
Date:   Wed Apr 16 11:40:28 2014 -0700

    clearer logic by eliminating checking_first_packet and bringing assignments to the same variable closer together
---
 oonib/daphn3.py |   23 +++++++++--------------
 1 file changed, 9 insertions(+), 14 deletions(-)

diff --git a/oonib/daphn3.py b/oonib/daphn3.py
index 01f241e..9c5f290 100644
--- a/oonib/daphn3.py
+++ b/oonib/daphn3.py
@@ -17,13 +17,6 @@ def read_pcap(filename):
 
     packets = rdpcap(filename)
 
-    checking_first_packet = True
-    client_ip_addr = None
-    server_ip_addr = None
-
-    ssl_packets = []
-    messages = []
-
     """
     pcap assumptions:
 
@@ -42,21 +35,23 @@ def read_pcap(filename):
     Minimally validate the pcap and also find out what's the client
     and server IP addresses.
     """
-    for packet in packets:
-        if checking_first_packet:
+    ssl_packets = []
+    client_ip_addr = None
+    server_ip_addr = None
+    for i, packet in enumerate(packets):
+        if i == 0:
             client_ip_addr = packet[IP].src
-            checking_first_packet = False
-        else:
-            if packet[IP].src != client_ip_addr:
-                server_ip_addr = packet[IP].src
+        elif packet[IP].src != client_ip_addr:
+            server_ip_addr = packet[IP].src
 
         try:
-            if (packet[Raw]):
+            if packet[Raw]:
                 ssl_packets.append(packet)
         except IndexError:
             pass
 
     """Form our list."""
+    messages = []
     for packet in ssl_packets:
         if packet[IP].src == client_ip_addr:
             messages.append({"client": str(packet[Raw])})





More information about the tor-commits mailing list