[Nym3-commit] r75 - trunk

nym3-devel@lists.noreply.org nym3-devel@lists.noreply.org
Wed, 04 Aug 2004 17:23:58 +0200


Author: jr
Date: 2004-08-04 17:23:54 +0200 (Wed, 04 Aug 2004)
New Revision: 75

Modified:
   trunk/Mail.py
   trunk/Main.py
   trunk/User.py
Log:

- getSyn also returns the idx of the entry being returned(User.py)
- add blobify(User.py)
- add bf(Mail.py)
- bug corrections(Main.py)
-- already sent synopses can be resent
-- idxList now contains the idx of the synopses beeing sent
and not only those of those which have to be sent

-This line, and those below, will be ignored--

M    trunk/User.py
M    trunk/Mail.py
M    trunk/Main.py


Modified: trunk/Mail.py
===================================================================
--- trunk/Mail.py	2004-08-04 15:15:16 UTC (rev 74)
+++ trunk/Mail.py	2004-08-04 15:23:54 UTC (rev 75)
@@ -5,7 +5,6 @@
 import base64
 import string
 import Common
-
 slen = 180
 midLen = Common.midLength
 random.seed(None)
@@ -31,6 +30,17 @@
 	
     return res + 'X-Octets: ' + repr(len(msg)) + "\n" + body
 
+def bf(l):
+    """take a list of index and generate a bitfield
+    the k-bit is set to 1 if k is in l
+    the bitfield is a 2 octets big endian string
+    """
+    t=[0,0]
+    for k in [x for x in l if x<16 and x >=0]:
+        (q,r)=divmod(k,8)
+        t[q] = t[q] | (1 << r)
+    return chr(t[0])+chr(t[1])
+
 def genMid(length = midLen):
     ret = oldestMid
     while ret == oldestMid:

Modified: trunk/Main.py
===================================================================
--- trunk/Main.py	2004-08-04 15:15:16 UTC (rev 74)
+++ trunk/Main.py	2004-08-04 15:23:54 UTC (rev 75)
@@ -1,5 +1,4 @@
 #!/usr/bin/env python2.3
-# $Id$
 
 import sys
 import os
@@ -110,9 +109,7 @@
 		    pass
 		elif (com.ct() == 5):
 		    pass
-		elif (com.ct() == 6):
-		    pass
-		elif (com.ct() == 7):
+                elif (com.ct() == 6):
                     def hasMail(midIdx,l):
                         if(nymUser.mbox.has_key(l[midIdx])):
                             True
@@ -122,14 +119,15 @@
                     synCnt=0
                     inter=[]
 		    midList=nymUser.midAfter(com.after)
-                    #TODO take a lock, or wait
+                    nymUser.lock()
                     nymUser.load_index()
                     nymUser.load_synbox()
                     nymUser.load_mbox()
                     #remove already sent synopsis mid
-                    for m in midList:
-                        if(index[m]['sent'] in ['synopsis','full']):
-                            midList.remove(m)
+                    #grumbl unwanted feature
+                    #for m in midList:
+                    #    if(index[m]['sent'] in ['synopsis','full']):
+                    #        midList.remove(m)
                     #we just need the com.num first
                     midList=midList[:com.num]
                     
@@ -139,56 +137,75 @@
                     #as long as midList isn't empty
                     while(midList):
                         #look for the synblob containing midList[0]
-                        for i, (ml, status, synblob) in enumerate(nymUser.syn):
-                            if(midList[0] in ml):
-                                #found
-                                if(status == 'clear'):
-                                    if(clearList == []):
-                                        bInf=i
-                                    clearList.append((ml[0],synblob))
-                                    if(len(clearList) == 16):
-                                        nymUser.syn[bInf:i+1]=[Mail.blobify(clearList)]
-                                        clearList=[]
-                                        (m,s,sy) = nymUser.syn[bInf]
-                                        def test(midx):
-                                            hasMail(midx,m)
-                                        sendList.append(Mail.bf(filter(test,range(len(m)))),sy)
-                                    else:
-                                        bSup=i+1
-                                elif(status == 'encrypted'):
-                                    if(clearList != []):
-                                        nymUser.syn[bInf:bSup]=[Mail.blobify(clearList)] 
-                                        clearList=[]
-                                        (m,s,sy) = nymUser.syn[bInf]
-                                        def test(midx):
-                                            hasMail(midx,m)
-                                        sendList.append(Mail.bf(filter(test,range(len(m)))),sy)
-                                    idxList=[ml.index(midList[0])]
+                        try:
+                            i, (ml, status, synblob) = nymUser.getSyn(midList[0])
+                            #found
+                            if(status == 'clear'):
+                                if(clearList == []):
+                                    bInf=i
+                                clearList.append((ml[0],synblob))
+                                if(len(clearList) == 16):
+                                    nymUser.syn[bInf:i+1]=[nymUser.blobify(clearList)]
+                                    clearList=[]
+                                    (m,s,sy) = nymUser.syn[bInf]
+                                    def test(midx):
+                                        hasMail(midx,m)
+                                    sendList.append(Mail.bf(filter(test,range(len(m)))),sy)
+                                else:
+                                    bSup=i+1
+                                del(midList[0])
+                            elif(status == 'encrypted'):
+                                if(clearList != []):
+                                    nymUser.syn[bInf:bSup]=[nymUser.blobify(clearList)] 
+                                    clearList=[]
+                                    (m,s,sy) = nymUser.syn[bInf]
+                                    def test(midx):
+                                        hasMail(midx,m)
+                                    sendList.append(Mail.bf(filter(test,range(len(m)))),sy)
+                                #idxList=[ml.index(midList[0])]
+                                def test(midx):
+                                    return (nymUser.timecmp(com.num,midx)<0)
+                                idxList=filter(test,ml)
+                                #remove from the midList the mid from idxList
+                                for j in idxList:
                                     try:
-                                        j=0
-                                        while(True):
-                                            j=j+1
-                                            idxList.append(ml.index(midList[j]))
-                                            del(midList[j])
+                                        midList.remove(j)
                                     except ValueError:
                                         pass
-                                    def test(midx):
-                                        hasMail(midx,ml)
-                                    sendList.append(Mail.bf(filter(test,idxList)),synblob)
-                                else:
-                                    #this should not happen
-                                    raise 'Bug'
-                                del(midList[0])
+                                def test(midx):
+                                    hasMail(midx,ml)
+                                sendList.append(Mail.bf(filter(test,idxList)),synblob)
                             else:
                                 #this should not happen
                                 raise 'Bug'
+                        except:
+                            #this should not happen
+                            raise 'Bug'
                     #if clearList isn't empty
                     if(clearList != []):
                         #this should be ok if we have proper locks
-                        nymUser.syn[bInf:bSup]=[Mail.blobify(clearList)] 
+                        nymUser.syn[bInf:bSup]=[nymUser.blobify(clearList)] 
                         (m,s,sy) = nymUser.syn[bInf]
                         sendList.append(Mail.bf(range(len(m))),sy)
-                    #send what is in sendList (list of BF,enc syn)        
+                    #TODO send what is in sendList (list of BF,enc syn)
+                    #TODO modify the state (['sent']='synopsis'
+                    nymUser.save_synbox()
+                    nymUser.save_index()
+                    #we do not modify the mbox
+                    nymUser.release()
+                elif (com.ct() == 7):
+		    nymUser.lock()
+                    nymUser.load_mbox()
+                    nymUser.load_index()
+                    nymUser.load_synbox()
+
+                    for mid in com.l:
+                        
+
+                    nymUser.save_mbox()
+                    nymUser.save_index()
+                    nymUser.save_synbox()
+                    nymUser.release()
 		elif (com.ct() == 8):
 		    if(com.opt in Common.userPolicy):
 			nymUser.data[com.opt] = com.val

Modified: trunk/User.py
===================================================================
--- trunk/User.py	2004-08-04 15:15:16 UTC (rev 74)
+++ trunk/User.py	2004-08-04 15:23:54 UTC (rev 75)
@@ -8,6 +8,7 @@
 import string
 import time
 import mixminion.Common
+from Message import intToStrBE
 
 surb_len = Common.surbLength
 
@@ -67,13 +68,25 @@
     def encKey(self):
         return self.data['encKey']
 
+    def blobify(self,l):
+        """encrypts a set of synopses
+        l is a list of pair (mid,synopsis)
+        """
+        s=""
+        m=[]
+        for mid, syn in l:
+            m.append(mid)
+            s = s + mid + intToStrBE(len(syn),2) + syn
+            return (m,'encrypted',Crypto.nym_encrypt(s,self.encKey()))
+        #TODO nym_encrypt and nym_decrypt
+
     def getSyn(self, mid):
 	"""Retrieve a blurb consisting of the synopsis of the
 	   requested synopsis mid. May contain unwanted synopsis
 	   too."""
 	self.load_synbox()
-	for midlist, status, synblob in self.syn:
-	    if mid in midlist: return (midlist, status, synblob)
+	for i, (midlist, status, synblob) in enumerate(self.syn):
+	    if mid in midlist: return i, (midlist, status, synblob)
 	raise "Not Found"
 
     def midAfter(self, mid):