http://hg.viff.dk/viff/rev/65cce3c355a0
changeset: 1163:65cce3c355a0
user: Martin Geisler <[email protected]>
date: Wed Apr 15 00:07:07 2009 +0200
summary: Rewrote sendData and stringRecived to use a simpler format.
The new format includes the length of the data as well for easier
unpacking.
diffstat:
1 file changed, 9 insertions(+), 13 deletions(-)
viff/runtime.py | 22 +++++++++-------------
diffs (41 lines):
diff -r 83282f6e20b9 -r 65cce3c355a0 viff/runtime.py
--- a/viff/runtime.py Tue Apr 14 23:30:34 2009 +0200
+++ b/viff/runtime.py Wed Apr 15 00:07:07 2009 +0200
@@ -302,17 +302,13 @@
self.transport.loseConnection()
self.factory.identify_peer(self)
else:
- # TODO: we cannot handle the empty string
- # also note that we cannot handle pcs longer than 256
- pc_size = ord(string[0])
- fmt = "%di" % (pc_size + 1)
- predata_size = struct.calcsize(fmt) + 1
- fmt = "%s%is" % (fmt, len(string)-predata_size)
-
- unpacked = struct.unpack(fmt, string[1:])
+ # TODO: We cannot handle the empty string.
+ pc_size, data_size, data_type = struct.unpack("!HHB", string[:5])
+ fmt = "!%dI%ds" % (pc_size, data_size)
+ unpacked = struct.unpack(fmt, string[5:])
program_counter = unpacked[:pc_size]
- data_type, data = unpacked[-2:]
+ data = unpacked[-1]
key = (program_counter, data_type)
@@ -327,10 +323,10 @@
def sendData(self, program_counter, data_type, data):
pc_size = len(program_counter)
- fmt = "%di%ds" % (pc_size + 1, len(data))
- data_tuple = program_counter + (data_type, data)
-
- self.sendString(chr(pc_size) + struct.pack(fmt, *data_tuple))
+ 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))
def sendShare(self, program_counter, share):
"""Send a share.
_______________________________________________
viff-commits mailing list
[email protected]
http://lists.viff.dk/listinfo.cgi/viff-commits-viff.dk