add dht seed node script
This commit is contained in:
parent
78b12dc411
commit
a237cbd963
2 changed files with 41 additions and 0 deletions
|
@ -16,6 +16,9 @@ class DictDataStore:
|
||||||
self._peer_manager = peer_manager
|
self._peer_manager = peer_manager
|
||||||
self.completed_blobs: typing.Set[str] = set()
|
self.completed_blobs: typing.Set[str] = set()
|
||||||
|
|
||||||
|
def __len__(self):
|
||||||
|
return self._data_store.__len__()
|
||||||
|
|
||||||
def removed_expired_peers(self):
|
def removed_expired_peers(self):
|
||||||
now = self.loop.time()
|
now = self.loop.time()
|
||||||
keys = list(self._data_store.keys())
|
keys = list(self._data_store.keys())
|
||||||
|
|
38
scripts/dht_node.py
Normal file
38
scripts/dht_node.py
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
import asyncio
|
||||||
|
import argparse
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from lbry.dht.constants import generate_id
|
||||||
|
from lbry.dht.node import Node
|
||||||
|
from lbry.dht.peer import PeerManager
|
||||||
|
from lbry.extras.daemon.storage import SQLiteStorage
|
||||||
|
from lbry.conf import Config
|
||||||
|
|
||||||
|
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)-4s %(name)s:%(lineno)d: %(message)s")
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
async def main(host: str, port: int):
|
||||||
|
loop = asyncio.get_event_loop()
|
||||||
|
conf = Config()
|
||||||
|
storage = SQLiteStorage(conf, ":memory:", loop, loop.time)
|
||||||
|
await storage.open()
|
||||||
|
node = Node(
|
||||||
|
loop, PeerManager(loop), generate_id(), port, port, 3333, None,
|
||||||
|
storage=storage
|
||||||
|
)
|
||||||
|
node.start(host, conf.known_dht_nodes)
|
||||||
|
while True:
|
||||||
|
await asyncio.sleep(10)
|
||||||
|
log.info("Known peers: %d. Storing contact information for %d blobs from %d peers.",
|
||||||
|
len(node.protocol.routing_table.get_peers()), len(node.protocol.data_store),
|
||||||
|
len(node.protocol.data_store.get_storing_contacts()))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
description="Starts a single DHT node, which then can be used as a seed node or just a contributing node.")
|
||||||
|
parser.add_argument("--host", default='0.0.0.0', help="Host to listen for requests. Default: 0.0.0.0")
|
||||||
|
parser.add_argument("--port", default=4444, help="Port to listen for requests. Default: 4444")
|
||||||
|
args = parser.parse_args()
|
||||||
|
asyncio.run(main(args.host, args.port))
|
Loading…
Reference in a new issue