up to 128 nodes

This commit is contained in:
Alex Grintsvayg 2021-01-22 09:41:51 -05:00
parent 366b0d590c
commit 99c64021eb
No known key found for this signature in database
GPG key ID: AEB3F089F86A22B5
2 changed files with 25 additions and 9 deletions

View file

@ -174,7 +174,9 @@ class Node:
if not self.joined.is_set(): if not self.joined.is_set():
self.joined.set() self.joined.set()
log.info( log.info(
"joined dht, %i peers known in %i buckets", len(self.protocol.routing_table.get_peers()), "%s: joined dht, %i peers known in %i buckets",
bytes.fromhex(self.protocol.node_id)[:8],
len(self.protocol.routing_table.get_peers()),
self.protocol.routing_table.buckets_with_contacts() self.protocol.routing_table.buckets_with_contacts()
) )
else: else:

View file

@ -2,11 +2,11 @@ import asyncio
import logging import logging
import signal import signal
import time import time
from aioupnp import upnp
import sqlite3 import sqlite3
import pickle import pickle
from os import path from os import path
from pprint import pprint from pprint import pprint
import aioupnp
from aiohttp import web from aiohttp import web
import json import json
@ -30,7 +30,7 @@ async def main():
pass # Not implemented on Windows pass # Not implemented on Windows
peer_manager = peer.PeerManager(loop) peer_manager = peer.PeerManager(loop)
u = await upnp.UPnP.discover() u = await aioupnp.upnp.UPnP.discover()
db = sqlite3.connect(data_dir + "/tracker.sqlite3") db = sqlite3.connect(data_dir + "/tracker.sqlite3")
db.execute( db.execute(
@ -43,7 +43,7 @@ async def main():
asyncio.create_task(run_web_api(loop, db)) asyncio.create_task(run_web_api(loop, db))
num_nodes = 16 num_nodes = 128
start_port = 4444 start_port = 4444
known_node_urls = [("lbrynet1.lbry.com", 4444), ("lbrynet2.lbry.com", 4444), ("lbrynet3.lbry.com", 4444)] known_node_urls = [("lbrynet1.lbry.com", 4444), ("lbrynet2.lbry.com", 4444), ("lbrynet3.lbry.com", 4444)]
external_ip = await u.get_external_ip() external_ip = await u.get_external_ip()
@ -52,12 +52,11 @@ async def main():
try: try:
for i in range(num_nodes): for i in range(num_nodes):
assert i < 16 # my ghetto int -> node_id converter requires this node_id = make_node_id(i, num_nodes)
node_id = '0123456789abcdef'[i] + '0' * 95
# pprint(node_id) # pprint(node_id)
port = start_port + i port = start_port + i
await u.get_next_mapping(port, "UDP", "lbry dht tracker") # await u.get_next_mapping(port, "UDP", "lbry dht tracker")
# SOMETHING ABOUT THIS DOESNT WORK # SOMETHING ABOUT THIS DOESNT WORK
# port = await u.get_next_mapping(start_port, "UDP", "lbry dht tracker") # port = await u.get_next_mapping(start_port, "UDP", "lbry dht tracker")
@ -109,8 +108,12 @@ async def main():
for n in nodes: for n in nodes:
node_id = bytes.hex(n.protocol.node_id) node_id = bytes.hex(n.protocol.node_id)
n.stop() n.stop()
print(f'deleting upnp port mapping {n.protocol.udp_port}') # print(f'deleting upnp port mapping {n.protocol.udp_port}')
await u.delete_port_mapping(n.protocol.udp_port, "UDP") try:
await u.delete_port_mapping(n.protocol.udp_port, "UDP")
except aioupnp.fault.UPnPError:
pass
state = n.get_state() state = n.get_state()
# keep existing rt if there is one # keep existing rt if there is one
@ -137,6 +140,17 @@ def shutdown():
raise ShutdownErr() raise ShutdownErr()
def make_node_id(i: int, n: int) -> str:
"""
split dht address space into N chunks and return the first id of the i'th chunk
make_node_id(0,n) returns 000...000 for any n
"""
if not 0 <= i < n:
raise ValueError("i must be between 0 (inclusive) and n (exclusive)")
bytes_in_id = 48
return "{0:0{1}x}".format(i * ((2**8)**bytes_in_id // n), bytes_in_id*2)
async def drain(n, q): async def drain(n, q):
print(f'drain started on {bytes.hex(n.protocol.node_id)[:8]}') print(f'drain started on {bytes.hex(n.protocol.node_id)[:8]}')
while True: while True: