Skip to content

Commit

Permalink
feat(brave): delegated peers and content routing (#739)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
lidel authored Aug 12, 2019
1 parent 544349a commit 254a3bd
Show file tree
Hide file tree
Showing 3 changed files with 218 additions and 50 deletions.
25 changes: 17 additions & 8 deletions add-on/src/lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ exports.optionDefaults = Object.freeze({
ipfsApiUrl: buildIpfsApiUrl(),
ipfsApiPollMs: 3000,
ipfsProxy: true, // window.ipfs
logNamespaces: 'jsipfs*,ipfs*,-*:ipns*,-ipfs:preload*,-ipfs-http-client:request*'
logNamespaces: 'jsipfs*,ipfs*,libp2p-delegated*,-*:ipns*,-ipfs:preload*,-ipfs-http-client:request*'
})

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

// Until we have MulticastDNS+DNS, peer discovery is done over ws-star
config.config.Addresses.Swarm = ['/dns4/ws-star1.par.dwebops.pub/tcp/443/wss/p2p-websocket-star']
config.config.Addresses.Swarm = [
'/dns4/ws-star1.par.dwebops.pub/tcp/443/wss/p2p-websocket-star',
'/dns4/ws-star.discovery.libp2p.io/tcp/443/wss/p2p-websocket-star'
]
// Until DHT and p2p transport are ready, delegate + preload
// Note: we use .preload.ipfs.io and .delegate.ipfs.io as means of http sharding (12 instead of 6 concurrent requests)
const delegates = [
'/dns4/node0.preload.ipfs.io/tcp/443/https',
'/dns4/node1.preload.ipfs.io/tcp/443/https'
'/dns4/node1.delegate.ipfs.io/tcp/443/https',
'/dns4/node0.delegate.ipfs.io/tcp/443/https'
]
// Delegated Content and Peer Routing: https://github.com/ipfs/js-ipfs/pull/2195
// TODO: delegated routing blocked by https://github.com/libp2p/js-libp2p-delegated-content-routing/issues/12
// config.config.Addresses.Delegates = delegates
// TODO: are preloads needed? should Brave have own nodes?
config.preload = { enabled: true, addresses: delegates }
config.config.Addresses.Delegates = delegates
// TODO: when we have p2p transport, are preloads still needed? should Brave have own nodes?
config.preload = {
enabled: true,
addresses: [
'/dns4/node1.preload.ipfs.io/tcp/443/https',
'/dns4/node0.preload.ipfs.io/tcp/443/https'
]
}
/*
(Sidenote on why we need API for Web UI)
Gateway can run without API port,
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
"private": true,
"preferGlobal": false,
"resolutions": {
"libp2p-delegated-content-routing": "0.2.4",
"libp2p-delegated-peer-routing": "0.2.4",
"@hapi/hapi": "https://github.com/lidel/hapi/tarball/ccbf84ba5edc9b24564fdd166e3ee6d81c4c02d8/hapi.tar.gz",
"pino": "5.12.3",
"hapi-pino": "https://github.com/pinojs/hapi-pino/tarball/3767ed6b67601831e176e084ed82ba4ed9f726e6/hapi-pino.tar.gz",
Expand Down Expand Up @@ -124,7 +126,7 @@
"get-port": "5.0.0",
"http-dns": "3.0.1",
"http-node": "1.2.0",
"ipfs": "https://github.com/ipfs/js-ipfs/tarball/2ae6b672c222555b1a068141f2acfe4b5f39b709/js-ipfs.tar.gz",
"ipfs": "https://github.com/ipfs/js-ipfs/tarball/6fa8f88310a4f7f451f0f6846e435134376703e6/js-ipfs.tar.gz",
"ipfs-css": "0.12.0",
"ipfs-http-client": "33.1.0",
"ipfs-http-response": "0.3.1",
Expand Down
Loading

0 comments on commit 254a3bd

Please sign in to comment.