'KRPC_TIMEOUT', 'KRPC_INITIAL_DELAY']:
self.config[k] = self.config_parser.gettime(section, k)
# The booleans in the config file
- elif k in ['SPEW']:
+ elif k in ['SPEW', 'LOCAL_OK']:
self.config[k] = self.config_parser.getboolean(section, k)
# Everything else is a string
else:
DHT_DEFAULTS = {'PORT': 9977,
'CHECKPOINT_INTERVAL': 300, 'CONCURRENT_REQS': 4,
'STORE_REDUNDANCY': 3, 'RETRIEVE_VALUES': -10000,
- 'MAX_FAILURES': 3,
+ 'MAX_FAILURES': 3, 'LOCAL_OK': True,
'MIN_PING_INTERVAL': 900,'BUCKET_STALENESS': 3600,
'KRPC_TIMEOUT': 14, 'KRPC_INITIAL_DELAY': 2,
'KEY_EXPIRE': 3600, 'SPEW': False, }
DHT_DEFAULTS = {'PORT': 9977,
'CHECKPOINT_INTERVAL': 300, 'CONCURRENT_REQS': 4,
'STORE_REDUNDANCY': 3, 'RETRIEVE_VALUES': -10000,
- 'MAX_FAILURES': 3,
+ 'MAX_FAILURES': 3, 'LOCAL_OK': True,
'MIN_PING_INTERVAL': 900,'BUCKET_STALENESS': 3600,
'KRPC_TIMEOUT': 14, 'KRPC_INITIAL_DELAY': 2,
'KEY_EXPIRE': 3600, 'SPEW': False, }
-"""The main Khashmir program."""
+"""The main Khashmir program.
+
+@var isLocal: a compiled regular expression suitable for testing if an
+ IP address is from a known local or private range
+"""
import warnings
warnings.simplefilter("ignore", DeprecationWarning)
from random import randrange, shuffle
from sha import sha
from copy import copy
-import os
+import os, re
from twisted.internet.defer import Deferred
from twisted.internet import protocol, reactor
from stats import StatsLogger
import krpc
+isLocal = re.compile('^(192\.168\.[0-9]{1,3}\.[0-9]{1,3})|'+
+ '(10\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})|'+
+ '(172\.0?([1][6-9])|([2][0-9])|([3][0-1])\.[0-9]{1,3}\.[0-9]{1,3})|'+
+ '(127\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})$')
+
class KhashmirBase(protocol.Factory):
"""The base Khashmir class, with base functionality and find node, no key-value mappings.
@param contacted: whether the new node is known to be good, i.e.
responded to a request (optional, defaults to True)
"""
+ # Don't add any local nodes to the routing table
+ if not self.config['LOCAL_OK'] and isLocal.match(node.host):
+ return
+
old = self.table.insertNode(node, contacted=contacted)
if (old and old.id != self.node.id and
(datetime.now() - old.lastSeen) >
DHT_DEFAULTS = {'PORT': 9977,
'CHECKPOINT_INTERVAL': 300, 'CONCURRENT_REQS': 4,
'STORE_REDUNDANCY': 3, 'RETRIEVE_VALUES': -10000,
- 'MAX_FAILURES': 3,
+ 'MAX_FAILURES': 3, 'LOCAL_OK': True,
'MIN_PING_INTERVAL': 900,'BUCKET_STALENESS': 3600,
'KRPC_TIMEOUT': 14, 'KRPC_INITIAL_DELAY': 2,
'KEY_EXPIRE': 3600, 'SPEW': False, }
DHT_DEFAULTS = {'PORT': 9977,
'CHECKPOINT_INTERVAL': 300, 'CONCURRENT_REQS': 4,
'STORE_REDUNDANCY': 3, 'RETRIEVE_VALUES': -10000,
- 'MAX_FAILURES': 3,
+ 'MAX_FAILURES': 3, 'LOCAL_OK': True,
'MIN_PING_INTERVAL': 900,'BUCKET_STALENESS': 3600,
'KRPC_TIMEOUT': 14, 'KRPC_INITIAL_DELAY': 2,
'KEY_EXPIRE': 3600, 'SPEW': False, }
<varlistentry>
<term><option>LOCAL_OK = <replaceable>boolean</replaceable></option></term>
<listitem>
- <para>Whether it's OK to use an IP addres from a known local or private range.
+ <para>Whether it's OK to use an IP address from a known local or private range.
(Default is false)</para>
</listitem>
</varlistentry>
(Default is 1 hour.)</para>
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>LOCAL_OK = <replaceable>boolean</replaceable></option></term>
+ <listitem>
+ <para>Whether it's OK to add nodes to the routing table that use an IP address
+ from a known local or private range.
+ (Default is to use the value specified in the DEFAULT section.)</para>
+ </listitem>
+ </varlistentry>
<varlistentry>
<term><option>KEY_EXPIRE = <replaceable>time</replaceable></option></term>
<listitem>