[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [ooni-probe/master] Implement sr1 in txscapy



commit 39262870b9d8741f39ad10b07158020578a0cac7
Author: Arturo Filastò <art@xxxxxxxxx>
Date:   Sat Nov 24 14:26:22 2012 +0100

    Implement sr1 in txscapy
---
 ooni/utils/txscapy.py |   17 ++++++++++++++++-
 1 files changed, 16 insertions(+), 1 deletions(-)

diff --git a/ooni/utils/txscapy.py b/ooni/utils/txscapy.py
index 2b108ca..d87a7a0 100644
--- a/ooni/utils/txscapy.py
+++ b/ooni/utils/txscapy.py
@@ -61,6 +61,10 @@ class ScapyProtocol(abstract.FileDescriptor):
         # twisted.internet.udp to see how this is done.
         self.receive = receive
 
+        # When 0 we stop when all the packets we have sent have received an
+        # answer
+        self.expected_answers = 0
+
     def fileno(self):
         return self.super_socket.ins.fileno()
 
@@ -71,15 +75,25 @@ class ScapyProtocol(abstract.FileDescriptor):
 
     def processAnswer(self, packet, answer_hr):
         log.debug("Got a packet from %s" % packet.src)
+        log.debug("%s" % self.__hash__)
         for i in range(len(answer_hr)):
             if packet.answers(answer_hr[i]):
                 self.answered_packets.append((answer_hr[i], packet))
                 if not self.multi:
                     del(answer_hr[i])
                 break
+
         if len(self.answered_packets) == len(self.sent_packets):
-            # All of our questions have been answered.
+            log.debug("All of our questions have been answered.")
+            log.debug("%s" % self.__hash__)
             self.stopSending()
+            return
+
+        if self.expected_answers and \
+                self.expected_answers == len(self.answered_packets):
+            log.debug("Got the number of expected answers")
+            self.stopSending()
+
 
     def doRead(self):
         timeout = time.time() - self._start_time
@@ -96,6 +110,7 @@ class ScapyProtocol(abstract.FileDescriptor):
                 self.processAnswer(packet, answer_hr)
 
     def stopSending(self):
+        log.debug("Stopping sending")
         self.stopReading()
         self.super_socket.close()
         if hasattr(self, "d"):



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits