mirror of
https://github.com/ComradCollective/Comrad
synced 2024-11-01 21:40:32 +00:00
>>>!>!?!?!?
This commit is contained in:
parent
20ed395434
commit
54ce769f7b
@ -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}')
|
||||
|
||||
|
89
p2p/p2p.py
89
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())
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user