def saveDHTNodes(): if __dht is None: return if not config_dir().exists(): config_dir().mkdir(parents=True) kad = config_dir() / 'kad.dat' nodes = __dht.bootstrappable_neighbors() nodes.append((getHostIP(), __dht.port)) kad.write_text('\n'.join( ["kad://%s:%d" % (node[0], node[1]) for node in set(nodes)])) loop = asyncio.get_event_loop() loop.call_later(600, saveDHTNodes)
def test_config_dir(): if platform.system() in ['Darwin', 'Linux']: home = os.getenv('HOME') elif platform.system() == 'Windows': home = os.getenv('ProgramData') else: home = os.getcwd() assert config_dir() == Path(home) / 'QuLab'
def getBootstrapNodes(): kad = config_dir() / 'kad.dat' if kad.exists(): with kad.open() as f: bootstrap_nodes = f.readlines() else: bootstrap_nodes = [] bootstrap_nodes.extend(DHT_config.get('bootstrap_nodes', [])) def parse(s): x = urlparse(s) return x.hostname, x.port bootstrap_nodes = set(map(parse, bootstrap_nodes)) return list(bootstrap_nodes)
def test_config_file(): assert config_file() == config_dir() / 'config.yml'