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
36 # magic id to use before we know a peer's id
39 # Kademlia "K" constant, this should be an even number
42 # SHA1 is 160 bits long
45 # checkpoint every this many seconds
46 'CHECKPOINT_INTERVAL': '15m', # fifteen minutes
49 # concurrent xmlrpc calls per find node/value request!
50 'CONCURRENT_REQS': '4',
52 # how many hosts to post to
53 'STORE_REDUNDANCY': '3',
55 ### ROUTING TABLE STUFF
56 # how many times in a row a node can fail to respond before it's booted from the routing table
59 # never ping a node more often than this
60 'MIN_PING_INTERVAL': '15m', # fifteen minutes
62 # refresh buckets that haven't been touched in this long
63 'BUCKET_STALENESS': '1h', # one hour
66 # time before expirer starts running
67 'KEINITIAL_DELAY': '15s', # 15 seconds - to clean out old stuff in persistent db
69 # time between expirer runs
70 'KE_DELAY': '20m', # 20 minutes
72 # expire entries older than this
73 'KE_AGE': '1h', # 60 minutes
76 class AptDHTConfigParser(SafeConfigParser):
78 Adds 'gettime' to ConfigParser to interpret the suffixes.
87 def gettime(self, section, option):
89 value = self.get(section, option)
91 raise ConfigError("Configuration parse error: [%s] %s" % (section, option))
92 suffix = value[-1].lower()
93 if suffix in self.time_multipliers.keys():
94 mult = self.time_multipliers[suffix]
96 return int(value)*mult
97 def getstring(self, section, option):
98 return self.get(section,option)
99 def getstringlist(self, section, option):
100 return self.get(section,option).split()
102 config = AptDHTConfigParser(DEFAULTS)
103 config.add_section(config.get('DEFAULT', 'DHT'))
104 for k in DHT_DEFAULTS:
105 config.set(config.get('DEFAULT', 'DHT'), k, DHT_DEFAULTS[k])