add option to set bootstrap_node
This commit is contained in:
parent
ecc71baf61
commit
156d89567e
1 changed files with 12 additions and 3 deletions
|
@ -1,6 +1,7 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
from lbry.dht.constants import generate_id
|
from lbry.dht.constants import generate_id
|
||||||
from lbry.dht.node import Node
|
from lbry.dht.node import Node
|
||||||
|
@ -12,16 +13,21 @@ logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)-4s %(na
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
async def main(host: str, port: int, db_file_path):
|
async def main(host: str, port: int, db_file_path: str, bootstrap_node: Optional[str]):
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
conf = Config()
|
conf = Config()
|
||||||
storage = SQLiteStorage(conf, db_file_path, loop, loop.time)
|
storage = SQLiteStorage(conf, db_file_path, loop, loop.time)
|
||||||
|
if bootstrap_node:
|
||||||
|
nodes = bootstrap_node.split(':')
|
||||||
|
nodes = [(nodes[0], int(nodes[1]))]
|
||||||
|
else:
|
||||||
|
nodes = conf.known_dht_nodes
|
||||||
await storage.open()
|
await storage.open()
|
||||||
node = Node(
|
node = Node(
|
||||||
loop, PeerManager(loop), generate_id(), port, port, 3333, None,
|
loop, PeerManager(loop), generate_id(), port, port, 3333, None,
|
||||||
storage=storage
|
storage=storage
|
||||||
)
|
)
|
||||||
node.start(host, conf.known_dht_nodes)
|
node.start(host, nodes)
|
||||||
while True:
|
while True:
|
||||||
await asyncio.sleep(10)
|
await asyncio.sleep(10)
|
||||||
log.info("Known peers: %d. Storing contact information for %d blobs from %d peers.",
|
log.info("Known peers: %d. Storing contact information for %d blobs from %d peers.",
|
||||||
|
@ -35,5 +41,8 @@ if __name__ == '__main__':
|
||||||
parser.add_argument("--host", default='0.0.0.0', type=str, help="Host to listen for requests. Default: 0.0.0.0")
|
parser.add_argument("--host", default='0.0.0.0', type=str, help="Host to listen for requests. Default: 0.0.0.0")
|
||||||
parser.add_argument("--port", default=4444, type=int, help="Port to listen for requests. Default: 4444")
|
parser.add_argument("--port", default=4444, type=int, help="Port to listen for requests. Default: 4444")
|
||||||
parser.add_argument("--db_file", default='/tmp/dht.db', type=str, help="DB file to save peers. Default: /tmp/dht.db")
|
parser.add_argument("--db_file", default='/tmp/dht.db', type=str, help="DB file to save peers. Default: /tmp/dht.db")
|
||||||
|
parser.add_argument("--bootstrap_node", default=None, type=str,
|
||||||
|
help="Node to connect for bootstraping this node. Leave unset to use the default ones. "
|
||||||
|
"Format: host:port Example: lbrynet1.lbry.com:4444")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
asyncio.run(main(args.host, args.port, args.db_file))
|
asyncio.run(main(args.host, args.port, args.db_file, args.bootstrap_node))
|
||||||
|
|
Loading…
Reference in a new issue