[Nym3-commit] r243 - trunk/nym3/Server
laurent at conuropsis.org
laurent at conuropsis.org
Fri May 6 16:49:40 CEST 2005
Author: laurent
Date: 2005-05-06 16:49:38 +0200 (Fri, 06 May 2005)
New Revision: 243
Modified:
trunk/nym3/Server/Main.py
trunk/nym3/Server/User.py
Log:
Rewrote sendList to prepareSummary, which appears to work now.
Modified: trunk/nym3/Server/Main.py
===================================================================
--- trunk/nym3/Server/Main.py 2005-05-06 14:48:34 UTC (rev 242)
+++ trunk/nym3/Server/Main.py 2005-05-06 14:49:38 UTC (rev 243)
@@ -46,7 +46,7 @@
try:
nymuser = User.User(localpart)
except User.NoSuchUser:
- print "No such user"
+ print "No such user " + localpart
sys.exit(73)
# TODO : we should honor the "Quota" sending policy.
if nymuser.usage() + len(msg) > nymuser.quota():
@@ -191,10 +191,11 @@
elif (com.ct() == Message.CToSCODE['Summarize']):
comList = []
- sendList = nymUser.sendList(com.num, com.after)
+ sendList = nymUser.prepareSummary(com.num, com.after)
mList = []
+ print str(sendList)
for (ml, bf, blob) in sendList:
- sumCom = Summary()
+ sumCom = Message.Summary()
sumCom.fromData(bf, blob)
comList.append(sumCom)
mList = mList + ml
Modified: trunk/nym3/Server/User.py
===================================================================
--- trunk/nym3/Server/User.py 2005-05-06 14:48:34 UTC (rev 242)
+++ trunk/nym3/Server/User.py 2005-05-06 14:49:38 UTC (rev 243)
@@ -537,84 +537,59 @@
except:
return False
- def sendList(self, num, after):
- """Returns a list of (ml, bf, synblob)
- in the process of creating it can modify the synbox,
- doing some encryption"""
- def lhasMail(midIdx, l):
- return self.mbox.has_key(l[midIdx])
- def addBlob(slist, mlist, ilist, blob):
- """append to slist (mlist, BF, blob)
- BF is the bitfield obtained from the elements e of ilist
- which verifies : the mid mlist[e] has a mail"""
- def test(midx):
- lhasMail(midx, mlist)
- slist.append(Mail.bf(filter(test, ilist)), blob)
- #the list of the mid after "after"
- midList = self.midAfter(after)
+ def prepareSummary(self, num, after):
+ """Return a list of (midList, bitfield, synblob) suitable for
+ a SUMMARY reply. Consider only mids older than `after', and
+ no more than `num'. May change the synbox if encryption is
+ necessary."""
+ def bfprepare(t):
+ bfl = map(self.hasMail, t[0])
+ u = (t[0], Mail.bf(bfl), t[2])
+ return u
#load the structures
self.load_index()
self.load_synbox()
self.load_mbox()
- #we just need the num first
- midList = midList[:num]
-
- #create a list of blobs containing the mid in midlist
- clearListEmpty = True #is there any non encrypted synopses between bInf and the current i, or bSup that need to be sent?
- sendList = [] #result list
-
- try:
- i, _ = self.getSyn(midList[0])
- except:
- #this should not happen
- raise 'Bug'
- #as long as midList isn't empty
- while(midList):
- #look for the synblob containing midList[0]
- (ml, status, synblob) = self.syn[i]
- if (status == 'clear'):
- if (clearListEmpty):
- bInf = i
- clearListEmpty = False
- if (i + 1 - bInf == 16):
- self.encryptSyn(bInf, i + 1)
- clearListEmpty = True
- (m, _, sy) = self.syn[bInf]
- addBlob(sendList, m, range(len(m)), sy)
- else:
- bSup = i+1
- del midList[0]
- elif (status == 'encrypted'):
- if (not clearListEmpty):
- self.encryptSyn(bInf, bSup)
- clearListEmpty = True
- (m,_,sy) = self.syn[bInf]
- addBlob(sendList, m, range(len(m)), sy)
- #idxList=[ml.index(midList[0])]
- def test(midx):
- return (self.timecmp(num, midx) < 0)
- #idxList contains the mid in ml older than num
- idxList = filter(test, ml)
- #remove from the midList the mid from idxList
- for j in idxList:
- try:
- midList.remove(j)
- except ValueError:
- pass
- tlist = []
- for j in idxList:
- tlist.append(ml.index(j))
- addBlob(sendList, ml, tList, synblob)
- else:
- #this should not happen
- raise 'Bug'
- i = i + 1
- #if clearList isn't empty
- if (not clearListEmpty):
- self.encryptSyn(bInf, bSup)
- (m, _, sy) = self.syn[bInf]
- addBlob(sendList, m, range(len(m)), sy)
- return sendList
+ # Prepare the midList.
+ midList = self.midAfter(after)[:num]
+ print "midlist has size " + str(len(midList))
+ ret = []
+ # Hold the clear syn
+ clearlist = []
+ nsyn = 0
+ while midList and (len(clearlist) + nsyn < num):
+ print "Et hop, un tour de while."
+ # look for the synblob containing midList[0]
+ try:
+ i, u = self.getSyn(midList[0])
+ except:
+ self.syn = self.syn + clearlist
+ print str(midList)
+ print str(self.syn)
+ print "Doh. Exception."
+ return ret
+ if (u[1] == 'clear'):
+ clearlist.append(u)
+ del self.syn[i]
+ del midList[0]
+ if len(clearlist) == 8:
+ foo = self.blobify(clearlist)
+ self.syn.append(foo)
+ ret.append(bfprepare(foo))
+ nsym += 8
+ clearlist = []
+ continue
+ elif (u[1] == 'encrypted'):
+ for i in u[0]:
+ if i in midList: midList.remove(i)
+ # Can we afford to add this blob?
+ if len(u[0]) + nsyn + len(clearlist) > num: continue
+ ret.append(bfprepare(u))
+ #
+ foo = self.blobify(clearlist)
+ self.syn.append(foo)
+ ret.append(bfprepare(foo))
+ return ret
if __name__ == '__main__':
try:
More information about the Nym3-commit
mailing list