def __init__(self, filename, historyFile, interval): """Initializes an EventLog that caches events in 'filename', and periodically writes to 'historyFile' every 'interval' seconds.""" NilEventLog.__init__(self) if os.path.exists(filename): self.__dict__.update(readPickled(filename)) assert self.count is not None assert self.lastRotation is not None assert self.accumulatedTime is not None for e in _EVENTS: if not self.count.has_key(e): self.count[e] = {} else: self.count = {} for e in _EVENTS: self.count[e] = {} self.lastRotation = time() self.accumulatedTime = 0 self.filename = filename self.historyFilename = historyFile for fn in filename, historyFile: parent = os.path.split(fn)[0] createPrivateDir(parent) self.rotateInterval = interval self.lastSave = time() self._setNextRotation() self._lock = RLock() self.save()
def rebuildIDCache(self): for fn in os.listdir(self.serverIDDir): fname = os.path.join(self.serverIDDir, fn) tp,val = readPickled(fname) if tp != "V0": LOG.warn("Weird file version %s on %s",tp,fname) continue nickname, ident = val ID = mixminion.Crypto.sha1(ident) self.idCache.insertID(nickname, ID)
def rebuildIDCache(self): for fn in os.listdir(self.serverIDDir): fname = os.path.join(self.serverIDDir, fn) tp, val = readPickled(fname) if tp != "V0": LOG.warn("Weird file version %s on %s", tp, fname) continue nickname, ident = val ID = mixminion.Crypto.sha1(ident) self.idCache.insertID(nickname, ID)
def rescan(self): """Reconstruct this ServerList object's internal state.""" try: self._lock() # First, build self.servers self.servers = {} for filename in os.listdir(self.serverDir): path = os.path.join(self.serverDir, filename) try: self.servers[filename] = ServerInfo(fname=path) except ConfigError, e: LOG.warn("Somehow, a bad server named %s got in our store", filename) LOG.warn(" (Error was: %s)", str(e)) _moveServer(self.serverDir, self.rejectDir, filename) # Next, rebuild self.serverIDs: self.serverIDs = {} for filename in os.listdir(self.serverIDDir): path = os.path.join(self.serverIDDir, filename) t = readPickled(path) if t[0] != 'V0': LOG.warn("Skipping confusing stored key in file %s", filename) continue nickname, key = t[1] key = pk_decode_public_key(key) if self.serverIDs.has_key(nickname.lower()): LOG.warn("Eeek! Multiple entries for %s", nickname) if not pk_same_public_key(self.serverIDs[nickname.lower()], key): raise MixFatalError( "Multiple conflicting entries for %s"%nickname) self.serverIDs[nickname.lower()] = key # (check for consistency) for s in self.servers.values(): lcn = s.getNickname().lower() try: ident = self.serverIDs[lcn] except KeyError: raise UIError("No stored key for server %s" % s.getNickname()) if not pk_same_public_key(ident, s.getIdentity()): raise UIError("Inconsistent stored key for server %s" % s.getNickname()) # Then, rebuild self.serversByNickname self.__buildNicknameMap()
def rescan(self): """Reconstruct this ServerList object's internal state.""" try: self._lock() # First, build self.servers self.servers = {} for filename in os.listdir(self.serverDir): path = os.path.join(self.serverDir, filename) try: self.servers[filename] = ServerInfo(fname=path) except ConfigError, e: LOG.warn("Somehow, a bad server named %s got in our store", filename) LOG.warn(" (Error was: %s)", str(e)) _moveServer(self.serverDir, self.rejectDir, filename) # Next, rebuild self.serverIDs: self.serverIDs = {} for filename in os.listdir(self.serverIDDir): path = os.path.join(self.serverIDDir, filename) t = readPickled(path) if t[0] != 'V0': LOG.warn("Skipping confusing stored key in file %s", filename) continue nickname, key = t[1] key = pk_decode_public_key(key) if self.serverIDs.has_key(nickname.lower()): LOG.warn("Eeek! Multiple entries for %s", nickname) if not pk_same_public_key(self.serverIDs[nickname.lower()], key): raise MixFatalError( "Multiple conflicting entries for %s" % nickname) self.serverIDs[nickname.lower()] = key # (check for consistency) for s in self.servers.values(): lcn = s.getNickname().lower() try: ident = self.serverIDs[lcn] except KeyError: raise UIError("No stored key for server %s" % s.getNickname()) if not pk_same_public_key(ident, s.getIdentity()): raise UIError("Inconsistent stored key for server %s" % s.getNickname()) # Then, rebuild self.serversByNickname self.__buildNicknameMap()