From 8127174fbdf21f5f34f06a1a0796fcbb998243de Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Thu, 5 Sep 2019 12:57:26 +0200 Subject: [PATCH] allow multiple nodes running at same time --- client/src/hooks/use-ipfs.tsx | 13 ++++++++++++- client/src/routes/Publish/Files/index.test.tsx | 16 ---------------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/client/src/hooks/use-ipfs.tsx b/client/src/hooks/use-ipfs.tsx index eae0c8f..d975bf4 100644 --- a/client/src/hooks/use-ipfs.tsx +++ b/client/src/hooks/use-ipfs.tsx @@ -2,6 +2,8 @@ import Ipfs from 'ipfs' import { useEffect, useState } from 'react' +import os from 'os' +import shortid from 'shortid' let ipfs: any = null let ipfsMessage = '' @@ -24,7 +26,16 @@ export default function useIpfs() { const message = 'IPFS started' console.time(message) - ipfs = await Ipfs.create() + ipfs = await Ipfs.create({ + repo: `${os.homedir()}/.jsipfs-${shortid.generate()}`, + config: { + Addresses: { + // 0 for port so system just assigns a new free port + // to allow multiple nodes running at same time + Swarm: ['/ip4/0.0.0.0/tcp/0'] + } + } + }) console.timeEnd(message) ipfsMessage = message diff --git a/client/src/routes/Publish/Files/index.test.tsx b/client/src/routes/Publish/Files/index.test.tsx index c490901..5b7d9da 100644 --- a/client/src/routes/Publish/Files/index.test.tsx +++ b/client/src/routes/Publish/Files/index.test.tsx @@ -5,22 +5,6 @@ import Files from '.' const onChange = jest.fn() -// filter out IPFS node messages -const originalLog = console.log - -beforeAll(() => { - console.log = (...args: any) => { - if (/Swarm listening/.test(args[0])) { - return - } - originalLog.call(console, ...args) - } -}) - -afterAll(() => { - console.log = originalLog -}) - afterEach(() => { mockAxios.reset() })