Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
refactor: return peer IDs as strings not CIDs (#2729)
Browse files Browse the repository at this point in the history
Also updates all examples to use the new API.

Depends on:

- [x] ipfs-inactive/interface-js-ipfs-core#581
- [x] ipfs-inactive/js-ipfs-http-client#1226
- [x] libp2p/js-libp2p#545

BREAKING CHANGE:

Where `PeerID`s were previously [CID](https://www.npmjs.com/package/cids)s, now they are Strings

- `ipfs.bitswap.stat().peers[n]` is now a String (was a CID)
- `ipfs.dht.findPeer().id` is now a String (was a CID)
- `ipfs.dht.findProvs()[n].id` is now a String (was a CID)
- `ipfs.dht.provide()[n].id` is now a String (was a CID)
- `ipfs.dht.put()[n].id` is now a String (was a CID)
- `ipfs.dht.query()[n].id` is now a String (was a CID)
- `ipfs.id().id` is now a String (was a CID)
- `ipfs.id().addresses[n]` are now [Multiaddr](https://www.npmjs.com/package/multiaddr)s (were Strings)
  • Loading branch information
achingbrain authored Feb 3, 2020
1 parent 3516bb8 commit 16d540c
Show file tree
Hide file tree
Showing 35 changed files with 359 additions and 250 deletions.
70 changes: 61 additions & 9 deletions .aegir.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
'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 os = require('os')

const ipfsdServer = IPFSFactory.createServer()
const preloadNode = MockPreloadNode.createNode()
const echoServer = EchoServer.createServer()

// 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' },
webpack: {
resolve: {
mainFields: ['browser', 'main'],
aliasFields: ['browser', 'browser-all-ipld-formats'],
}
},
...(process.env.NODE_ENV === 'test' ? {
plugins: [
new webpack.EnvironmentPlugin(['DEBUG'])
]
} : {})
},
karma: {
files: [{
Expand All @@ -39,14 +52,53 @@ module.exports = {
},
browser: {
pre: async () => {
await ipfsdServer.start()
await preloadNode.start()
await echoServer.start()
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
}, {
type: 'js',
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'),
ipfsOptions: {
config: {
libp2p: {
dialer: {
dialTimeout: 60e3 // increase timeout because travis is slow
}
}
}
}
}, {
go: {
ipfsBin: require.resolve(`go-ipfs-dep/go-ipfs/ipfs${os.platform() === 'win32' ? '.exe' : ''}`)
}
}).start()
},
post: async () => {
await ipfsdServer.stop()
await preloadNode.stop()
await echoServer.stop()
await ipfsdServer.stop()
await preloadNode.stop()
await echoServer.stop()
await sigServerA.stop()
await sigServerB.stop()
}
}
}
Expand Down
48 changes: 21 additions & 27 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,28 @@ jobs:
addons:
chrome: stable
script:
- npx aegir test -t browser -t webworker
- 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 -- --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
Expand All @@ -76,44 +90,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_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_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_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_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
Expand All @@ -128,7 +122,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
Expand Down
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<br>
</p>

### Project status - `Alpha`
### Project status - `Alpha` <!-- omit in toc -->

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 🐉..

Expand All @@ -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 <!-- omit in toc -->

[David Dias](https://github.com/daviddias)

## Lead Maintainer
## Lead Maintainer <!-- omit in toc -->

[Alan Shaw](https://github.com/alanshaw)

## Table of Contents
## Table of Contents <!-- omit in toc -->

- [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)
Expand All @@ -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)
Expand Down Expand Up @@ -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) |
Expand Down
2 changes: 1 addition & 1 deletion examples/browser-video-streaming/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<body>
<video id="video" controls></video>
<script src="../../dist/index.js"></script>
<script src="https://unpkg.com/hlsjs-ipfs-loader@0.1.4/dist/index.js"></script>
<script src="https://unpkg.com/hlsjs-ipfs-loader@0.2.3/dist/index.js"></script>
<script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
<script src="streaming.js"></script>
</body>
Expand Down
1 change: 0 additions & 1 deletion examples/browser-video-streaming/streaming.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

/* global Hls Ipfs HlsjsIpfsLoader */
/* eslint-env browser */

document.addEventListener('DOMContentLoaded', async () => {
const testHash = 'QmdpAidwAsBGptFB3b6A9Pyi5coEbgjHrL3K2Qrsutmj9K'
const repoPath = 'ipfs-' + Math.random()
Expand Down
2 changes: 1 addition & 1 deletion examples/circuit-relaying/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"license": "MIT",
"dependencies": {
"ipfs": "file:../../",
"ipfs-pubsub-room": "^1.4.0"
"ipfs-pubsub-room": "^2.0.1"
},
"devDependencies": {
"aegir": "^20.0.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/circuit-relaying/src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
4 changes: 3 additions & 1 deletion examples/circuit-relaying/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ 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
.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}`)
Expand Down
19 changes: 10 additions & 9 deletions examples/custom-ipfs-repo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -79,19 +80,19 @@ 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:', filesAdded[0].path, filesAdded[0].hash)
})) {
// Log out the added files metadata and cat the file from IPFS
console.log('\nAdded file:', file.path, file.cid)

const data = await node.cat(filesAdded[0].hash)
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(data)
// Print out the files contents to console
console.log('\nFetched file content:')
process.stdout.write(data)
}

// After everything is done, shut the node down
console.log('\n\nStopping the node')
Expand Down
3 changes: 2 additions & 1 deletion examples/custom-ipfs-repo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
16 changes: 4 additions & 12 deletions examples/custom-libp2p/index.js
Original file line number Diff line number Diff line change
@@ -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')

/**
Expand All @@ -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,
Expand All @@ -49,8 +43,7 @@ const libp2pBundle = (opts) => {
},
modules: {
transport: [
TCP,
wsstar
TCP
],
streamMuxer: [
MPLEX,
Expand All @@ -61,8 +54,7 @@ const libp2pBundle = (opts) => {
],
peerDiscovery: [
MulticastDNS,
Bootstrap,
wsstar.discovery
Bootstrap
],
dht: KadDHT
},
Expand Down
Loading

0 comments on commit 16d540c

Please sign in to comment.