Parcourir la source

[1288] a small cleanup: check xfrout quota before doing other checks
in _check_xfrout_available().

JINMEI Tatuya il y a 13 ans
Parent
commit
0b9c1b299f
2 fichiers modifiés avec 11 ajouts et 2 suppressions
  1. 2 0
      src/bin/xfrout/tests/xfrout_test.py.in
  2. 9 2
      src/bin/xfrout/xfrout.py.in

+ 2 - 0
src/bin/xfrout/tests/xfrout_test.py.in

@@ -82,6 +82,8 @@ class Dbserver:
         self._shutdown_event = threading.Event()
     def get_db_file(self):
         return None
+    def increase_transfers_counter(self):
+        return True
     def decrease_transfers_counter(self):
         pass
 

+ 9 - 2
src/bin/xfrout/xfrout.py.in

@@ -264,6 +264,12 @@ class XfroutSession():
            TODO, Get zone's configuration from cfgmgr or some other place
            eg. check allow_transfer setting,
         '''
+
+        # Reject the attempt if we are too busy.  Check this first to avoid
+        # unnecessary resource consumption even if we discard it soon.
+        if not self._server.increase_transfers_counter():
+            return Rcode.REFUSED()
+
         # If the current name server does not have authority for the
         # zone, xfrout can't serve for it, return rcode NOTAUTH.
         if not self._zone_exist(zone_name):
@@ -276,8 +282,6 @@ class XfroutSession():
             return Rcode.SERVFAIL()
 
         #TODO, check allow_transfer
-        if not self._server.increase_transfers_counter():
-            return Rcode.REFUSED()
 
         return Rcode.NOERROR()
 
@@ -536,6 +540,9 @@ class UnixSockServer(socketserver_mixin.NoPollMixIn,
     def finish_request(self, sock_fd, request_data):
         '''Finish one request by instantiating RequestHandlerClass.
 
+        This is an entry point of a separate thread spawned in
+        UnixSockServer.process_request().
+
         This method creates a XfroutSession object.
         '''
         self._lock.acquire()