[Nym3-commit] r317 - trunk/nymbaron/Server
jr at conuropsis.org
jr at conuropsis.org
Wed Oct 5 18:10:30 CEST 2005
Author: jr
Date: 2005-10-05 18:10:29 +0200 (Wed, 05 Oct 2005)
New Revision: 317
Modified:
trunk/nymbaron/Server/Config.py
trunk/nymbaron/Server/User.py
Log:
- modify addSurbs to check if added surbs are not already in the store or used
- add a initialization value for User['inidgst']
Modified: trunk/nymbaron/Server/Config.py
===================================================================
--- trunk/nymbaron/Server/Config.py 2005-10-04 21:11:58 UTC (rev 316)
+++ trunk/nymbaron/Server/Config.py 2005-10-05 16:10:29 UTC (rev 317)
@@ -46,7 +46,7 @@
'MaxSURBsPerDay' : 10, 'EncryptSummaryAfter' : 24,
'HoldUntilAck' : 'always', 'ShutdownPhrase' : None,
'HoldSURBs' : 5,
- 'nSurbs' : 0, 'up' : False, 'cr' : ""}
+ 'nSurbs' : 0, 'up' : False, 'cr' : "", 'inidgst' : "" }
"""The default settings of a user account."""
#up : the user account has been initialized and the answer to the challenge is correct
#cr : response to the challenge
Modified: trunk/nymbaron/Server/User.py
===================================================================
--- trunk/nymbaron/Server/User.py 2005-10-04 21:11:58 UTC (rev 316)
+++ trunk/nymbaron/Server/User.py 2005-10-05 16:10:29 UTC (rev 317)
@@ -319,28 +319,59 @@
surbs = parseReplyBlocks(buffer)
goods = []
for surb in surbs:
- if check_surb(surb):
- goods.append(surb)
+ surbp = surb.pack() #the value of surb as a string
+ if check_surb(surbp):
+ goods.append(surbp)
f = open(self.surbfile(), "w")
- for surb in goods:
- f.write(surb)
+ for surbp in goods:
+ f.write(surbp)
self.data['nSurbs'] = len(goods)
f.close()
- def addSurbs(self, surbs):
- """Adds surbs to the store of surbs"""
+ def addSurbs(self, newsurbs):
+ """Adds newsurbs to the store of surbs. We make sure they are neither
+ used, nor already present"""
+ #TODO call to mixminion to remove once the clientAPI is ok
+ #load the surbs
+ fname = self.surbfile()
+ surbslist = []
try:
- #TODO debbuging cruft to remove
- nb = len(parseReplyBlocks(surbs))
- self['nSurbs'] += nb
+ f = open(fname, "r")
+ surbs = f.read()
+ f.close()
+ #TODO catch the possible parseError here?
+ surbslist = parseReplyBlocks(surbs)
+ except IOError:
+ surbslist = []
+ #keep the not used ones
+ goods = []
+ na = 0
+ nr = 0
+ for surb in surbslist:
+ surbp = surb.pack()
+ if check_surb(surbp):
+ goods.append(surbp)
+ else:
+ nr = nr + 1
+ try:
+ #add the new ones
+ newsurbslist = parseReplyBlocks(newsurbs)
+ for newsurb in newsurbslist:
+ newsurbp = newsurb.pack()
+ if (not newsurbp in goods) and check_surb(newsurbp):
+ goods.append(newsurbp)
+ na = na + 1
+ #save the result
+ self['nSurbs'] = len(goods)
+ fname = self.surbfile()
+ f = open(fname, "w")
+ for surbp in goods:
+ f.write(surbp)
+ f.close()
+ print "%d surbs added\n%d used surbs removed" % (na, nr)
except ParseError:
#the provided binary data isn't a succession of binary surbs
return
- fname = self.surbfile()
- f = open(fname, "a")
- f.write(surbs)
- f.close()
- print "%d surbs added" % nb
def delSurbs(self):
"""Deletes all the surbs of the surb store"""
More information about the Nym3-commit
mailing list