[Nym3-commit] r180 - in trunk/nym3: . Client

laurent at conuropsis.org laurent at conuropsis.org
Sat Apr 9 18:56:35 CEST 2005


Author: laurent
Date: 2005-04-09 18:56:31 +0200 (Sat, 09 Apr 2005)
New Revision: 180

Modified:
   trunk/nym3/Client/Account.py
   trunk/nym3/Client/Config.py
   trunk/nym3/Client/Main.py
   trunk/nym3/Client/README.Dev
   trunk/nym3/Message.py
Log:
setupAccount almost works now.


Modified: trunk/nym3/Client/Account.py
===================================================================
--- trunk/nym3/Client/Account.py	2005-04-09 13:24:02 UTC (rev 179)
+++ trunk/nym3/Client/Account.py	2005-04-09 16:56:31 UTC (rev 180)
@@ -34,7 +34,11 @@
 import nym3.Message as Message
 import mixminion.ClientAPI as mapi
 import pickle
+import tempfile
+import time
 
+SEQNO_LEN = 20
+
 class NoSuchAccount(Exception): pass
 """Exception thrown when a user identified by her nym can't be found"""
 
@@ -119,39 +123,53 @@
 	  it is used to name the subdirectory holding this account's data
 	- datafile is the file which holds all of this. A mere pickling
 	- index. What was that again?
-	- params is a dictionnary of misc parameters
+	- misc parameters that needs further documentation.
 	- syn is the synopsis box (synbox)
-	- mbox is self explanatory"""
+	- mbox is self explanatory
+	- data is the hash that contains all of this
+	- datafile is the file where we pickle from and to the data hash
+	- a journal which is hash of seqno -> (message, time sent) and is
+	  pickled from/to journalfile"""
 
     def __init__(self, config, nickname, create = 0):
 	"""Load from an existing account, or create a new, or fail"""
 	# Set data to dummy values
-	self.idTag = None
+	#self.idTag = None
         self.datafile = None
-	self.index = None
-	self.mbox = None
-	self.syn = None
-	self.params = None
+	self.journalfile = None
+	#self.index = None
+	#self.mbox = None
+	#self.syn = None
+	self.data = {}
+	self.journal = {}
 	self.lock = None
 	self.config = config
 
 	if create == 1:
 	    tagmap = TagMap(config.path + os.sep + 'tagmap')
-	    self.idTag = tagmap.getnewId(nickname)
+	    self['idTag'] = tagmap.getnewId(nickname)
 	    # If the nick already existed, we're out of this because of
 	    # a thrown AlreadySuchAccount.
-	# Everything below this line has not been reread and can be considered
-	# work in progress.
+	    # Create the dir that holds this account data
+	    os.mkdir(config.path + os.sep + self['idTag'])
+	self.base_path = config.path + os.sep + self['idTag']
 	self._lock()
-            
-    def __del__(self):
-	"""Flushes the user account to the disk"""
-        self._save_index()
-        self._save_synbox()
-        self._save_mbox()
-        self._save_data()
-        if self.lock: self._release()
-    
+
+    def generateSurbs(self, n):
+        """Generate surbs"""
+	# TODO : this should be done via ClientAPI.
+	surbdir = tempfile.mkdtemp()
+	surbspath = surbdir + os.sep + "surbs"
+	mixcall = "mixminion generate-surb -t %s -b -n %d -o %s --identity='%s'"
+	mixcall = mixcall % (self['returnaddress'], n, surbspath, self['idTag'])
+	os.system(mixcall)
+	f = open(surbspath, "r")
+	data = f.read()
+	f.close()
+	os.unlink(surbspath)
+	os.rmdir(surbdir)
+	return data
+
     def __getitem__(self, key):
 	"""Gets user account field as in a hashtable"""
 	return self.data[key]
@@ -160,19 +178,77 @@
 	"""Gets user account field as in a hashtable"""
 	self.data[key] = value
 
+    def get_seqno(self): pass
+
+    def send(self, body):
+	# TODO : this should be done via ClientAPI.
+	(f, msgpath) = tempfile.mkstemp()
+	os.close(f)
+	f = open(msgpath, "w")
+	f.write(body)
+	f.close()
+	mixcall = "mixminion send -t %s -i %s" % \
+		  (self['servername'], msgpath)
+	os.system(mixcall)
+	os.unlink(msgpath)
+
+    def mboxfile(self):
+	"""Gets the path of the mailbox"""
+	return self.base_path + os.sep + 'mbox'
+
     def _lock(self):
 	"""Locks the user. For well behaved functions."""
-	self.lock = mixminion.Common.Lockfile(self.config.path + os.sep + self.idTag + '.lck')
+	self.lock = mixminion.Common.Lockfile(self.config.path + os.sep + 
+		    self['idTag'] + '.lck')
 	self.lock.acquire()
 
     def _release(self):
 	"""Releases the lock"""
 	self.lock.release()
+	self.lock = None
 
     def homeDir(self):
 	"""Gets the home directory of this account"""
-        return  Config.path + os.sep + self.idTag + os.sep
+        return self.base_path
 
+    def sendControl(self, l, idKey):
+	"""Sends a list of command messages to the nymserver"""
+        msg = Message.buildMessage(l)
+	seqno = self.get_seqno()
+        hdr = self.buildHeader(msg, seqno, idKey)
+	self.record(seqno, msg)
+	self.send(msg)
+
+    def buildHeader(self, msg, seqno, idKey):
+	"""Generates a header for a message using the identification key"""
+        h = Message.Header()
+        sig = _cr.pk_sign(_cr.sha1(chr(len(self['username'])) +
+				   self['username'] + msg), idKey)
+        h.fromData(self.data['username'], seqno, sig)
+        return str(h)
+
+    def record(self, seqno, msg):
+	"""Store a control message in the journal"""
+	self.journal[seqno] = (msg, int(time.time()))
+
+    def get_seqno(self):
+	"""Return a previously unused sequence number"""
+	ret = chr(0) * SEQNO_LEN
+	while self.journal.has_key(ret):
+	    ret = Mail.genMid(SEQNO_LEN)
+	return ret
+
+    # Everything below this line has not been reread and can be considered
+    # work in progress.
+            
+    def __del__(self):
+	"""Flushes the user account to the disk"""
+        #self._save_index()
+        #self._save_synbox()
+        #self._save_mbox()
+        self._save_data()
+        if self.lock: self._release()
+    
     def load_mbox(self):
 	"""Loads the mailbox from the disk"""
 	if not self.mbox == None: return
@@ -184,10 +260,6 @@
 	except IOError:
 	    self.mbox = {}
 
-    def mboxfile(self):
-	"""Gets the path of the mailbox"""
-	return self.home + 'mbox'
-
     def _save_mbox(self):
 	"""Flushes the mailbox to the disk"""
 	if self.mbox == None: return
@@ -245,46 +317,3 @@
     def _save_data(self):
 	"""Flushes the data to the disk"""
 	pass
-
-    def generateKeys(self):
-	"""Generates keys for this account"""
-        self.data['idKey'] = _cr.pk_generate()
-        self.data['encKey'] = _cr.pk_generate()
-        
-    def getSeqNo(self):
-	"""?"""
-        return chr(0)*Common.seqNoLength
-
-    def addHeader(self, msg):
-	"""Generates a header for a message using the identification key"""
-        h = Message.Header()
-        sig = _cr.pk_sign(_cr.sha1(msg), self.data['idKey'])
-        h.fromData(self.data['username'], self.getSeqNo(), sig)
-        return str(h) + msg
-
-    def setServer(self, serv):
-	"""Sets the name of the nymserver hosting the nym account"""
-        self.data['server'] = serv
-
-    def setAddress(self, add):
-	"""?"""
-        #TODOcheck that add has a good format?
-        self.data['address'] = add
-    
-    def send(self, msg):
-	"""Sends a message from the nymholder to the nymserver"""
-        pass
-
-    def sendControl(self, l):
-	"""Sends a list of command messages to the nymserver"""
-        msg = Message.buildMessage(l)
-        msg = self.addHeader(msg)
-        nymUser.send(msg)
-        
-    def generateSurbs(self, n):
-        """Generate surbs"""
-	capi = mapi.ClientEnv(); # TODO: create it once and share it.
-	return [ "wait for ClientAPI... or write it."] * n
-	return capi.generateSURBs(n, messageDest = self.data['address'],
-				  identity = self.idTag);
-    

Modified: trunk/nym3/Client/Config.py
===================================================================
--- trunk/nym3/Client/Config.py	2005-04-09 13:24:02 UTC (rev 179)
+++ trunk/nym3/Client/Config.py	2005-04-09 16:56:31 UTC (rev 180)
@@ -31,7 +31,7 @@
 	# through mixminion or output them on stdout
 	self.DEBUG = False
 	#The path to the directory containing the user accounts
-	self.path = '.'
+	self.path = '/tmp'
 
 	self.pubring_path = self.path + os.sep + "pubring"
 	self.secring_path = self.path + os.sep + "secring"

Modified: trunk/nym3/Client/Main.py
===================================================================
--- trunk/nym3/Client/Main.py	2005-04-09 13:24:02 UTC (rev 179)
+++ trunk/nym3/Client/Main.py	2005-04-09 16:56:31 UTC (rev 180)
@@ -109,18 +109,22 @@
 	    ui.display("This account name is already in use")
 	    nickname = ui.prompt("New account name")
 	if account: break
+    account['nickname'] = nickname
     if not serverName:
 	serverName = ui.prompt("At which server do you want to register"
 			       " this account")
+    account['servername'] = serverName
     if not usernamelist:
 	ui.display("You need a username for this account.")
 	usernamelist = ui.promptmultiline("Enter several choices, one per line,"
 				 " finish by a blank line")
+    account['username'] = "" # Not yet created
     if not emailAddress:
 	emailAddress = ui.prompt("What is the default email address for "
 				 "returning messages")
-    idKey = _cr.pk_generate()
-    encKey = _cr.pk_generate()
+    account['returnaddress'] = emailAddress
+    idKey = _cr.pk_generate(bits=2048)
+    encKey = _cr.pk_generate(bits=2048)
     # We have gathered the relevant information for this account, except for
     # the policy which we don't let the user change at this point for the sake
     # of simplicity. So, let's store all of that in the account and prepare the
@@ -162,6 +166,7 @@
     newpkc.fromData(idKey, encKey)
     surbc = Message.Surb()
     surbc.fromData(account.generateSurbs(7))
+    account.sendControl([createc, newpkc, surbc], idKey)
 	
 def main(args):
     if len(args) < 2:

Modified: trunk/nym3/Client/README.Dev
===================================================================
--- trunk/nym3/Client/README.Dev	2005-04-09 13:24:02 UTC (rev 179)
+++ trunk/nym3/Client/README.Dev	2005-04-09 16:56:31 UTC (rev 180)
@@ -36,7 +36,8 @@
 is the following:
 
     NYMROOT/
-	  | keyring
+	  | secring
+	  | pubring
 	  | tagmap
 	  | account1/
 	  |	   | synbox

Modified: trunk/nym3/Message.py
===================================================================
--- trunk/nym3/Message.py	2005-04-09 13:24:02 UTC (rev 179)
+++ trunk/nym3/Message.py	2005-04-09 16:56:31 UTC (rev 180)
@@ -267,6 +267,7 @@
 		else:
 			if(len(sig) != sigLength):
 				raise BadArgument("Buildheader.__init__ : sig length doesn't match sigLength")	
+			else: self.sig = sig
 		self.nl = len(nym)
 		self.nym = nym
 		self.seqNo = seqNo
@@ -984,13 +985,11 @@
 		return chr(self.ct()) + intToStrBE(len(s), 3) + s
 
 def buildMessage(comList):
-	"""Turn a list of Command into a sendable message
-	"""
-	s = ""
-	for c in comList:
-		s = s + str(c)
-	
-	return s
+    """Turn a list of Command into a sendable message"""
+    s = ""
+    for c in comList:
+	s = s + str(c)
+    return s
 
 if (__name__ == '__main__'):
 	import Mail



More information about the Nym3-commit mailing list