Remove the originated time from the DHT value storage.
[quix0rs-apt-p2p.git] / apt_dht / apt_dht_conf.py
1
2 import os, sys
3 from ConfigParser import SafeConfigParser
4
5 from twisted.python import log, versions
6
7 class ConfigError(Exception):
8     def __init__(self, message):
9         self.message = message
10     def __str__(self):
11         return repr(self.message)
12
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]))
19 DEFAULT_CONFIG_FILES=['/etc/apt-dht/apt-dht.conf',
20                       home + '/.apt-dht/apt-dht.conf']
21
22 DEFAULTS = {
23
24     # Port to listen on for all requests (TCP and UDP)
25     'PORT': '9977',
26     
27     # Directory to store the downloaded files in
28     'CACHE_DIR': home + '/.apt-dht/cache',
29     
30     # Other directories containing packages to share with others
31     # WARNING: all files in these directories will be hashed and available
32     #          for everybody to download
33     'OTHER_DIRS': """""",
34     
35     # User name to try and run as
36     'USERNAME': '',
37     
38     # Whether it's OK to use an IP addres from a known local/private range
39     'LOCAL_OK': 'no',
40
41     # Which DHT implementation to use.
42     # It must be possile to do "from <DHT>.DHT import DHT" to get a class that
43     # implements the IDHT interface.
44     'DHT': 'apt_dht_Khashmir',
45
46     # Whether to only run the DHT (for providing only a bootstrap node)
47     'DHT-ONLY': 'no',
48 }
49
50 DHT_DEFAULTS = {
51     # bootstrap nodes to contact to join the DHT
52     'BOOTSTRAP': """www.camrdale.org:9977
53         steveholt.hopto.org:9976""",
54     
55     # whether this node is a bootstrap node
56     'BOOTSTRAP_NODE': "no",
57     
58     # Kademlia "K" constant, this should be an even number
59     'K': '8',
60     
61     # SHA1 is 160 bits long
62     'HASH_LENGTH': '160',
63     
64     # checkpoint every this many seconds
65     'CHECKPOINT_INTERVAL': '15m', # fifteen minutes
66     
67     ### SEARCHING/STORING
68     # concurrent xmlrpc calls per find node/value request!
69     'CONCURRENT_REQS': '4',
70     
71     # how many hosts to post to
72     'STORE_REDUNDANCY': '3',
73     
74     ###  ROUTING TABLE STUFF
75     # how many times in a row a node can fail to respond before it's booted from the routing table
76     'MAX_FAILURES': '3',
77     
78     # never ping a node more often than this
79     'MIN_PING_INTERVAL': '15m', # fifteen minutes
80     
81     # refresh buckets that haven't been touched in this long
82     'BUCKET_STALENESS': '1h', # one hour
83     
84     ###  KEY EXPIRER
85     # time before expirer starts running
86     'KEINITIAL_DELAY': '15s', # 15 seconds - to clean out old stuff in persistent db
87     
88     # time between expirer runs
89     'KE_DELAY': '20m', # 20 minutes
90     
91     # expire entries older than this
92     'KE_AGE': '1h', # 60 minutes
93     
94     # whether to spew info about the requests/responses in the protocol
95     'SPEW': 'yes',
96 }
97
98 class AptDHTConfigParser(SafeConfigParser):
99     """
100     Adds 'gettime' to ConfigParser to interpret the suffixes.
101     """
102     time_multipliers={
103         's': 1,    #seconds
104         'm': 60,   #minutes
105         'h': 3600, #hours
106         'd': 86400,#days
107         }
108
109     def gettime(self, section, option):
110         mult = 1
111         value = self.get(section, option)
112         if len(value) == 0:
113             raise ConfigError("Configuration parse error: [%s] %s" % (section, option))
114         suffix = value[-1].lower()
115         if suffix in self.time_multipliers.keys():
116             mult = self.time_multipliers[suffix]
117             value = value[:-1]
118         return int(value)*mult
119     def getstring(self, section, option):
120         return self.get(section,option)
121     def getstringlist(self, section, option):
122         return self.get(section,option).split()
123     def optionxform(self, option):
124         return option.upper()
125
126 config = AptDHTConfigParser(DEFAULTS)
127 config.add_section(config.get('DEFAULT', 'DHT'))
128 for k in DHT_DEFAULTS:
129     config.set(config.get('DEFAULT', 'DHT'), k, DHT_DEFAULTS[k])