From 5c2a71a672aeedcedc091a34adc3332dec8eb5bc Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 23 Jan 2020 10:34:01 +0000 Subject: [PATCH 01/55] docs: updated examples to new api --- examples/browser-video-streaming/index.html | 4 + examples/browser-video-streaming/streaming.js | 143 +++++++++++++++++- examples/circuit-relaying/package.json | 2 +- examples/circuit-relaying/src/helpers.js | 6 +- examples/circuit-relaying/test.js | 6 +- examples/custom-ipfs-repo/index.js | 20 ++- examples/custom-libp2p/index.js | 16 +- examples/custom-libp2p/package.json | 21 ++- examples/custom-libp2p/test.js | 7 +- examples/exchange-files-in-browser/README.md | 33 +++- .../exchange-files-in-browser/public/app.js | 67 +++----- examples/exchange-files-in-browser/test.js | 38 +++-- examples/ipfs-101/1.js | 14 +- examples/running-multiple-nodes/README.md | 4 +- examples/running-multiple-nodes/test.js | 25 ++- examples/test-all.js | 2 + examples/traverse-ipld-graphs/test.js | 2 +- examples/traverse-ipld-graphs/tree.js | 7 +- examples/utils.js | 32 +++- src/core/components/id.js | 6 +- src/core/components/start.js | 3 +- src/core/components/swarm/peers.js | 4 +- 22 files changed, 321 insertions(+), 141 deletions(-) diff --git a/examples/browser-video-streaming/index.html b/examples/browser-video-streaming/index.html index 2b33f7debf..83138154ff 100644 --- a/examples/browser-video-streaming/index.html +++ b/examples/browser-video-streaming/index.html @@ -2,7 +2,11 @@ + diff --git a/examples/browser-video-streaming/streaming.js b/examples/browser-video-streaming/streaming.js index d42631a73e..576d938d33 100644 --- a/examples/browser-video-streaming/streaming.js +++ b/examples/browser-video-streaming/streaming.js @@ -2,7 +2,6 @@ /* global Hls Ipfs HlsjsIpfsLoader */ /* eslint-env browser */ - document.addEventListener('DOMContentLoaded', async () => { const testHash = 'QmdpAidwAsBGptFB3b6A9Pyi5coEbgjHrL3K2Qrsutmj9K' const repoPath = 'ipfs-' + Math.random() @@ -20,3 +19,145 @@ document.addEventListener('DOMContentLoaded', async () => { hls.on(Hls.Events.MANIFEST_PARSED, () => video.play()) } }) + +// TODO: remove everything below here once https://github.com/ipfs/js-ipfs/pull/2683 +// and https://github.com/moshisushi/hlsjs-ipfs-loader/pull/16 are released + +class HlsjsIpfsLoader { + constructor(config) { + this.ipfs = config.ipfs + this.hash = config.ipfsHash + if (config.debug === false) { + this.debug = function() {} + } else if (config.debug === true) { + this.debug = console.log + } else { + this.debug = config.debug + } + if(config.m3u8provider) { + this.m3u8provider = config.m3u8provider; + } else { + this.m3u8provider = null; + } + if(config.tsListProvider) { + this.tsListProvider = config.tsListProvider; + } else { + this.tsListProvider = null; + } + } + + destroy() { + } + + abort() { + } + + load(context, config, callbacks) { + this.context = context + this.config = config + this.callbacks = callbacks + this.stats = { trequest: performance.now(), retry: 0 } + this.retryDelay = config.retryDelay + this.loadInternal() + } + /** + * Call this by getting the HLSIPFSLoader instance from hls.js hls.coreComponents[0].loaders.manifest.setM3U8Provider() + * @param {function} provider + */ + setM3U8Provider(provider) { + this.m3u8provider = provider; + } + /** + * + * @param {function} provider + */ + setTsListProvider(provider) { + this.tsListProvider = provider; + } + + loadInternal() { + const { stats, context, callbacks } = this + + stats.tfirst = Math.max(performance.now(), stats.trequest) + stats.loaded = 0 + + const urlParts = context.url.split("/") + const filename = urlParts[urlParts.length - 1] + + if(filename.split(".")[1] === "m3u8" && this.m3u8provider !== null) { + const res = this.m3u8provider(); + let data; + if(Buffer.isBuffer(res)) { + data = buf2str(res) + } else { + data = res; + } + const response = { url: context.url, data: data } + callbacks.onSuccess(response, stats, context) + return; + } + if(filename.split(".")[1] === "m3u8" && this.tsListProvider !== null) { + var tslist = this.tsListProvider(); + var hash = tslist[filename]; + if(hash) { + this.cat(hash).then(res => { + let data; + if(Buffer.isBuffer(res)) { + data = buf2str(res) + } else { + data = res; + } + stats.loaded = stats.total = data.length + stats.tload = Math.max(stats.tfirst, performance.now()) + const response = { url: context.url, data: data } + callbacks.onSuccess(response, stats, context) + }); + } + return; + } + getFile(this.ipfs, this.hash, filename, this.debug).then(res => { + const data = (context.responseType === 'arraybuffer') ? res : buf2str(res) + stats.loaded = stats.total = data.length + stats.tload = Math.max(stats.tfirst, performance.now()) + const response = { url: context.url, data: data } + callbacks.onSuccess(response, stats, context) + }, console.error) + } +} + +async function getFile(ipfs, rootHash, filename, debug) { + debug(`Fetching hash for '${rootHash}/${filename}'`) + if(filename === null) { + return cat(rootHash, ipfs, debug) + } + + for await (const link of ipfs.ls(rootHash)) { + if (link.name !== filename) { + continue + } + + debug(`Requesting '${link.path}'`) + + return cat(link.cid, ipfs, debug) + } + + throw new Error(`File not found: ${rootHash}/${filename}`) +} + +function buf2str(buf) { + return String.fromCharCode.apply(null, new Uint8Array(buf)) +} + +async function cat (cid, ipfs, debug) { + let value = new Uint8Array(0) + + for await (const buf of ipfs.cat(cid)) { + const newBuf = new Uint8Array(value.length + buf.length) + newBuf.set(value) + newBuf.set(buf, value.length) + value = newBuf + } + + debug(`Received data for file '${cid}' size: ${value.length}`) + return value +} diff --git a/examples/circuit-relaying/package.json b/examples/circuit-relaying/package.json index 7261bfa83f..f810bdbb9b 100644 --- a/examples/circuit-relaying/package.json +++ b/examples/circuit-relaying/package.json @@ -15,7 +15,7 @@ "license": "MIT", "dependencies": { "ipfs": "file:../../", - "ipfs-pubsub-room": "^1.4.0" + "ipfs-pubsub-room": "ipfs-shipyard/ipfs-pubsub-room#update-to-async-iterators" }, "devDependencies": { "aegir": "^20.0.0", diff --git a/examples/circuit-relaying/src/helpers.js b/examples/circuit-relaying/src/helpers.js index 26a277ef2a..3b14969e66 100644 --- a/examples/circuit-relaying/src/helpers.js +++ b/examples/circuit-relaying/src/helpers.js @@ -15,7 +15,7 @@ const mkRoomName = (name) => { module.exports = (ipfs, peersSet) => { const createRoom = (name) => { - const room = Room(ipfs, mkRoomName(name)) + const room = new Room(ipfs, mkRoomName(name)) room.on('peer joined', (peer) => { console.log('peer ' + peer + ' joined') @@ -31,9 +31,9 @@ module.exports = (ipfs, peersSet) => { // send and receive messages room.on('message', (message) => { - console.log('got message from ' + message.from + ': ' + message.data.toString()) + console.log('got message from ' + message.from.toString() + ': ' + message.data.toString()) const node = document.createElement(`li`) - node.innerText = `${message.from.substr(-4)}: ${message.data.toString()}` + node.innerText = `${message.from.toString().substr(-4)}: ${message.data.toString()}` $msgs.appendChild(node) }) diff --git a/examples/circuit-relaying/test.js b/examples/circuit-relaying/test.js index 499abc69f4..c6d700eadb 100644 --- a/examples/circuit-relaying/test.js +++ b/examples/circuit-relaying/test.js @@ -66,7 +66,7 @@ async function runTest () { try { const id = await ipfsd.api.id() - const address = id.addresses.filter(addr => addr.includes('/ws/ipfs/Qm')).pop() + const address = id.addresses.filter(addr => addr.includes('/ws/p2p/Qm')).pop() if (!address) { throw new Error(`Could not find web socket address in ${id.addresses}`) @@ -145,8 +145,8 @@ module.exports[pkg.name] = function (browser) { .pause(1000) .click('#send') - browser.expect.element('#msgs').text.to.contain(`${remotePeerId.substr(-4)}: hello`) - browser.expect.element('#msgs').text.to.contain(`${localPeerId.substr(-4)}: hello`) + browser.expect.element('#msgs').text.to.contain(`${remotePeerId.toString().substr(-4)}: hello`) + browser.expect.element('#msgs').text.to.contain(`${localPeerId.toString().substr(-4)}: hello`) }) browser.end() diff --git a/examples/custom-ipfs-repo/index.js b/examples/custom-ipfs-repo/index.js index 8458bf7209..7bfbf8ef66 100644 --- a/examples/custom-ipfs-repo/index.js +++ b/examples/custom-ipfs-repo/index.js @@ -79,19 +79,23 @@ async function main () { console.log('Version:', version) // Once we have the version, let's add a file to IPFS - const filesAdded = await node.add({ + for await (const file of node.add({ path: 'test-data.txt', content: Buffer.from('We are using a customized repo!') - }) + })) { + // Log out the added files metadata and cat the file from IPFS + console.log('\nAdded file:', file.path, file.cid) - // Log out the added files metadata and cat the file from IPFS - console.log('\nAdded file:', filesAdded[0].path, filesAdded[0].hash) + const bufs = [] - const data = await node.cat(filesAdded[0].hash) + for await (const buf of node.cat(file.cid)) { + bufs.push(buf) + } - // Print out the files contents to console - console.log('\nFetched file content:') - process.stdout.write(data) + // Print out the files contents to console + console.log('\nFetched file content:') + process.stdout.write(Buffer.concat(bufs)) + } // After everything is done, shut the node down console.log('\n\nStopping the node') diff --git a/examples/custom-libp2p/index.js b/examples/custom-libp2p/index.js index fa1a097b86..1b5d2387e8 100644 --- a/examples/custom-libp2p/index.js +++ b/examples/custom-libp2p/index.js @@ -1,14 +1,13 @@ 'use strict' const Libp2p = require('libp2p') -const IPFS = require('ipfs') +const IPFS = require('../../') const TCP = require('libp2p-tcp') const MulticastDNS = require('libp2p-mdns') -const WebSocketStar = require('libp2p-websocket-star') const Bootstrap = require('libp2p-bootstrap') const SPDY = require('libp2p-spdy') const KadDHT = require('libp2p-kad-dht') -const MPLEX = require('pull-mplex') +const MPLEX = require('libp2p-mplex') const SECIO = require('libp2p-secio') /** @@ -32,11 +31,6 @@ const libp2pBundle = (opts) => { const peerBook = opts.peerBook const bootstrapList = opts.config.Bootstrap - // Create our WebSocketStar transport and give it our PeerId, straight from the ipfs node - const wsstar = new WebSocketStar({ - id: peerInfo.id - }) - // Build and return our libp2p node return new Libp2p({ peerInfo, @@ -49,8 +43,7 @@ const libp2pBundle = (opts) => { }, modules: { transport: [ - TCP, - wsstar + TCP ], streamMuxer: [ MPLEX, @@ -61,8 +54,7 @@ const libp2pBundle = (opts) => { ], peerDiscovery: [ MulticastDNS, - Bootstrap, - wsstar.discovery + Bootstrap ], dht: KadDHT }, diff --git a/examples/custom-libp2p/package.json b/examples/custom-libp2p/package.json index 197b8d5c5f..3d0a253e32 100644 --- a/examples/custom-libp2p/package.json +++ b/examples/custom-libp2p/package.json @@ -9,18 +9,17 @@ }, "license": "MIT", "dependencies": { - "ipfs": "file:../../", - "libp2p": "^0.26.2", - "libp2p-bootstrap": "~0.9.7", - "libp2p-kad-dht": "~0.16.0", - "libp2p-mdns": "~0.12.2", - "libp2p-secio": "~0.11.1", - "libp2p-spdy": "~0.13.3", - "libp2p-tcp": "~0.13.0", - "libp2p-websocket-star": "~0.10.2", - "pull-mplex": "~0.1.0" + "libp2p": "github:libp2p/js-libp2p#refactor/async-await", + "libp2p-bootstrap": "^0.10.should generate a new rsa key", + "libp2p-kad-dht": "^0.18.3", + "libp2p-mdns": "^0.13.1", + "libp2p-mplex": "^0.9.3", + "libp2p-secio": "^0.12.2", + "libp2p-spdy": "^0.13.3", + "libp2p-tcp": "^0.14.3", + "libp2p-webrtc-star": "^0.17.2" }, "devDependencies": { - "execa": "^3.2.0" + "execa": "^4.0.0" } } diff --git a/examples/custom-libp2p/test.js b/examples/custom-libp2p/test.js index b4666f67b9..3240104e38 100644 --- a/examples/custom-libp2p/test.js +++ b/examples/custom-libp2p/test.js @@ -5,13 +5,11 @@ const execa = require('execa') const Libp2p = require('libp2p') const TCP = require('libp2p-tcp') const SPDY = require('libp2p-spdy') -const MPLEX = require('pull-mplex') +const MPLEX = require('libp2p-mplex') const SECIO = require('libp2p-secio') const PeerInfo = require('peer-info') const PeerId = require('peer-id') const multiaddr = require('multiaddr') -const promisify = require('promisify-es6') -const PeerBook = require('peer-book') async function test () { let output = '' @@ -31,12 +29,11 @@ async function test () { console.info('Dialling', address) - const peerInfo = new PeerInfo(await promisify(PeerId.create)()) + const peerInfo = new PeerInfo(await PeerId.create()) peerInfo.multiaddrs.add(multiaddr('/ip4/127.0.0.1/tcp/0')) const libp2p = new Libp2p({ peerInfo, - peerBook: new PeerBook(), modules: { transport: [ TCP diff --git a/examples/exchange-files-in-browser/README.md b/examples/exchange-files-in-browser/README.md index adb86df2fb..30a4f47edc 100644 --- a/examples/exchange-files-in-browser/README.md +++ b/examples/exchange-files-in-browser/README.md @@ -2,7 +2,7 @@ This tutorial will help you exchange files between browser nodes and go-ipfs or js-ipfs nodes! -**Note:** As `js-ipfs@0.33.x` currently doesn't support DHT peer discovery, the peer from which you are fetching data should be within the reach (local or in public IP) of the browser node. +**Note:** As `js-ipfs@0.41.x` currently doesn't support DHT peer discovery, the peer from which you are fetching data should be within the reach (local or in public IP) of the browser node. That being said, we will explain how to circumvent these caveats and once they are fixed, we'll update the tutorial as well. @@ -35,9 +35,10 @@ Here's what we are going to be doing: 1. Install a `go-ipfs` or `js-ipfs` node in your machine 2. Make your daemons listen on WebSockets -3. Start the app -4. Dial to a node using WebSockets (your desktop ones) -5. Transfer files between all of your nodes! +3. Start a `libp2p-webrtc-star` signaling server +4. Start the app +5. Dial to a node using WebSockets (your desktop ones) +6. Transfer files between all of your nodes! Just follow the instructions below and it will be up and running in no time! @@ -121,7 +122,25 @@ Daemon is ready Check the `/ws` in line 5, that means it is listening. Cool. -### 3. Start the app +### 3. Start a `libp2p-webrtc-star` signaling server + +This server allows the two browser nodes to talk to each other by doing the initial handshake and network introductions. + +First install the `libp2p-webrtc-star` module globally: + +```sh +> npm install -g libp2p-webrtc-star +``` + +This will give you the `webrtc-star` command. Use this to start a signaling server: + +```sh +> webrtc-star +``` + +By default it will listen to all incoming connections on port 13579. Override this with the `--host` and/or `--port` options. + +### 4. Start the app Make sure you're in `js-ipfs/examples/exchange-files-in-browser`. @@ -147,7 +166,7 @@ Hit CTRL-C to stop the server Now go to http://127.0.0.1:12345 in a modern browser and you're on! -### 4. Dial to a node using WebSockets (your desktop ones) +### 5. Dial to a node using WebSockets (your desktop ones) Make sure you have a daemon running. If you don't, run: @@ -179,7 +198,7 @@ Check that you got connected: [js-libp2p-crypto#105]: https://github.com/libp2p/js-libp2p-crypto/issues/105 -### 5. Transfer files between all of your nodes! +### 6. Transfer files between all of your nodes! Now you can add files through the CLI with: diff --git a/examples/exchange-files-in-browser/public/app.js b/examples/exchange-files-in-browser/public/app.js index f23ca84f14..6267b568f3 100644 --- a/examples/exchange-files-in-browser/public/app.js +++ b/examples/exchange-files-in-browser/public/app.js @@ -1,7 +1,7 @@ /* global location */ 'use strict' -const IPFS = require('ipfs') +const IPFS = require('../../../dist') const { Buffer } = IPFS // Node @@ -31,7 +31,7 @@ const $workspaceInput = document.querySelector('#workspace-input') const $workspaceBtn = document.querySelector('#workspace-btn') let FILES = [] -let workspace = location.hash +let workspace = (location.hash || 'default-workspace').replace(/^#/, '') let fileSize = 0 @@ -44,20 +44,29 @@ let info async function start () { if (!node) { - const options = { + node = await IPFS.create({ repo: 'ipfs-' + Math.random(), config: { Addresses: { - Swarm: ['/dns4/ws-star.discovery.libp2p.io/tcp/443/wss/p2p-websocket-star'] + Swarm: [ + //'/dns4/ws-star.discovery.libp2p.io/tcp/443/wss/p2p-websocket-star' + '/ip4/127.0.0.1/tcp/13579/wss/p2p-webrtc-star' + ] } } - } - - node = await IPFS.create(options) + }) try { info = await node.id() - updateView('ready', node) + + const addressesHtml = info.addresses.map((address) => { + return `
  • ${address}
  • ` + }).join('') + $nodeId.innerText = info.id + $nodeAddresses.innerHTML = addressesHtml + $allDisabledButtons.forEach(b => { b.disabled = false }) + $allDisabledInputs.forEach(b => { b.disabled = false }) + $allDisabledElements.forEach(el => { el.classList.remove('disabled') }) } catch (err) { return onError(err) } @@ -114,7 +123,7 @@ async function start () { =========================================================================== */ const messageHandler = (message) => { - const myNode = info.id + const myNode = info.id.toString() const hash = message.data.toString() const messageSender = message.from @@ -127,7 +136,7 @@ const messageHandler = (message) => { const subscribeToWorkpsace = async () => { await node.pubsub.subscribe(workspace, messageHandler) - const msg = `Subscribed to workspace ${workspace}` + const msg = `Subscribed to workspace '${workspace}'` $logs.innerHTML = msg } @@ -138,7 +147,7 @@ const workspaceUpdated = async () => { FILES = [] $fileHistory.innerHTML = '' - workspace = location.hash + workspace = location.hash.replace(/^#/, '') await subscribeToWorkpsace() } @@ -207,15 +216,13 @@ async function getFile () { FILES.push(hash) - const files = await node.get(hash) - - return Promise.all(files.map(async (file) => { + for await (const file of node.get(hash)) { if (file.content) { await appendFile(file.name, hash, file.size, file.content) onSuccess(`The ${file.name} file was added.`) $emptyRow.style.display = 'none' } - })) + } } /* Drag & Drop @@ -272,10 +279,11 @@ async function refreshPeerList () { .map((peer) => { if (peer.addr) { const addr = peer.addr.toString() - if (addr.indexOf('ipfs') >= 0) { + + if (addr.indexOf('/p2p/') >= 0) { return addr } else { - return addr + peer.peer.id.toB58String() + return addr + peer.peer.toString() } } }) @@ -322,31 +330,6 @@ function onError (err) { window.onerror = onError -/* =========================================================================== - App states - =========================================================================== */ - -const states = { - ready: () => { - const addressesHtml = info.addresses.map((address) => { - return `
  • ${address}
  • ` - }).join('') - $nodeId.innerText = info.id - $nodeAddresses.innerHTML = addressesHtml - $allDisabledButtons.forEach(b => { b.disabled = false }) - $allDisabledInputs.forEach(b => { b.disabled = false }) - $allDisabledElements.forEach(el => { el.classList.remove('disabled') }) - } -} - -function updateView (state, ipfs) { - if (states[state] !== undefined) { - states[state]() - } else { - throw new Error('Could not find state "' + state + '"') - } -} - /* =========================================================================== Boot the app =========================================================================== */ diff --git a/examples/exchange-files-in-browser/test.js b/examples/exchange-files-in-browser/test.js index 2e9f164395..a019545271 100644 --- a/examples/exchange-files-in-browser/test.js +++ b/examples/exchange-files-in-browser/test.js @@ -19,12 +19,12 @@ const df = createFactory({ js: { ipfsBin: path.resolve(`${__dirname}/../../src/cli/bin.js`) } -} -) +}) const { startServer } = require('../utils') const pkg = require('./package.json') +const webRTCStarSigServer = require('libp2p-webrtc-star/src/sig-server') async function testUI (env) { const proc = execa('nightwatch', [path.join(__dirname, 'test.js')], { @@ -44,7 +44,13 @@ async function testUI (env) { } async function runTest () { - const ipfsd = await df.spawn({ + const sigServer = await webRTCStarSigServer.start({ + host: '127.0.0.1', + port: 13579 + }) + + const relay = await df.spawn({ + type: 'js', ipfsOptions: { config: { Addresses: { @@ -56,15 +62,18 @@ async function runTest () { } }) - const [{ - hash: cid - }] = await ipfsd.api.add('A file with some content') + let cid + + for await (const imported of relay.api.add('A file with some content')) { + cid = imported.cid + } + const server1 = await startServer(__dirname) const server2 = await startServer(__dirname) try { - const id = await ipfsd.api.id() - const address = id.addresses.filter(addr => addr.includes('/ws/ipfs/Qm')).pop() + const id = await relay.api.id() + const address = id.addresses.find(addr => addr.includes('/ws/p2p/')) if (!address) { throw new Error(`Could not find web socket address in ${id.addresses}`) @@ -74,10 +83,12 @@ async function runTest () { const peerA = path.join(os.tmpdir(), `test-${Date.now()}-a.txt`) const peerB = path.join(os.tmpdir(), `test-${Date.now()}-b.txt`) + console.info('Relay address', address) + await Promise.all([ testUI({ IPFS_EXAMPLE_TEST_URL: server1.url, - IPFS_RELAY_ADDRESS: id.addresses[0], + IPFS_RELAY_ADDRESS: address, IPFS_CID: cid, IPFS_WORKSPACE_NAME: workspaceName, IPFS_ADD_FILE: true, @@ -86,7 +97,7 @@ async function runTest () { }), testUI({ IPFS_EXAMPLE_TEST_URL: server1.url, - IPFS_RELAY_ADDRESS: id.addresses[0], + IPFS_RELAY_ADDRESS: address, IPFS_CID: cid, IPFS_WORKSPACE_NAME: workspaceName, IPFS_LOCAL_PEER_ID_FILE: peerB, @@ -94,9 +105,10 @@ async function runTest () { }) ]) } finally { - await ipfsd.stop() - await server1.stop() await server2.stop() + await server1.stop() + await relay.stop() + await sigServer.stop() } } @@ -108,7 +120,7 @@ module.exports[pkg.name] = function (browser) { browser .url(process.env.IPFS_EXAMPLE_TEST_URL) - .waitForElementVisible('.node-addresses li pre') + .waitForElementVisible('#connected-peers tr td') .pause(1000) console.info('dialling relay', process.env.IPFS_RELAY_ADDRESS) diff --git a/examples/ipfs-101/1.js b/examples/ipfs-101/1.js index 3b832eb98d..ea45be2320 100644 --- a/examples/ipfs-101/1.js +++ b/examples/ipfs-101/1.js @@ -8,16 +8,20 @@ async function main () { console.log('Version:', version.version) - const filesAdded = await node.add({ + for await (const file of await node.add({ path: 'hello.txt', content: Buffer.from('Hello World 101') - }) + })) { + console.log('Added file:', file.path, file.cid.toString()) - console.log('Added file:', filesAdded[0].path, filesAdded[0].hash) + const bufs = [] - const fileBuffer = await node.cat(filesAdded[0].hash) + for await (const buf of node.cat(file.cid)) { + bufs.push(buf) + } - console.log('Added file contents:', fileBuffer.toString()) + console.log('Added file contents:', Buffer.concat(bufs).toString()) + } } main() diff --git a/examples/running-multiple-nodes/README.md b/examples/running-multiple-nodes/README.md index 9683075b53..dcf836eb54 100644 --- a/examples/running-multiple-nodes/README.md +++ b/examples/running-multiple-nodes/README.md @@ -42,7 +42,7 @@ Firstly, you'll want to pass the [`repo`](https://github.com/ipfs/js-ipfs#option ```js // The repo path by default is `os.homedir() + '/.jsipfs'`. -new IPFS({ repo: os.homedir() + '/.jsipfs2' }) +await IPFS.create({ repo: os.homedir() + '/.jsipfs2' }) ``` Secondly, you'll need them to bind to different ports because otherwise bad things happen. @@ -50,7 +50,7 @@ Secondly, you'll need them to bind to different ports because otherwise bad thin To do this, simply pass the different ports to the [`config`](https://github.com/ipfs/js-ipfs#optionsconfig) constructor option. All together: ```js -new IPFS({ +await IPFS.create({ repo: os.homedir() + '/.jsipfs2', config: { Addresses: { diff --git a/examples/running-multiple-nodes/test.js b/examples/running-multiple-nodes/test.js index 76eefe9cf2..9aa41f680f 100644 --- a/examples/running-multiple-nodes/test.js +++ b/examples/running-multiple-nodes/test.js @@ -6,8 +6,8 @@ const execa = require('execa') const os = require('os') const path = require('path') const hat = require('hat') +const delay = require('delay') const { - ephemeralPort, waitForOutput } = require('../utils') @@ -29,9 +29,9 @@ async function startCliNode () { const ipfs = path.resolve(__dirname, '../../src/cli/bin.js') await execa(ipfs, ['init'], opts) - await execa(ipfs, ['config', 'Addresses.Swarm', '--json', JSON.stringify([`/ip4/0.0.0.0/tcp/${ephemeralPort()}`, `/ip4/127.0.0.1/tcp/${ephemeralPort()}/ws`])], opts) - await execa(ipfs, ['config', 'Addresses.API', `/ip4/127.0.0.1/tcp/${ephemeralPort()}`], opts) - await execa(ipfs, ['config', 'Addresses.Gateway', `/ip4/127.0.0.1/tcp/${ephemeralPort()}`], opts) + await execa(ipfs, ['config', 'Addresses.Swarm', '--json', JSON.stringify([`/ip4/0.0.0.0/tcp/0`, `/ip4/127.0.0.1/tcp/0/ws`])], opts) + await execa(ipfs, ['config', 'Addresses.API', `/ip4/127.0.0.1/tcp/0`], opts) + await execa(ipfs, ['config', 'Addresses.Gateway', `/ip4/127.0.0.1/tcp/0`], opts) return waitForOutput('Daemon is ready', ipfs, ['daemon'], opts) } @@ -45,25 +45,24 @@ async function testProgramatically () { async function startProgramaticNode () { const repoDir = path.join(os.tmpdir(), `repo-${hat()}`) - const node = new IPFS({ + const node = await IPFS.create({ repo: repoDir, config: { Addresses: { Swarm: [ - `/ip4/0.0.0.0/tcp/${ephemeralPort()}`, - `/ip4/127.0.0.1/tcp/${ephemeralPort()}/ws` + `/ip4/0.0.0.0/tcp/0`, + `/ip4/127.0.0.1/tcp/0/ws` ], - API: `/ip4/127.0.0.1/tcp/${ephemeralPort()}`, - Gateway: `/ip4/127.0.0.1/tcp/${ephemeralPort()}` + API: `/ip4/127.0.0.1/tcp/0`, + Gateway: `/ip4/127.0.0.1/tcp/0` }, Bootstrap: [] } }) - console.info('Initialising programmatic node') - await node.init() - console.info('Starting programmatic node') - await node.start() + // https://github.com/ChainSafe/gossipsub-js/pull/59 + await delay(5000) + console.info('Stopping programmatic node') await node.stop() } diff --git a/examples/test-all.js b/examples/test-all.js index 50ae41a98d..a4eb7fa809 100644 --- a/examples/test-all.js +++ b/examples/test-all.js @@ -24,6 +24,8 @@ async function testAll () { continue } + console.info('Testing example', dir) + await waitForOutput('npm info ok', 'npm', ['test', '--verbose', '--', dir], { cwd: __dirname }) diff --git a/examples/traverse-ipld-graphs/test.js b/examples/traverse-ipld-graphs/test.js index 45ae20aed9..e40d25349d 100644 --- a/examples/traverse-ipld-graphs/test.js +++ b/examples/traverse-ipld-graphs/test.js @@ -19,7 +19,7 @@ async function runTest () { await waitForOutput('capoeira', path.resolve(__dirname, 'get-path-accross-formats.js')) console.info('Testing tree.js') - await waitForOutput("'hobbies/0/Links'", path.resolve(__dirname, 'tree.js')) + await waitForOutput("hobbies/0/Links", path.resolve(__dirname, 'tree.js')) console.info('Testing eth.js') await waitForOutput('302516', path.resolve(__dirname, 'eth.js')) diff --git a/examples/traverse-ipld-graphs/tree.js b/examples/traverse-ipld-graphs/tree.js index 7f52206d7c..3b37d2f9ac 100644 --- a/examples/traverse-ipld-graphs/tree.js +++ b/examples/traverse-ipld-graphs/tree.js @@ -4,6 +4,7 @@ const createNode = require('./create-node') const { DAGNode } = require('ipld-dag-pb') +const delay = require('delay') async function main () { const ipfs = await createNode() @@ -29,9 +30,11 @@ async function main () { hashAlg: 'sha3-512' }) - const paths = await ipfs.dag.tree(cborNodeCid, { recursive: true }) + for await (const path of ipfs.dag.tree(cborNodeCid, { recursive: true })) { + console.log(path) + } - console.log(paths) + await ipfs.stop() } main() diff --git a/examples/utils.js b/examples/utils.js index 98cc5d2beb..7c1b0ee41c 100644 --- a/examples/utils.js +++ b/examples/utils.js @@ -125,28 +125,48 @@ async function waitForOutput (expectedOutput, command, args = [], opts = {}) { let output = '' const time = 120000 - const timeout = setTimeout(() => { - throw new Error(`Did not see "${expectedOutput}" in output from "${[command].concat(args).join(' ')}" after ${time / 1000}s`) - }, time) + let foundExpectedOutput = false + let cancelTimeout + const timeoutPromise = new Promise((resolve, reject) => { + const timeout = setTimeout(() => { + reject(new Error(`Did not see "${expectedOutput}" in output from "${[command].concat(args).join(' ')}" after ${time / 1000}s`)) + + setTimeout(() => { + proc.kill() + }, 100) + }, time) + + cancelTimeout = () => { + clearTimeout(timeout) + resolve() + } + }) proc.all.on('data', (data) => { process.stdout.write(data) - output += data.toString('utf8') if (output.includes(expectedOutput)) { - clearTimeout(timeout) + foundExpectedOutput = true proc.kill() + cancelTimeout() } }) try { - await proc + await Promise.race([ + proc, + timeoutPromise + ]) } catch (err) { if (!err.killed) { throw err } } + + if (!foundExpectedOutput) { + throw new Error(`Did not see "${expectedOutput}" in output from "${[command].concat(args).join(' ')}"`) + } } module.exports = { diff --git a/src/core/components/id.js b/src/core/components/id.js index 8e5fcab862..95c60efb5b 100644 --- a/src/core/components/id.js +++ b/src/core/components/id.js @@ -4,12 +4,14 @@ const pkgversion = require('../../../package.json').version module.exports = ({ peerInfo }) => { return async function id () { // eslint-disable-line require-await + const id = peerInfo.id.toB58String() + return { - id: peerInfo.id.toB58String(), + id, publicKey: peerInfo.id.pubKey.bytes.toString('base64'), addresses: peerInfo.multiaddrs .toArray() - .map(ma => `${ma}/p2p/${peerInfo.id.toB58String()}`) + .map(ma => `${ma}/p2p/${id}`) .sort(), agentVersion: `js-ipfs/${pkgversion}`, protocolVersion: '9000' diff --git a/src/core/components/start.js b/src/core/components/start.js index fecf76d357..0cc574f0ff 100644 --- a/src/core/components/start.js +++ b/src/core/components/start.js @@ -268,7 +268,8 @@ function createApi ({ localAddrs: Components.swarm.localAddrs({ peerInfo }), peers: Components.swarm.peers({ libp2p }) }, - version: Components.version({ repo }) + version: Components.version({ repo }), + libp2p } return api diff --git a/src/core/components/swarm/peers.js b/src/core/components/swarm/peers.js index 3fbc45c9c8..f9d7b16745 100644 --- a/src/core/components/swarm/peers.js +++ b/src/core/components/swarm/peers.js @@ -1,7 +1,5 @@ 'use strict' -const CID = require('cids') - module.exports = ({ libp2p }) => { return async function peers (options) { // eslint-disable-line require-await options = options || {} @@ -13,7 +11,7 @@ module.exports = ({ libp2p }) => { for (const connection of connections) { const tupple = { addr: connection.remoteAddr, - peer: new CID(peerId) + peer: peerId } if (verbose || options.direction) { From 4597d88f8cb3c0c93321efd559f757324aa1da38 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Fri, 24 Jan 2020 11:46:53 +0000 Subject: [PATCH 02/55] chore: fix linting --- src/core/components/start.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/core/components/start.js b/src/core/components/start.js index 0cc574f0ff..fecf76d357 100644 --- a/src/core/components/start.js +++ b/src/core/components/start.js @@ -268,8 +268,7 @@ function createApi ({ localAddrs: Components.swarm.localAddrs({ peerInfo }), peers: Components.swarm.peers({ libp2p }) }, - version: Components.version({ repo }), - libp2p + version: Components.version({ repo }) } return api From 17e336c33e6f519c51d38c71e64f9cb98f462f38 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Fri, 24 Jan 2020 12:56:33 +0000 Subject: [PATCH 03/55] chore: update deps --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index a1d58bee32..41e5f8e061 100644 --- a/package.json +++ b/package.json @@ -91,7 +91,7 @@ "ipfs-bitswap": "github:ipfs/js-ipfs-bitswap#refactor/libp2p-async", "ipfs-block": "~0.8.1", "ipfs-block-service": "~0.16.0", - "ipfs-http-client": "^42.0.0-pre.0", + "ipfs-http-client": "ipfs/ipfs-http-client#return-peer-ids-as-strings", "ipfs-http-response": "^0.5.0", "ipfs-mfs": "^1.0.0", "ipfs-multipart": "^0.3.0", @@ -176,7 +176,7 @@ "execa": "^3.0.0", "form-data": "^3.0.0", "hat": "0.0.3", - "interface-ipfs-core": "^0.129.0", + "interface-ipfs-core": "ipfs/interface-js-ipfs-core#return-peer-ids-as-strings", "ipfs-interop": "github:ipfs/interop#refactor/async-await", "ipfsd-ctl": "github:ipfs/js-ipfsd-ctl#feat/force-kill", "ncp": "^2.0.0", From e7329788e07b53f915503dfdf3cdb88df5edb46d Mon Sep 17 00:00:00 2001 From: achingbrain Date: Fri, 24 Jan 2020 13:22:53 +0000 Subject: [PATCH 04/55] chore: update gh urls --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 41e5f8e061..502892208d 100644 --- a/package.json +++ b/package.json @@ -91,7 +91,7 @@ "ipfs-bitswap": "github:ipfs/js-ipfs-bitswap#refactor/libp2p-async", "ipfs-block": "~0.8.1", "ipfs-block-service": "~0.16.0", - "ipfs-http-client": "ipfs/ipfs-http-client#return-peer-ids-as-strings", + "ipfs-http-client": "github:ipfs/ipfs-http-client#return-peer-ids-as-strings", "ipfs-http-response": "^0.5.0", "ipfs-mfs": "^1.0.0", "ipfs-multipart": "^0.3.0", @@ -176,7 +176,7 @@ "execa": "^3.0.0", "form-data": "^3.0.0", "hat": "0.0.3", - "interface-ipfs-core": "ipfs/interface-js-ipfs-core#return-peer-ids-as-strings", + "interface-ipfs-core": "github:ipfs/interface-js-ipfs-core#return-peer-ids-as-strings", "ipfs-interop": "github:ipfs/interop#refactor/async-await", "ipfsd-ctl": "github:ipfs/js-ipfsd-ctl#feat/force-kill", "ncp": "^2.0.0", From 732e786a6cacf02f810cf378cea24a93291e6047 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Fri, 24 Jan 2020 13:40:56 +0000 Subject: [PATCH 05/55] chore: http gh urls maybe --- package.json | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 502892208d..6459a3365e 100644 --- a/package.json +++ b/package.json @@ -88,10 +88,10 @@ "hapi-pino": "^6.1.0", "hashlru": "^2.3.0", "interface-datastore": "~0.8.0", - "ipfs-bitswap": "github:ipfs/js-ipfs-bitswap#refactor/libp2p-async", + "ipfs-bitswap": "ipfs/js-ipfs-bitswap#refactor/libp2p-async", "ipfs-block": "~0.8.1", "ipfs-block-service": "~0.16.0", - "ipfs-http-client": "github:ipfs/ipfs-http-client#return-peer-ids-as-strings", + "ipfs-http-client": "ipfs/ipfs-http-client#return-peer-ids-as-strings", "ipfs-http-response": "^0.5.0", "ipfs-mfs": "^1.0.0", "ipfs-multipart": "^0.3.0", @@ -122,13 +122,13 @@ "just-safe-set": "^2.1.0", "ky": "^0.15.0", "ky-universal": "~0.3.0", - "libp2p": "github:libp2p/js-libp2p#refactor/async-await", + "libp2p": "libp2p/js-libp2p#refactor/async-await", "libp2p-bootstrap": "^0.10.2", "libp2p-crypto": "^0.17.1", "libp2p-delegated-content-routing": "^0.4.1", "libp2p-delegated-peer-routing": "^0.4.0", "libp2p-floodsub": "^0.20.0", - "libp2p-gossipsub": "github:ChainSafe/gossipsub-js#71cb905983b125b50c64a9b75d745dfd7fb8f094", + "libp2p-gossipsub": "ChainSafe/gossipsub-js#71cb905983b125b50c64a9b75d745dfd7fb8f094", "libp2p-kad-dht": "^0.18.3", "libp2p-keychain": "^0.6.0", "libp2p-mdns": "^0.13.0", @@ -176,9 +176,9 @@ "execa": "^3.0.0", "form-data": "^3.0.0", "hat": "0.0.3", - "interface-ipfs-core": "github:ipfs/interface-js-ipfs-core#return-peer-ids-as-strings", - "ipfs-interop": "github:ipfs/interop#refactor/async-await", - "ipfsd-ctl": "github:ipfs/js-ipfsd-ctl#feat/force-kill", + "interface-ipfs-core": "ipfs/interface-js-ipfs-core#return-peer-ids-as-strings", + "ipfs-interop": "ipfs/interop#refactor/async-await", + "ipfsd-ctl": "ipfs/js-ipfsd-ctl#feat/force-kill", "ncp": "^2.0.0", "p-event": "^4.1.0", "p-map": "^3.0.0", From 82326a3ef6b3a6036fd37ef4a338c3481b48eced Mon Sep 17 00:00:00 2001 From: achingbrain Date: Fri, 24 Jan 2020 13:51:53 +0000 Subject: [PATCH 06/55] chore: revert previous --- package.json | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 6459a3365e..502892208d 100644 --- a/package.json +++ b/package.json @@ -88,10 +88,10 @@ "hapi-pino": "^6.1.0", "hashlru": "^2.3.0", "interface-datastore": "~0.8.0", - "ipfs-bitswap": "ipfs/js-ipfs-bitswap#refactor/libp2p-async", + "ipfs-bitswap": "github:ipfs/js-ipfs-bitswap#refactor/libp2p-async", "ipfs-block": "~0.8.1", "ipfs-block-service": "~0.16.0", - "ipfs-http-client": "ipfs/ipfs-http-client#return-peer-ids-as-strings", + "ipfs-http-client": "github:ipfs/ipfs-http-client#return-peer-ids-as-strings", "ipfs-http-response": "^0.5.0", "ipfs-mfs": "^1.0.0", "ipfs-multipart": "^0.3.0", @@ -122,13 +122,13 @@ "just-safe-set": "^2.1.0", "ky": "^0.15.0", "ky-universal": "~0.3.0", - "libp2p": "libp2p/js-libp2p#refactor/async-await", + "libp2p": "github:libp2p/js-libp2p#refactor/async-await", "libp2p-bootstrap": "^0.10.2", "libp2p-crypto": "^0.17.1", "libp2p-delegated-content-routing": "^0.4.1", "libp2p-delegated-peer-routing": "^0.4.0", "libp2p-floodsub": "^0.20.0", - "libp2p-gossipsub": "ChainSafe/gossipsub-js#71cb905983b125b50c64a9b75d745dfd7fb8f094", + "libp2p-gossipsub": "github:ChainSafe/gossipsub-js#71cb905983b125b50c64a9b75d745dfd7fb8f094", "libp2p-kad-dht": "^0.18.3", "libp2p-keychain": "^0.6.0", "libp2p-mdns": "^0.13.0", @@ -176,9 +176,9 @@ "execa": "^3.0.0", "form-data": "^3.0.0", "hat": "0.0.3", - "interface-ipfs-core": "ipfs/interface-js-ipfs-core#return-peer-ids-as-strings", - "ipfs-interop": "ipfs/interop#refactor/async-await", - "ipfsd-ctl": "ipfs/js-ipfsd-ctl#feat/force-kill", + "interface-ipfs-core": "github:ipfs/interface-js-ipfs-core#return-peer-ids-as-strings", + "ipfs-interop": "github:ipfs/interop#refactor/async-await", + "ipfsd-ctl": "github:ipfs/js-ipfsd-ctl#feat/force-kill", "ncp": "^2.0.0", "p-event": "^4.1.0", "p-map": "^3.0.0", From 45a6f26ecd90e79d42fac83c9c02f847b38d9e88 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Fri, 24 Jan 2020 14:54:00 +0000 Subject: [PATCH 07/55] chore: use correct gh url --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 502892208d..c81c3ed94f 100644 --- a/package.json +++ b/package.json @@ -91,7 +91,7 @@ "ipfs-bitswap": "github:ipfs/js-ipfs-bitswap#refactor/libp2p-async", "ipfs-block": "~0.8.1", "ipfs-block-service": "~0.16.0", - "ipfs-http-client": "github:ipfs/ipfs-http-client#return-peer-ids-as-strings", + "ipfs-http-client": "github:ipfs/js-ipfs-http-client#return-peer-ids-as-strings", "ipfs-http-response": "^0.5.0", "ipfs-mfs": "^1.0.0", "ipfs-multipart": "^0.3.0", From ef6518356049c09cecd841be31ba89e15b02787e Mon Sep 17 00:00:00 2001 From: achingbrain Date: Fri, 24 Jan 2020 15:34:58 +0000 Subject: [PATCH 08/55] chore: update dep version --- examples/custom-libp2p/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/custom-libp2p/package.json b/examples/custom-libp2p/package.json index 3d0a253e32..d66fe55c6e 100644 --- a/examples/custom-libp2p/package.json +++ b/examples/custom-libp2p/package.json @@ -9,8 +9,8 @@ }, "license": "MIT", "dependencies": { - "libp2p": "github:libp2p/js-libp2p#refactor/async-await", - "libp2p-bootstrap": "^0.10.should generate a new rsa key", + "libp2p": "^0.27.0-rc.0", + "libp2p-bootstrap": "^0.10.3", "libp2p-kad-dht": "^0.18.3", "libp2p-mdns": "^0.13.1", "libp2p-mplex": "^0.9.3", From f3e9c7682b570423a99ae94482329cee57e5e7fb Mon Sep 17 00:00:00 2001 From: achingbrain Date: Fri, 24 Jan 2020 15:54:29 +0000 Subject: [PATCH 09/55] fix: fix failing tests --- test/http-api/inject/pin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/http-api/inject/pin.js b/test/http-api/inject/pin.js index e196ceb9dc..f4a77ab1d6 100644 --- a/test/http-api/inject/pin.js +++ b/test/http-api/inject/pin.js @@ -234,7 +234,7 @@ module.exports = (http) => { }) expect(res.statusCode).to.equal(200) - expect(res.result.Keys).to.include.all.keys(Object.values(pins)) + expect(res.result.Keys).to.include.keys(Object.values(pins)) }) it('finds all pinned objects streaming', async () => { From 23464887851777a31a862f07b82e6b5049a0a503 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Fri, 24 Jan 2020 18:19:55 +0000 Subject: [PATCH 10/55] chore: remove gh url --- examples/circuit-relaying/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/circuit-relaying/package.json b/examples/circuit-relaying/package.json index f810bdbb9b..6e50b64d0f 100644 --- a/examples/circuit-relaying/package.json +++ b/examples/circuit-relaying/package.json @@ -15,7 +15,7 @@ "license": "MIT", "dependencies": { "ipfs": "file:../../", - "ipfs-pubsub-room": "ipfs-shipyard/ipfs-pubsub-room#update-to-async-iterators" + "ipfs-pubsub-room": "^2.0.0" }, "devDependencies": { "aegir": "^20.0.0", From a9ac189fc92066c7f14e66a5ace99c0f97a2104e Mon Sep 17 00:00:00 2001 From: achingbrain Date: Mon, 27 Jan 2020 14:46:48 +0000 Subject: [PATCH 11/55] docs: update module maintainers --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index c81c3ed94f..a1d58bee32 100644 --- a/package.json +++ b/package.json @@ -91,7 +91,7 @@ "ipfs-bitswap": "github:ipfs/js-ipfs-bitswap#refactor/libp2p-async", "ipfs-block": "~0.8.1", "ipfs-block-service": "~0.16.0", - "ipfs-http-client": "github:ipfs/js-ipfs-http-client#return-peer-ids-as-strings", + "ipfs-http-client": "^42.0.0-pre.0", "ipfs-http-response": "^0.5.0", "ipfs-mfs": "^1.0.0", "ipfs-multipart": "^0.3.0", @@ -176,7 +176,7 @@ "execa": "^3.0.0", "form-data": "^3.0.0", "hat": "0.0.3", - "interface-ipfs-core": "github:ipfs/interface-js-ipfs-core#return-peer-ids-as-strings", + "interface-ipfs-core": "^0.129.0", "ipfs-interop": "github:ipfs/interop#refactor/async-await", "ipfsd-ctl": "github:ipfs/js-ipfsd-ctl#feat/force-kill", "ncp": "^2.0.0", From ba3998d9ae0014c40f8dc1cdf504a571518cc840 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Mon, 27 Jan 2020 14:47:06 +0000 Subject: [PATCH 12/55] fix: returns string peer ids from all api methods --- src/core/components/dht.js | 6 +++--- src/core/components/id.js | 4 +++- src/core/components/swarm/addrs.js | 5 ++++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/core/components/dht.js b/src/core/components/dht.js index 428627ccde..8eaed7cc76 100644 --- a/src/core/components/dht.js +++ b/src/core/components/dht.js @@ -77,7 +77,7 @@ module.exports = ({ libp2p, repo }) => { for await (const peerInfo of libp2p._dht.findProviders(key, options)) { yield { - id: new CID(peerInfo.id.toB58String()), + id: peerInfo.id.toB58String(), addrs: peerInfo.multiaddrs.toArray() } } @@ -97,7 +97,7 @@ module.exports = ({ libp2p, repo }) => { const peerInfo = await libp2p._dht.findPeer(peerId) return { - id: new CID(peerInfo.id.toB58String()), + id: peerInfo.id.toB58String(), addrs: peerInfo.multiaddrs.toArray() } }, @@ -153,7 +153,7 @@ module.exports = ({ libp2p, repo }) => { for await (const closerPeerId of libp2p._dht.getClosestPeers(peerId.toBytes())) { yield { - id: new CID(closerPeerId.toB58String()), + id: closerPeerId.toB58String(), addrs: [] // TODO: get addrs? } } diff --git a/src/core/components/id.js b/src/core/components/id.js index 95c60efb5b..1b25d25c71 100644 --- a/src/core/components/id.js +++ b/src/core/components/id.js @@ -1,6 +1,7 @@ 'use strict' const pkgversion = require('../../../package.json').version +const multiaddr = require('multiaddr') module.exports = ({ peerInfo }) => { return async function id () { // eslint-disable-line require-await @@ -12,7 +13,8 @@ module.exports = ({ peerInfo }) => { addresses: peerInfo.multiaddrs .toArray() .map(ma => `${ma}/p2p/${id}`) - .sort(), + .sort() + .map(ma => multiaddr(ma)), agentVersion: `js-ipfs/${pkgversion}`, protocolVersion: '9000' } diff --git a/src/core/components/swarm/addrs.js b/src/core/components/swarm/addrs.js index 16f6ca8efa..b79448af03 100644 --- a/src/core/components/swarm/addrs.js +++ b/src/core/components/swarm/addrs.js @@ -6,7 +6,10 @@ module.exports = ({ libp2p }) => { return async function addrs () { // eslint-disable-line require-await const peers = [] for (const [peerId, peerInfo] of libp2p.peerStore.peers.entries()) { - peers.push({ id: new CID(peerId), addrs: peerInfo.multiaddrs.toArray() }) + peers.push({ + id: peerId, + addrs: peerInfo.multiaddrs.toArray() + }) } return peers } From 3ce9db44546e92337f00997561b1370960d2fa38 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Mon, 27 Jan 2020 15:02:50 +0000 Subject: [PATCH 13/55] docs: update module maintainers --- README.md | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 93c08d2b2c..2e00436b55 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@

    -### Project status - `Alpha` +### Project status - `Alpha` We've come a long way, but this project is still in Alpha, lots of development is happening, API might change, beware of the Dragons 🐉.. @@ -40,19 +40,16 @@ We've come a long way, but this project is still in Alpha, lots of development i [**`Weekly Core Implementations Call`**](https://github.com/ipfs/team-mgmt/issues/992) -## Tech Lead +## Tech Lead [David Dias](https://github.com/daviddias) -## Lead Maintainer +## Lead Maintainer [Alan Shaw](https://github.com/alanshaw) -## Table of Contents +## Table of Contents -- [Tech Lead](#tech-lead) -- [Lead Maintainer](#lead-maintainer) -- [Table of Contents](#table-of-contents) - [Install](#install) - [npm](#npm) - [Use in Node.js](#use-in-nodejs) @@ -66,6 +63,7 @@ We've come a long way, but this project is still in Alpha, lots of development i - [API](#api) - [IPFS Constructor](#ipfs-constructor) - [`options.repo`](#optionsrepo) + - [`options.repoAutoMigrate`](#optionsrepoautomigrate) - [`options.init`](#optionsinit) - [`options.start`](#optionsstart) - [`options.pass`](#optionspass) @@ -1106,7 +1104,7 @@ Listing of the main packages used in the IPFS ecosystem. There are also three sp | [`ipfs-mfs`](//github.com/ipfs/js-ipfs-mfs) | [![npm](https://img.shields.io/npm/v/ipfs-mfs.svg?maxAge=86400&style=flat-square)](//github.com/ipfs/js-ipfs-mfs/releases) | [![Deps](https://david-dm.org/ipfs/js-ipfs-mfs.svg?style=flat-square)](https://david-dm.org/ipfs/js-ipfs-mfs) | [![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs-mfs.svg?branch=master)](https://travis-ci.com/ipfs/js-ipfs-mfs) | [![codecov](https://codecov.io/gh/ipfs/js-ipfs-mfs/branch/master/graph/badge.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs-mfs) | [Alex Potsides](mailto:alex.potsides@protocol.ai) | | [`ipfs-unixfs`](//github.com/ipfs/js-ipfs-unixfs) | [![npm](https://img.shields.io/npm/v/ipfs-unixfs.svg?maxAge=86400&style=flat-square)](//github.com/ipfs/js-ipfs-unixfs/releases) | [![Deps](https://david-dm.org/ipfs/js-ipfs-unixfs.svg?style=flat-square)](https://david-dm.org/ipfs/js-ipfs-unixfs) | [![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs-unixfs.svg?branch=master)](https://travis-ci.com/ipfs/js-ipfs-unixfs) | [![codecov](https://codecov.io/gh/ipfs/js-ipfs-unixfs/branch/master/graph/badge.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs-unixfs) | [Alex Potsides](mailto:alex.potsides@protocol.ai) | | **Repo** | -| [`ipfs-repo`](//github.com/ipfs/js-ipfs-repo) | [![npm](https://img.shields.io/npm/v/ipfs-repo.svg?maxAge=86400&style=flat-square)](//github.com/ipfs/js-ipfs-repo/releases) | [![Deps](https://david-dm.org/ipfs/js-ipfs-repo.svg?style=flat-square)](https://david-dm.org/ipfs/js-ipfs-repo) | [![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs-repo.svg?branch=master)](https://travis-ci.com/ipfs/js-ipfs-repo) | [![codecov](https://codecov.io/gh/ipfs/js-ipfs-repo/branch/master/graph/badge.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs-repo) | [Jacob Heun](mailto:jacobheun@gmail.com) | +| [`ipfs-repo`](//github.com/ipfs/js-ipfs-repo) | [![npm](https://img.shields.io/npm/v/ipfs-repo.svg?maxAge=86400&style=flat-square)](//github.com/ipfs/js-ipfs-repo/releases) | [![Deps](https://david-dm.org/ipfs/js-ipfs-repo.svg?style=flat-square)](https://david-dm.org/ipfs/js-ipfs-repo) | [![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs-repo.svg?branch=master)](https://travis-ci.com/ipfs/js-ipfs-repo) | [![codecov](https://codecov.io/gh/ipfs/js-ipfs-repo/branch/master/graph/badge.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs-repo) | [Alex Potsides](mailto:alex.potsides@protocol.ai) | | **Exchange** | | [`ipfs-block-service`](//github.com/ipfs/js-ipfs-block-service) | [![npm](https://img.shields.io/npm/v/ipfs-block-service.svg?maxAge=86400&style=flat-square)](//github.com/ipfs/js-ipfs-block-service/releases) | [![Deps](https://david-dm.org/ipfs/js-ipfs-block-service.svg?style=flat-square)](https://david-dm.org/ipfs/js-ipfs-block-service) | [![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs-block-service.svg?branch=master)](https://travis-ci.com/ipfs/js-ipfs-block-service) | [![codecov](https://codecov.io/gh/ipfs/js-ipfs-block-service/branch/master/graph/badge.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs-block-service) | [Volker Mische](mailto:volker.mische@gmail.com) | | [`ipfs-block`](//github.com/ipfs/js-ipfs-block) | [![npm](https://img.shields.io/npm/v/ipfs-block.svg?maxAge=86400&style=flat-square)](//github.com/ipfs/js-ipfs-block/releases) | [![Deps](https://david-dm.org/ipfs/js-ipfs-block.svg?style=flat-square)](https://david-dm.org/ipfs/js-ipfs-block) | [![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs-block.svg?branch=master)](https://travis-ci.com/ipfs/js-ipfs-block) | [![codecov](https://codecov.io/gh/ipfs/js-ipfs-block/branch/master/graph/badge.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs-block) | [Volker Mische](mailto:volker.mische@gmail.com) | From 7f79b695aa1cf77c36c0232aff5287c728466d06 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Mon, 27 Jan 2020 15:03:08 +0000 Subject: [PATCH 14/55] chore: fix linter --- src/core/components/swarm/addrs.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/core/components/swarm/addrs.js b/src/core/components/swarm/addrs.js index b79448af03..adf6857c72 100644 --- a/src/core/components/swarm/addrs.js +++ b/src/core/components/swarm/addrs.js @@ -1,7 +1,5 @@ 'use strict' -const CID = require('cids') - module.exports = ({ libp2p }) => { return async function addrs () { // eslint-disable-line require-await const peers = [] From 6597e371d0ab5c56bbfbb1cd2b90a4f8be6f9b3a Mon Sep 17 00:00:00 2001 From: achingbrain Date: Mon, 27 Jan 2020 16:22:51 +0000 Subject: [PATCH 15/55] chore: run pubsub room tests against master --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 1672d57a02..b5ac1a3c60 100644 --- a/.travis.yml +++ b/.travis.yml @@ -128,7 +128,7 @@ jobs: - stage: test name: external - ipfs-pubsub-room script: - - npm run test:external -- ipfs-pubsub-room https://github.com/ipfs-shipyard/ipfs-pubsub-room.git --branch upgrade-to-latest-js-ipfs-rc + - npm run test:external -- ipfs-pubsub-room https://github.com/ipfs-shipyard/ipfs-pubsub-room.git - stage: test name: external - peer-base From 4a420630ddec8ca6d9af2a8a76b6a8e528a53c01 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Tue, 28 Jan 2020 09:10:37 +0000 Subject: [PATCH 16/55] fix: fix circuit relaying test --- examples/circuit-relaying/package.json | 2 +- examples/circuit-relaying/test.js | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/circuit-relaying/package.json b/examples/circuit-relaying/package.json index 6e50b64d0f..e317e9d15c 100644 --- a/examples/circuit-relaying/package.json +++ b/examples/circuit-relaying/package.json @@ -15,7 +15,7 @@ "license": "MIT", "dependencies": { "ipfs": "file:../../", - "ipfs-pubsub-room": "^2.0.0" + "ipfs-pubsub-room": "^2.0.1" }, "devDependencies": { "aegir": "^20.0.0", diff --git a/examples/circuit-relaying/test.js b/examples/circuit-relaying/test.js index c6d700eadb..f62e4ababa 100644 --- a/examples/circuit-relaying/test.js +++ b/examples/circuit-relaying/test.js @@ -66,7 +66,9 @@ async function runTest () { try { const id = await ipfsd.api.id() - const address = id.addresses.filter(addr => addr.includes('/ws/p2p/Qm')).pop() + const address = id.addresses + .map(ma => ma.toString()) + .find(addr => addr.includes('/ws/p2p/Qm')) if (!address) { throw new Error(`Could not find web socket address in ${id.addresses}`) @@ -146,7 +148,7 @@ module.exports[pkg.name] = function (browser) { .click('#send') browser.expect.element('#msgs').text.to.contain(`${remotePeerId.toString().substr(-4)}: hello`) - browser.expect.element('#msgs').text.to.contain(`${localPeerId.toString().substr(-4)}: hello`) + browser.expect.element('#msgs').text.to.contain(`${localPeerId.toString().substr(-4)}: hellos`) }) browser.end() From 7064f6bae542f21df09675bbdeaf364169cacb3c Mon Sep 17 00:00:00 2001 From: achingbrain Date: Tue, 28 Jan 2020 09:49:41 +0000 Subject: [PATCH 17/55] fix: really fix circuit relay test --- examples/circuit-relaying/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/circuit-relaying/test.js b/examples/circuit-relaying/test.js index f62e4ababa..4c08f7f070 100644 --- a/examples/circuit-relaying/test.js +++ b/examples/circuit-relaying/test.js @@ -148,7 +148,7 @@ module.exports[pkg.name] = function (browser) { .click('#send') browser.expect.element('#msgs').text.to.contain(`${remotePeerId.toString().substr(-4)}: hello`) - browser.expect.element('#msgs').text.to.contain(`${localPeerId.toString().substr(-4)}: hellos`) + browser.expect.element('#msgs').text.to.contain(`${localPeerId.toString().substr(-4)}: hello`) }) browser.end() From cdc767dc30c798081295dea12faf9be02bd78841 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Tue, 28 Jan 2020 11:08:17 +0000 Subject: [PATCH 18/55] wip: add debug --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index b5ac1a3c60..5d825e7269 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,6 +23,7 @@ env: # This stops Windows builds from hanging # https://travis-ci.community/t/timeout-after-build-finished-and-succeeded/1336 - YARN_GPG=no + - DEBUG=ipfs* addons: apt: From a404a3649ac2a21a50a6180bea00aeddef57da21 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Tue, 28 Jan 2020 11:35:05 +0000 Subject: [PATCH 19/55] wip: debug only test job and restore gh versions --- .travis.yml | 3 +-- package.json | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5d825e7269..1992781b9b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,7 +23,6 @@ env: # This stops Windows builds from hanging # https://travis-ci.community/t/timeout-after-build-finished-and-succeeded/1336 - YARN_GPG=no - - DEBUG=ipfs* addons: apt: @@ -36,7 +35,7 @@ addons: - dpkg chrome: stable -script: npx nyc -s npx aegir test -t node --timeout 10000 --bail +script: DEBUG=ipfs* npx nyc -s npx aegir test -t node --timeout 10000 --bail after_success: - npx nyc report --reporter=text-lcov > coverage.lcov && npx codecov diff --git a/package.json b/package.json index a1d58bee32..c81c3ed94f 100644 --- a/package.json +++ b/package.json @@ -91,7 +91,7 @@ "ipfs-bitswap": "github:ipfs/js-ipfs-bitswap#refactor/libp2p-async", "ipfs-block": "~0.8.1", "ipfs-block-service": "~0.16.0", - "ipfs-http-client": "^42.0.0-pre.0", + "ipfs-http-client": "github:ipfs/js-ipfs-http-client#return-peer-ids-as-strings", "ipfs-http-response": "^0.5.0", "ipfs-mfs": "^1.0.0", "ipfs-multipart": "^0.3.0", @@ -176,7 +176,7 @@ "execa": "^3.0.0", "form-data": "^3.0.0", "hat": "0.0.3", - "interface-ipfs-core": "^0.129.0", + "interface-ipfs-core": "github:ipfs/interface-js-ipfs-core#return-peer-ids-as-strings", "ipfs-interop": "github:ipfs/interop#refactor/async-await", "ipfsd-ctl": "github:ipfs/js-ipfsd-ctl#feat/force-kill", "ncp": "^2.0.0", From 6b0de9fe950ceae1d880e2b632ccaed3d86cf21d Mon Sep 17 00:00:00 2001 From: achingbrain Date: Tue, 28 Jan 2020 13:29:53 +0000 Subject: [PATCH 20/55] fix: fix exchange files in browser test --- examples/exchange-files-in-browser/test.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/exchange-files-in-browser/test.js b/examples/exchange-files-in-browser/test.js index a019545271..723a00ba29 100644 --- a/examples/exchange-files-in-browser/test.js +++ b/examples/exchange-files-in-browser/test.js @@ -73,7 +73,9 @@ async function runTest () { try { const id = await relay.api.id() - const address = id.addresses.find(addr => addr.includes('/ws/p2p/')) + const address = id.addresses + .map(ma => ma.toString()) + .find(addr => addr.includes('/ws/p2p')) if (!address) { throw new Error(`Could not find web socket address in ${id.addresses}`) From 0c30d05a6287b444d7fbf7e58c1253d4a2702951 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Tue, 28 Jan 2020 13:30:43 +0000 Subject: [PATCH 21/55] chore: remove gh urls --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index c81c3ed94f..720fee68d0 100644 --- a/package.json +++ b/package.json @@ -122,13 +122,13 @@ "just-safe-set": "^2.1.0", "ky": "^0.15.0", "ky-universal": "~0.3.0", - "libp2p": "github:libp2p/js-libp2p#refactor/async-await", + "libp2p": "^0.27.0", "libp2p-bootstrap": "^0.10.2", "libp2p-crypto": "^0.17.1", "libp2p-delegated-content-routing": "^0.4.1", "libp2p-delegated-peer-routing": "^0.4.0", "libp2p-floodsub": "^0.20.0", - "libp2p-gossipsub": "github:ChainSafe/gossipsub-js#71cb905983b125b50c64a9b75d745dfd7fb8f094", + "libp2p-gossipsub": "^0.2.2", "libp2p-kad-dht": "^0.18.3", "libp2p-keychain": "^0.6.0", "libp2p-mdns": "^0.13.0", From bc7e62d8dbe1af1127879e6f8fe448f286b11ecd Mon Sep 17 00:00:00 2001 From: achingbrain Date: Tue, 28 Jan 2020 16:07:17 +0000 Subject: [PATCH 22/55] wip: really force kill daemon --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 720fee68d0..96c1be1e2a 100644 --- a/package.json +++ b/package.json @@ -88,7 +88,7 @@ "hapi-pino": "^6.1.0", "hashlru": "^2.3.0", "interface-datastore": "~0.8.0", - "ipfs-bitswap": "github:ipfs/js-ipfs-bitswap#refactor/libp2p-async", + "ipfs-bitswap": "^0.27.0", "ipfs-block": "~0.8.1", "ipfs-block-service": "~0.16.0", "ipfs-http-client": "github:ipfs/js-ipfs-http-client#return-peer-ids-as-strings", @@ -178,7 +178,7 @@ "hat": "0.0.3", "interface-ipfs-core": "github:ipfs/interface-js-ipfs-core#return-peer-ids-as-strings", "ipfs-interop": "github:ipfs/interop#refactor/async-await", - "ipfsd-ctl": "github:ipfs/js-ipfsd-ctl#feat/force-kill", + "ipfsd-ctl": "github:ipfs/js-ipfsd-ctl#feat/really-force-kill", "ncp": "^2.0.0", "p-event": "^4.1.0", "p-map": "^3.0.0", From a1d52de59e4734b42b8a7eaf7958560e3f37ff80 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Tue, 28 Jan 2020 16:13:03 +0000 Subject: [PATCH 23/55] chore: correct branch name --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 96c1be1e2a..df217f9e8f 100644 --- a/package.json +++ b/package.json @@ -178,7 +178,7 @@ "hat": "0.0.3", "interface-ipfs-core": "github:ipfs/interface-js-ipfs-core#return-peer-ids-as-strings", "ipfs-interop": "github:ipfs/interop#refactor/async-await", - "ipfsd-ctl": "github:ipfs/js-ipfsd-ctl#feat/really-force-kill", + "ipfsd-ctl": "github:ipfs/js-ipfsd-ctl#really-force-kill", "ncp": "^2.0.0", "p-event": "^4.1.0", "p-map": "^3.0.0", From 92bc0157828af087ada696e26755529b1854d981 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Tue, 28 Jan 2020 16:29:42 +0000 Subject: [PATCH 24/55] chore: make unhandled rejections fail tests --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index df217f9e8f..7c05b032eb 100644 --- a/package.json +++ b/package.json @@ -168,7 +168,7 @@ "yargs-promise": "^1.1.0" }, "devDependencies": { - "aegir": "^20.4.1", + "aegir": "github:ipfs/aegir#make-unhandled-promise-rejections-fail-tests", "base64url": "^3.0.1", "clear-module": "^4.0.0", "delay": "^4.1.0", From dcf052feb6f59a4b0a57f027936eb55c75aaee70 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Tue, 28 Jan 2020 17:19:10 +0000 Subject: [PATCH 25/55] chore: if debug is enabled do not treat stderr output as error --- test/cli/daemon.js | 5 +++++ test/core/create-node.spec.js | 2 ++ 2 files changed, 7 insertions(+) diff --git a/test/cli/daemon.js b/test/cli/daemon.js index 2b5a6f2d18..a6cd835420 100644 --- a/test/cli/daemon.js +++ b/test/cli/daemon.js @@ -38,6 +38,11 @@ const daemonReady = async (daemon, options) => { }) daemon.stderr.on('data', (data) => { + if (process && process.env && process.env.DEBUG) { + // causes data to be written out to stderr + return + } + if (!data.toString().includes('ExperimentalWarning')) { reject(new Error('Daemon didn\'t start ' + data)) } diff --git a/test/core/create-node.spec.js b/test/core/create-node.spec.js index c0f72c8fa4..8b63ee1ae0 100644 --- a/test/core/create-node.spec.js +++ b/test/core/create-node.spec.js @@ -113,6 +113,8 @@ describe('create node', function () { }) it('should be silent', async function () { + if (process && process.env && process.env.DEBUG) return this.skip() + this.timeout(30 * 1000) sinon.spy(console, 'log') From b831a037fa236b3935a5b469aa3edd91bef1360f Mon Sep 17 00:00:00 2001 From: achingbrain Date: Tue, 28 Jan 2020 17:32:02 +0000 Subject: [PATCH 26/55] chore: skip silent test when debug log is turned on --- test/cli/daemon.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/cli/daemon.js b/test/cli/daemon.js index a6cd835420..8a0692cde7 100644 --- a/test/cli/daemon.js +++ b/test/cli/daemon.js @@ -184,6 +184,8 @@ describe('daemon', () => { }) it('should be silent', async function () { + if (process && process.env && process.env.DEBUG) return this.skip() + this.timeout(100 * 1000) await ipfs('init') From db52fba6289ccff79f9bc01ebaae0b4107446d68 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Wed, 29 Jan 2020 10:38:03 +0000 Subject: [PATCH 27/55] chore: update deps --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 7c05b032eb..8cfa6580cc 100644 --- a/package.json +++ b/package.json @@ -168,7 +168,7 @@ "yargs-promise": "^1.1.0" }, "devDependencies": { - "aegir": "github:ipfs/aegir#make-unhandled-promise-rejections-fail-tests", + "aegir": "^20.5.1", "base64url": "^3.0.1", "clear-module": "^4.0.0", "delay": "^4.1.0", @@ -178,7 +178,7 @@ "hat": "0.0.3", "interface-ipfs-core": "github:ipfs/interface-js-ipfs-core#return-peer-ids-as-strings", "ipfs-interop": "github:ipfs/interop#refactor/async-await", - "ipfsd-ctl": "github:ipfs/js-ipfsd-ctl#really-force-kill", + "ipfsd-ctl": "github:ipfs/js-ipfsd-ctl#feat/force-kill", "ncp": "^2.0.0", "p-event": "^4.1.0", "p-map": "^3.0.0", From 41a738eb12aefe540ac14afa3dce5c48441b8e3a Mon Sep 17 00:00:00 2001 From: achingbrain Date: Wed, 29 Jan 2020 13:19:29 +0000 Subject: [PATCH 28/55] fix: peer ids are strings, do not stringify them --- examples/circuit-relaying/src/helpers.js | 4 ++-- examples/circuit-relaying/test.js | 4 ++-- examples/custom-ipfs-repo/index.js | 9 +++------ examples/custom-ipfs-repo/package.json | 3 ++- examples/custom-libp2p/package.json | 3 +-- examples/exchange-files-in-browser/public/app.js | 5 +++-- examples/ipfs-101/1.js | 9 +++------ examples/ipfs-101/package.json | 3 ++- examples/package.json | 1 - examples/running-multiple-nodes/test.js | 4 ---- examples/traverse-ipld-graphs/tree.js | 1 - 11 files changed, 18 insertions(+), 28 deletions(-) diff --git a/examples/circuit-relaying/src/helpers.js b/examples/circuit-relaying/src/helpers.js index 3b14969e66..61330bf212 100644 --- a/examples/circuit-relaying/src/helpers.js +++ b/examples/circuit-relaying/src/helpers.js @@ -31,9 +31,9 @@ module.exports = (ipfs, peersSet) => { // send and receive messages room.on('message', (message) => { - console.log('got message from ' + message.from.toString() + ': ' + message.data.toString()) + console.log('got message from ' + message.from + ': ' + message.data.toString()) const node = document.createElement(`li`) - node.innerText = `${message.from.toString().substr(-4)}: ${message.data.toString()}` + node.innerText = `${message.from.substr(-4)}: ${message.data.toString()}` $msgs.appendChild(node) }) diff --git a/examples/circuit-relaying/test.js b/examples/circuit-relaying/test.js index 4c08f7f070..955f6580fe 100644 --- a/examples/circuit-relaying/test.js +++ b/examples/circuit-relaying/test.js @@ -147,8 +147,8 @@ module.exports[pkg.name] = function (browser) { .pause(1000) .click('#send') - browser.expect.element('#msgs').text.to.contain(`${remotePeerId.toString().substr(-4)}: hello`) - browser.expect.element('#msgs').text.to.contain(`${localPeerId.toString().substr(-4)}: hello`) + browser.expect.element('#msgs').text.to.contain(`${remotePeerId.substr(-4)}: hello`) + browser.expect.element('#msgs').text.to.contain(`${localPeerId.substr(-4)}: hello`) }) browser.end() diff --git a/examples/custom-ipfs-repo/index.js b/examples/custom-ipfs-repo/index.js index 7bfbf8ef66..058bbd2ec3 100644 --- a/examples/custom-ipfs-repo/index.js +++ b/examples/custom-ipfs-repo/index.js @@ -3,6 +3,7 @@ const IPFS = require('ipfs') const Repo = require('ipfs-repo') const fsLock = require('ipfs-repo/src/lock') +const all = require('it-all') // Create our custom options const customRepositoryOptions = { @@ -86,15 +87,11 @@ async function main () { // Log out the added files metadata and cat the file from IPFS console.log('\nAdded file:', file.path, file.cid) - const bufs = [] - - for await (const buf of node.cat(file.cid)) { - bufs.push(buf) - } + const data = Buffer.concat(await all(node.cat(file.cid))) // Print out the files contents to console console.log('\nFetched file content:') - process.stdout.write(Buffer.concat(bufs)) + process.stdout.write(data) } // After everything is done, shut the node down diff --git a/examples/custom-ipfs-repo/package.json b/examples/custom-ipfs-repo/package.json index f7289d7bca..7e52503e29 100644 --- a/examples/custom-ipfs-repo/package.json +++ b/examples/custom-ipfs-repo/package.json @@ -11,7 +11,8 @@ "dependencies": { "datastore-fs": "^0.9.1", "ipfs": "file:../../", - "ipfs-repo": "^0.28.0" + "ipfs-repo": "^0.28.0", + "it-all": "^1.0.1" }, "devDependencies": { "execa": "^3.2.0" diff --git a/examples/custom-libp2p/package.json b/examples/custom-libp2p/package.json index d66fe55c6e..62c1a398fc 100644 --- a/examples/custom-libp2p/package.json +++ b/examples/custom-libp2p/package.json @@ -16,8 +16,7 @@ "libp2p-mplex": "^0.9.3", "libp2p-secio": "^0.12.2", "libp2p-spdy": "^0.13.3", - "libp2p-tcp": "^0.14.3", - "libp2p-webrtc-star": "^0.17.2" + "libp2p-tcp": "^0.14.3" }, "devDependencies": { "execa": "^4.0.0" diff --git a/examples/exchange-files-in-browser/public/app.js b/examples/exchange-files-in-browser/public/app.js index 6267b568f3..2ef1e507f5 100644 --- a/examples/exchange-files-in-browser/public/app.js +++ b/examples/exchange-files-in-browser/public/app.js @@ -49,7 +49,8 @@ async function start () { config: { Addresses: { Swarm: [ - //'/dns4/ws-star.discovery.libp2p.io/tcp/443/wss/p2p-websocket-star' + // This is a public webrtc-star server + // '/dns4/ws-star.discovery.libp2p.io/tcp/443/wss/p2p-websocket-star' '/ip4/127.0.0.1/tcp/13579/wss/p2p-webrtc-star' ] } @@ -283,7 +284,7 @@ async function refreshPeerList () { if (addr.indexOf('/p2p/') >= 0) { return addr } else { - return addr + peer.peer.toString() + return addr + peer.peer } } }) diff --git a/examples/ipfs-101/1.js b/examples/ipfs-101/1.js index ea45be2320..314f2dabbe 100644 --- a/examples/ipfs-101/1.js +++ b/examples/ipfs-101/1.js @@ -1,6 +1,7 @@ 'use strict' const IPFS = require('ipfs') +const all = require('it-all') async function main () { const node = await IPFS.create() @@ -14,13 +15,9 @@ async function main () { })) { console.log('Added file:', file.path, file.cid.toString()) - const bufs = [] + const data = Buffer.concat(await all(node.cat(file.cid))) - for await (const buf of node.cat(file.cid)) { - bufs.push(buf) - } - - console.log('Added file contents:', Buffer.concat(bufs).toString()) + console.log('Added file contents:', data.toString()) } } diff --git a/examples/ipfs-101/package.json b/examples/ipfs-101/package.json index 7b77539945..663bd15e1a 100644 --- a/examples/ipfs-101/package.json +++ b/examples/ipfs-101/package.json @@ -9,6 +9,7 @@ "author": "David Dias ", "license": "MIT", "dependencies": { - "ipfs": "file:../../" + "ipfs": "file:../../", + "it-all": "^1.0.1" } } diff --git a/examples/package.json b/examples/package.json index ed9608c395..42f4f055a2 100644 --- a/examples/package.json +++ b/examples/package.json @@ -9,7 +9,6 @@ "license": "MIT", "dependencies": { "chromedriver": "^79.0.0", - "delay": "^4.1.0", "execa": "^3.2.0", "fs-extra": "^8.1.0", "http-server": "~0.11.1", diff --git a/examples/running-multiple-nodes/test.js b/examples/running-multiple-nodes/test.js index 9aa41f680f..c62577d6a5 100644 --- a/examples/running-multiple-nodes/test.js +++ b/examples/running-multiple-nodes/test.js @@ -6,7 +6,6 @@ const execa = require('execa') const os = require('os') const path = require('path') const hat = require('hat') -const delay = require('delay') const { waitForOutput } = require('../utils') @@ -60,9 +59,6 @@ async function startProgramaticNode () { } }) - // https://github.com/ChainSafe/gossipsub-js/pull/59 - await delay(5000) - console.info('Stopping programmatic node') await node.stop() } diff --git a/examples/traverse-ipld-graphs/tree.js b/examples/traverse-ipld-graphs/tree.js index 3b37d2f9ac..1acba5e58d 100644 --- a/examples/traverse-ipld-graphs/tree.js +++ b/examples/traverse-ipld-graphs/tree.js @@ -4,7 +4,6 @@ const createNode = require('./create-node') const { DAGNode } = require('ipld-dag-pb') -const delay = require('delay') async function main () { const ipfs = await createNode() From b6988ee81969cb0fe5e0c4fb69c34206a18bd8e9 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Wed, 29 Jan 2020 23:36:22 +0000 Subject: [PATCH 29/55] fix: use gh url for ipfsd-ctl --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8cfa6580cc..3d8ce381b8 100644 --- a/package.json +++ b/package.json @@ -178,7 +178,7 @@ "hat": "0.0.3", "interface-ipfs-core": "github:ipfs/interface-js-ipfs-core#return-peer-ids-as-strings", "ipfs-interop": "github:ipfs/interop#refactor/async-await", - "ipfsd-ctl": "github:ipfs/js-ipfsd-ctl#feat/force-kill", + "ipfsd-ctl": "github:ipfs/js-ipfsd-ctl#only-require-http-client-if-not-specified", "ncp": "^2.0.0", "p-event": "^4.1.0", "p-map": "^3.0.0", From b5d76a325237fda389370858ca38207b55f0790c Mon Sep 17 00:00:00 2001 From: achingbrain Date: Wed, 29 Jan 2020 23:48:40 +0000 Subject: [PATCH 30/55] fix: use version of interface tests without js-ipfs --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3d8ce381b8..3f23047ac7 100644 --- a/package.json +++ b/package.json @@ -176,7 +176,7 @@ "execa": "^3.0.0", "form-data": "^3.0.0", "hat": "0.0.3", - "interface-ipfs-core": "github:ipfs/interface-js-ipfs-core#return-peer-ids-as-strings", + "interface-ipfs-core": "github:ipfs/interface-js-ipfs-core#do-not-assume-js-ipfs", "ipfs-interop": "github:ipfs/interop#refactor/async-await", "ipfsd-ctl": "github:ipfs/js-ipfsd-ctl#only-require-http-client-if-not-specified", "ncp": "^2.0.0", From 684b873601889aff0bde5804da3b0d8e2f691267 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 30 Jan 2020 07:58:31 +0000 Subject: [PATCH 31/55] chore: remove debug env var --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 1992781b9b..b5ac1a3c60 100644 --- a/.travis.yml +++ b/.travis.yml @@ -35,7 +35,7 @@ addons: - dpkg chrome: stable -script: DEBUG=ipfs* npx nyc -s npx aegir test -t node --timeout 10000 --bail +script: npx nyc -s npx aegir test -t node --timeout 10000 --bail after_success: - npx nyc report --reporter=text-lcov > coverage.lcov && npx codecov From 2b6f0e9116da773dbca6a6523a3811e1a2552c55 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 30 Jan 2020 20:38:37 +0000 Subject: [PATCH 32/55] fix: start webrtc sigserve during tests so browsers can dial things --- .aegir.js | 7 +++++++ src/core/components/id.js | 12 +++++++++++- test/core/interface.spec.js | 13 +++++++++++-- test/utils/factory.js | 14 ++++++++++++++ 4 files changed, 43 insertions(+), 3 deletions(-) diff --git a/.aegir.js b/.aegir.js index 93a928004c..4ae4b45c83 100644 --- a/.aegir.js +++ b/.aegir.js @@ -3,10 +3,12 @@ const IPFSFactory = require('ipfsd-ctl') const MockPreloadNode = require('./test/utils/mock-preload-node') const EchoServer = require('interface-ipfs-core/src/utils/echo-http-server') +const webRTCStarSigServer = require('libp2p-webrtc-star/src/sig-server') const ipfsdServer = IPFSFactory.createServer() const preloadNode = MockPreloadNode.createNode() const echoServer = EchoServer.createServer() +let sigServer module.exports = { bundlesize: { maxSize: '652kB' }, @@ -42,11 +44,16 @@ module.exports = { await ipfsdServer.start() await preloadNode.start() await echoServer.start() + sigServer = await webRTCStarSigServer.start({ + host: '127.0.0.1', + port: 14579 + }) }, post: async () => { await ipfsdServer.stop() await preloadNode.stop() await echoServer.stop() + await sigServer.stop() } } } diff --git a/src/core/components/id.js b/src/core/components/id.js index 1b25d25c71..ecc6843b8c 100644 --- a/src/core/components/id.js +++ b/src/core/components/id.js @@ -12,7 +12,17 @@ module.exports = ({ peerInfo }) => { publicKey: peerInfo.id.pubKey.bytes.toString('base64'), addresses: peerInfo.multiaddrs .toArray() - .map(ma => `${ma}/p2p/${id}`) + .map(ma => { + const str = ma.toString() + + // some relay-style transports add our peer id to the ma for us + // so don't double-add + if (str.endsWith(`/p2p/${id}`)) { + return str + } + + return `${str}/p2p/${id}` + }) .sort() .map(ma => multiaddr(ma)), agentVersion: `js-ipfs/${pkgversion}`, diff --git a/test/core/interface.spec.js b/test/core/interface.spec.js index 19ce074cea..4b4815cdde 100644 --- a/test/core/interface.spec.js +++ b/test/core/interface.spec.js @@ -4,7 +4,7 @@ const tests = require('interface-ipfs-core') const merge = require('merge-options') const { createFactory } = require('ipfsd-ctl') -const { isNode } = require('ipfs-utils/src/env') +const { isNode, isBrowser } = require('ipfs-utils/src/env') const IPFS = require('../../src') /** @typedef { import("ipfsd-ctl").ControllerOptions } ControllerOptions */ @@ -23,7 +23,16 @@ describe('interface-ipfs-core tests', function () { ref: require('ipfs-http-client') }, ipfsOptions: { - pass: 'ipfs-is-awesome-software' + pass: 'ipfs-is-awesome-software', + ...(isBrowser ? { + config: { + Addresses: { + Swarm: [ + '/ip4/127.0.0.1/tcp/14579/wss/p2p-webrtc-star' + ] + } + } + } : {}) } } const overrides = { diff --git a/test/utils/factory.js b/test/utils/factory.js index e8152175e9..dd2884369e 100644 --- a/test/utils/factory.js +++ b/test/utils/factory.js @@ -1,6 +1,7 @@ 'use strict' const { createFactory } = require('ipfsd-ctl') const merge = require('merge-options') +const { isBrowser } = require('ipfs-utils/src/env') const factory = (options, overrides) => createFactory( merge({ @@ -18,6 +19,19 @@ const factory = (options, overrides) => createFactory( merge({ js: { ipfsBin: './src/cli/bin.js' + }, + proc: { + ...(isBrowser ? { + ipfsOptions: { + config: { + Addresses: { + Swarm: [ + '/ip4/127.0.0.1/tcp/14579/wss/p2p-webrtc-star' + ] + } + } + } + } : {}) } }, overrides) ) From 7b868a3720f04e17fe8950e4928cbc4af0d65873 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Fri, 31 Jan 2020 06:40:07 +0000 Subject: [PATCH 33/55] fix: include go-ipfs-dep for interop testing --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 3f23047ac7..e2470b8b32 100644 --- a/package.json +++ b/package.json @@ -175,6 +175,7 @@ "dir-compare": "^1.7.3", "execa": "^3.0.0", "form-data": "^3.0.0", + "go-ipfs-dep": "^0.4.23", "hat": "0.0.3", "interface-ipfs-core": "github:ipfs/interface-js-ipfs-core#do-not-assume-js-ipfs", "ipfs-interop": "github:ipfs/interop#refactor/async-await", From 602f7615aacaa1eb5872e3b6ac7470e80a78b0d4 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Fri, 31 Jan 2020 06:56:24 +0000 Subject: [PATCH 34/55] fix: specify ipfs js module for interop tests --- .travis.yml | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b5ac1a3c60..bcdba6c621 100644 --- a/.travis.yml +++ b/.travis.yml @@ -79,6 +79,7 @@ jobs: - mkdir -p node_modules/ipfs-interop/node_modules - ln -s `pwd` node_modules/ipfs-interop/node_modules/ipfs - export IPFS_JS_EXEC=`pwd`/src/cli/bin.js + - export IPFS_JS_MODULE=`pwd` - export IPFS_REUSEPORT=false - cd node_modules/ipfs-interop - npx aegir test -t node --bail @@ -89,6 +90,7 @@ jobs: - mkdir -p node_modules/ipfs-interop/node_modules - ln -s `pwd` node_modules/ipfs-interop/node_modules/ipfs - export IPFS_JS_EXEC=`pwd`/src/cli/bin.js + - export IPFS_JS_MODULE=`pwd` - export IPFS_REUSEPORT=false - cd node_modules/ipfs-interop - npx aegir test -t browser --bail @@ -100,6 +102,7 @@ jobs: - mkdir -p node_modules/ipfs-interop/node_modules - ln -s `pwd` node_modules/ipfs-interop/node_modules/ipfs - export IPFS_JS_EXEC=`pwd`/src/cli/bin.js + - export IPFS_JS_MODULE=`pwd` - export IPFS_REUSEPORT=false - cd node_modules/ipfs-interop - npx aegir test -t electron-main -f ./test/node.js --bail --timeout 10000 @@ -111,6 +114,7 @@ jobs: - mkdir -p node_modules/ipfs-interop/node_modules - ln -s `pwd` node_modules/ipfs-interop/node_modules/ipfs - export IPFS_JS_EXEC=`pwd`/src/cli/bin.js + - export IPFS_JS_MODULE=`pwd` - export IPFS_REUSEPORT=false - cd node_modules/ipfs-interop - npx aegir test -t electron-renderer -f ./test/browser.js --bail --timeout 10000 diff --git a/package.json b/package.json index e2470b8b32..015f7d9b6b 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "test:node:cli": "aegir test -t node -f test/cli/index.js", "test:node:interface": "aegir test -t node -f test/core/interface.spec.js", "test:bootstrapers": "IPFS_TEST=bootstrapers aegir test -t browser -f test/bootstrapers.js", - "test:interop": "IPFS_JS_EXEC=$PWD/src/cli/bin.js ipfs-interop", + "test:interop": "IPFS_JS_EXEC=$PWD/src/cli/bin.js IPFS_JS_MODULE=$PWD ipfs-interop", "test:external": "aegir test-external", "coverage": "nyc --reporter=text --reporter=lcov npm run test:node", "benchmark": "echo \"Error: no benchmarks yet\" && exit 1", From acd2409731ae89fdd2bc30b5caec6aa774eadcbf Mon Sep 17 00:00:00 2001 From: achingbrain Date: Fri, 31 Jan 2020 07:26:54 +0000 Subject: [PATCH 35/55] fix: simplify interop test runs --- .travis.yml | 32 ++++---------------------------- package.json | 8 ++++++-- 2 files changed, 10 insertions(+), 30 deletions(-) diff --git a/.travis.yml b/.travis.yml index bcdba6c621..e445b499a1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -76,48 +76,24 @@ jobs: - stage: test name: interop - node script: - - mkdir -p node_modules/ipfs-interop/node_modules - - ln -s `pwd` node_modules/ipfs-interop/node_modules/ipfs - - export IPFS_JS_EXEC=`pwd`/src/cli/bin.js - - export IPFS_JS_MODULE=`pwd` - - export IPFS_REUSEPORT=false - - cd node_modules/ipfs-interop - - npx aegir test -t node --bail + - npm run test:interop:node -- --bail - stage: test name: interop - browser script: - - mkdir -p node_modules/ipfs-interop/node_modules - - ln -s `pwd` node_modules/ipfs-interop/node_modules/ipfs - - export IPFS_JS_EXEC=`pwd`/src/cli/bin.js - - export IPFS_JS_MODULE=`pwd` - - export IPFS_REUSEPORT=false - - cd node_modules/ipfs-interop - - npx aegir test -t browser --bail + - npm run test:interop:browser -- --bail - stage: test name: interop - electron-main os: osx script: - - mkdir -p node_modules/ipfs-interop/node_modules - - ln -s `pwd` node_modules/ipfs-interop/node_modules/ipfs - - export IPFS_JS_EXEC=`pwd`/src/cli/bin.js - - export IPFS_JS_MODULE=`pwd` - - export IPFS_REUSEPORT=false - - cd node_modules/ipfs-interop - - npx aegir test -t electron-main -f ./test/node.js --bail --timeout 10000 + - npm run test:interop:electron-main -- --bail --timeout 10000 - stage: test name: interop - electron-renderer os: osx script: - - mkdir -p node_modules/ipfs-interop/node_modules - - ln -s `pwd` node_modules/ipfs-interop/node_modules/ipfs - - export IPFS_JS_EXEC=`pwd`/src/cli/bin.js - - export IPFS_JS_MODULE=`pwd` - - export IPFS_REUSEPORT=false - - cd node_modules/ipfs-interop - - npx aegir test -t electron-renderer -f ./test/browser.js --bail --timeout 10000 + - npm run test:interop:electron-renderer -- --bail --timeout 10000 - stage: test name: external - ipfs-companion diff --git a/package.json b/package.json index 015f7d9b6b..4ea56a948b 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,11 @@ "test:node:cli": "aegir test -t node -f test/cli/index.js", "test:node:interface": "aegir test -t node -f test/core/interface.spec.js", "test:bootstrapers": "IPFS_TEST=bootstrapers aegir test -t browser -f test/bootstrapers.js", - "test:interop": "IPFS_JS_EXEC=$PWD/src/cli/bin.js IPFS_JS_MODULE=$PWD ipfs-interop", + "test:interop": "IPFS_JS_EXEC=$PWD/src/cli/bin.js IPFS_JS_MODULE=$PWD IPFS_REUSEPORT=false ipfs-interop", + "test:interop:node": "IPFS_JS_EXEC=$PWD/src/cli/bin.js IPFS_JS_MODULE=$PWD IPFS_REUSEPORT=false ipfs-interop -- -t node", + "test:interop:browser": "IPFS_JS_EXEC=$PWD/src/cli/bin.js IPFS_JS_MODULE=$PWD IPFS_REUSEPORT=false ipfs-interop -- -t browser", + "test:interop:electron-main": "IPFS_JS_EXEC=$PWD/src/cli/bin.js IPFS_JS_MODULE=$PWD IPFS_REUSEPORT=false ipfs-interop -- -t electron-main -f ./test/node.js", + "test:interop:electron-renderer": "IPFS_JS_EXEC=$PWD/src/cli/bin.js IPFS_JS_MODULE=$PWD IPFS_REUSEPORT=false ipfs-interop -- -t electron-renderer -f ./test/browser.js", "test:external": "aegir test-external", "coverage": "nyc --reporter=text --reporter=lcov npm run test:node", "benchmark": "echo \"Error: no benchmarks yet\" && exit 1", @@ -178,7 +182,7 @@ "go-ipfs-dep": "^0.4.23", "hat": "0.0.3", "interface-ipfs-core": "github:ipfs/interface-js-ipfs-core#do-not-assume-js-ipfs", - "ipfs-interop": "github:ipfs/interop#refactor/async-await", + "ipfs-interop": "github:ipfs/interop#refactor/async-await-and-pass-extra-args", "ipfsd-ctl": "github:ipfs/js-ipfsd-ctl#only-require-http-client-if-not-specified", "ncp": "^2.0.0", "p-event": "^4.1.0", From 192d4fadd03b5a6a75163cc1472dfcfadf0470d1 Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Fri, 31 Jan 2020 12:59:03 +0000 Subject: [PATCH 36/55] fix: update sigserver url Co-Authored-By: Alan Shaw --- examples/exchange-files-in-browser/public/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/exchange-files-in-browser/public/app.js b/examples/exchange-files-in-browser/public/app.js index 2ef1e507f5..29a3850a88 100644 --- a/examples/exchange-files-in-browser/public/app.js +++ b/examples/exchange-files-in-browser/public/app.js @@ -50,7 +50,7 @@ async function start () { Addresses: { Swarm: [ // This is a public webrtc-star server - // '/dns4/ws-star.discovery.libp2p.io/tcp/443/wss/p2p-websocket-star' + // '/dns4/star-signal.cloud.ipfs.team/wss/p2p-webrtc-star' '/ip4/127.0.0.1/tcp/13579/wss/p2p-webrtc-star' ] } From 2bb99f56c0e8b5c9ba6c54601be46b41f5342763 Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Fri, 31 Jan 2020 13:02:47 +0000 Subject: [PATCH 37/55] fix: use ws and not wss How did this ever work? Co-Authored-By: Alan Shaw --- test/core/interface.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/core/interface.spec.js b/test/core/interface.spec.js index 4b4815cdde..736239f316 100644 --- a/test/core/interface.spec.js +++ b/test/core/interface.spec.js @@ -28,7 +28,7 @@ describe('interface-ipfs-core tests', function () { config: { Addresses: { Swarm: [ - '/ip4/127.0.0.1/tcp/14579/wss/p2p-webrtc-star' + '/ip4/127.0.0.1/tcp/14579/ws/p2p-webrtc-star' ] } } From 4f7fbe770eabd7be5c601cf579df36207f888289 Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Fri, 31 Jan 2020 13:03:01 +0000 Subject: [PATCH 38/55] Update test/utils/factory.js How did this ever work? Co-Authored-By: Alan Shaw --- test/utils/factory.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/utils/factory.js b/test/utils/factory.js index dd2884369e..995325828b 100644 --- a/test/utils/factory.js +++ b/test/utils/factory.js @@ -26,7 +26,7 @@ const factory = (options, overrides) => createFactory( config: { Addresses: { Swarm: [ - '/ip4/127.0.0.1/tcp/14579/wss/p2p-webrtc-star' + '/ip4/127.0.0.1/tcp/14579/ws/p2p-webrtc-star' ] } } From 2671356601f91553df735a8ed5b4f7aad88a569a Mon Sep 17 00:00:00 2001 From: achingbrain Date: Fri, 31 Jan 2020 12:56:06 +0000 Subject: [PATCH 39/55] chore: remove gh urls Not required --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 4ea56a948b..1f3c9144bf 100644 --- a/package.json +++ b/package.json @@ -95,7 +95,7 @@ "ipfs-bitswap": "^0.27.0", "ipfs-block": "~0.8.1", "ipfs-block-service": "~0.16.0", - "ipfs-http-client": "github:ipfs/js-ipfs-http-client#return-peer-ids-as-strings", + "ipfs-http-client": "^42.0.0-pre.2", "ipfs-http-response": "^0.5.0", "ipfs-mfs": "^1.0.0", "ipfs-multipart": "^0.3.0", @@ -181,9 +181,9 @@ "form-data": "^3.0.0", "go-ipfs-dep": "^0.4.23", "hat": "0.0.3", - "interface-ipfs-core": "github:ipfs/interface-js-ipfs-core#do-not-assume-js-ipfs", - "ipfs-interop": "github:ipfs/interop#refactor/async-await-and-pass-extra-args", - "ipfsd-ctl": "github:ipfs/js-ipfsd-ctl#only-require-http-client-if-not-specified", + "interface-ipfs-core": "^0.131.0", + "ipfs-interop": "^0.2.1", + "ipfsd-ctl": "^2.1.0", "ncp": "^2.0.0", "p-event": "^4.1.0", "p-map": "^3.0.0", From bf9ac59c00ee75ebbef4c71bb679879f7a4a6095 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Fri, 31 Jan 2020 20:36:07 +0000 Subject: [PATCH 40/55] fix: fix up ipfsd-ctl config for browser tests Use common ipfsd config for module and interface tests. Also start second webrtc sig serve for the interface tests. --- .aegir.js | 60 +++++++++++++++++++++++-------- package.json | 6 ++-- test/core/interface.spec.js | 50 +++++--------------------- test/utils/factory.js | 70 ++++++++++++++++++++++--------------- 4 files changed, 98 insertions(+), 88 deletions(-) diff --git a/.aegir.js b/.aegir.js index 4ae4b45c83..75a60d3b58 100644 --- a/.aegir.js +++ b/.aegir.js @@ -1,14 +1,19 @@ 'use strict' -const IPFSFactory = require('ipfsd-ctl') +const { createServer } = require('ipfsd-ctl') const MockPreloadNode = require('./test/utils/mock-preload-node') const EchoServer = require('interface-ipfs-core/src/utils/echo-http-server') const webRTCStarSigServer = require('libp2p-webrtc-star/src/sig-server') +const path = require('path') +const webpack = require('webpack') -const ipfsdServer = IPFSFactory.createServer() const preloadNode = MockPreloadNode.createNode() const echoServer = EchoServer.createServer() -let sigServer + +// the second signalling server is needed for the inferface test 'should list peers only once even if they have multiple addresses' +let sigServerA +let sigServerB +let ipfsdServer module.exports = { bundlesize: { maxSize: '652kB' }, @@ -16,7 +21,12 @@ module.exports = { resolve: { mainFields: ['browser', 'main'], aliasFields: ['browser', 'browser-all-ipld-formats'], - } + }, + ...(process.env.NODE_ENV === 'test' ? { + plugins: [ + new webpack.EnvironmentPlugin(['DEBUG']) + ] + } : {}) }, karma: { files: [{ @@ -41,19 +51,39 @@ module.exports = { }, browser: { pre: async () => { - await ipfsdServer.start() - await preloadNode.start() - await echoServer.start() - sigServer = await webRTCStarSigServer.start({ - host: '127.0.0.1', - port: 14579 - }) + await preloadNode.start() + await echoServer.start() + sigServerA = await webRTCStarSigServer.start({ + host: '127.0.0.1', + port: 14579, + metrics: false + }) + sigServerB = await webRTCStarSigServer.start({ + host: '127.0.0.1', + port: 14578, + metrics: false + }) + ipfsdServer = await createServer({ + host: '127.0.0.1', + port: 43134 + }, { + ipfsModule: { + path: __dirname, + ref: require(__dirname) + }, + ipfsHttpModule: { + path: require.resolve('ipfs-http-client'), + ref: require('ipfs-http-client') + }, + ipfsBin: path.join(__dirname, 'src', 'cli', 'bin.js') + }).start() }, post: async () => { - await ipfsdServer.stop() - await preloadNode.stop() - await echoServer.stop() - await sigServer.stop() + await ipfsdServer.stop() + await preloadNode.stop() + await echoServer.stop() + await sigServerA.stop() + await sigServerB.stop() } } } diff --git a/package.json b/package.json index 1f3c9144bf..3ab9997321 100644 --- a/package.json +++ b/package.json @@ -140,7 +140,7 @@ "libp2p-record": "~0.7.0", "libp2p-secio": "^0.12.1", "libp2p-tcp": "^0.14.2", - "libp2p-webrtc-star": "^0.17.0", + "libp2p-webrtc-star": "^0.17.5", "libp2p-websockets": "^0.13.0", "mafmt": "^7.0.0", "merge-options": "^2.0.0", @@ -181,9 +181,9 @@ "form-data": "^3.0.0", "go-ipfs-dep": "^0.4.23", "hat": "0.0.3", - "interface-ipfs-core": "^0.131.0", + "interface-ipfs-core": "^0.131.1", "ipfs-interop": "^0.2.1", - "ipfsd-ctl": "^2.1.0", + "ipfsd-ctl": "github:ipfs/js-ipfsd-ctl#remove-option-normalisation", "ncp": "^2.0.0", "p-event": "^4.1.0", "p-map": "^3.0.0", diff --git a/test/core/interface.spec.js b/test/core/interface.spec.js index 736239f316..837e40a36c 100644 --- a/test/core/interface.spec.js +++ b/test/core/interface.spec.js @@ -2,45 +2,13 @@ 'use strict' const tests = require('interface-ipfs-core') -const merge = require('merge-options') -const { createFactory } = require('ipfsd-ctl') -const { isNode, isBrowser } = require('ipfs-utils/src/env') -const IPFS = require('../../src') +const { isNode } = require('ipfs-utils/src/env') +const factory = require('../utils/factory') /** @typedef { import("ipfsd-ctl").ControllerOptions } ControllerOptions */ describe('interface-ipfs-core tests', function () { - /** @type ControllerOptions */ - const commonOptions = { - test: true, - type: 'proc', - ipfsModule: { - path: require.resolve('../../src'), - ref: IPFS - }, - ipfsHttpModule: { - path: require.resolve('ipfs-http-client'), - ref: require('ipfs-http-client') - }, - ipfsOptions: { - pass: 'ipfs-is-awesome-software', - ...(isBrowser ? { - config: { - Addresses: { - Swarm: [ - '/ip4/127.0.0.1/tcp/14579/ws/p2p-webrtc-star' - ] - } - } - } : {}) - } - } - const overrides = { - js: { - ipfsBin: './src/cli/bin.js' - } - } - const commonFactory = createFactory(commonOptions, overrides) + const commonFactory = factory() tests.root(commonFactory, { skip: isNode ? null : [{ @@ -82,19 +50,19 @@ describe('interface-ipfs-core tests', function () { tests.miscellaneous(commonFactory) - tests.name(createFactory(merge(commonOptions, { + tests.name(factory({ ipfsOptions: { offline: true } - }), overrides)) + })) - tests.namePubsub(createFactory(merge(commonOptions, { + tests.namePubsub(factory({ ipfsOptions: { EXPERIMENTAL: { ipnsPubsub: true } } - }), overrides)) + })) tests.object(commonFactory) @@ -102,11 +70,11 @@ describe('interface-ipfs-core tests', function () { tests.ping(commonFactory) - tests.pubsub(createFactory(commonOptions, merge(overrides, { + tests.pubsub(factory({}, { go: { args: ['--enable-pubsub-experiment'] } - })), { + }), { skip: isNode ? null : [ { name: 'should receive messages from a different node', diff --git a/test/utils/factory.js b/test/utils/factory.js index 995325828b..fe2906908b 100644 --- a/test/utils/factory.js +++ b/test/utils/factory.js @@ -1,39 +1,51 @@ 'use strict' const { createFactory } = require('ipfsd-ctl') const merge = require('merge-options') -const { isBrowser } = require('ipfs-utils/src/env') +const { isNode, isBrowser } = require('ipfs-utils/src/env') -const factory = (options, overrides) => createFactory( - merge({ - test: true, - type: 'proc', - ipfsModule: { - path: require.resolve('../../src'), - ref: require('../../src') - }, - ipfsHttpModule: { - path: require.resolve('ipfs-http-client'), - ref: require('ipfs-http-client') - } - }, options), - merge({ - js: { +const commonOptions = { + test: true, + type: 'proc', + ipfsHttpModule: { + path: require.resolve('ipfs-http-client'), + ref: require('ipfs-http-client') + }, + ipfsModule: { + path: require.resolve('../../src'), + ref: require('../../src') + }, + ipfsOptions: { + pass: 'ipfs-is-awesome-software' + } +} + +const commonOverrides = { + js: { + ...(isNode ? { ipfsBin: './src/cli/bin.js' - }, - proc: { - ...(isBrowser ? { - ipfsOptions: { - config: { - Addresses: { - Swarm: [ - '/ip4/127.0.0.1/tcp/14579/ws/p2p-webrtc-star' - ] - } + } : {}), + ...(isBrowser ? { + remote: true + } : {}) + }, + proc: { + ...(isBrowser ? { + ipfsOptions: { + config: { + Addresses: { + Swarm: [ + '/ip4/127.0.0.1/tcp/14579/ws/p2p-webrtc-star' + ] } } - } : {}) - } - }, overrides) + } + } : {}) + } +} + +const factory = (options = {}, overrides = {}) => createFactory( + merge(commonOptions, options), + merge(commonOverrides, overrides) ) module.exports = factory From dd0eb4e14ae91a9a068c7214edb658728716486e Mon Sep 17 00:00:00 2001 From: achingbrain Date: Fri, 31 Jan 2020 22:52:44 +0000 Subject: [PATCH 41/55] fix: increase dialer timeout in tests --- test/utils/factory.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/utils/factory.js b/test/utils/factory.js index fe2906908b..7aff724c77 100644 --- a/test/utils/factory.js +++ b/test/utils/factory.js @@ -15,7 +15,12 @@ const commonOptions = { ref: require('../../src') }, ipfsOptions: { - pass: 'ipfs-is-awesome-software' + pass: 'ipfs-is-awesome-software', + libp2p: { + dialer: { + dialTimeout: 60e3 // increase timeout because travis is slow + } + } } } From b0e2ee5fb97574921fe66fc2234f7114e1ef5612 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Fri, 31 Jan 2020 23:08:00 +0000 Subject: [PATCH 42/55] chore: enable libp2p debug for chrome build --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e445b499a1..c27d2a4aa2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -52,7 +52,7 @@ jobs: addons: chrome: stable script: - - npx aegir test -t browser -t webworker + - DEBUG=libp2p*,ipfs* npx aegir test -t browser -t webworker - stage: test name: firefox From cbb6f247e42ee12773326631eb64f57dc47679b6 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Fri, 31 Jan 2020 23:16:37 +0000 Subject: [PATCH 43/55] chore: fail fast on browser builds --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index c27d2a4aa2..982fc2bc31 100644 --- a/.travis.yml +++ b/.travis.yml @@ -52,14 +52,14 @@ jobs: addons: chrome: stable script: - - DEBUG=libp2p*,ipfs* npx aegir test -t browser -t webworker + - DEBUG=libp2p*,ipfs* npx aegir test -t browser -t webworker --bail - stage: test name: firefox addons: firefox: latest script: - - npx aegir test -t browser -t webworker -- --browsers FirefoxHeadless + - npx aegir test -t browser -t webworker --bail -- --browsers FirefoxHeadless - stage: test name: electron-main From 5aa630decba8ef15a7b596ef63fcacd744138dcc Mon Sep 17 00:00:00 2001 From: achingbrain Date: Fri, 31 Jan 2020 23:36:17 +0000 Subject: [PATCH 44/55] chore: just run the failing tests --- test/core/interface.spec.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/core/interface.spec.js b/test/core/interface.spec.js index 837e40a36c..5fce33181a 100644 --- a/test/core/interface.spec.js +++ b/test/core/interface.spec.js @@ -17,7 +17,9 @@ describe('interface-ipfs-core tests', function () { }] }) - tests.bitswap(commonFactory) + tests.bitswap(commonFactory, { + only: true + }) tests.block(commonFactory) From 6f7aca2cabd65f38e11b6c538761db49b77db2ca Mon Sep 17 00:00:00 2001 From: achingbrain Date: Sat, 1 Feb 2020 00:07:20 +0000 Subject: [PATCH 45/55] chore: split webworker tests out from browsers --- .travis.yml | 18 ++++++++++++++++-- test/core/interface.spec.js | 4 +--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 982fc2bc31..e816ea620b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -52,14 +52,28 @@ jobs: addons: chrome: stable script: - - DEBUG=libp2p*,ipfs* npx aegir test -t browser -t webworker --bail + - npx aegir test -t browser --bail + + - stage: test + name: chrome webworker + addons: + chrome: stable + script: + - npx aegir test -t webworker --bail - stage: test name: firefox addons: firefox: latest script: - - npx aegir test -t browser -t webworker --bail -- --browsers FirefoxHeadless + - npx aegir test -t browser --bail -- --browsers FirefoxHeadless + + - stage: test + name: firefox webworker + addons: + firefox: latest + script: + - npx aegir test -t webworker --bail -- --browsers FirefoxHeadless - stage: test name: electron-main diff --git a/test/core/interface.spec.js b/test/core/interface.spec.js index 5fce33181a..837e40a36c 100644 --- a/test/core/interface.spec.js +++ b/test/core/interface.spec.js @@ -17,9 +17,7 @@ describe('interface-ipfs-core tests', function () { }] }) - tests.bitswap(commonFactory, { - only: true - }) + tests.bitswap(commonFactory) tests.block(commonFactory) From 67e2bd8dcd86b9bc34f0027bd65219a70e2c89f8 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Sun, 2 Feb 2020 09:39:32 +0000 Subject: [PATCH 46/55] fix: use go nodes with webworker interface tests --- .aegir.js | 12 +++++++++++- package.json | 5 ++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/.aegir.js b/.aegir.js index 75a60d3b58..3a41b6e2a7 100644 --- a/.aegir.js +++ b/.aegir.js @@ -67,6 +67,7 @@ module.exports = { host: '127.0.0.1', port: 43134 }, { + type: 'js', ipfsModule: { path: __dirname, ref: require(__dirname) @@ -75,7 +76,16 @@ module.exports = { path: require.resolve('ipfs-http-client'), ref: require('ipfs-http-client') }, - ipfsBin: path.join(__dirname, 'src', 'cli', 'bin.js') + ipfsBin: path.join(__dirname, 'src', 'cli', 'bin.js'), + ipfsOptions: { + config: { + libp2p: { + dialer: { + dialTimeout: 60e3 // increase timeout because travis is slow + } + } + } + } }).start() }, post: async () => { diff --git a/package.json b/package.json index 3ab9997321..40ffad6069 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,9 @@ "test:node": "aegir test -t node", "test:browser": "aegir test -t browser", "test:webworker": "aegir test -t webworker", + "test:electron": "aegir test -t electron-main -t electron-renderer", + "test:electron-main": "aegir test -t electron-main", + "test:electron-renderer": "aegir test -t electron-renderer", "test:node:core": "aegir test -t node -f test/core/**/*.js", "test:node:http": "aegir test -t node -f test/http-api/index.js", "test:node:gateway": "aegir test -t node -f test/gateway/index.js", @@ -181,7 +184,7 @@ "form-data": "^3.0.0", "go-ipfs-dep": "^0.4.23", "hat": "0.0.3", - "interface-ipfs-core": "^0.131.1", + "interface-ipfs-core": "^0.131.3", "ipfs-interop": "^0.2.1", "ipfsd-ctl": "github:ipfs/js-ipfsd-ctl#remove-option-normalisation", "ncp": "^2.0.0", From 75727b84e69a1a9403a59a393c715902d0ac2b67 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Sun, 2 Feb 2020 10:30:04 +0000 Subject: [PATCH 47/55] fix: use js for pubsub tests as before --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 40ffad6069..b63b681614 100644 --- a/package.json +++ b/package.json @@ -184,7 +184,7 @@ "form-data": "^3.0.0", "go-ipfs-dep": "^0.4.23", "hat": "0.0.3", - "interface-ipfs-core": "^0.131.3", + "interface-ipfs-core": "^0.131.4", "ipfs-interop": "^0.2.1", "ipfsd-ctl": "github:ipfs/js-ipfsd-ctl#remove-option-normalisation", "ncp": "^2.0.0", From 57277efb970b0ef79a89894d3cbfa1a68f4579a8 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Mon, 3 Feb 2020 11:29:47 +0000 Subject: [PATCH 48/55] fix: go-ipfs pubsub is no longer experimental --- package.json | 2 +- test/core/interface.spec.js | 6 +----- test/http-api/interface.js | 6 +----- 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index b63b681614..76bf858e1f 100644 --- a/package.json +++ b/package.json @@ -184,7 +184,7 @@ "form-data": "^3.0.0", "go-ipfs-dep": "^0.4.23", "hat": "0.0.3", - "interface-ipfs-core": "^0.131.4", + "interface-ipfs-core": "^0.131.6", "ipfs-interop": "^0.2.1", "ipfsd-ctl": "github:ipfs/js-ipfsd-ctl#remove-option-normalisation", "ncp": "^2.0.0", diff --git a/test/core/interface.spec.js b/test/core/interface.spec.js index 837e40a36c..f74fc92985 100644 --- a/test/core/interface.spec.js +++ b/test/core/interface.spec.js @@ -70,11 +70,7 @@ describe('interface-ipfs-core tests', function () { tests.ping(commonFactory) - tests.pubsub(factory({}, { - go: { - args: ['--enable-pubsub-experiment'] - } - }), { + tests.pubsub(commonFactory, { skip: isNode ? null : [ { name: 'should receive messages from a different node', diff --git a/test/http-api/interface.js b/test/http-api/interface.js index 3ed25a6224..88d3793ab0 100644 --- a/test/http-api/interface.js +++ b/test/http-api/interface.js @@ -98,11 +98,7 @@ describe('interface-ipfs-core over ipfs-http-client tests', function () { }] }) - tests.pubsub(createFactory(commonOptions, merge(overrides, { - go: { - args: ['--enable-pubsub-experiment'] - } - }))) + tests.pubsub(commonFactory) tests.repo(commonFactory) From e629d4af299af6767c736e8da37bb5e07781ed85 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Mon, 3 Feb 2020 12:15:22 +0000 Subject: [PATCH 49/55] fix: configure go-ipfs bin for ipfsd server --- .aegir.js | 5 +++++ test/core/interface.spec.js | 7 ++++++- test/http-api/interface.js | 6 +++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/.aegir.js b/.aegir.js index 3a41b6e2a7..32ea00d0f1 100644 --- a/.aegir.js +++ b/.aegir.js @@ -6,6 +6,7 @@ const EchoServer = require('interface-ipfs-core/src/utils/echo-http-server') const webRTCStarSigServer = require('libp2p-webrtc-star/src/sig-server') const path = require('path') const webpack = require('webpack') +const os = require('os') const preloadNode = MockPreloadNode.createNode() const echoServer = EchoServer.createServer() @@ -86,6 +87,10 @@ module.exports = { } } } + }, { + go: { + ipfsBin: require.resolve('go-ipfs-dep/go-ipfs/ipfs' + (os.platform() === 'win32' ? '.exe' : '')) + } }).start() }, post: async () => { diff --git a/test/core/interface.spec.js b/test/core/interface.spec.js index f74fc92985..24f59cc4dc 100644 --- a/test/core/interface.spec.js +++ b/test/core/interface.spec.js @@ -70,7 +70,12 @@ describe('interface-ipfs-core tests', function () { tests.ping(commonFactory) - tests.pubsub(commonFactory, { + tests.pubsub(factory({}, { + go: { + args: ['--enable-pubsub-experiment'] + } + }), { + only: true, skip: isNode ? null : [ { name: 'should receive messages from a different node', diff --git a/test/http-api/interface.js b/test/http-api/interface.js index 88d3793ab0..3ed25a6224 100644 --- a/test/http-api/interface.js +++ b/test/http-api/interface.js @@ -98,7 +98,11 @@ describe('interface-ipfs-core over ipfs-http-client tests', function () { }] }) - tests.pubsub(commonFactory) + tests.pubsub(createFactory(commonOptions, merge(overrides, { + go: { + args: ['--enable-pubsub-experiment'] + } + }))) tests.repo(commonFactory) From b3cb06d2d68e48213ba8f96f7f68374c2b663cd2 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Mon, 3 Feb 2020 12:16:09 +0000 Subject: [PATCH 50/55] refactor: use string template --- .aegir.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.aegir.js b/.aegir.js index 32ea00d0f1..a8b6c78773 100644 --- a/.aegir.js +++ b/.aegir.js @@ -89,7 +89,7 @@ module.exports = { } }, { go: { - ipfsBin: require.resolve('go-ipfs-dep/go-ipfs/ipfs' + (os.platform() === 'win32' ? '.exe' : '')) + ipfsBin: require.resolve(`go-ipfs-dep/go-ipfs/ipfs${os.platform() === 'win32' ? '.exe' : ''}`) } }).start() }, From 30036f591b0355b0ac155a705aa551cb0d643aba Mon Sep 17 00:00:00 2001 From: achingbrain Date: Mon, 3 Feb 2020 12:28:33 +0000 Subject: [PATCH 51/55] fix: update interface tests and remove only --- package.json | 2 +- test/core/interface.spec.js | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index 76bf858e1f..deace85d90 100644 --- a/package.json +++ b/package.json @@ -184,7 +184,7 @@ "form-data": "^3.0.0", "go-ipfs-dep": "^0.4.23", "hat": "0.0.3", - "interface-ipfs-core": "^0.131.6", + "interface-ipfs-core": "^0.131.7", "ipfs-interop": "^0.2.1", "ipfsd-ctl": "github:ipfs/js-ipfsd-ctl#remove-option-normalisation", "ncp": "^2.0.0", diff --git a/test/core/interface.spec.js b/test/core/interface.spec.js index 24f59cc4dc..837e40a36c 100644 --- a/test/core/interface.spec.js +++ b/test/core/interface.spec.js @@ -75,7 +75,6 @@ describe('interface-ipfs-core tests', function () { args: ['--enable-pubsub-experiment'] } }), { - only: true, skip: isNode ? null : [ { name: 'should receive messages from a different node', From 2b53ccb356484264113f9af9d0998467dabf8e01 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Mon, 3 Feb 2020 13:24:10 +0000 Subject: [PATCH 52/55] chore: update ipfs-interop dep --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index deace85d90..0b62c7e518 100644 --- a/package.json +++ b/package.json @@ -185,7 +185,7 @@ "go-ipfs-dep": "^0.4.23", "hat": "0.0.3", "interface-ipfs-core": "^0.131.7", - "ipfs-interop": "^0.2.1", + "ipfs-interop": "github:ipfs/interop#refactor/async-await", "ipfsd-ctl": "github:ipfs/js-ipfsd-ctl#remove-option-normalisation", "ncp": "^2.0.0", "p-event": "^4.1.0", From e154bf58415c908f4eea4a31f69d8197ce5465a8 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Mon, 3 Feb 2020 14:15:59 +0000 Subject: [PATCH 53/55] fix: hls example --- examples/browser-video-streaming/index.html | 6 +- examples/browser-video-streaming/streaming.js | 142 ------------------ 2 files changed, 1 insertion(+), 147 deletions(-) diff --git a/examples/browser-video-streaming/index.html b/examples/browser-video-streaming/index.html index 83138154ff..29b2cac70e 100644 --- a/examples/browser-video-streaming/index.html +++ b/examples/browser-video-streaming/index.html @@ -2,11 +2,7 @@ - + diff --git a/examples/browser-video-streaming/streaming.js b/examples/browser-video-streaming/streaming.js index 576d938d33..2781419613 100644 --- a/examples/browser-video-streaming/streaming.js +++ b/examples/browser-video-streaming/streaming.js @@ -19,145 +19,3 @@ document.addEventListener('DOMContentLoaded', async () => { hls.on(Hls.Events.MANIFEST_PARSED, () => video.play()) } }) - -// TODO: remove everything below here once https://github.com/ipfs/js-ipfs/pull/2683 -// and https://github.com/moshisushi/hlsjs-ipfs-loader/pull/16 are released - -class HlsjsIpfsLoader { - constructor(config) { - this.ipfs = config.ipfs - this.hash = config.ipfsHash - if (config.debug === false) { - this.debug = function() {} - } else if (config.debug === true) { - this.debug = console.log - } else { - this.debug = config.debug - } - if(config.m3u8provider) { - this.m3u8provider = config.m3u8provider; - } else { - this.m3u8provider = null; - } - if(config.tsListProvider) { - this.tsListProvider = config.tsListProvider; - } else { - this.tsListProvider = null; - } - } - - destroy() { - } - - abort() { - } - - load(context, config, callbacks) { - this.context = context - this.config = config - this.callbacks = callbacks - this.stats = { trequest: performance.now(), retry: 0 } - this.retryDelay = config.retryDelay - this.loadInternal() - } - /** - * Call this by getting the HLSIPFSLoader instance from hls.js hls.coreComponents[0].loaders.manifest.setM3U8Provider() - * @param {function} provider - */ - setM3U8Provider(provider) { - this.m3u8provider = provider; - } - /** - * - * @param {function} provider - */ - setTsListProvider(provider) { - this.tsListProvider = provider; - } - - loadInternal() { - const { stats, context, callbacks } = this - - stats.tfirst = Math.max(performance.now(), stats.trequest) - stats.loaded = 0 - - const urlParts = context.url.split("/") - const filename = urlParts[urlParts.length - 1] - - if(filename.split(".")[1] === "m3u8" && this.m3u8provider !== null) { - const res = this.m3u8provider(); - let data; - if(Buffer.isBuffer(res)) { - data = buf2str(res) - } else { - data = res; - } - const response = { url: context.url, data: data } - callbacks.onSuccess(response, stats, context) - return; - } - if(filename.split(".")[1] === "m3u8" && this.tsListProvider !== null) { - var tslist = this.tsListProvider(); - var hash = tslist[filename]; - if(hash) { - this.cat(hash).then(res => { - let data; - if(Buffer.isBuffer(res)) { - data = buf2str(res) - } else { - data = res; - } - stats.loaded = stats.total = data.length - stats.tload = Math.max(stats.tfirst, performance.now()) - const response = { url: context.url, data: data } - callbacks.onSuccess(response, stats, context) - }); - } - return; - } - getFile(this.ipfs, this.hash, filename, this.debug).then(res => { - const data = (context.responseType === 'arraybuffer') ? res : buf2str(res) - stats.loaded = stats.total = data.length - stats.tload = Math.max(stats.tfirst, performance.now()) - const response = { url: context.url, data: data } - callbacks.onSuccess(response, stats, context) - }, console.error) - } -} - -async function getFile(ipfs, rootHash, filename, debug) { - debug(`Fetching hash for '${rootHash}/${filename}'`) - if(filename === null) { - return cat(rootHash, ipfs, debug) - } - - for await (const link of ipfs.ls(rootHash)) { - if (link.name !== filename) { - continue - } - - debug(`Requesting '${link.path}'`) - - return cat(link.cid, ipfs, debug) - } - - throw new Error(`File not found: ${rootHash}/${filename}`) -} - -function buf2str(buf) { - return String.fromCharCode.apply(null, new Uint8Array(buf)) -} - -async function cat (cid, ipfs, debug) { - let value = new Uint8Array(0) - - for await (const buf of ipfs.cat(cid)) { - const newBuf = new Uint8Array(value.length + buf.length) - newBuf.set(value) - newBuf.set(buf, value.length) - value = newBuf - } - - debug(`Received data for file '${cid}' size: ${value.length}`) - return value -} From 8f57ee34cd677f168f2a4324688c316dbc982aed Mon Sep 17 00:00:00 2001 From: achingbrain Date: Mon, 3 Feb 2020 14:31:40 +0000 Subject: [PATCH 54/55] fix: use libp2p with ping patch --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0b62c7e518..77429e2756 100644 --- a/package.json +++ b/package.json @@ -129,7 +129,7 @@ "just-safe-set": "^2.1.0", "ky": "^0.15.0", "ky-universal": "~0.3.0", - "libp2p": "^0.27.0", + "libp2p": "github:libp2p/js-libp2p#stop-stream-after-first-pong", "libp2p-bootstrap": "^0.10.2", "libp2p-crypto": "^0.17.1", "libp2p-delegated-content-routing": "^0.4.1", From 67e073d09e445b818d84c886dfb6cddcdcb166c2 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Mon, 3 Feb 2020 14:58:13 +0000 Subject: [PATCH 55/55] chore: remove gh version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 77429e2756..a146a49819 100644 --- a/package.json +++ b/package.json @@ -129,7 +129,7 @@ "just-safe-set": "^2.1.0", "ky": "^0.15.0", "ky-universal": "~0.3.0", - "libp2p": "github:libp2p/js-libp2p#stop-stream-after-first-pong", + "libp2p": "^0.27.1", "libp2p-bootstrap": "^0.10.2", "libp2p-crypto": "^0.17.1", "libp2p-delegated-content-routing": "^0.4.1",