[tor-commits] [oonib/master] 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.

art at torproject.org art at torproject.org
Wed Apr 23 14:31:51 UTC 2014


commit afb5dd4da67a684ba3f5630a8a9945592c56b221
Author: Darius Bacon <darius at 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):
         """





More information about the tor-commits mailing list