add ipfs reconnect before publishing if not connected to peers

pull/8/head
Konstantine Tsafatinos 2023-06-25 17:21:25 -04:00
parent cbc9a89bb8
commit 8f24c72762
3 changed files with 16 additions and 1 deletions

View File

@ -66,7 +66,7 @@ class SkynetDGPUDaemon:
resp = await self.conn.begin_work(rid)
if 'code' in resp:
logging.info(f'probably beign worked on already... skip.')
logging.info(f'probably being worked on already... skip.')
else:
try:

View File

@ -211,6 +211,12 @@ class SkynetGPUConnector:
img = Image.open(io.BytesIO(raw_img))
img.save(f'ipfs-docker-staging/image.png')
# check for connections to peers, reconnect if none
peers = self.ipfs_node.check_connect()
if peers == "":
self.ipfs_node.connect(
'/ip4/169.197.140.154/tcp/4001/p2p/12D3KooWKWogLFNEcNNMKnzU7Snrnuj84RZdMBg3sLiQSQc51oEv')
ipfs_hash = self.ipfs_node.add('image.png')
self.ipfs_node.pin(ipfs_hash)

View File

@ -38,6 +38,15 @@ class IPFSDocker:
assert ec == 0
def check_connect(self):
ec, out = self._container.exec_run(
['ipfs', 'swarm', 'peers'])
if ec != 0:
logging.error(out)
assert ec == 0
return out
@cm
def open_ipfs_node(name='skynet-ipfs'):