George Notaras avatar George Notaras committed abe58ba

CLOSED #229: Add delay feature to hashing backends
http://www.codetrax.org/issues/show/229

Comments (0)

Files changed (2)

etc/tinyids.conf.default

 #Default test names are: binhash
 tests =
 
+# Hashing delay. This is the time in milliseconds tinyids should wait between
+# two consequent hashing operations. This feature exists in order to reduce
+# the disk I/O operations per second.
+hashing_delay = 10
+
 #
 # Remote Servers Section
 #

src/TinyIDS/client.py

 import glob
 import socket
 import getpass
+import time
 
 import TinyIDS.backends
 from TinyIDS import config
         self.hasher = sha1()
         self.cfg = config.get_client_configuration()
         
+        # Default hashing delay
+        self.default_hashing_delay = self._get_hashing_delay()
+        
         # PKI Module
         _keys_dir = self.cfg.get('main', 'keys_dir')
         self.pki = crypto.RSAModule(_keys_dir)
         self.sock = None
         self.server_name = None
     
+    def _get_hashing_delay(self):
+        """Returns the hashing delay in seconds."""
+        delay_msec = self.default_hashing_delay = self.cfg.getfloat('main', 'hashing_delay')
+        delay_sec = delay_msec / 1000
+        logger.debug('Hashing delay set to %.3f seconds' % delay_sec)
+        return delay_sec
         
     def _run_checks(self):
         backends = []
     
     def hash_data(self, data):
         self.hasher.update(data)
+        time.sleep(self.default_hashing_delay)
     
     def run(self):
         """Main client method."""
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.