changeset 1207:2eb256e7e36c

Output the amount of transferred data when connection closed.
author Marcel Keller <mkeller@cs.au.dk>
date Wed, 09 Sep 2009 11:24:10 +0200
parents 104d89587c94
children 49c14731cf5e
files viff/runtime.py
diffstat 1 files changed, 11 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/viff/runtime.py	Tue Sep 08 15:55:02 2009 +0200
+++ b/viff/runtime.py	Wed Sep 09 11:24:10 2009 +0200
@@ -288,11 +288,16 @@
         #: Data expected to be received in the future.
         self.incoming_data = {}
         self.waiting_deferreds = {}
+        #: Statistics
+        self.sent_packets = 0
+        self.sent_bytes = 0
 
     def connectionMade(self):
         self.sendString(str(self.factory.runtime.id))
 
     def connectionLost(self, reason):
+        print "Transfer to peer %d: %d bytes in %d packets" % \
+              (self.peer_id, self.sent_bytes, self.sent_packets)
         reason.trap(ConnectionDone)
         self.lost_connection.callback(self)
 
@@ -362,7 +367,10 @@
         data_size = len(data)
         fmt = "!HHB%dI%ds" % (pc_size, data_size)
         t = (pc_size, data_size, data_type) + program_counter + (data,)
-        self.sendString(struct.pack(fmt, *t))
+        packet = struct.pack(fmt, *t)
+        self.sendString(packet)
+        self.sent_packets += 1
+        self.sent_bytes += len(packet)
 
     def sendShare(self, program_counter, share):
         """Send a share.
@@ -578,7 +586,7 @@
 
         def close_connections(_):
             print "done."
-            print "Closing connections...",
+            print "Closing connections..."
             results = [maybeDeferred(self.port.stopListening)]
             for protocol in self.protocols.itervalues():
                 results.append(protocol.lost_connection)
@@ -586,7 +594,7 @@
             return DeferredList(results)
 
         def stop_reactor(_):
-            print "done."
+            print "Connections closed."
             print "Stopping reactor...",
             reactor.stop()
             print "done."