commit 4c483d5bedba1d74795048d54b0f3eebd21d07d4 Author: Darius Bacon darius@wry.me Date: Fri Mar 28 11:24:44 2014 -0700
Load the bouncer file just once. The previous code read it twice, which could create inconsistent datastructures if the file got edited at the wrong time. --- oonib/bouncer/handlers.py | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-)
diff --git a/oonib/bouncer/handlers.py b/oonib/bouncer/handlers.py index 0ff103e..2c7a1fe 100644 --- a/oonib/bouncer/handlers.py +++ b/oonib/bouncer/handlers.py @@ -7,33 +7,31 @@ from oonib.config import config
class Bouncer(object): def __init__(self): - self.knownHelpers = {} - self.updateKnownHelpers() - self.updateKnownCollectors() + with open(config.main.bouncer_file) as f: + bouncerFile = yaml.safe_load(f) + self.updateKnownHelpers(bouncerFile) + self.updateKnownCollectors(bouncerFile)
- def updateKnownCollectors(self): + def updateKnownCollectors(self, bouncerFile): """ - Returns the list of all known collectors + Initialize the list of all known collectors """ self.knownCollectors = [] - with open(config.main.bouncer_file) as f: - bouncerFile = yaml.safe_load(f) - for collectorName, helpers in bouncerFile['collector'].items(): - if collectorName not in self.knownCollectors: - self.knownCollectors.append(collectorName) + for collectorName, helpers in bouncerFile['collector'].items(): + if collectorName not in self.knownCollectors: + self.knownCollectors.append(collectorName)
- def updateKnownHelpers(self): - with open(config.main.bouncer_file) as f: - bouncerFile = yaml.safe_load(f) - for collectorName, helpers in bouncerFile['collector'].items(): - for helperName, helperAddress in helpers['test-helper'].items(): - if helperName not in self.knownHelpers.keys(): - self.knownHelpers[helperName] = [] - - self.knownHelpers[helperName].append({ - 'collector-name': collectorName, - 'helper-address': helperAddress - }) + def updateKnownHelpers(self, bouncerFile): + self.knownHelpers = {} + for collectorName, helpers in bouncerFile['collector'].items(): + for helperName, helperAddress in helpers['test-helper'].items(): + if helperName not in self.knownHelpers.keys(): + self.knownHelpers[helperName] = [] + + self.knownHelpers[helperName].append({ + 'collector-name': collectorName, + 'helper-address': helperAddress + })
def getHelperAddresses(self, helper_name): """
tor-commits@lists.torproject.org