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 = ''
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]
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):
"""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,
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,
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):
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):
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,
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,