File tree Expand file tree Collapse file tree 5 files changed +32
-17
lines changed Expand file tree Collapse file tree 5 files changed +32
-17
lines changed Original file line number Diff line number Diff line change
1
+ from libp2p .custom_types import (
2
+ TProtocol ,
3
+ )
4
+
5
+ # Constants for the Kademlia algorithm
6
+ ALPHA = 3 # Concurrency parameter
7
+ PROTOCOL_ID = TProtocol ("/ipfs/kad/1.0.0" )
8
+ QUERY_TIMEOUT = 10
9
+
10
+ TTL = DEFAULT_TTL = 24 * 60 * 60 # 24 hours in seconds
Original file line number Diff line number Diff line change 49
49
from .value_store import (
50
50
ValueStore ,
51
51
)
52
+ from .common import (
53
+ PROTOCOL_ID ,
54
+ ALPHA ,
55
+ QUERY_TIMEOUT
56
+ )
52
57
53
58
logger = logging .getLogger ("kademlia-example.kad_dht" )
54
59
# logger = logging.getLogger("libp2p.kademlia")
55
60
# Default parameters
56
- PROTOCOL_ID = TProtocol ("/ipfs/kad/1.0.0" )
57
- ROUTING_TABLE_REFRESH_INTERVAL = 1 * 60 # 1 min in seconds for testing
58
- TTL = 24 * 60 * 60 # 24 hours in seconds
59
- ALPHA = 3
60
- QUERY_TIMEOUT = 10 # seconds
61
-
61
+ ROUTING_TABLE_REFRESH_INTERVAL = 60 # 1 min in seconds for testing
62
62
63
63
class DHTMode (Enum ):
64
64
"""DHT operation modes."""
Original file line number Diff line number Diff line change 25
25
PeerInfo ,
26
26
)
27
27
28
+
28
29
from .pb .kademlia_pb2 import (
29
30
Message ,
30
31
)
31
32
from .routing_table import (
32
33
RoutingTable ,
33
34
)
35
+ from .common import (
36
+ PROTOCOL_ID ,
37
+ ALPHA
38
+ )
34
39
from .utils import (
35
40
sort_peer_ids_by_distance ,
36
41
)
37
42
38
43
# logger = logging.getLogger("libp2p.kademlia.peer_routing")
39
44
logger = logging .getLogger ("kademlia-example.peer_routing" )
40
45
41
- # Constants for the Kademlia algorithm
42
- ALPHA = 3 # Concurrency parameter
43
46
MAX_PEER_LOOKUP_ROUNDS = 20 # Maximum number of rounds in peer lookup
44
- PROTOCOL_ID = TProtocol ("/ipfs/kad/1.0.0" )
45
47
46
48
47
49
class PeerRouting (IPeerRouting ):
Original file line number Diff line number Diff line change 33
33
Message ,
34
34
)
35
35
36
+ from .common import (
37
+ PROTOCOL_ID ,
38
+ ALPHA ,
39
+ QUERY_TIMEOUT
40
+ )
41
+
36
42
# logger = logging.getLogger("libp2p.kademlia.provider_store")
37
43
logger = logging .getLogger ("kademlia-example.provider_store" )
38
44
39
45
# Constants for provider records (based on IPFS standards)
40
46
PROVIDER_RECORD_REPUBLISH_INTERVAL = 22 * 60 * 60 # 22 hours in seconds
41
47
PROVIDER_RECORD_EXPIRATION_INTERVAL = 48 * 60 * 60 # 48 hours in seconds
42
48
PROVIDER_ADDRESS_TTL = 30 * 60 # 30 minutes in seconds
43
- PROTOCOL_ID = TProtocol ("/ipfs/kad/1.0.0" )
44
- ALPHA = 3 # Number of parallel queries/advertisements
45
- QUERY_TIMEOUT = 10 # Timeout for each query in seconds
46
49
47
50
48
51
class ProviderRecord :
Original file line number Diff line number Diff line change 23
23
Message ,
24
24
)
25
25
26
+ from .common import (
27
+ PROTOCOL_ID ,
28
+ DEFAULT_TTL
29
+ )
30
+
26
31
# logger = logging.getLogger("libp2p.kademlia.value_store")
27
32
logger = logging .getLogger ("kademlia-example.value_store" )
28
33
29
- # Default time to live for values in seconds (24 hours)
30
- DEFAULT_TTL = 24 * 60 * 60
31
- PROTOCOL_ID = TProtocol ("/ipfs/kad/1.0.0" )
32
-
33
-
34
34
class ValueStore :
35
35
"""
36
36
Store for key-value pairs in a Kademlia DHT.
You can’t perform that action at this time.
0 commit comments