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

[minion-cvs] Tweaks gearing up for 0.0.6rc1.



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

Modified Files:
	EventStats.py ServerConfig.py ServerKeys.py ServerMain.py 
Log Message:
Tweaks gearing up for 0.0.6rc1.

Common:
  - Document log configuration code; make it easier to force server logs 
    onto/off of the console

test:
  - Add tests for ServerInfo.displayServer.
  - Refactor kegen tests to account for new hostname/IP consistency checking.

EventStats:
  - Add boilerplate at the head of new stats files.

ServerConfig:
  - Document new file configuration functions

ServerKeys:
  - Warn if we're configured with a hostname that we can't resolve, or
    that doesn't resolve to our IP.

ServerMain:
  - Document new directory layout correctly.
  - Refactor --echo handling so that it actually works.



Index: EventStats.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/server/EventStats.py,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- EventStats.py	28 Nov 2003 04:14:04 -0000	1.12
+++ EventStats.py	3 Dec 2003 23:18:53 -0000	1.13
@@ -102,6 +102,15 @@
         """
         self._log("UnretriableDelivery", arg)
 
+
+BOILERPLATE = """\
+# Mixminion server statistics
+#
+# NOTE: These statistics _do not_ necessarily cover the current interval
+# of operation.  To see pending statistics that have not yet been flushed
+# to this file, run 'mixminion server-stats'.
+"""
+
 class EventLog(NilEventLog):
     """An EventLog records events, aggregates them according to some time
        periods, and logs the totals to disk.
@@ -226,8 +235,10 @@
         LOG.debug("Flushing statistics log")
         if now is None: now = time()
 
-        #XXXX006 dump boilerplate when starting new file.
+        starting = not os.path.exists(self.historyFilename)
         f = open(self.historyFilename, 'a')
+        if starting:
+            f.write(BOILERPLATE)
         self.dump(f, now)
         f.close()
 
@@ -311,7 +322,6 @@
             os.makedirs(os.path.split(statsfile)[0], 0700)
 
         workfile = os.path.join(config.getWorkDir(), "stats.tmp")
-        #XXXX006 ensure parent.
         log = EventLog(
            workfile, statsfile, config['Server']['StatsInterval'].getSeconds())
         LOG.info("Statistics logging enabled")

Index: ServerConfig.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/server/ServerConfig.py,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -d -r1.43 -r1.44
--- ServerConfig.py	28 Nov 2003 04:14:04 -0000	1.43
+++ ServerConfig.py	3 Dec 2003 23:18:53 -0000	1.44
@@ -185,7 +185,10 @@
         _validateRetrySchedule(mixInterval, entry, sectionName)
 
     def _get_fname(self, sec, ent, defaultRel):
-        """DOCDOC"""
+        """Helper function.  Returns the filename in self[sec][ent],
+           but defaults to ${BASEDIR}/defaultRel.  All relative paths
+           are also interpreted relative to ${BASEDIR}.
+        """
         raw = self[sec].get(ent)
         homedir = self.getBaseDir()
         if not raw:
@@ -196,30 +199,31 @@
             return os.path.join(homedir, raw)
 
     def getBaseDir(self):
-        """DOCDOC"""
+        """Return the base directory for this configuration."""
         v = self["Server"]["BaseDir"]
         if v is None:
             v = self["Server"]["Homedir"]
         if v is None:
             v = "/var/spool/minion"
         return v
+
     def getLogFile(self):
-        """DOCDOC"""
+        """Return the configured logfile location."""
         return self._get_fname("Server", "LogFile", "log")
     def getStatsFile(self):
-        """DOCDOC"""
+        """Return the configured stats file location."""
         return self._get_fname("Server", "StatsFile", "stats")
     def getKeyDir(self):
-        """DOCDOC"""
+        """Return the configured key directory"""
         return self._get_fname("Server", "KeyDir", "keys")
     def getWorkDir(self):
-        """DOCDOC"""
+        """Return the configured work directory"""
         return self._get_fname("Server", "WorkDir", "work")
     def getPidFile(self):
-        """DOCDOC"""
+        """Return the configured PID file location"""
         return self._get_fname("Server", "PidFile", "pid")
     def getQueueDir(self):
-        """DOCDOC"""
+        """Return the configured queue directory."""
         if self["Server"]["QueueDir"] is None:
             return os.path.join(self.getWorkDir(), 'queues')
         else:

Index: ServerKeys.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/server/ServerKeys.py,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -d -r1.60 -r1.61
--- ServerKeys.py	28 Nov 2003 04:14:04 -0000	1.60
+++ ServerKeys.py	3 Dec 2003 23:18:53 -0000	1.61
@@ -31,9 +31,9 @@
 from mixminion.ServerInfo import ServerInfo, PACKET_KEY_BYTES, MMTP_KEY_BYTES,\
      signServerInfo
 from mixminion.Common import AtomicFile, LOG, MixError, MixFatalError, \
-     ceilDiv, createPrivateDir, checkPrivateFile, formatBase64, formatDate, \
-     formatTime, previousMidnight, readFile, secureDelete, tryUnlink, \
-     UIError, writeFile
+     ceilDiv, createPrivateDir, checkPrivateFile, englishSequence, \
+     formatBase64, formatDate, formatTime, previousMidnight, readFile, \
+     secureDelete, tryUnlink, UIError, writeFile
 from mixminion.Config import ConfigError
 
 #----------------------------------------------------------------------
@@ -71,6 +71,7 @@
     #      have keys on disk.
     # currentKeys: None, if we haven't checked for currently live keys, or
     #      a list of currently live ServerKeyset objects.
+    # dhFile: pathname to file holding diffie-helman parameters.
     # _lock: A lock to prevent concurrent key generation or rotation.
 
     def __init__(self, config):
@@ -84,7 +85,6 @@
         self.homeDir = config.getBaseDir()
         self.keyDir = config.getKeyDir()
         self.hashDir = os.path.join(config.getWorkDir(), 'hashlogs')
-        #DOCDOC
         self.dhFile = os.path.join(config.getWorkDir(), 'tls', 'dhparam')
         self.keyOverlap = config['Server']['PublicKeyOverlap'].getSeconds()
         self.nextUpdate = None
@@ -783,6 +783,7 @@
 
        If 'log' is true, warn as well.  Does not check keys.
     """
+    #XXXX This needs unit tests.  For now, though, it seems to work.
     warn = _WarnWrapper(silence = not log, isPublished=isPublished)
 
     config_s = config['Server']
@@ -1006,6 +1007,16 @@
         fields['Hostname'] = socket.getfqdn()
         LOG.warn("No Hostname configured; guessing %s",fields['Hostname'])
     _checkHostnameIsLocal(fields['Hostname'])
+    try:
+        dnsResults = mixminion.NetUtils.getIPs(fields['Hostname'])
+    except socket.error, e:
+        LOG.warn("Can't resolve configured hostname %r: %s",
+                 fields['Hostname'],str(e))
+    else:
+        found = [ ip for _,ip,_ in dnsResults ]
+        if fields['IP'] not in found:
+            LOG.warn("Configured hostname %r resolves to %s, but we're publishing the IP %s",
+                     fields['Hostname'], englishSequence(found), fields['IP'])
 
     # Fill in a stock server descriptor.  Note the empty Digest: and
     # Signature: lines.

Index: ServerMain.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/server/ServerMain.py,v
retrieving revision 1.104
retrieving revision 1.105
diff -u -d -r1.104 -r1.105
--- ServerMain.py	28 Nov 2003 04:14:05 -0000	1.104
+++ ServerMain.py	3 Dec 2003 23:18:53 -0000	1.105
@@ -10,30 +10,35 @@
 
 #XXXX make usage messages have the same format.
 
-## Directory layout:  DOCDOC this is now more complicated. :P
-#    MINION_HOME/work/queues/incoming/ [Queue of received,unprocessed pkts]
-#                            mix/ [Mix pool]
-#                            outgoing/ [Packets for mmtp delivery]
-#                            deliver/*/ [Messages for delivery via modules]
-#                      tls/dhparam [Diffie-Hellman parameters]
-#                      hashlogs/hash_1*  [HashLogs of packet hashes
-#                               hash_2*    corresponding to key sets]
-#                                ...
-#                      stats.tmp [Cache of stats from latest period]
-#                log [Messages from the server]
-#                keys/identity.key [Long-lived identity PK]
-#                     key_0001/ServerDesc [Server descriptor]
-#                              mix.key [packet key]
-#                              mmtp.key [mmtp key]
-#                              mmtp.cert [mmtp key's x509 cert chain]
-#                              published [present if this desc is published]
-#                     key_0002/...
-#                conf/miniond.conf [configuration file]
-#                current-desc [Filename of current server descriptor.]
-#                stats [Log of server statistics]
-#                version [Version of homedir format.]
-
-# FFFF Support to put keys/queues in separate directories.
+## Directory layout:  
+#    ${BASEDIR}/current-desc [Filename of current server descriptor.]
+#               version      [Version of homedir format.]
+#
+#    WORKDIR defaults to ${BASEDIR}/work
+#    ${WORKDIR}/tls/dhparam       [Diffie-Hellman parameters]
+#               hashlogs/hash_1*  [HashLogs of packet hashes
+#                        hash_2*     corresponding to key sets]
+#                          ...
+#               stats.tmp         [Cache of stats from latest period]
+#
+#    QUEUEDIR defaults to ${WORKDIR}/queues
+#    ${QUEUEDIR}/incoming/        [Queue of received,unprocessed pkts]
+#                mix/             [Mix pool]
+#                outgoing/        [Packets for mmtp delivery]
+#                deliver/*/       [Messages for delivery via modules]
+#
+#    KEYDIR defaults to ${BASEDIR}/keys
+#    ${KEYDIR}/identity.key [Long-lived identity private key]
+#              key_0001/ServerDesc [Server descriptor]
+#                       mix.key [packet key]
+#                       mmtp.key [mmtp key]
+#                       mmtp.cert [mmtp key's x509 cert chain]
+#                       published [present if this desc is published]
+#              key_0002/...
+#
+#   LOGFILE defaults to ${BASEDIR}/log
+#   PIDFILE defaults to ${BASEDIR}/pid
+#   STATSFILE defaults to ${BASEDIR}/stats
 
 __all__ = [ 'MixminionServer' ]
 
@@ -840,7 +845,7 @@
 
         # This is the last possible moment to shut down the console log, so
         # we have to do it now.
-        mixminion.Common.LOG.configure(self.config, keepStderr=0)
+        mixminion.Common.LOG.configure(self.config, keepStderr=_ECHO_OPT)
         if self.config['Server'].get("Daemon",1):
             closeUnusedFDs()
 
@@ -985,8 +990,10 @@
     sys.stdout = sys.__stdout__ = LogStream("STDOUT", "WARN")
     sys.stderr = sys.__stderr__ = LogStream("STDERR", "WARN")
 
-# Global flag: has the user requested a quiet startui?
+# Global flag: has the user requested a quiet start?
 _QUIET_OPT = 0
+# Global flag: has the user requested that the console log be kept?
+_ECHO_OPT = 0
 
 def configFromServerArgs(cmd, args, usage):
     """Given cmd and args as passed to one of the entry commands,
@@ -995,6 +1002,7 @@
        Otherwise, find and parse the configuration file.
     """
     global _QUIET_OPT
+    global _ECHO_OPT
     options, args = getopt.getopt(args, "hQf:",
                                   ["help", "quiet", "config=",
                                    "daemon", "nodaemon", "echo", "severity="])
@@ -1019,19 +1027,18 @@
         elif o == '--daemon':
             forceDaemon = 1
         elif o == '--echo':
-            echo = 1
+            _ECHO_OPT = 1
         elif o == '--severity':
             try:
                 severity = mixminion.Config._parseSeverity(v)
             except mixminion.Config.ConfigError, e:
                 raise UIError(str(e))
 
-    #DOCDOC
     config = readConfigFile(configFile)
     if forceDaemon == 0 and not _QUIET_OPT:
-        echo = 1
-    if echo:
-        config['Server']['EchoMessages'] = 2#DOCDOC
+        # If we've been forced to use the console, go verbose as well, since
+        # people probably want that.
+        _ECHO_OPT = 1
     elif _QUIET_OPT:
         config['Server']['EchoMessages'] = 0
     if forceDaemon is not None:
@@ -1093,7 +1100,7 @@
     config = configFromServerArgs(cmd, args, _SERVER_START_USAGE)
     checkHomedirVersion(config)
     daemonMode = config['Server'].get("Daemon",1)
-    quiet = _QUIET_OPT or daemonMode
+    quiet = (_QUIET_OPT or daemonMode) and not _ECHO_OPT
     try:
         # Configure the log, but delay disabling stderr until the last
         # possible minute; we want to keep echoing to the terminal until