Skip to content

Commit

Permalink
Add Kademlia constants.
Browse files Browse the repository at this point in the history
  • Loading branch information
Renelvon committed May 17, 2015
1 parent b6adf2c commit 134cc38
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
46 changes: 46 additions & 0 deletions dht/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# ######## KADEMLIA CONSTANTS ###########

BIT_NODE_ID_LEN = 160
HEX_NODE_ID_LEN = BIT_NODE_ID_LEN // 4

# Small number representing the degree of
# parallelism in network calls
ALPHA = 3

# Maximum number of contacts stored in a bucket
# NOTE: Should be an even number.
K = 24 # pylint: disable=invalid-name

# Maximum number of contacts stored in the
# replacement cache of a bucket
# NOTE: Should be an even number.
CACHE_K = 32

# Timeout for network operations
# [seconds]
RPC_TIMEOUT = 0.1

# Delay between iterations of iterative node lookups
# (for loose parallelism)
# [seconds]
ITERATIVE_LOOKUP_DELAY = RPC_TIMEOUT / 2

# If a KBucket has not been used for this amount of time, refresh it.
# [seconds]
REFRESH_TIMEOUT = 60 * 60 * 1000 # 1 hour

# The interval in which the node should check whether any buckets
# need refreshing or whether any data needs to be republished
# [seconds]
CHECK_REFRESH_INTERVAL = REFRESH_TIMEOUT / 5

# The interval at which nodes replicate (republish/refresh)
# the data they hold
# [seconds]
REPLICATE_INTERVAL = REFRESH_TIMEOUT

# The time it takes for data to expire in the network;
# the original publisher of the data will also republish
# the data at this time if it is still valid
# [seconds]
DATE_EXPIRE_TIMEOUT = 86400 # 24 hours
6 changes: 3 additions & 3 deletions tests/dht/test_contact.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest

from dht import contact
from dht import constants, contact


class TestContact(unittest.TestCase):
Expand All @@ -9,8 +9,8 @@ class TestContact(unittest.TestCase):
"""
@classmethod
def setUpClass(cls):
cls.guid1 = '1' * 40
cls.guid2 = 'f' * 40
cls.guid1 = '1' * constants.HEX_NODE_ID_LEN
cls.guid2 = 'f' * constants.HEX_NODE_ID_LEN
cls.ipv4 = '123.45.67.89'
cls.ipv6 = '2001:db8:85a3::8a2e:370:7334'
cls.port1 = 12345
Expand Down

0 comments on commit 134cc38

Please sign in to comment.