[Nym3-commit] r56 - trunk

nym3-devel@lists.noreply.org nym3-devel@lists.noreply.org
Mon, 02 Aug 2004 16:22:18 +0200


Author: jr
Date: 2004-08-02 16:22:15 +0200 (Mon, 02 Aug 2004)
New Revision: 56

Added:
   trunk/Common.py
Modified:
   trunk/Config.py
   trunk/Mail.py
   trunk/Main.py
   trunk/Message.py
   trunk/User.py
Log:
- add Common.py, which holds the constants used in various modules
- add the gestion of Create2, Surb and Newpk commands(Main.py)
- add delSurbs(User.py)
- change the names of the User defined policy options(Config.py)


Added: trunk/Common.py
===================================================================
--- trunk/Common.py	2004-08-02 13:33:59 UTC (rev 55)
+++ trunk/Common.py	2004-08-02 14:22:15 UTC (rev 56)
@@ -0,0 +1,9 @@
+#constants
+surbLength = 2104
+sigLength = 256
+seqNoLength = 20
+midLength = 20
+
+userPolicy = ["SendMsgAfter", "SendSummaryAfter", "EncryptSummaryAfter",
+              "MaxSURBsPerDay", "HoldSURBs", "HoldUntilAck",
+              "ShutdownPhrase"] 

Modified: trunk/Config.py
===================================================================
--- trunk/Config.py	2004-08-02 13:33:59 UTC (rev 55)
+++ trunk/Config.py	2004-08-02 14:22:15 UTC (rev 56)
@@ -1,18 +1,11 @@
-#constants
-surbLength = 2104
-sigLength = 256
-seqNoLength = 20
-midLength = 20
-
-
 #path = '/var/lib/nym3'
 path = '.'
 
 default_settings = { 'quota' : 10 * 2**20, 'usage' : 0,
 		     'idKey' : None, 'encKey' : None, 'policy' : None,
-		     'maxMailLat' : 24, 'maxSynLat' : 12, 
-		     'maxSURBSperDay' : 10, 'maxClearSyn' : '24',
-		     'hold' : 'Always', 'shutdownHash' : None,
+		     'SendMsgAfter' : 24, 'SendSummaryAfter' : 12, 
+		     'MaxSURBsPerDay' : 10, 'EncryptSummaryAfter' : '24',
+		     'HoldUntilAck' : 'Always', 'ShutdownPhrase' : None,
                      'nSurbs' : 0, 'up' : False, 'cr' = ""}
 
 #up : the user account has been initialized and the answer to the challenge is correct

Modified: trunk/Mail.py
===================================================================
--- trunk/Mail.py	2004-08-02 13:33:59 UTC (rev 55)
+++ trunk/Mail.py	2004-08-02 14:22:15 UTC (rev 56)
@@ -3,10 +3,10 @@
 import random
 import base64
 import string
-import Config
+import Common
 
 slen = 180
-midLen = Config.midLength
+midLen = Common.midLength
 random.seed(None)
 
 

Modified: trunk/Main.py
===================================================================
--- trunk/Main.py	2004-08-02 13:33:59 UTC (rev 55)
+++ trunk/Main.py	2004-08-02 14:22:15 UTC (rev 56)
@@ -6,6 +6,7 @@
 import User
 import Config
 import Message
+import Common
 import Crypto
 
 def processIncoming(localpart, msg):
@@ -81,7 +82,7 @@
             sys.exit(2) #TODO smart error code
     else:
         try:
-            nymuser = User.user(h.nym)
+            nymUser = User.user(h.nym)
         except User.NoSuchUser:
             print "No such user"
             sys.exit(73) #TODO is it the smart error code
@@ -91,23 +92,30 @@
                 #we ignore the Create command if it comes from the nymholder of an account, should we rise an error?
                 pass
             elif (com.ct() == 1):
-                pass
-            elif (com.ct() == 2):
-                pass
-            elif (com.ct() == 3):
-                pass
-            elif (com.ct() == 4):
-                pass
-            elif (com.ct() == 5):
-                pass
-            elif (com.ct() == 6):
-                pass
-            elif (com.ct() == 7):
-                pass
-            elif (com.ct() == 8):
-                pass
-            else:
-                pass
+                if (nymUser.isInitialized() and (nymUser.data['up'] == False)):
+                    if(nymUser['cr'] == com.cr):
+                        nymUser['up'] = True
+                #if the account is not initialized, or if it is already up we ignore Create2 messages
+            elif (nymUser.data['up'] == True):
+                if (com.ct() == 2):
+                    if( len(com.surbs) == 0):
+                        nymUser.delSurbs()
+                    else:
+                        nymUser.addSurbs(com.surbs)
+                elif (com.ct() == 3):
+                    nymUser.setKeys(com.kid,com.kenc)
+                elif (com.ct() == 4):
+                    pass
+                elif (com.ct() == 5):
+                    pass
+                elif (com.ct() == 6):
+                    pass
+                elif (com.ct() == 7):
+                    pass
+                elif (com.ct() == 8):
+                    pass
+                else:
+                    pass
                     
     
 if __name__ == '__main__':

Modified: trunk/Message.py
===================================================================
--- trunk/Message.py	2004-08-02 13:33:59 UTC (rev 55)
+++ trunk/Message.py	2004-08-02 14:22:15 UTC (rev 56)
@@ -1,5 +1,5 @@
 import types
-import Config
+import Common
 
 class ParseError(Exception):
 	"""ParseError : error raised if anything goes wrong during parsing"""
@@ -46,10 +46,10 @@
 	else:
 		return False
 
-surbLength = Config.surbLength
-sigLength = Config.sigLength
-seqNoLength = Config.seqNoLength
-midLength = Config.midLength
+surbLength = Common.surbLength
+sigLength = Common.sigLength
+seqNoLength = Common.seqNoLength
+midLength = Common.midLength
 
 class StrReader:
 	"""wraps a string and gives method to read it chunk by chunk"""

Modified: trunk/User.py
===================================================================
--- trunk/User.py	2004-08-02 13:33:59 UTC (rev 55)
+++ trunk/User.py	2004-08-02 14:22:15 UTC (rev 56)
@@ -91,6 +91,12 @@
         f.close()
         self.data['nSurbs'] = self.data['nSurbs'] + ( len(surbs) / surb_len)
 
+    def delSurbs(self):
+        fname = self.surbfile()
+        f = open(fname, "w") #TODO check that this truncate the file (the file must be empty after that
+        f.close()
+        self.data['nSurbs'] = 0
+        
     def store(self, msg):
 	"Store an incoming message"
 	syn = Mail.synopsize(msg)