[Nym3-commit] r219 - in trunk/nym3: Client Server
jr at conuropsis.org
jr at conuropsis.org
Mon May 2 14:04:44 CEST 2005
Author: jr
Date: 2005-05-02 14:04:43 +0200 (Mon, 02 May 2005)
New Revision: 219
Modified:
trunk/nym3/Client/Account.py
trunk/nym3/Server/Config.py
trunk/nym3/Server/Main.py
trunk/nym3/Server/User.py
Log:
- add STATUS processing
- improve handling of the number of surbs in store
Modified: trunk/nym3/Client/Account.py
===================================================================
--- trunk/nym3/Client/Account.py 2005-05-02 11:49:13 UTC (rev 218)
+++ trunk/nym3/Client/Account.py 2005-05-02 12:04:43 UTC (rev 219)
@@ -37,6 +37,8 @@
import tempfile
import time
import re
+#TODO debugging cruft associated to seqno display
+import binascii
SEQNO_LEN = 20
SURB_LEN = 2104
@@ -265,6 +267,8 @@
"""Sends a list of command messages to the nymserver"""
msg = Message.buildMessage(l)
seqno = self.get_seqno()
+ #TODO debugging cruft
+ print "send message: %s" % binascii.hexlify(seqno)
hdr = self.buildHeader(msg, seqno, idKey)
self.record(seqno, hdr + msg)
self.send(hdr + msg)
@@ -289,6 +293,8 @@
for el in seqno_list:
if self.journal.has_key(el):
del self.journal[el]
+ #TODO debugging cruft
+ print "acknowledged message : %s" % binascii.hexlify(el)
self.journal_status = 'dirty'
def get_seqno(self):
Modified: trunk/nym3/Server/Config.py
===================================================================
--- trunk/nym3/Server/Config.py 2005-05-02 11:49:13 UTC (rev 218)
+++ trunk/nym3/Server/Config.py 2005-05-02 12:04:43 UTC (rev 219)
@@ -34,7 +34,7 @@
serverName = 'nymserv.komite.net'
"""The hostname of the host on which the nymserver is running."""
-path = '.'
+path = '/tmp'
"""The path to the directory containing the server data"""
default_settings = { 'quota' : 10 * 2**20, 'usage' : 0,
Modified: trunk/nym3/Server/Main.py
===================================================================
--- trunk/nym3/Server/Main.py 2005-05-02 11:49:13 UTC (rev 218)
+++ trunk/nym3/Server/Main.py 2005-05-02 12:04:43 UTC (rev 219)
@@ -121,11 +121,12 @@
nymUser.abort()
raise MyException()
else: # Valid account creation request. Send CREATED
+ nymUser.received(h.seqNo)
created = Message.Created()
created.fromData(nymUser.username, "")
nymUser.setUp()
- nymUser.send(Message.buildMessage([created]))
- except MyException:
+ nymUser.advanced_send(Message.buildMessage([created]))
+ except MyException:
#if you come here something went wrong during the account
#initialization
print "Bad formed account creation message"
@@ -138,6 +139,10 @@
sys.exit(73) #TODO is it the smart error code
if(not nymUser.checkMessageSign(msg[Message.sigLength:],h.sig)):
return
+ #The message comes from a known nick and is authenticated
+ #register the seqNo as received
+ #TODO is it ok?
+ nymUser.received(h.seqNo)
comList = sr.readCommandCToSList()
for com in comList:
if (com.ct() == Message.CToSCODE['Create']):
@@ -151,7 +156,7 @@
#other commands are only taken into account if the account is up
elif (nymUser.isUp()):
if (com.ct() == Message.CToSCODE['Surb']):
- if( len(com.surbs) == 0):
+ if (len(com.surbs) == 0):
nymUser.delSurbs()
else:
nymUser.addSurbs(com.surbs)
@@ -172,7 +177,8 @@
msgCom.fromData(m,nymUser.getMail(m))
msgList.append(msgCom)
sendList.append(m)
- ec = nymUser.send(Message.buildMessage(msgList))
+ ec = nymUser.advanced_send(
+ Message.buildMessage(msgList))
if (ec == 0):
nymUser.markMid(sendList,lifeCycle['sent-in-full'])
if(nymUser['HoldUntilAck'] == 'never'):
Modified: trunk/nym3/Server/User.py
===================================================================
--- trunk/nym3/Server/User.py 2005-05-02 11:49:13 UTC (rev 218)
+++ trunk/nym3/Server/User.py 2005-05-02 12:04:43 UTC (rev 219)
@@ -31,12 +31,15 @@
import nym3.Common as Common
import nym3.Mail as Mail
import nym3.Crypto as Crypto
+import nym3.Message as Message
import pickle
import string
import time
import mixminion.Common
from nym3.Message import intToStrBE
import mixminion.Crypto as _cr
+from mixminion.BuildMessage import getNPacketsToEncode
+from mixminion.Packet import parseReplyBlocks, ParseError
lifeCycle = Common.lifeCycle
"""The life cycle of a mail received by a nym"""
@@ -93,7 +96,9 @@
if create == 0: raise NoSuchUser()
self.data = Config.default_settings
self.data['username'] = username
-
+ self.data['received'] = []
+ self.data['nSurbs'] = 0
+
def __del__(self):
"""Flush the information contained in this User to the disk
"""
@@ -160,6 +165,9 @@
self.data['usage'] = sum
return sum
+ def received(self, seqNo):
+ self['received'].append(seqNo)
+
def idKey(self):
"""Gets the user public key used for identification"""
return self.data['idKey']
@@ -224,9 +232,53 @@
"""
return Config.path + os.sep + self.data['username'] + '.surbs'
+ def advanced_send(self, msg, add_status = True):
+ """Sends a message to the nymholder through the mixminion network,
+ using the surbs provided by the nymholder. Adds a status control
+ message if the add_status argument is True. Also updates the number
+ of surbs"""
+ #TODO add the filling of the remaining place available in the the
+ #message by syns and msgs here
+ statusc = Message.Status()
+ nMsg = 0
+ usage = 0
+ cmsg = msg
+ if add_status:
+ #determine the status elements, the number of surbs is assumed
+ #to stay equal to its value
+ self.load_index()
+ for mid, v in self.index.iteritems():
+ if v['status'] in [lifeCycle['nothing-sent'], lifeCycle['synopsis-sent']]:
+ nMsg += 1
+ usage = self.usage()
+ statusc.fromData(nMsg, 0, self.quota(), usage, self['received'])
+ cmsg += str(statusc)
+ nb_req_surb = getNPacketsToEncode(cmsg, 0)
+ if add_status:
+ while True:
+ statusc.fromData(nMsg, self['nSurbs'] - nb_req_surb,
+ self.quota(), usage, self['received'])
+ cmsg = msg + str(statusc)
+ act_nb = getNPacketsToEncode(cmsg, 0)
+ old_nb_req_surb = nb_req_surb
+ nb_req_surb = act_nb
+ if nb_req_surb <= old_nb_req_surb:
+ break
+ if nb_req_surb > self['nSurbs']:
+ #TODO
+ # - send an Error message "low on surbs" if a surb is available
+ # - store the message we couldn't send for later
+ return
+ #TODO debbuging cruft
+ print "%d surbs used to send control messages" % nb_req_surb
+ self['nSurbs'] -= nb_req_surb
+ self['received'] = []
+ self.send(cmsg)
+
+
def send(self, msg):
- """Sends a message to the nymholder through the mixminion network, using the surbs provided
- by the nymholder"""
+ """Sends a message to the nymholder through the mixminion network,
+ using the surbs provided by the nymholder"""
if Config.DEBUG:
print msg
return 0
@@ -270,15 +322,21 @@
self.data['nSurbs'] = self.data['nSurbs'] + 1
f.close()
- def addSurbs(self,surbs):
+ def addSurbs(self, surbs):
"""Adds surbs to the store of surbs"""
+ try:
+ #TODO debbuging cruft to remove
+ nb = len(parseReplyBlocks(surbs))
+ self['nSurbs'] += nb
+ 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()
- #self.data['nSurbs'] = self.data['nSurbs'] + ( len(surbs) / surb_len)
- # TODO : we need a _correct_ way to calculate the number of SURBs.
-
+ print "%d surbs added" % nb
+
def delSurbs(self):
"""Deletes all the surbs of the surb store"""
fname = self.surbfile()
More information about the Nym3-commit
mailing list