From 62d613d730727fdd335b4aeec034c62bba1ef9e3 Mon Sep 17 00:00:00 2001 From: apostolof Date: Wed, 17 Feb 2021 22:05:24 +0200 Subject: [PATCH] fix: resolve rendezvous host only when docker prefix used --- .../concordia-pinner/src/options/ipfsOptions.js | 3 +-- packages/concordia-pinner/src/utils/ipfsUtils.js | 15 +++++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/concordia-pinner/src/options/ipfsOptions.js b/packages/concordia-pinner/src/options/ipfsOptions.js index 56e1fbb..e32f5f8 100644 --- a/packages/concordia-pinner/src/options/ipfsOptions.js +++ b/packages/concordia-pinner/src/options/ipfsOptions.js @@ -7,8 +7,7 @@ const getIpfsOptions = async () => getSwarmAddresses() .then((swarmAddresses) => { logger.info(`Swarm addresses used: ${swarmAddresses.join(', ')}`); return swarmAddresses; - }) - .then((swarmAddresses) => { + }).then((swarmAddresses) => { const IPFS_DIRECTORY = process.env.IPFS_DIRECTORY || IPFS_DIRECTORY_DEFAULT; logger.info(`Setting up IPFS in repo: ${IPFS_DIRECTORY}`); diff --git a/packages/concordia-pinner/src/utils/ipfsUtils.js b/packages/concordia-pinner/src/utils/ipfsUtils.js index 4a8ffe3..3491c5f 100644 --- a/packages/concordia-pinner/src/utils/ipfsUtils.js +++ b/packages/concordia-pinner/src/utils/ipfsUtils.js @@ -5,10 +5,17 @@ import { logger } from './logger'; const dnsLookup = util.promisify(dns.lookup); -export const getResolvedRendezvousUrl = async () => dnsLookup(rendezvousHost, { family: 4 }) - .catch((error) => logger.error(new Error(`DNS lookup of ${rendezvousHost} failed.\n${error}`))); +export const getResolvedRendezvousUrl = async () => { + if (rendezvousHost.startsWith('/docker/')) { + return dnsLookup(rendezvousHost.substring('/docker/'.length), { family: 4 }) + .then((resolvedDomain) => `/ip4/${resolvedDomain.address}`) + .catch((error) => logger.error(new Error(`DNS lookup of ${rendezvousHost} failed.\n${error}`))); + } + + return Promise.resolve(rendezvousHost); +}; export const getSwarmAddresses = async () => getResolvedRendezvousUrl() - .then((resolvedRendezvousUrl) => [ - `${resolvedRendezvousUrl.address}/tcp/${rendezvousPort}/wss/p2p-webrtc-star`, + .then((resolvedRendezvousHost) => [ + `${resolvedRendezvousHost}/tcp/${rendezvousPort}/wss/p2p-webrtc-star`, ]);