viff

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 diff
     1.1 --- a/viff/runtime.py	Tue Sep 08 15:55:02 2009 +0200
     1.2 +++ b/viff/runtime.py	Wed Sep 09 11:24:10 2009 +0200
     1.3 @@ -288,11 +288,16 @@
     1.4          #: Data expected to be received in the future.
     1.5          self.incoming_data = {}
     1.6          self.waiting_deferreds = {}
     1.7 +        #: Statistics
     1.8 +        self.sent_packets = 0
     1.9 +        self.sent_bytes = 0
    1.10  
    1.11      def connectionMade(self):
    1.12          self.sendString(str(self.factory.runtime.id))
    1.13  
    1.14      def connectionLost(self, reason):
    1.15 +        print "Transfer to peer %d: %d bytes in %d packets" % \
    1.16 +              (self.peer_id, self.sent_bytes, self.sent_packets)
    1.17          reason.trap(ConnectionDone)
    1.18          self.lost_connection.callback(self)
    1.19  
    1.20 @@ -362,7 +367,10 @@
    1.21          data_size = len(data)
    1.22          fmt = "!HHB%dI%ds" % (pc_size, data_size)
    1.23          t = (pc_size, data_size, data_type) + program_counter + (data,)
    1.24 -        self.sendString(struct.pack(fmt, *t))
    1.25 +        packet = struct.pack(fmt, *t)
    1.26 +        self.sendString(packet)
    1.27 +        self.sent_packets += 1
    1.28 +        self.sent_bytes += len(packet)
    1.29  
    1.30      def sendShare(self, program_counter, share):
    1.31          """Send a share.
    1.32 @@ -578,7 +586,7 @@
    1.33  
    1.34          def close_connections(_):
    1.35              print "done."
    1.36 -            print "Closing connections...",
    1.37 +            print "Closing connections..."
    1.38              results = [maybeDeferred(self.port.stopListening)]
    1.39              for protocol in self.protocols.itervalues():
    1.40                  results.append(protocol.lost_connection)
    1.41 @@ -586,7 +594,7 @@
    1.42              return DeferredList(results)
    1.43  
    1.44          def stop_reactor(_):
    1.45 -            print "done."
    1.46 +            print "Connections closed."
    1.47              print "Stopping reactor...",
    1.48              reactor.stop()
    1.49              print "done."