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

Commit 16d540c

Browse files
authored
refactor: return peer IDs as strings not CIDs (#2729)
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)
1 parent 3516bb8 commit 16d540c

File tree

35 files changed

+359
-250
lines changed

35 files changed

+359
-250
lines changed

.aegir.js

+61-9
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,33 @@
11
'use strict'
22

3-
const IPFSFactory = require('ipfsd-ctl')
3+
const { createServer } = require('ipfsd-ctl')
44
const MockPreloadNode = require('./test/utils/mock-preload-node')
55
const EchoServer = require('interface-ipfs-core/src/utils/echo-http-server')
6+
const webRTCStarSigServer = require('libp2p-webrtc-star/src/sig-server')
7+
const path = require('path')
8+
const webpack = require('webpack')
9+
const os = require('os')
610

7-
const ipfsdServer = IPFSFactory.createServer()
811
const preloadNode = MockPreloadNode.createNode()
912
const echoServer = EchoServer.createServer()
1013

14+
// the second signalling server is needed for the inferface test 'should list peers only once even if they have multiple addresses'
15+
let sigServerA
16+
let sigServerB
17+
let ipfsdServer
18+
1119
module.exports = {
1220
bundlesize: { maxSize: '652kB' },
1321
webpack: {
1422
resolve: {
1523
mainFields: ['browser', 'main'],
1624
aliasFields: ['browser', 'browser-all-ipld-formats'],
17-
}
25+
},
26+
...(process.env.NODE_ENV === 'test' ? {
27+
plugins: [
28+
new webpack.EnvironmentPlugin(['DEBUG'])
29+
]
30+
} : {})
1831
},
1932
karma: {
2033
files: [{
@@ -39,14 +52,53 @@ module.exports = {
3952
},
4053
browser: {
4154
pre: async () => {
42-
await ipfsdServer.start()
43-
await preloadNode.start()
44-
await echoServer.start()
55+
await preloadNode.start()
56+
await echoServer.start()
57+
sigServerA = await webRTCStarSigServer.start({
58+
host: '127.0.0.1',
59+
port: 14579,
60+
metrics: false
61+
})
62+
sigServerB = await webRTCStarSigServer.start({
63+
host: '127.0.0.1',
64+
port: 14578,
65+
metrics: false
66+
})
67+
ipfsdServer = await createServer({
68+
host: '127.0.0.1',
69+
port: 43134
70+
}, {
71+
type: 'js',
72+
ipfsModule: {
73+
path: __dirname,
74+
ref: require(__dirname)
75+
},
76+
ipfsHttpModule: {
77+
path: require.resolve('ipfs-http-client'),
78+
ref: require('ipfs-http-client')
79+
},
80+
ipfsBin: path.join(__dirname, 'src', 'cli', 'bin.js'),
81+
ipfsOptions: {
82+
config: {
83+
libp2p: {
84+
dialer: {
85+
dialTimeout: 60e3 // increase timeout because travis is slow
86+
}
87+
}
88+
}
89+
}
90+
}, {
91+
go: {
92+
ipfsBin: require.resolve(`go-ipfs-dep/go-ipfs/ipfs${os.platform() === 'win32' ? '.exe' : ''}`)
93+
}
94+
}).start()
4595
},
4696
post: async () => {
47-
await ipfsdServer.stop()
48-
await preloadNode.stop()
49-
await echoServer.stop()
97+
await ipfsdServer.stop()
98+
await preloadNode.stop()
99+
await echoServer.stop()
100+
await sigServerA.stop()
101+
await sigServerB.stop()
50102
}
51103
}
52104
}

.travis.yml

+21-27
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,28 @@ jobs:
5252
addons:
5353
chrome: stable
5454
script:
55-
- npx aegir test -t browser -t webworker
55+
- npx aegir test -t browser --bail
56+
57+
- stage: test
58+
name: chrome webworker
59+
addons:
60+
chrome: stable
61+
script:
62+
- npx aegir test -t webworker --bail
5663

5764
- stage: test
5865
name: firefox
5966
addons:
6067
firefox: latest
6168
script:
62-
- npx aegir test -t browser -t webworker -- --browsers FirefoxHeadless
69+
- npx aegir test -t browser --bail -- --browsers FirefoxHeadless
70+
71+
- stage: test
72+
name: firefox webworker
73+
addons:
74+
firefox: latest
75+
script:
76+
- npx aegir test -t webworker --bail -- --browsers FirefoxHeadless
6377

6478
- stage: test
6579
name: electron-main
@@ -76,44 +90,24 @@ jobs:
7690
- stage: test
7791
name: interop - node
7892
script:
79-
- mkdir -p node_modules/ipfs-interop/node_modules
80-
- ln -s `pwd` node_modules/ipfs-interop/node_modules/ipfs
81-
- export IPFS_JS_EXEC=`pwd`/src/cli/bin.js
82-
- export IPFS_REUSEPORT=false
83-
- cd node_modules/ipfs-interop
84-
- npx aegir test -t node --bail
93+
- npm run test:interop:node -- --bail
8594

8695
- stage: test
8796
name: interop - browser
8897
script:
89-
- mkdir -p node_modules/ipfs-interop/node_modules
90-
- ln -s `pwd` node_modules/ipfs-interop/node_modules/ipfs
91-
- export IPFS_JS_EXEC=`pwd`/src/cli/bin.js
92-
- export IPFS_REUSEPORT=false
93-
- cd node_modules/ipfs-interop
94-
- npx aegir test -t browser --bail
98+
- npm run test:interop:browser -- --bail
9599

96100
- stage: test
97101
name: interop - electron-main
98102
os: osx
99103
script:
100-
- mkdir -p node_modules/ipfs-interop/node_modules
101-
- ln -s `pwd` node_modules/ipfs-interop/node_modules/ipfs
102-
- export IPFS_JS_EXEC=`pwd`/src/cli/bin.js
103-
- export IPFS_REUSEPORT=false
104-
- cd node_modules/ipfs-interop
105-
- npx aegir test -t electron-main -f ./test/node.js --bail --timeout 10000
104+
- npm run test:interop:electron-main -- --bail --timeout 10000
106105

107106
- stage: test
108107
name: interop - electron-renderer
109108
os: osx
110109
script:
111-
- mkdir -p node_modules/ipfs-interop/node_modules
112-
- ln -s `pwd` node_modules/ipfs-interop/node_modules/ipfs
113-
- export IPFS_JS_EXEC=`pwd`/src/cli/bin.js
114-
- export IPFS_REUSEPORT=false
115-
- cd node_modules/ipfs-interop
116-
- npx aegir test -t electron-renderer -f ./test/browser.js --bail --timeout 10000
110+
- npm run test:interop:electron-renderer -- --bail --timeout 10000
117111

118112
- stage: test
119113
name: external - ipfs-companion
@@ -128,7 +122,7 @@ jobs:
128122
- stage: test
129123
name: external - ipfs-pubsub-room
130124
script:
131-
- npm run test:external -- ipfs-pubsub-room https://github.com/ipfs-shipyard/ipfs-pubsub-room.git --branch upgrade-to-latest-js-ipfs-rc
125+
- npm run test:external -- ipfs-pubsub-room https://github.com/ipfs-shipyard/ipfs-pubsub-room.git
132126

133127
- stage: test
134128
name: external - peer-base

README.md

+6-8
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<br>
3131
</p>
3232

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

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

@@ -40,19 +40,16 @@ We've come a long way, but this project is still in Alpha, lots of development i
4040

4141
[**`Weekly Core Implementations Call`**](https://github.com/ipfs/team-mgmt/issues/992)
4242

43-
## Tech Lead
43+
## Tech Lead <!-- omit in toc -->
4444

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

47-
## Lead Maintainer
47+
## Lead Maintainer <!-- omit in toc -->
4848

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

51-
## Table of Contents
51+
## Table of Contents <!-- omit in toc -->
5252

53-
- [Tech Lead](#tech-lead)
54-
- [Lead Maintainer](#lead-maintainer)
55-
- [Table of Contents](#table-of-contents)
5653
- [Install](#install)
5754
- [npm](#npm)
5855
- [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
6663
- [API](#api)
6764
- [IPFS Constructor](#ipfs-constructor)
6865
- [`options.repo`](#optionsrepo)
66+
- [`options.repoAutoMigrate`](#optionsrepoautomigrate)
6967
- [`options.init`](#optionsinit)
7068
- [`options.start`](#optionsstart)
7169
- [`options.pass`](#optionspass)
@@ -1106,7 +1104,7 @@ Listing of the main packages used in the IPFS ecosystem. There are also three sp
11061104
| [`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:[email protected]) |
11071105
| [`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:[email protected]) |
11081106
| **Repo** |
1109-
| [`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:[email protected]) |
1107+
| [`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:[email protected]) |
11101108
| **Exchange** |
11111109
| [`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:[email protected]) |
11121110
| [`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:[email protected]) |

examples/browser-video-streaming/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<body>
33
<video id="video" controls></video>
44
<script src="../../dist/index.js"></script>
5-
<script src="https://unpkg.com/hlsjs-ipfs-loader@0.1.4/dist/index.js"></script>
5+
<script src="https://unpkg.com/hlsjs-ipfs-loader@0.2.3/dist/index.js"></script>
66
<script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
77
<script src="streaming.js"></script>
88
</body>

examples/browser-video-streaming/streaming.js

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
/* global Hls Ipfs HlsjsIpfsLoader */
44
/* eslint-env browser */
5-
65
document.addEventListener('DOMContentLoaded', async () => {
76
const testHash = 'QmdpAidwAsBGptFB3b6A9Pyi5coEbgjHrL3K2Qrsutmj9K'
87
const repoPath = 'ipfs-' + Math.random()

examples/circuit-relaying/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"license": "MIT",
1616
"dependencies": {
1717
"ipfs": "file:../../",
18-
"ipfs-pubsub-room": "^1.4.0"
18+
"ipfs-pubsub-room": "^2.0.1"
1919
},
2020
"devDependencies": {
2121
"aegir": "^20.0.0",

examples/circuit-relaying/src/helpers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const mkRoomName = (name) => {
1515

1616
module.exports = (ipfs, peersSet) => {
1717
const createRoom = (name) => {
18-
const room = Room(ipfs, mkRoomName(name))
18+
const room = new Room(ipfs, mkRoomName(name))
1919

2020
room.on('peer joined', (peer) => {
2121
console.log('peer ' + peer + ' joined')

examples/circuit-relaying/test.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ async function runTest () {
6666

6767
try {
6868
const id = await ipfsd.api.id()
69-
const address = id.addresses.filter(addr => addr.includes('/ws/ipfs/Qm')).pop()
69+
const address = id.addresses
70+
.map(ma => ma.toString())
71+
.find(addr => addr.includes('/ws/p2p/Qm'))
7072

7173
if (!address) {
7274
throw new Error(`Could not find web socket address in ${id.addresses}`)

examples/custom-ipfs-repo/index.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const IPFS = require('ipfs')
44
const Repo = require('ipfs-repo')
55
const fsLock = require('ipfs-repo/src/lock')
6+
const all = require('it-all')
67

78
// Create our custom options
89
const customRepositoryOptions = {
@@ -79,19 +80,19 @@ async function main () {
7980
console.log('Version:', version)
8081

8182
// Once we have the version, let's add a file to IPFS
82-
const filesAdded = await node.add({
83+
for await (const file of node.add({
8384
path: 'test-data.txt',
8485
content: Buffer.from('We are using a customized repo!')
85-
})
86-
87-
// Log out the added files metadata and cat the file from IPFS
88-
console.log('\nAdded file:', filesAdded[0].path, filesAdded[0].hash)
86+
})) {
87+
// Log out the added files metadata and cat the file from IPFS
88+
console.log('\nAdded file:', file.path, file.cid)
8989

90-
const data = await node.cat(filesAdded[0].hash)
90+
const data = Buffer.concat(await all(node.cat(file.cid)))
9191

92-
// Print out the files contents to console
93-
console.log('\nFetched file content:')
94-
process.stdout.write(data)
92+
// Print out the files contents to console
93+
console.log('\nFetched file content:')
94+
process.stdout.write(data)
95+
}
9596

9697
// After everything is done, shut the node down
9798
console.log('\n\nStopping the node')

examples/custom-ipfs-repo/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"dependencies": {
1212
"datastore-fs": "^0.9.1",
1313
"ipfs": "file:../../",
14-
"ipfs-repo": "^0.28.0"
14+
"ipfs-repo": "^0.28.0",
15+
"it-all": "^1.0.1"
1516
},
1617
"devDependencies": {
1718
"execa": "^3.2.0"

examples/custom-libp2p/index.js

+4-12
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
'use strict'
22

33
const Libp2p = require('libp2p')
4-
const IPFS = require('ipfs')
4+
const IPFS = require('../../')
55
const TCP = require('libp2p-tcp')
66
const MulticastDNS = require('libp2p-mdns')
7-
const WebSocketStar = require('libp2p-websocket-star')
87
const Bootstrap = require('libp2p-bootstrap')
98
const SPDY = require('libp2p-spdy')
109
const KadDHT = require('libp2p-kad-dht')
11-
const MPLEX = require('pull-mplex')
10+
const MPLEX = require('libp2p-mplex')
1211
const SECIO = require('libp2p-secio')
1312

1413
/**
@@ -32,11 +31,6 @@ const libp2pBundle = (opts) => {
3231
const peerBook = opts.peerBook
3332
const bootstrapList = opts.config.Bootstrap
3433

35-
// Create our WebSocketStar transport and give it our PeerId, straight from the ipfs node
36-
const wsstar = new WebSocketStar({
37-
id: peerInfo.id
38-
})
39-
4034
// Build and return our libp2p node
4135
return new Libp2p({
4236
peerInfo,
@@ -49,8 +43,7 @@ const libp2pBundle = (opts) => {
4943
},
5044
modules: {
5145
transport: [
52-
TCP,
53-
wsstar
46+
TCP
5447
],
5548
streamMuxer: [
5649
MPLEX,
@@ -61,8 +54,7 @@ const libp2pBundle = (opts) => {
6154
],
6255
peerDiscovery: [
6356
MulticastDNS,
64-
Bootstrap,
65-
wsstar.discovery
57+
Bootstrap
6658
],
6759
dht: KadDHT
6860
},

0 commit comments

Comments
 (0)