Skip to content

Commit

Permalink
Expand and test constant names.
Browse files Browse the repository at this point in the history
* Purge exec flag from constants.py
* Define the maximum number of contacts per replacement cache.
* Define HEX_NODE_LEN_ID as the length of a node ID in hex.
  • Loading branch information
Renelvon committed Oct 10, 2014
1 parent 6ebca74 commit 19f73de
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
10 changes: 9 additions & 1 deletion node/constants.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
# ######## 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
# NOTE: Should be an even number.
k = 80

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

# Timeout for network operations
# [seconds]
rpcTimeout = 0.1
Expand Down
34 changes: 34 additions & 0 deletions test/test_constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import unittest

from node import constants


class TestConstants(unittest.TestCase):

def test_exported_names(self):
self.assertEqual(160, constants.BIT_NODE_ID_LEN)
self.assertEqual(
constants.BIT_NODE_ID_LEN // 4,
constants.HEX_NODE_ID_LEN
)
self.assertEqual(80, constants.k)
self.assertEqual(80, constants.cache_k)
self.assertEqual(0.1, constants.rpcTimeout)
self.assertEqual(86400, constants.dataExpireTimeout)
self.assertEqual(60 * 60 * 1000, constants.refreshTimeout)
self.assertEqual(
constants.rpcTimeout / 2,
constants.iterativeLookupDelay
)
self.assertEqual(constants.replicateInterval, constants.refreshTimeout)
self.assertEqual(
constants.refreshTimeout / 5,
constants.checkRefreshInterval
)
self.assertEqual(8192, constants.udpDatagramMaxSize)
self.assertEqual("db/ob.db", constants.DB_PATH)
self.assertEqual("0.2.1", constants.VERSION)


if __name__ == "__main__":
unittest.main()

0 comments on commit 19f73de

Please sign in to comment.