viff

changeset 1169:05bcb213270c

Make players ignore bad data.
author Martin Geisler <mg@cs.au.dk>
date Tue, 21 Apr 2009 15:19:57 +0200
parents 421a199020e9
children 98eb6e0cfa88
files viff/runtime.py
diffstat 1 files changed, 17 insertions(+), 15 deletions(-) [+]
line diff
     1.1 --- a/viff/runtime.py	Wed Apr 15 11:30:07 2009 +0200
     1.2 +++ b/viff/runtime.py	Tue Apr 21 15:19:57 2009 +0200
     1.3 @@ -302,24 +302,26 @@
     1.4                      self.transport.loseConnection()
     1.5              self.factory.identify_peer(self)
     1.6          else:
     1.7 -            # TODO: We cannot handle the empty string.
     1.8 -            pc_size, data_size, data_type = struct.unpack("!HHB", string[:5])
     1.9 -            fmt = "!%dI%ds" % (pc_size, data_size)
    1.10 -            unpacked = struct.unpack(fmt, string[5:])
    1.11 +            try:
    1.12 +                pc_size, data_size, data_type = struct.unpack("!HHB", string[:5])
    1.13 +                fmt = "!%dI%ds" % (pc_size, data_size)
    1.14 +                unpacked = struct.unpack(fmt, string[5:])
    1.15  
    1.16 -            program_counter = unpacked[:pc_size]
    1.17 -            data = unpacked[-1]
    1.18 +                program_counter = unpacked[:pc_size]
    1.19 +                data = unpacked[-1]
    1.20  
    1.21 -            key = (program_counter, data_type)
    1.22 +                key = (program_counter, data_type)
    1.23  
    1.24 -            deq = self.incoming_data.setdefault(key, deque())
    1.25 -            if deq and isinstance(deq[0], Deferred):
    1.26 -                deferred = deq.popleft()
    1.27 -                if not deq:
    1.28 -                    del self.incoming_data[key]
    1.29 -                deferred.callback(data)
    1.30 -            else:
    1.31 -                deq.append(data)
    1.32 +                deq = self.incoming_data.setdefault(key, deque())
    1.33 +                if deq and isinstance(deq[0], Deferred):
    1.34 +                    deferred = deq.popleft()
    1.35 +                    if not deq:
    1.36 +                        del self.incoming_data[key]
    1.37 +                    deferred.callback(data)
    1.38 +                else:
    1.39 +                    deq.append(data)
    1.40 +            except struct.error, e:
    1.41 +                print "*** bad data: %s" % e
    1.42  
    1.43      def sendData(self, program_counter, data_type, data):
    1.44          """Send data to the peer.