]> git.mxchange.org Git - quix0rs-apt-p2p.git/blob - apt_dht/apt_dht_conf.py
Added scanning of other directories for cached packages.
[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
20 DEFAULTS = {
21
22     # Port to listen on for all requests (TCP and UDP)
23     'PORT': '9977',
24     
25     # Directory to store the downloaded files in
26     'CACHE_DIR': home + '/.apt-dht/cache',
27     
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
31     'OTHER_DIRS': """""",
32     
33     # User name to try and run as
34     'USERNAME': '',
35
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',
40
41     # Whether to only run the DHT (for providing only a bootstrap node)
42     'DHT-ONLY': 'no',
43 }
44
45 DHT_DEFAULTS = {
46     # bootstrap nodes to contact to join the DHT
47     'BOOTSTRAP': """www.camrdale.org:9977
48         steveholt.hopto.org:9976""",
49     
50     # whether this node is a bootstrap node
51     'BOOTSTRAP_NODE': "no",
52     
53     # Kademlia "K" constant, this should be an even number
54     'K': '8',
55     
56     # SHA1 is 160 bits long
57     'HASH_LENGTH': '160',
58     
59     # checkpoint every this many seconds
60     'CHECKPOINT_INTERVAL': '15m', # fifteen minutes
61     
62     ### SEARCHING/STORING
63     # concurrent xmlrpc calls per find node/value request!
64     'CONCURRENT_REQS': '4',
65     
66     # how many hosts to post to
67     'STORE_REDUNDANCY': '3',
68     
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
71     'MAX_FAILURES': '3',
72     
73     # never ping a node more often than this
74     'MIN_PING_INTERVAL': '15m', # fifteen minutes
75     
76     # refresh buckets that haven't been touched in this long
77     'BUCKET_STALENESS': '1h', # one hour
78     
79     ###  KEY EXPIRER
80     # time before expirer starts running
81     'KEINITIAL_DELAY': '15s', # 15 seconds - to clean out old stuff in persistent db
82     
83     # time between expirer runs
84     'KE_DELAY': '20m', # 20 minutes
85     
86     # expire entries older than this
87     'KE_AGE': '1h', # 60 minutes
88     
89     # whether to spew info about the requests/responses in the protocol
90     'SPEW': 'yes',
91 }
92
93 class AptDHTConfigParser(SafeConfigParser):
94     """
95     Adds 'gettime' to ConfigParser to interpret the suffixes.
96     """
97     time_multipliers={
98         's': 1,    #seconds
99         'm': 60,   #minutes
100         'h': 3600, #hours
101         'd': 86400,#days
102         }
103
104     def gettime(self, section, option):
105         mult = 1
106         value = self.get(section, option)
107         if len(value) == 0:
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]
112             value = value[:-1]
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()
120
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])