configure where to save peers

This commit is contained in:
Victor Shyba 2021-09-28 03:58:31 -03:00
parent 62e65d61f4
commit 0e2fbe1c40

View file

@ -12,10 +12,10 @@ 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): async def main(host: str, port: int, db_file_path):
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()
conf = Config() conf = Config()
storage = SQLiteStorage(conf, ":memory:", loop, loop.time) storage = SQLiteStorage(conf, db_file_path, loop, loop.time)
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,
@ -34,5 +34,6 @@ if __name__ == '__main__':
description="Starts a single DHT node, which then can be used as a seed node or just a contributing node.") 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', 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")
args = parser.parse_args() args = parser.parse_args()
asyncio.run(main(args.host, args.port)) asyncio.run(main(args.host, args.port, args.db_file))