Use the version number in the Khashmir node ID.
authorCameron Dale <camrdale@gmail.com>
Sun, 15 Jun 2008 01:12:26 +0000 (18:12 -0700)
committerCameron Dale <camrdale@gmail.com>
Sun, 15 Jun 2008 01:12:26 +0000 (18:12 -0700)
apt-p2p.py
apt_p2p/apt_p2p_conf.py
apt_p2p_Khashmir/DHT.py
apt_p2p_Khashmir/khashmir.py

index 911dfce162bfd55d0cbc19097a77ee00a285a77a..8d69b06faee658b52c2fdade8455d0b85b634b15 100644 (file)
@@ -16,7 +16,7 @@ from twisted.application import service, internet, app, strports
 from twisted.internet import reactor
 from twisted.python import usage, log
 
 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 = ''
 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])
 
 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]
 log.msg("Successfully loaded config files: '%s'" % "', '".join(config_read))
 try:
     uid,gid = pwd.getpwnam(config.get('DEFAULT', 'USERNAME'))[2:4]
index 6b58c8fe68a37206a5f18d1ee1fe6126b2281192..3198be173223d5f978062e0cd4dff7146f683178 100644 (file)
@@ -25,6 +25,18 @@ class ConfigError(Exception):
 
 version = versions.Version('apt-p2p', 0, 1, 3)
 
 
 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):
 # Set the home parameter
 home = os.path.expandvars('${HOME}')
 if home == '${HOME}' or not os.path.isdir(home):
index ddcaa7ac0c304cac21988f4603be7fef7ccc212d..dbaf6836ec327c249fb2301c822efa7268f1ea90 100644 (file)
@@ -332,7 +332,7 @@ class TestSimpleDHT(unittest.TestCase):
     """Simple 2-node unit tests for the DHT."""
     
     timeout = 50
     """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,
                     '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
     
     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,
                     'CHECKPOINT_INTERVAL': 300, 'CONCURRENT_REQS': 8,
                     'STORE_REDUNDANCY': 6, 'RETRIEVE_VALUES': -10000,
                     'MAX_FAILURES': 3, 'LOCAL_OK': True,
index 394d75e42fa6af2188db8d07c10d6f8d0a63510c..f711a6a62a315964a339b03085d809079b0a2b6d 100644 (file)
@@ -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()
     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):
         return self._Node(id, host, port)
         
     def checkpoint(self):
@@ -368,9 +368,10 @@ class KhashmirBase(protocol.Factory):
             self.next_checkpoint.cancel()
         except:
             pass
             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):
         self.store.close()
     
     def getStats(self):
@@ -601,7 +602,7 @@ class Khashmir(KhashmirWrite):
 class SimpleTests(unittest.TestCase):
     
     timeout = 10
 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,
                     '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
     
     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,
                     'CHECKPOINT_INTERVAL': 300, 'CONCURRENT_REQS': 8,
                     'STORE_REDUNDANCY': 6, 'RETRIEVE_VALUES': -10000,
                     'MAX_FAILURES': 3, 'LOCAL_OK': True,