From 78829dcf0888613ee73f2ae473f534b22934c860 Mon Sep 17 00:00:00 2001 From: Zooko O'Whielacronx Date: Tue, 22 Apr 2008 12:28:18 -0700 Subject: [PATCH] key_generator: make default key size be a constructor argument instead of a class variable, pass default key size of 522 (the smallest that we can do) in unit tests to make them faster --- src/allmydata/key_generator.py | 12 ++++++------ src/allmydata/scripts/keygen.py | 3 +-- src/allmydata/test/test_keygen.py | 4 ++-- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/allmydata/key_generator.py b/src/allmydata/key_generator.py index fd9b096f..97f7b13e 100644 --- a/src/allmydata/key_generator.py +++ b/src/allmydata/key_generator.py @@ -14,15 +14,15 @@ from allmydata.interfaces import RIKeyGenerator class KeyGenerator(service.MultiService, foolscap.Referenceable): implements(RIKeyGenerator) - DEFAULT_KEY_SIZE = 2048 pool_size = 16 # no. keys to keep on hand in the pool pool_refresh_delay = 6 # no. sec to wait after a fetch before generating new keys verbose = False - def __init__(self): + def __init__(self, default_key_size=2048): service.MultiService.__init__(self) self.keypool = [] self.last_fetch = 0 + self.default_key_size = default_key_size def startService(self): self.timer = reactor.callLater(0, self.maybe_refill_pool) @@ -52,7 +52,7 @@ class KeyGenerator(service.MultiService, foolscap.Referenceable): if self.last_fetch + self.pool_refresh_delay < now: self.vlog('%s refilling pool' % (self,)) while len(self.keypool) < self.pool_size: - self.keypool.append(self.gen_key(self.DEFAULT_KEY_SIZE)) + self.keypool.append(self.gen_key(self.default_key_size)) else: self.vlog('%s not refilling pool' % (self,)) reactor.callLater(1, self.maybe_refill_pool) @@ -65,7 +65,7 @@ class KeyGenerator(service.MultiService, foolscap.Referenceable): def remote_get_rsa_key_pair(self, key_size): self.vlog('%s remote_get_key' % (self,)) - if key_size != self.DEFAULT_KEY_SIZE or not self.keypool: + if key_size != self.default_key_size or not self.keypool: key = self.gen_key(key_size) self.reset_timer() return key @@ -76,12 +76,12 @@ class KeyGenerator(service.MultiService, foolscap.Referenceable): class KeyGeneratorService(service.MultiService): furl_file = 'key_generator.furl' - def __init__(self, basedir='.', display_furl=True): + def __init__(self, basedir='.', display_furl=True, default_key_size=2048): service.MultiService.__init__(self) self.basedir = basedir self.tub = foolscap.Tub(certFile=os.path.join(self.basedir, 'key_generator.pem')) self.tub.setServiceParent(self) - self.key_generator = KeyGenerator() + self.key_generator = KeyGenerator(default_key_size=default_key_size) self.key_generator.setServiceParent(self) portnum = self.get_portnum() diff --git a/src/allmydata/scripts/keygen.py b/src/allmydata/scripts/keygen.py index f41e4956..c08422f9 100644 --- a/src/allmydata/scripts/keygen.py +++ b/src/allmydata/scripts/keygen.py @@ -14,9 +14,8 @@ keygen_tac = """ from allmydata import key_generator from twisted.application import service -k = key_generator.KeyGeneratorService() +k = key_generator.KeyGeneratorService(2048) #k.key_generator.verbose = False -#k.key_generator.DEFAULT_KEY_SIZE = 2048 #k.key_generator.pool_size = 16 #k.key_generator.pool_refresh_delay = 6 diff --git a/src/allmydata/test/test_keygen.py b/src/allmydata/test/test_keygen.py index a6f354d6..27ed94db 100644 --- a/src/allmydata/test/test_keygen.py +++ b/src/allmydata/test/test_keygen.py @@ -40,11 +40,11 @@ class KeyGenService(unittest.TestCase, testutil.PollMixin): return junk #print 'starting key generator service' - kgs = key_generator.KeyGeneratorService(display_furl=False) + keysize = 522 + kgs = key_generator.KeyGeneratorService(display_furl=False, default_key_size=keysize) kgs.key_generator.verbose = True kgs.setServiceParent(self.parent) kgs.key_generator.pool_size = 8 - keysize = kgs.key_generator.DEFAULT_KEY_SIZE def keypool_full(): return len(kgs.key_generator.keypool) == kgs.key_generator.pool_size -- 2.45.2