lbry-sdk/scripts/dht_monitor.py

66 lines
1.4 KiB
Python
Raw Permalink Normal View History

2017-10-10 19:31:07 +02:00
import curses
import time
2019-01-22 23:45:13 +01:00
import asyncio
2020-10-09 19:34:45 +02:00
import lbry.wallet
from lbry.conf import Config
from lbry.extras.daemon.client import daemon_rpc
2017-10-10 19:31:07 +02:00
stdscr = curses.initscr()
def init_curses():
curses.noecho()
curses.cbreak()
stdscr.nodelay(1)
stdscr.keypad(1)
def teardown_curses():
curses.nocbreak()
stdscr.keypad(0)
curses.echo()
curses.endwin()
2019-01-22 23:45:13 +01:00
def refresh(routing_table_info):
2017-10-10 19:31:07 +02:00
height, width = stdscr.getmaxyx()
2019-01-22 23:45:13 +01:00
node_id = routing_table_info['node_id']
2017-10-10 19:31:07 +02:00
for y in range(height):
stdscr.addstr(y, 0, " " * (width - 1))
buckets = routing_table_info['buckets']
2019-01-22 23:45:13 +01:00
stdscr.addstr(0, 0, f"node id: {node_id}")
stdscr.addstr(1, 0, f"{len(buckets)} buckets")
2017-10-10 19:31:07 +02:00
y = 3
2019-01-22 23:45:13 +01:00
for i in range(len(buckets)):
2017-10-10 19:31:07 +02:00
stdscr.addstr(y, 0, "bucket %s" % i)
y += 1
2019-01-22 23:45:13 +01:00
for peer in buckets[str(i)]:
stdscr.addstr(y, 0, f"{peer['node_id'][:8]} ({peer['address']}:{peer['udp_port']})")
2017-10-10 19:31:07 +02:00
y += 1
y += 1
stdscr.addstr(y + 1, 0, str(time.time()))
stdscr.refresh()
2019-01-22 23:45:13 +01:00
async def main():
2019-01-23 22:41:14 +01:00
conf = Config()
2017-10-10 19:31:07 +02:00
try:
init_curses()
2019-01-22 23:45:13 +01:00
c = None
while c not in [ord('q'), ord('Q')]:
2019-01-23 22:41:14 +01:00
routing_info = await daemon_rpc(conf, 'routing_table_get')
2019-01-22 23:45:13 +01:00
refresh(routing_info)
c = stdscr.getch()
time.sleep(0.1)
2017-10-10 19:31:07 +02:00
finally:
teardown_curses()
if __name__ == "__main__":
2019-01-22 23:45:13 +01:00
asyncio.run(main())