Skip to content

Commit 254a3bd

Browse files
authored
feat(brave): delegated peers and content routing (#739)
* feat(brave): delegated peers and content routing This enables delegated routers in embedded js-ipfs running in Brave. Coupled with preload, this gives us basic file sharing functionality back, until we have real p2p transport, native DHT etc. * fix: callback-based delgates + DNS caching This switches to 0.2.x versions of delegate modules which work correctly with js-libp2p + wip [1] fix for js-ipfs that caches DNS records for 1 minute, greatly reducing the HTTP request overhead to remote APIs. [1]: ipfs/js-ipfs#2304
1 parent 544349a commit 254a3bd

File tree

3 files changed

+218
-50
lines changed

3 files changed

+218
-50
lines changed

add-on/src/lib/options.js

+17-8
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ exports.optionDefaults = Object.freeze({
2424
ipfsApiUrl: buildIpfsApiUrl(),
2525
ipfsApiPollMs: 3000,
2626
ipfsProxy: true, // window.ipfs
27-
logNamespaces: 'jsipfs*,ipfs*,-*:ipns*,-ipfs:preload*,-ipfs-http-client:request*'
27+
logNamespaces: 'jsipfs*,ipfs*,libp2p-delegated*,-*:ipns*,-ipfs:preload*,-ipfs-http-client:request*'
2828
})
2929

3030
function buildCustomGatewayUrl () {
@@ -60,17 +60,26 @@ function buildDefaultIpfsNodeConfig () {
6060
config.config.Addresses.Gateway = '/ip4/127.0.0.1/tcp/9091'
6161

6262
// Until we have MulticastDNS+DNS, peer discovery is done over ws-star
63-
config.config.Addresses.Swarm = ['/dns4/ws-star1.par.dwebops.pub/tcp/443/wss/p2p-websocket-star']
63+
config.config.Addresses.Swarm = [
64+
'/dns4/ws-star1.par.dwebops.pub/tcp/443/wss/p2p-websocket-star',
65+
'/dns4/ws-star.discovery.libp2p.io/tcp/443/wss/p2p-websocket-star'
66+
]
6467
// Until DHT and p2p transport are ready, delegate + preload
68+
// Note: we use .preload.ipfs.io and .delegate.ipfs.io as means of http sharding (12 instead of 6 concurrent requests)
6569
const delegates = [
66-
'/dns4/node0.preload.ipfs.io/tcp/443/https',
67-
'/dns4/node1.preload.ipfs.io/tcp/443/https'
70+
'/dns4/node1.delegate.ipfs.io/tcp/443/https',
71+
'/dns4/node0.delegate.ipfs.io/tcp/443/https'
6872
]
6973
// Delegated Content and Peer Routing: https://github.com/ipfs/js-ipfs/pull/2195
70-
// TODO: delegated routing blocked by https://github.com/libp2p/js-libp2p-delegated-content-routing/issues/12
71-
// config.config.Addresses.Delegates = delegates
72-
// TODO: are preloads needed? should Brave have own nodes?
73-
config.preload = { enabled: true, addresses: delegates }
74+
config.config.Addresses.Delegates = delegates
75+
// TODO: when we have p2p transport, are preloads still needed? should Brave have own nodes?
76+
config.preload = {
77+
enabled: true,
78+
addresses: [
79+
'/dns4/node1.preload.ipfs.io/tcp/443/https',
80+
'/dns4/node0.preload.ipfs.io/tcp/443/https'
81+
]
82+
}
7483
/*
7584
(Sidenote on why we need API for Web UI)
7685
Gateway can run without API port,

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@
6666
"private": true,
6767
"preferGlobal": false,
6868
"resolutions": {
69+
"libp2p-delegated-content-routing": "0.2.4",
70+
"libp2p-delegated-peer-routing": "0.2.4",
6971
"@hapi/hapi": "https://github.com/lidel/hapi/tarball/ccbf84ba5edc9b24564fdd166e3ee6d81c4c02d8/hapi.tar.gz",
7072
"pino": "5.12.3",
7173
"hapi-pino": "https://github.com/pinojs/hapi-pino/tarball/3767ed6b67601831e176e084ed82ba4ed9f726e6/hapi-pino.tar.gz",
@@ -124,7 +126,7 @@
124126
"get-port": "5.0.0",
125127
"http-dns": "3.0.1",
126128
"http-node": "1.2.0",
127-
"ipfs": "https://github.com/ipfs/js-ipfs/tarball/2ae6b672c222555b1a068141f2acfe4b5f39b709/js-ipfs.tar.gz",
129+
"ipfs": "https://github.com/ipfs/js-ipfs/tarball/6fa8f88310a4f7f451f0f6846e435134376703e6/js-ipfs.tar.gz",
128130
"ipfs-css": "0.12.0",
129131
"ipfs-http-client": "33.1.0",
130132
"ipfs-http-response": "0.3.1",

0 commit comments

Comments
 (0)