Skip to content

Commit 8d2ff1d

Browse files
committed
refactor(wip): async iterators
This is PoC use of ipfs/js-ipfs#2591 BREAKING CHANGE: switched to Async Iterators version of JS API https://blog.ipfs.io/2020-02-01-async-await-refactor/ Code that is not related to embedded node with chromesockets will be refactored in separate commit.
1 parent 9467fd2 commit 8d2ff1d

File tree

8 files changed

+1949
-2338
lines changed

8 files changed

+1949
-2338
lines changed

add-on/src/lib/ipfs-client/embedded-chromesockets/config.js

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,22 @@
33
const browser = require('webextension-polyfill')
44

55
const { optionDefaults } = require('../../options')
6-
const chromeSocketsBundle = require('./libp2p-bundle')
76
const mergeOptions = require('merge-options')
87
const getPort = require('get-port')
98
const { getIPv4, getIPv6 } = require('webrtc-ips')
109

10+
const Libp2p = require('libp2p')
11+
const TCP = require('libp2p-tcp')
12+
const MulticastDNS = require('libp2p-mdns')
13+
1114
const multiaddr = require('multiaddr')
1215
const maToUri = require('multiaddr-to-uri')
1316
const multiaddr2httpUrl = (ma) => maToUri(ma.includes('/http') ? ma : multiaddr(ma).encapsulate('/http'))
1417

18+
const debug = require('debug')
19+
const log = debug('ipfs-companion:client:embedded:config')
20+
log.error = debug('ipfs-companion:client:embedded:config:error')
21+
1522
// additional default js-ipfs config specific to runtime with chrome.sockets APIs
1623
const chromeDefaultOpts = {
1724
config: {
@@ -25,11 +32,10 @@ const chromeDefaultOpts = {
2532
Swarm: [
2633
// optional ws-star signaling provides a backup for non-LAN peer discovery
2734
// (this will be removed when autorelay and DHT are stable in js-ipfs)
28-
'/dns4/ws-star.discovery.libp2p.io/tcp/443/wss/p2p-websocket-star'
35+
'/dns4/wrtc-star.discovery.libp2p.io/tcp/443/wss/p2p-webrtc-star'
2936
],
3037
// Delegated Content and Peer Routing: https://github.com/ipfs/js-ipfs/pull/2195
31-
Delegates: // [] // TODO: enable delegates
32-
[
38+
Delegates: [
3339
'/dns4/node1.delegate.ipfs.io/tcp/443/https',
3440
'/dns4/node0.delegate.ipfs.io/tcp/443/https'
3541
]
@@ -42,8 +48,8 @@ const chromeDefaultOpts = {
4248
},
4349
Swarm: {
4450
ConnMgr: {
45-
LowWater: 100,
46-
HighWater: 250
51+
LowWater: 50,
52+
HighWater: 150
4753
}
4854
},
4955
Bootstrap: [
@@ -113,7 +119,36 @@ async function buildConfig (opts, log) {
113119
// merge configs
114120
const finalOpts = {
115121
start: false,
116-
libp2p: chromeSocketsBundle
122+
// a function that customizes libp2p config: https://github.com/ipfs/js-ipfs/pull/2591
123+
libp2p: ({ libp2pOptions, peerInfo }) => {
124+
libp2pOptions.modules = mergeOptions.call({ concatArrays: true }, libp2pOptions.modules, {
125+
transports: [TCP]
126+
})
127+
128+
libp2pOptions.modules = mergeOptions.call({ concatArrays: true }, libp2pOptions.modules, {
129+
peerDiscovery: [MulticastDNS]
130+
})
131+
132+
libp2pOptions.config = mergeOptions(libp2pOptions.config, {
133+
peerDiscovery: {
134+
autoDial: true,
135+
mdns: {
136+
enabled: true
137+
},
138+
bootstrap: {
139+
enabled: true
140+
},
141+
webRTCStar: {
142+
enabled: true
143+
}
144+
}
145+
})
146+
147+
libp2pOptions.metrics = { enabled: false }
148+
149+
log('initializing libp2p with libp2pOptions', libp2pOptions)
150+
return new Libp2p(libp2pOptions)
151+
}
117152
}
118153
const ipfsNodeConfig = mergeOptions(defaultOpts, userOpts, chromeOpts, finalOpts)
119154

add-on/src/lib/ipfs-client/embedded-chromesockets/libp2p-bundle.js

Lines changed: 0 additions & 107 deletions
This file was deleted.

add-on/src/lib/ipfs-client/embedded-chromesockets/libp2p.js

Lines changed: 0 additions & 91 deletions
This file was deleted.

0 commit comments

Comments
 (0)