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 # Other directories containing packages to share with others
29 # WARNING: all files in these directories will be hashed and available
30 # for everybody to download
33 # User name to try and run as
36 # Which DHT implementation to use.
37 # It must be possile to do "from <DHT>.DHT import DHT" to get a class that
38 # implements the IDHT interface.
39 'DHT': 'apt_dht_Khashmir',
41 # Whether to only run the DHT (for providing only a bootstrap node)
46 # bootstrap nodes to contact to join the DHT
47 'BOOTSTRAP': """www.camrdale.org:9977
48 steveholt.hopto.org:9976""",
50 # whether this node is a bootstrap node
51 'BOOTSTRAP_NODE': "no",
53 # Kademlia "K" constant, this should be an even number
56 # SHA1 is 160 bits long
59 # checkpoint every this many seconds
60 'CHECKPOINT_INTERVAL': '15m', # fifteen minutes
63 # concurrent xmlrpc calls per find node/value request!
64 'CONCURRENT_REQS': '4',
66 # how many hosts to post to
67 'STORE_REDUNDANCY': '3',
69 ### ROUTING TABLE STUFF
70 # how many times in a row a node can fail to respond before it's booted from the routing table
73 # never ping a node more often than this
74 'MIN_PING_INTERVAL': '15m', # fifteen minutes
76 # refresh buckets that haven't been touched in this long
77 'BUCKET_STALENESS': '1h', # one hour
80 # time before expirer starts running
81 'KEINITIAL_DELAY': '15s', # 15 seconds - to clean out old stuff in persistent db
83 # time between expirer runs
84 'KE_DELAY': '20m', # 20 minutes
86 # expire entries older than this
87 'KE_AGE': '1h', # 60 minutes
89 # whether to spew info about the requests/responses in the protocol
93 class AptDHTConfigParser(SafeConfigParser):
95 Adds 'gettime' to ConfigParser to interpret the suffixes.
104 def gettime(self, section, option):
106 value = self.get(section, option)
108 raise ConfigError("Configuration parse error: [%s] %s" % (section, option))
109 suffix = value[-1].lower()
110 if suffix in self.time_multipliers.keys():
111 mult = self.time_multipliers[suffix]
113 return int(value)*mult
114 def getstring(self, section, option):
115 return self.get(section,option)
116 def getstringlist(self, section, option):
117 return self.get(section,option).split()
118 def optionxform(self, option):
119 return option.upper()
121 config = AptDHTConfigParser(DEFAULTS)
122 config.add_section(config.get('DEFAULT', 'DHT'))
123 for k in DHT_DEFAULTS:
124 config.set(config.get('DEFAULT', 'DHT'), k, DHT_DEFAULTS[k])