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

[minion-cvs] Abstract parsing the right delivery method for a given ...



Update of /home/minion/cvsroot/src/minion/lib/mixminion
In directory moria.mit.edu:/tmp/cvs-serv2341/lib/mixminion

Modified Files:
	Packet.py 
Log Message:
Abstract parsing the right delivery method for a given type

Index: Packet.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/Packet.py,v
retrieving revision 1.61
retrieving revision 1.62
diff -u -d -r1.61 -r1.62
--- Packet.py	9 Oct 2003 15:26:16 -0000	1.61
+++ Packet.py	13 Oct 2003 17:32:04 -0000	1.62
@@ -33,6 +33,7 @@
 import re
 import struct
 import sys
+import types
 import zlib
 from socket import inet_ntoa, inet_aton
 from mixminion.Common import MixError, MixFatalError, encodeBase64, \
@@ -552,6 +553,23 @@
 
 #----------------------------------------------------------------------
 # Routing info
+
+def parseRelayInfoByType(routingType,routingInfo):
+    """DOCDOC: Returns rt, (IPV4Info/MMTPHostInfo)."""
+    if routingType in (mixminion.Packet.FWD_IPV4_TYPE,
+                       mixminion.Packet.SWAP_FWD_IPV4_TYPE):
+        parseFn = mixminion.Packet.parseIPV4Info
+        parsedType = mixminion.Packet.IPV4Info
+    elif routingType in (mixminion.Packet.FWD_HOST_TYPE,
+                         mixminion.Packet.SWAP_FWD_HOST_TYPE):
+        parseFn = mixminion.Packet.parseMMTPHost
+        parsedType = mixminion.Packet.MMTPHostInfo
+    else:
+        raise MixFatalError("Unrecognized relay type 0x%04X"%routingType)
+    if type(routingInfo) == types.StringType:
+        routingInfo = parseFn(routingInfo)
+    assert isinstance(routingInfo, parsedType)
+    return routingInfo
 
 # An IPV4 address (Used by SWAP_FWD and FWD) is packed as: four bytes
 # of IP address, a short for the portnum, and DIGEST_LEN bytes of keyid.