From: Cameron Dale Date: Fri, 22 Feb 2008 19:33:50 +0000 (-0800) Subject: Move the key expiring to the checkpoint function. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=1fb0d1714e1b0af6dc6abb8adc75a9e31f77fa29;p=quix0rs-apt-p2p.git Move the key expiring to the checkpoint function. --- diff --git a/apt-dht.conf b/apt-dht.conf index 7f42e4d..709a0d3 100644 --- a/apt-dht.conf +++ b/apt-dht.conf @@ -82,14 +82,8 @@ MIN_PING_INTERVAL = 15m # refresh buckets that haven't been touched in this long BUCKET_STALENESS = 1h -# time before expirer starts running -KEINITIAL_DELAY = 15s - -# time between expirer runs -KE_DELAY = 20m - -# expire entries older than this -KE_AGE = 1h +# expire unrefreshed entries older than this +KEY_EXPIRE = 1h # whether to spew info about the requests/responses in the protocol SPEW = no diff --git a/apt_dht/apt_dht_conf.py b/apt_dht/apt_dht_conf.py index 16f10c1..931d46c 100644 --- a/apt_dht/apt_dht_conf.py +++ b/apt_dht/apt_dht_conf.py @@ -86,15 +86,8 @@ DHT_DEFAULTS = { # refresh buckets that haven't been touched in this long 'BUCKET_STALENESS': '1h', # one hour - ### KEY EXPIRER - # time before expirer starts running - 'KEINITIAL_DELAY': '15s', # 15 seconds - to clean out old stuff in persistent db - - # time between expirer runs - 'KE_DELAY': '20m', # 20 minutes - # expire entries older than this - 'KE_AGE': '1h', # 60 minutes + 'KEY_EXPIRE': '1h', # 60 minutes # whether to spew info about the requests/responses in the protocol 'SPEW': 'yes', diff --git a/apt_dht_Khashmir/DHT.py b/apt_dht_Khashmir/DHT.py index e62f304..ab206d2 100644 --- a/apt_dht_Khashmir/DHT.py +++ b/apt_dht_Khashmir/DHT.py @@ -49,7 +49,7 @@ class DHT: 'MAX_FAILURES', 'PORT']: self.config[k] = self.config_parser.getint(section, k) elif k in ['CHECKPOINT_INTERVAL', 'MIN_PING_INTERVAL', - 'BUCKET_STALENESS', 'KEINITIAL_DELAY', 'KE_DELAY', 'KE_AGE']: + 'BUCKET_STALENESS', 'KEY_EXPIRE']: self.config[k] = self.config_parser.gettime(section, k) elif k in ['SPEW']: self.config[k] = self.config_parser.getboolean(section, k) @@ -186,8 +186,7 @@ class TestSimpleDHT(unittest.TestCase): 'CHECKPOINT_INTERVAL': 300, 'CONCURRENT_REQS': 4, 'STORE_REDUNDANCY': 3, 'MAX_FAILURES': 3, 'MIN_PING_INTERVAL': 900,'BUCKET_STALENESS': 3600, - 'KEINITIAL_DELAY': 15, 'KE_DELAY': 1200, - 'KE_AGE': 3600, 'SPEW': False, } + 'KEY_EXPIRE': 3600, 'SPEW': False, } def setUp(self): self.a = DHT() @@ -279,8 +278,7 @@ class TestMultiDHT(unittest.TestCase): 'CHECKPOINT_INTERVAL': 300, 'CONCURRENT_REQS': 4, 'STORE_REDUNDANCY': 3, 'MAX_FAILURES': 3, 'MIN_PING_INTERVAL': 900,'BUCKET_STALENESS': 3600, - 'KEINITIAL_DELAY': 15, 'KE_DELAY': 1200, - 'KE_AGE': 3600, 'SPEW': False, } + 'KEY_EXPIRE': 3600, 'SPEW': False, } def setUp(self): self.l = [] diff --git a/apt_dht_Khashmir/actions.py b/apt_dht_Khashmir/actions.py index 7822579..05349d4 100644 --- a/apt_dht_Khashmir/actions.py +++ b/apt_dht_Khashmir/actions.py @@ -236,20 +236,3 @@ class StoreValue(ActionBase): self.nodes = nodes self.nodes.sort(self.sort) self.schedule() - - -class KeyExpirer: - def __init__(self, store, config): - self.store = store - self.config = config - self.next_expire = reactor.callLater(self.config['KEINITIAL_DELAY'], self.doExpire) - - def doExpire(self): - self.store.expireValues(self.config['KE_AGE']) - self.next_expire = reactor.callLater(self.config['KE_DELAY'], self.doExpire) - - def shutdown(self): - try: - self.next_expire.cancel() - except: - pass diff --git a/apt_dht_Khashmir/khashmir.py b/apt_dht_Khashmir/khashmir.py index d3479e6..a9a7867 100644 --- a/apt_dht_Khashmir/khashmir.py +++ b/apt_dht_Khashmir/khashmir.py @@ -17,7 +17,7 @@ from db import DB from ktable import KTable from knode import KNodeBase, KNodeRead, KNodeWrite, NULL_ID from khash import newID, newIDInRange -from actions import FindNode, GetValue, KeyExpirer, StoreValue +from actions import FindNode, GetValue, StoreValue import krpc # this is the base class, has base functionality and find node, no key-value mappings @@ -39,7 +39,6 @@ class KhashmirBase(protocol.Factory): self.udp.protocol = krpc.KRPC self.listenport = reactor.listenUDP(self.port, self.udp) self._loadRoutingTable() - self.expirer = KeyExpirer(self.store, config) self.refreshTable(force=1) self.next_checkpoint = reactor.callLater(60, self.checkpoint, (1,)) @@ -65,6 +64,7 @@ class KhashmirBase(protocol.Factory): self.token_secrets.pop() self.store.saveSelfNode(self.node.id) self.store.dumpRoutingTable(self.table.buckets) + self.store.expireValues(self.config['KEY_EXPIRE']) self.refreshTable() if auto: self.next_checkpoint = reactor.callLater(randrange(int(self.config['CHECKPOINT_INTERVAL'] * .9), @@ -196,7 +196,6 @@ class KhashmirBase(protocol.Factory): self.next_checkpoint.cancel() except: pass - self.expirer.shutdown() self.store.close() #### Remote Interface - called by remote nodes @@ -301,8 +300,7 @@ class SimpleTests(unittest.TestCase): 'CHECKPOINT_INTERVAL': 300, 'CONCURRENT_REQS': 4, 'STORE_REDUNDANCY': 3, 'MAX_FAILURES': 3, 'MIN_PING_INTERVAL': 900,'BUCKET_STALENESS': 3600, - 'KEINITIAL_DELAY': 15, 'KE_DELAY': 1200, - 'KE_AGE': 3600, 'SPEW': False, } + 'KEY_EXPIRE': 3600, 'SPEW': False, } def setUp(self): krpc.KRPC.noisy = 0 @@ -375,8 +373,7 @@ class MultiTest(unittest.TestCase): 'CHECKPOINT_INTERVAL': 300, 'CONCURRENT_REQS': 4, 'STORE_REDUNDANCY': 3, 'MAX_FAILURES': 3, 'MIN_PING_INTERVAL': 900,'BUCKET_STALENESS': 3600, - 'KEINITIAL_DELAY': 15, 'KE_DELAY': 1200, - 'KE_AGE': 3600, 'SPEW': False, } + 'KEY_EXPIRE': 3600, 'SPEW': False, } def _done(self, val): self.done = 1 diff --git a/debian/apt-dht.conf.sgml b/debian/apt-dht.conf.sgml index 6b7762d..b481193 100644 --- a/debian/apt-dht.conf.sgml +++ b/debian/apt-dht.conf.sgml @@ -227,21 +227,7 @@ - - - The time to wait after startup before starting the key expirer. - (Default is 15 seconds.) - - - - - - The time to wait between runs of the key expirer. - (Default is 20 minutes.) - - - - + The time to wait before expiring unrefreshed keys. (Default is 1 hour.) diff --git a/test.py b/test.py index cfac85b..66f0fc6 100755 --- a/test.py +++ b/test.py @@ -376,14 +376,8 @@ MIN_PING_INTERVAL = 15m # refresh buckets that haven't been touched in this long BUCKET_STALENESS = 1h -# time before expirer starts running -KEINITIAL_DELAY = 15s - -# time between expirer runs -KE_DELAY = 20m - # expire entries older than this -KE_AGE = 1h +KEY_EXPIRE = 1h # whether to spew info about the requests/responses in the protocol SPEW = yes