3 from ConfigParser import SafeConfigParser
5 from twisted.python import log, versions
7 class ConfigError(Exception):
8 def __init__(self, message):
11 return repr(self.message)
13 version = versions.Version('apt-dht', 0, 0, 0)
14 home = os.path.expandvars('${HOME}')
15 if home == '${HOME}' or not os.path.isdir(home):
16 home = os.path.expanduser('~')
17 if not os.path.isdir(home):
18 home = os.path.abspath(os.path.dirname(sys.argv[0]))
22 # Port to listen on for all requests (TCP and UDP)
25 # Directory to store the downloaded files in
26 'CACHE_DIR': home + '/.apt-dht/cache',
28 # User name to try and run as
31 # Which DHT implementation to use.
32 # It must be possile to do "from <DHT>.DHT import DHT" to get a class that
33 # implements the IDHT interface.
34 'DHT': 'apt_dht_Khashmir',
36 # Whether to only run the DHT (for providing a login node)
41 # bootstrap nodes to contact to join the DHT
42 'BOOTSTRAP': """www.camrdale.org:9977
43 steveholt.hopto.org:9977""",
45 # Kademlia "K" constant, this should be an even number
48 # SHA1 is 160 bits long
51 # checkpoint every this many seconds
52 'CHECKPOINT_INTERVAL': '15m', # fifteen minutes
55 # concurrent xmlrpc calls per find node/value request!
56 'CONCURRENT_REQS': '4',
58 # how many hosts to post to
59 'STORE_REDUNDANCY': '3',
61 ### ROUTING TABLE STUFF
62 # how many times in a row a node can fail to respond before it's booted from the routing table
65 # never ping a node more often than this
66 'MIN_PING_INTERVAL': '15m', # fifteen minutes
68 # refresh buckets that haven't been touched in this long
69 'BUCKET_STALENESS': '1h', # one hour
72 # time before expirer starts running
73 'KEINITIAL_DELAY': '15s', # 15 seconds - to clean out old stuff in persistent db
75 # time between expirer runs
76 'KE_DELAY': '20m', # 20 minutes
78 # expire entries older than this
79 'KE_AGE': '1h', # 60 minutes
82 class AptDHTConfigParser(SafeConfigParser):
84 Adds 'gettime' to ConfigParser to interpret the suffixes.
93 def gettime(self, section, option):
95 value = self.get(section, option)
97 raise ConfigError("Configuration parse error: [%s] %s" % (section, option))
98 suffix = value[-1].lower()
99 if suffix in self.time_multipliers.keys():
100 mult = self.time_multipliers[suffix]
102 return int(value)*mult
103 def getstring(self, section, option):
104 return self.get(section,option)
105 def getstringlist(self, section, option):
106 return self.get(section,option).split()
107 def optionxform(self, option):
108 return option.upper()
110 config = AptDHTConfigParser(DEFAULTS)
111 config.add_section(config.get('DEFAULT', 'DHT'))
112 for k in DHT_DEFAULTS:
113 config.set(config.get('DEFAULT', 'DHT'), k, DHT_DEFAULTS[k])