Merge pull request #8 from guilledk/ipfs-reconnect

add ipfs reconnect before publishing if not connected to peers
pull/14/head
Guillermo Rodriguez 2023-06-26 17:06:32 +00:00 committed by GitHub
commit 61ab42c118
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 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,11 @@ class SkynetGPUConnector:
img = Image.open(io.BytesIO(raw_img))
img.save(f'ipfs-docker-staging/image.png')
# check peer connections, reconnect to skynet gateway if not
peers = self.ipfs_node.check_connect()
if self.ipfs_url not in peers:
self.ipfs_node.connect(self.ipfs_url)
ipfs_hash = self.ipfs_node.add('image.png')
self.ipfs_node.pin(ipfs_hash)

11
skynet/ipfs/docker.py 100644 → 100755
View File

@ -21,6 +21,8 @@ class IPFSDocker:
def add(self, file: str) -> str:
ec, out = self._container.exec_run(
['ipfs', 'add', '-w', f'/export/{file}', '-Q'])
if ec != 0:
logging.error(out)
assert ec == 0
return out.decode().rstrip()
@ -38,6 +40,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.splitlines()
@cm
def open_ipfs_node(name='skynet-ipfs'):