[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[minion-cvs] The directory implementation can now accept and publish...



Update of /home/minion/cvsroot/src/minion/lib/mixminion/directory
In directory moria.mit.edu:/tmp/cvs-serv8058/lib/mixminion/directory

Modified Files:
	DirCGI.py Directory.py ServerInbox.py ServerList.py 
Log Message:
The directory implementation can now accept and publish a serverdesc

Index: DirCGI.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/directory/DirCGI.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- DirCGI.py	28 May 2003 07:42:22 -0000	1.5
+++ DirCGI.py	28 May 2003 08:37:48 -0000	1.6
@@ -14,6 +14,8 @@
 import os
 import sys
 from mixminion.directory.Directory import Directory
+from mixminion.directory.ServerInbox import ServerQueuedException
+from mixminion.Common import UIError
 
 try:
     import cgitb
@@ -44,7 +46,13 @@
     address = "<%s:%s>" % (os.environ.get("REMOTE_ADDR"),
                            os.environ.get("REMOTE_PORT"))
 
-    inbox.receiveServer(desc, address)
+    try:
+	os.umask(022)
+        inbox.receiveServer(desc, address)
+        print "Status: 1\nMessage: Accepted."
+    except UIError, e:
+        print "Status: 0\nMessage: %s"%e
+    except ServerQueuedException, e:
+        print "Status: 1\nMessage: %s"%e
 
 
-    

Index: Directory.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/directory/Directory.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- Directory.py	28 May 2003 06:37:37 -0000	1.7
+++ Directory.py	28 May 2003 08:37:48 -0000	1.8
@@ -75,7 +75,7 @@
 
     def getIDCache(self):
         if not self.cache:
-            self.cache = IDCache(self.cacheFile)
+            self.cache = IDCache(self.cacheFile,self._setCacheMode)
         return self.cache
 
     def _setCacheMode(self):
@@ -177,10 +177,11 @@
 
 class IDCache:
     """DOCDOC"""
-    def __init__(self, location):
+    def __init__(self, location, postSave=None):
         self.location = location
         self.dirty = 0
         self.cache = None
+        self.postSave = postSave
 
     def emptyCache(self):
         self.dirty = 1
@@ -254,6 +255,8 @@
         writePickled(self.location,
                      ("V0", self.cache),
                      0640)
+        if self.postSave:
+            self.postSave()
         self.dirty = 0
             
 def getIDFingerprint(server):

Index: ServerInbox.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/directory/ServerInbox.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- ServerInbox.py	28 May 2003 07:54:08 -0000	1.5
+++ ServerInbox.py	28 May 2003 08:37:49 -0000	1.6
@@ -12,7 +12,7 @@
 import os
 
 from mixminion.Common import LOG, MixError, MixFatalError, UIError, \
-     readPickled, writePickled
+     readPickled, writePickled,formatBase64
 from mixminion.ServerInfo import ServerInfo
 
 from mixminion.directory.Directory import getIDFingerprint, MismatchedID
@@ -133,7 +133,7 @@
         # lcnickname->nicknames
         nicknames = {}
     
-        for f,s,t,fp in incoming:
+        for fname,s,t,fp in incoming:
             nickname = s.getNickname()
             lcnickname = nickname.lower()
             nicknames.setdefault(lcnickname, []).append(nickname)
@@ -151,7 +151,7 @@
             ss = servers[lcnickname]
             if len(ss) > 1:
                 print >>f, ("***** MULTIPLE KEYIDS FOR %s:"%nickname)
-            for fp, s in ss:
+            for fp, s in ss.items():
                 print >>f, (format%(nickname,fp,len(s)))
 
 class IncomingQueue:
@@ -168,11 +168,11 @@
     def queueIncomingServer(self, contents, server):
         """DOCDOC"""
         nickname = server.getNickname()
-        _writeServer(nickname, contents, self.incomingDir)
+        _writeServer(self.incomingDir, contents, nickname, 0644)
 
     def queueRejectedServer(self, contents, server):
         nickname = server.getNickname()
-        _writeServer(nickname, contents, self.rejectDir)        
+        _writeServer(self.rejectDir, contents, nickname, 0644)
 
     def newServersPending(self, newServ):
         """DOCDOC"""
@@ -189,13 +189,14 @@
                 LOG.warn("Removed a bad server descriptor %s from incoming dir: %s",
                          fname, e)
                 continue
-            res.append((fname, server, text, getIDFingerprint(server)))
+            fp = formatBase64(getIDFingerprint(server))
+            res.append((fname, server, text, fp))
         return res
 
     def delPendingServers(self, fnames):
         for fname in fnames:
             try:
-                os.path.unlink(os.path.join(self.incomingDir, fname))
+                os.unlink(os.path.join(self.incomingDir, fname))
             except OSError:
                 LOG.warn("delPendingServers: no such server %s"%fname)
 

Index: ServerList.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/directory/ServerList.py,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- ServerList.py	26 May 2003 21:08:13 -0000	1.20
+++ ServerList.py	28 May 2003 08:37:49 -0000	1.21
@@ -424,9 +424,9 @@
         self.rlock.release()
 
 
-def _writeServer(directory, contents, nickname):
+def _writeServer(directory, contents, nickname, mode=0600):
     newFile = nickname+"-"+formatFnameTime()
-    f, newFile = openUnique(os.path.join(directory, "newFile"))
+    f, newFile = openUnique(os.path.join(directory, newFile), 'w', mode)
     newFile = os.path.split(newFile)[1]
     f.write(contents)
     f.close()