From 54ce769f7bf8c35dbe346939b87475744c66ddcb Mon Sep 17 00:00:00 2001 From: quadrismegistus Date: Thu, 20 Aug 2020 21:08:47 +0100 Subject: [PATCH] >>>!>!?!?!? --- p2p/api.py | 4 +-- p2p/p2p.py | 89 +++++++++++++++++++++++++++++------------------------- 2 files changed, 50 insertions(+), 43 deletions(-) diff --git a/p2p/api.py b/p2p/api.py index e2f7b14..9fe3a5f 100644 --- a/p2p/api.py +++ b/p2p/api.py @@ -79,10 +79,10 @@ class Api(object): #self._node=self.connect() pass - async def connect_forever(self): + async def connect_forever(self,port=PORT_LISTEN): try: i = 0 - self._node = await self.connect() + self._node = await self.connect(port=port) while True: if not i%10: self.log(f'Node status (tick {i}): {self._node}') diff --git a/p2p/p2p.py b/p2p/p2p.py index 8c7e366..192ced7 100644 --- a/p2p/p2p.py +++ b/p2p/p2p.py @@ -13,7 +13,39 @@ NODES_PRIME = [("68.66.241.111",8467)] # ("10.42.0.13",8467)] async def echo(msg): print('echo',msg) -def boot_selfless_node(port=8468, loop=None): +# def boot_selfless_node(port=8468, loop=None): +# # handler = logging.StreamHandler() +# # formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') +# # handler.setFormatter(formatter) +# # log = logging.getLogger('kademlia') +# # log.addHandler(handler) +# # log.setLevel(logging.DEBUG) + +# if not loop: loop = asyncio.get_event_loop() +# loop.set_debug(True) + +# # shelf = HalfForgetfulStorage() + +# #server = Server(storage=shelf) +# try: +# from kad import KadServer,HalfForgetfulStorage +# except ImportError: +# from .kad import KadServer,HalfForgetfulStorage + +# server = KadServer(storage=HalfForgetfulStorage()) +# loop.create_task(server.listen(port)) + +# # try: +# # loop.run_forever() +# # except KeyboardInterrupt: +# # pass +# # finally: +# # server.stop() +# # loop.close() +# return server,loop + + +def boot_lonely_selfless_node(port=8467): # handler = logging.StreamHandler() # formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') # handler.setFormatter(formatter) @@ -21,49 +53,24 @@ def boot_selfless_node(port=8468, loop=None): # log.addHandler(handler) # log.setLevel(logging.DEBUG) - if not loop: loop = asyncio.get_event_loop() - loop.set_debug(True) + # import asyncio + # loop = asyncio.new_event_loop() - # shelf = HalfForgetfulStorage() + # # async def go(): + # # from api import _getdb + # # node = await _getdb() + # # i=0 + # # while i+1: + # # if not i%10: print(node) + # # await asyncio.sleep(5) + # # i+=1 - #server = Server(storage=shelf) - try: - from kad import KadServer,HalfForgetfulStorage - except ImportError: - from .kad import KadServer,HalfForgetfulStorage - server = KadServer(storage=HalfForgetfulStorage()) - loop.create_task(server.listen(port)) - - # try: - # loop.run_forever() - # except KeyboardInterrupt: - # pass - # finally: - # server.stop() - # loop.close() - return server,loop - - -def boot_lonely_selfless_node(port=8467): - handler = logging.StreamHandler() - formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') - handler.setFormatter(formatter) - log = logging.getLogger('kademlia') - log.addHandler(handler) - log.setLevel(logging.DEBUG) - + + # asyncio.run(go()) async def go(): - from api import _getdb - node = await _getdb() - i=0 - while i+1: - if not i%10: print(node) - await asyncio.sleep(5) - i+=1 - + from api import Api,PORT_LISTEN + API = Api() + await API.connect_forever(PORT_LISTEN - 1) asyncio.run(go()) - - -