From 8f24c727623861fc5b7c75c6e8628cc660d6fac1 Mon Sep 17 00:00:00 2001 From: Konstantine Tsafatinos Date: Sun, 25 Jun 2023 17:21:25 -0400 Subject: [PATCH] add ipfs reconnect before publishing if not connected to peers --- skynet/dgpu/daemon.py | 2 +- skynet/dgpu/network.py | 6 ++++++ skynet/ipfs/docker.py | 9 +++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/skynet/dgpu/daemon.py b/skynet/dgpu/daemon.py index 216a800..bf7c176 100644 --- a/skynet/dgpu/daemon.py +++ b/skynet/dgpu/daemon.py @@ -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: diff --git a/skynet/dgpu/network.py b/skynet/dgpu/network.py index 466dc59..dc6362f 100644 --- a/skynet/dgpu/network.py +++ b/skynet/dgpu/network.py @@ -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) diff --git a/skynet/ipfs/docker.py b/skynet/ipfs/docker.py index 8158d2e..f13a596 100644 --- a/skynet/ipfs/docker.py +++ b/skynet/ipfs/docker.py @@ -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'):