<commit_before># Copyright 2002-2003 <NAME>.  See LICENSE for licensing information.
# $Id: ServerMain.py,v 1.66 2003/06/02 17:54:57 nickm Exp $

"""mixminion.ServerMain

   The main loop and related functionality for a Mixminion server.

   See the "MixminionServer" class for more information about how it
   all works. """

#XXXX make usage messages have the same format.

## Directory layout:
#    MINION_HOME/work/queues/incoming/ [Queue of received,unprocessed pkts]
#                            mix/ [Mix pool]
#                            outgoing/ [Messages for mmtp delivery]
#                            deliver/mbox/ [DOCDOC]
#                            deliver/smtp/
#                            deliver/*/
#                      tls/dhparam [Diffie-Hellman parameters]
#                      hashlogs/hash_1*  [HashLogs of packet hashes
#                               hash_2*    corresponding to key sets]
#                                ...
#                      stats.tmp [DOCDOC]
#                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 [mmmtp key x509 cert]
#                              published [present if this desc is published]
#                     key_0002/...
#                conf/miniond.conf [configuration file]
#                current-desc
#                stats [DOCDOC]
#                version [DOCDOC]

# FFFF Support to put keys/queues in separate directories.


__all__ = [ 'MixminonServer' ]

import errno
import getopt
import os
import sys
import signal
import time
import threading
from types import *
# We pull this from mixminion.Common, just in case somebody still has
# a copy of the old "mixminion/server/Queue.py" (since renamed to
# ServerQueue.py)
from mixminion.Common import MessageQueue

import mixminion.Config
import mixminion.Crypto
import mixminion.server.MMTPServer
import mixminion.server.Modules
import mixminion.server.PacketHandler
import mixminion.server.ServerQueue
import mixminion.server.ServerConfig
import mixminion.server.ServerKeys
import mixminion.server.EventStats as EventStats

from bisect import insort
from mixminion.Common import LOG, LogStream, MixError, MixFatalError,\
     UIError, ceilDiv, createPrivateDir, formatBase64, formatTime, \
     installSIGCHLDHandler, Lockfile, readFile, secureDelete, waitForChildren,\
     writeFile

#DOCDOC
# For backward-incompatible changes only.
SERVER_HOMEDIR_VERSION = "1001"

def getHomedirVersion(config):
    homeDir = config['Server']['Homedir']
    versionFile = os.path.join(homeDir, "version")
    if not os.path.exists(homeDir):
        return None
    else:
        try:
            dirVersion = readFile(versionFile).strip()
        except (OSError, IOError), e:
            if e.errno == errno.ENOENT:
                # The file doesn't exist; the version must be '1000'.
                dirVersion = "1000"
            elif e.errno == errnoe.EACCES:
                raise UIError("You don't have permission to read %s"%
                              versionFile)
            else:
                raise UIError("Unexpected error while reading %s: %s",
                              versionFile, e)

    return dirVersion

def checkHomedirVersion(config):
    dirVersion = getHomedirVersion(config)

    if dirVersion is None:
        return None
    elif dirVersion != SERVER_HOMEDIR_VERSION:
        if float(dirVersion) < float(SERVER_HOMEDIR_VERSION):<commit_msg>fix typo in last bugfix<commit_after># Copyright 2002-2003 <NAME>.  See LICENSE for licensing information.
# $Id: ServerMain.py,v 1.67 2003/06/02 17:56:34 nickm Exp $

"""mixminion.ServerMain

   The main loop and related functionality for a Mixminion server.

   See the "MixminionServer" class for more information about how it
   all works. """

#XXXX make usage messages have the same format.

## Directory layout:
#    MINION_HOME/work/queues/incoming/ [Queue of received,unprocessed pkts]
#                            mix/ [Mix pool]
#                            outgoing/ [Messages for mmtp delivery]
#                            deliver/mbox/ [DOCDOC]
#                            deliver/smtp/
#                            deliver/*/
#                      tls/dhparam [Diffie-Hellman parameters]
#                      hashlogs/hash_1*  [HashLogs of packet hashes
#                               hash_2*    corresponding to key sets]
#                                ...
#                      stats.tmp [DOCDOC]
#                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 [mmmtp key x509 cert]
#                              published [present if this desc is published]
#                     key_0002/...
#                conf/miniond.conf [configuration file]
#                current-desc
#                stats [DOCDOC]
#                version [DOCDOC]

# FFFF Support to put keys/queues in separate directories.


__all__ = [ 'MixminonServer' ]

import errno
import getopt
import os
import sys
import signal
import time
import threading
from types import *
# We pull this from mixminion.Common, just in case somebody still has
# a copy of the old "mixminion/server/Queue.py" (since renamed to
# ServerQueue.py)
from mixminion.Common import MessageQueue

import mixminion.Config
import mixminion.Crypto
import mixminion.server.MMTPServer
import mixminion.server.Modules
import mixminion.server.PacketHandler
import mixminion.server.ServerQueue
import mixminion.server.ServerConfig
import mixminion.server.ServerKeys
import mixminion.server.EventStats as EventStats

from bisect import insort
from mixminion.Common import LOG, LogStream, MixError, MixFatalError,\
     UIError, ceilDiv, createPrivateDir, formatBase64, formatTime, \
     installSIGCHLDHandler, Lockfile, readFile, secureDelete, waitForChildren,\
     writeFile

#DOCDOC
# For backward-incompatible changes only.
SERVER_HOMEDIR_VERSION = "1001"

def getHomedirVersion(config):
    homeDir = config['Server']['Homedir']
    versionFile = os.path.join(homeDir, "version")
    if not os.path.exists(homeDir):
        return None
    else:
        try:
            dirVersion = readFile(versionFile).strip()
        except (OSError, IOError), e:
            if e.errno == errno.ENOENT:
                # The file doesn't exist; the version must be '1000'.
                dirVersion = "1000"
            elif e.errno == errnoe.EACCES:
                raise UIError("You don't have permission to read %s"%
                              versionFile)
            else:
                raise UIError("Unexpected error while reading %s: %s"%(
                              versionFile, e))

    return dirVersion

def checkHomedirVersion(config):
    dirVersion = getHomedirVersion(config)

    if dirVersion is None:
        return None
    elif dirVersion != SERVER_HOMEDIR_VERSION:
        if float(dirVersion) < float(SERVER_HOMEDIR_VERSION):
{'fraction_non_alphanumeric': 0.07774140752864157, 'fraction_numerical': 0.014184397163120567, 'mean_word_length': 1.9894007337953525, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7538188', 'n_tokens_mistral': 2102, 'n_tokens_neox': 1955, 'n_words': 593}