From: Cameron Dale Date: Sun, 15 Jun 2008 01:12:26 +0000 (-0700) Subject: Use the version number in the Khashmir node ID. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=c14ca771c67c88699e7b4eb065d834976e4711ba;p=quix0rs-apt-p2p.git Use the version number in the Khashmir node ID. --- diff --git a/apt-p2p.py b/apt-p2p.py index 911dfce..8d69b06 100644 --- a/apt-p2p.py +++ b/apt-p2p.py @@ -16,7 +16,7 @@ from twisted.application import service, internet, app, strports from twisted.internet import reactor from twisted.python import usage, log -from apt_p2p.apt_p2p_conf import config, version, DEFAULT_CONFIG_FILES +from apt_p2p.apt_p2p_conf import config, version, versionID, DEFAULT_CONFIG_FILES from apt_p2p.interfaces import IDHT, IDHTStatsFactory config_file = '' @@ -53,6 +53,7 @@ if __name__ == '__main__': log.msg("Loading config files: '%s'" % "', '".join(DEFAULT_CONFIG_FILES + [config_file])) config_read = config.read(DEFAULT_CONFIG_FILES + [config_file]) +config.set(config.get('DEFAULT', 'DHT'), 'VERSION', versionID) log.msg("Successfully loaded config files: '%s'" % "', '".join(config_read)) try: uid,gid = pwd.getpwnam(config.get('DEFAULT', 'USERNAME'))[2:4] diff --git a/apt_p2p/apt_p2p_conf.py b/apt_p2p/apt_p2p_conf.py index 6b58c8f..3198be1 100644 --- a/apt_p2p/apt_p2p_conf.py +++ b/apt_p2p/apt_p2p_conf.py @@ -25,6 +25,18 @@ class ConfigError(Exception): version = versions.Version('apt-p2p', 0, 1, 3) +mapbase64 = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-' +versionID = 'A' +for subver in version.base().split('.', 2): + while type(subver) != int and len(subver) > 0: + try: + subver = int(subver) + except: + subver = subver[:-1] + if type(subver) != int or subver >= 64: + subver = 0 + versionID += mapbase64[subver] + # Set the home parameter home = os.path.expandvars('${HOME}') if home == '${HOME}' or not os.path.isdir(home): diff --git a/apt_p2p_Khashmir/DHT.py b/apt_p2p_Khashmir/DHT.py index ddcaa7a..dbaf683 100644 --- a/apt_p2p_Khashmir/DHT.py +++ b/apt_p2p_Khashmir/DHT.py @@ -332,7 +332,7 @@ class TestSimpleDHT(unittest.TestCase): """Simple 2-node unit tests for the DHT.""" timeout = 50 - DHT_DEFAULTS = {'PORT': 9977, + DHT_DEFAULTS = {'VERSION': 'A000', 'PORT': 9977, 'CHECKPOINT_INTERVAL': 300, 'CONCURRENT_REQS': 8, 'STORE_REDUNDANCY': 6, 'RETRIEVE_VALUES': -10000, 'MAX_FAILURES': 3, 'LOCAL_OK': True, @@ -453,7 +453,7 @@ class TestMultiDHT(unittest.TestCase): timeout = 200 num = 20 - DHT_DEFAULTS = {'PORT': 9977, + DHT_DEFAULTS = {'VERSION': 'A000', 'PORT': 9977, 'CHECKPOINT_INTERVAL': 300, 'CONCURRENT_REQS': 8, 'STORE_REDUNDANCY': 6, 'RETRIEVE_VALUES': -10000, 'MAX_FAILURES': 3, 'LOCAL_OK': True, diff --git a/apt_p2p_Khashmir/khashmir.py b/apt_p2p_Khashmir/khashmir.py index 394d75e..f711a6a 100644 --- a/apt_p2p_Khashmir/khashmir.py +++ b/apt_p2p_Khashmir/khashmir.py @@ -123,8 +123,8 @@ class KhashmirBase(protocol.Factory): def _loadSelfNode(self, host, port): """Create this node, loading any previously saved one.""" id = self.store.getSelfNode() - if not id: - id = newID() + if not id or not id.endswith(self.config['VERSION']): + id = newID(self.config['VERSION']) return self._Node(id, host, port) def checkpoint(self): @@ -368,9 +368,10 @@ class KhashmirBase(protocol.Factory): self.next_checkpoint.cancel() except: pass - for call in self.pinging: - if isinstance(call, DelayedCall) and call.active(): - call.cancel() + for nodeid in self.pinging.keys(): + if isinstance(self.pinging[nodeid], DelayedCall) and self.pinging[nodeid].active(): + self.pinging[nodeid].cancel() + del self.pinging[nodeid] self.store.close() def getStats(self): @@ -601,7 +602,7 @@ class Khashmir(KhashmirWrite): class SimpleTests(unittest.TestCase): timeout = 10 - DHT_DEFAULTS = {'PORT': 9977, + DHT_DEFAULTS = {'VERSION': 'A000', 'PORT': 9977, 'CHECKPOINT_INTERVAL': 300, 'CONCURRENT_REQS': 8, 'STORE_REDUNDANCY': 6, 'RETRIEVE_VALUES': -10000, 'MAX_FAILURES': 3, 'LOCAL_OK': True, @@ -693,7 +694,7 @@ class MultiTest(unittest.TestCase): timeout = 30 num = 20 - DHT_DEFAULTS = {'PORT': 9977, + DHT_DEFAULTS = {'VERSION': 'A000', 'PORT': 9977, 'CHECKPOINT_INTERVAL': 300, 'CONCURRENT_REQS': 8, 'STORE_REDUNDANCY': 6, 'RETRIEVE_VALUES': -10000, 'MAX_FAILURES': 3, 'LOCAL_OK': True,