Skip to content

Commit

Permalink
feat: enable TCP transport and TCP Bootstrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
lidel committed Sep 11, 2019
1 parent 7ba096d commit 3c04858
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 58 deletions.
23 changes: 20 additions & 3 deletions add-on/src/lib/ipfs-client/embedded-chromesockets.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
/* eslint-env browser, webextensions */
const browser = require('webextension-polyfill')

/* *********************************************************
This file is a wip sandbox.
Code will be refactored when kinks are ironed out.
********************************************************* */

const debug = require('debug')
const log = debug('ipfs-companion:client:embedded')
log.error = debug('ipfs-companion:client:embedded:error')
Expand All @@ -18,6 +23,12 @@ const multiaddr = require('multiaddr')
const maToUri = require('multiaddr-to-uri')
const getPort = require('get-port')

// libp2p
// const WS = require('libp2p-websockets')
// const WSM = require('libp2p-websocket-star-multi')
const TCP = require('libp2p-tcp')
const Bootstrap = require('libp2p-bootstrap')

const { optionDefaults } = require('../options')

// js-ipfs with embedded hapi HTTP server
Expand All @@ -26,16 +37,22 @@ let nodeHttpApi = null

async function buildConfig (opts) {
const defaultOpts = JSON.parse(optionDefaults.ipfsNodeConfig)
defaultOpts.libp2p = {
const userOpts = JSON.parse(opts.ipfsNodeConfig)

const ipfsNodeConfig = mergeOptions.call({ concatArrays: true }, defaultOpts, userOpts, { start: false })

ipfsNodeConfig.libp2p = {
modules: {
transport: [new TCP()],
peerDiscovery: [new Bootstrap({ list: ipfsNodeConfig.config.Bootstrap })]
},
config: {
dht: {
// TODO: check if below is needed after js-ipfs is released with DHT disabled
enabled: false
}
}
}
const userOpts = JSON.parse(opts.ipfsNodeConfig)
const ipfsNodeConfig = mergeOptions.call({ concatArrays: true }, defaultOpts, userOpts, { start: false })

// Detect when API or Gateway port is not available (taken by something else)
// We find the next free port and update configuration to use it instead
Expand Down
31 changes: 31 additions & 0 deletions add-on/src/lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,33 @@ function buildDefaultIpfsNodeConfig () {
config: {
Addresses: {
Swarm: []
},
Bootstrap: [
'/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z',
'/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ',
'/ip4/104.236.179.241/tcp/4001/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM',
'/ip4/162.243.248.213/tcp/4001/ipfs/QmSoLueR4xBeUbY9WZ9xGUUxunbKWcrNFTDAadQJmocnWm',
'/ip4/128.199.219.111/tcp/4001/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu',
'/ip4/104.236.76.40/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64',
'/ip4/178.62.158.247/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd',
'/ip4/178.62.61.185/tcp/4001/ipfs/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3',
'/ip4/104.236.151.122/tcp/4001/ipfs/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx',
'/ip6/2604:a880:1:20::1f9:9001/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z',
'/ip6/2604:a880:1:20::203:d001/tcp/4001/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM',
'/ip6/2604:a880:0:1010::23:d001/tcp/4001/ipfs/QmSoLueR4xBeUbY9WZ9xGUUxunbKWcrNFTDAadQJmocnWm',
'/ip6/2400:6180:0:d0::151:6001/tcp/4001/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu',
'/ip6/2604:a880:800:10::4a:5001/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64',
'/ip6/2a03:b0c0:0:1010::23:1001/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd',
'/ip6/2a03:b0c0:1:d0::e7:1/tcp/4001/ipfs/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3',
'/ip6/2604:a880:1:20::1d9:6001/tcp/4001/ipfs/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx',
'/dns4/node0.preload.ipfs.io/tcp/443/wss/ipfs/QmZMxNdpMkewiVZLMRxaNxUeZpDUb34pWjZ1kZvsd16Zic',
'/dns4/node1.preload.ipfs.io/tcp/443/wss/ipfs/Qmbut9Ywz9YEDrz8ySBSgWyJk41Uvm2QJPhwDJzJyGFsD6'
],
Swarm: {
ConnMgr: {
LowWater: 50,
HighWater: 100
}
}
}
}
Expand All @@ -61,9 +88,11 @@ function buildDefaultIpfsNodeConfig () {

// Until we have MulticastDNS+DNS, peer discovery is done over ws-star
config.config.Addresses.Swarm = [
'/ip4/0.0.0.0/tcp/0',
'/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 = [
Expand All @@ -80,6 +109,8 @@ function buildDefaultIpfsNodeConfig () {
'/dns4/node0.preload.ipfs.io/tcp/443/https'
]
}
*/
config.preload = { enabled: false }
/*
(Sidenote on why we need API for Web UI)
Gateway can run without API port,
Expand Down
93 changes: 38 additions & 55 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -729,13 +729,20 @@
resolved "https://registry.yarnpkg.com/@hapi/address/-/address-2.0.0.tgz#9f05469c88cb2fd3dcd624776b54ee95c312126a"
integrity sha512-mV6T0IYqb0xL1UALPFplXYQmR0twnXG0M6jUswpquqT2sD12BOiCiLy3EvMp/Fy7s3DZElC4/aPjEjo2jeZpvw==

"@hapi/ammo@3.x.x", "@hapi/ammo@^3.1.0":
"@hapi/ammo@3.x.x":
version "3.1.0"
resolved "https://registry.yarnpkg.com/@hapi/ammo/-/ammo-3.1.0.tgz#a3281ecb68bf7af2ffa6d0f7656536a7d23700ed"
integrity sha512-iFQBEfm3WwWy8JdPQ8l6qXVLPtzmjITVfaxwl6dfoP8kKv6i2Uk43Ax+ShkNfOVyfEnNggqL2IyZTY3DaaRGNg==
dependencies:
"@hapi/hoek" "6.x.x"

"@hapi/ammo@^3.1.0":
version "3.1.1"
resolved "https://registry.yarnpkg.com/@hapi/ammo/-/ammo-3.1.1.tgz#ab700dac10f0b7fc5b7168c550c6be45ec3b981b"
integrity sha512-NYFK27VSPGyQ/KmOQedpQH4PSjE7awLntepX68vrYtRvuJO21W1kX0bK2p3C+6ltUwtCQSvmNT8a4uMVAysC6Q==
dependencies:
"@hapi/hoek" "8.x.x"

"@hapi/boom@7.x.x", "@hapi/boom@^7.4.2":
version "7.4.2"
resolved "https://registry.yarnpkg.com/@hapi/boom/-/boom-7.4.2.tgz#c16957cd09796f6c1bfb4031bdc39d66d6d750c3"
Expand Down Expand Up @@ -6933,7 +6940,7 @@ ipfs-css@0.13.1:
resolved "https://registry.yarnpkg.com/ipfs-css/-/ipfs-css-0.13.1.tgz#f751be9cc89e30c34c50325848233f6da6b6728e"
integrity sha512-hofJSYVBE3VC3/MOYZKfF66SKuHgnYkhXUmPDS8PISI8ygcljGOyBSSU4Je3dfgZX5UHDBEnzq5XyrTU822EDg==

ipfs-http-client@33.1.1, ipfs-http-client@^33.0.1, ipfs-http-client@^33.0.2:
ipfs-http-client@33.1.1, ipfs-http-client@^33.0.1, ipfs-http-client@^33.0.2, ipfs-http-client@^33.1.0:
version "33.1.1"
resolved "https://registry.yarnpkg.com/ipfs-http-client/-/ipfs-http-client-33.1.1.tgz#6ddc13e86f8db768093290b19537d2388c74dd45"
integrity sha512-iwtLL3lOIzxXJFwLnOEtFUv1cYTuWJ0NauD7rpMEd/y4C7z6fuN6TSF4h547lxMh7sJWv+6Z0PmOA5N8FzUHJw==
Expand Down Expand Up @@ -6984,57 +6991,6 @@ ipfs-http-client@33.1.1, ipfs-http-client@^33.0.1, ipfs-http-client@^33.0.2:
tar-stream "^2.0.1"
through2 "^3.0.1"

ipfs-http-client@^33.1.0:
version "33.1.0"
resolved "https://registry.yarnpkg.com/ipfs-http-client/-/ipfs-http-client-33.1.0.tgz#4d3beceba27fcef26cf1940375a5f8c9d609f0dd"
integrity sha512-hkS8nXay3DGKb/KXU1RDvTyxnvkAdhS5enlXxNXaS7yKvADlf5SEuQGYjW+VknkPPQ4FNbY3JttQ3YW+LTuoRA==
dependencies:
async "^2.6.1"
bignumber.js "^9.0.0"
bl "^3.0.0"
bs58 "^4.0.1"
buffer "^5.2.1"
cids "~0.7.1"
concat-stream "github:hugomrdias/concat-stream#feat/smaller"
debug "^4.1.0"
detect-node "^2.0.4"
end-of-stream "^1.4.1"
err-code "^1.1.2"
flatmap "0.0.3"
glob "^7.1.3"
ipfs-block "~0.8.1"
ipfs-utils "~0.0.3"
ipld-dag-cbor "~0.15.0"
ipld-dag-pb "~0.17.3"
ipld-raw "^4.0.0"
is-ipfs "~0.6.1"
is-pull-stream "0.0.0"
is-stream "^2.0.0"
iso-stream-http "~0.1.2"
iso-url "~0.4.6"
just-kebab-case "^1.1.0"
just-map-keys "^1.1.0"
kind-of "^6.0.2"
lru-cache "^5.1.1"
multiaddr "^6.0.6"
multibase "~0.6.0"
multicodec "~0.5.1"
multihashes "~0.4.14"
ndjson "github:hugomrdias/ndjson#feat/readable-stream3"
once "^1.4.0"
peer-id "~0.12.2"
peer-info "~0.15.1"
promisify-es6 "^1.0.3"
pull-defer "~0.2.3"
pull-stream "^3.6.9"
pull-to-stream "~0.1.1"
pump "^3.0.0"
qs "^6.5.2"
readable-stream "^3.1.1"
stream-to-pull-stream "^1.7.2"
tar-stream "^2.0.1"
through2 "^3.0.1"

ipfs-http-response@0.3.1, ipfs-http-response@~0.3.1:
version "0.3.1"
resolved "https://registry.yarnpkg.com/ipfs-http-response/-/ipfs-http-response-0.3.1.tgz#5cc351f8abf5f77dae47a41781fd7bc0c88fcaf8"
Expand Down Expand Up @@ -9036,7 +8992,7 @@ libp2p-websocket-star@~0.10.2:
socket.io-client "^2.1.1"
socket.io-pull-stream "~0.1.5"

libp2p-websockets@^0.12.2, libp2p-websockets@~0.12.2:
libp2p-websockets@^0.12.2:
version "0.12.2"
resolved "https://registry.yarnpkg.com/libp2p-websockets/-/libp2p-websockets-0.12.2.tgz#eecf25564cbe6b0e9017bb411c2a8abec8c9f29b"
integrity sha512-K/Jg/fWFfP5NyiLx01EJcoAcYQO00RSHpZfPQDR3May6ABvOseAjq45SrUDdDCW5mCS0502Vz1VjRrZdOXw8zQ==
Expand All @@ -9048,6 +9004,18 @@ libp2p-websockets@^0.12.2, libp2p-websockets@~0.12.2:
multiaddr-to-uri "^4.0.1"
pull-ws hugomrdias/pull-ws#fix/bundle-size

libp2p-websockets@~0.12.2:
version "0.12.3"
resolved "https://registry.yarnpkg.com/libp2p-websockets/-/libp2p-websockets-0.12.3.tgz#f4bc201b0f381bd6b53f5e92446394761f29ceb3"
integrity sha512-qA5YZv7RoxGUtMlcD8JwquonM0/19MCV0UPDRihCjzTi4wRgGKhIXZSwd/fs+8RRTKHMEUngAxit7ZLSlYgdQQ==
dependencies:
class-is "^1.1.0"
debug "^4.1.1"
interface-connection "~0.3.3"
mafmt "^6.0.7"
multiaddr-to-uri "^5.0.0"
pull-ws hugomrdias/pull-ws#fix/bundle-size

libp2p@~0.25.4:
version "0.25.5"
resolved "https://registry.yarnpkg.com/libp2p/-/libp2p-0.25.5.tgz#f7153064cb64555c4520b086a79b787bd2de2161"
Expand Down Expand Up @@ -9952,6 +9920,13 @@ multiaddr-to-uri@4.0.1, multiaddr-to-uri@^4.0.1:
dependencies:
multiaddr "^6.0.3"

multiaddr-to-uri@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/multiaddr-to-uri/-/multiaddr-to-uri-5.0.0.tgz#f62421bd905d2690030acdae09b0719f60b6a91c"
integrity sha512-aVc52fdGXso3DwvVKUTjMddhLyuFBXcpGSbsIju0lKiYKFBUEREXSLpcqTOZlO8w1G1TivVmDe4CBUKQ/xMm5A==
dependencies:
multiaddr "^6.1.0"

multiaddr@6.1.0, multiaddr@^4.0.0, multiaddr@^5.0.0, multiaddr@^6.0.3, multiaddr@^6.0.4, multiaddr@^6.0.6, multiaddr@^6.1.0:
version "6.1.0"
resolved "https://registry.yarnpkg.com/multiaddr/-/multiaddr-6.1.0.tgz#1f93afce58a33db5cc32a5917d8a14105d94330e"
Expand Down Expand Up @@ -14075,14 +14050,22 @@ superagent@^3.1.0, superagent@~3.8.1:
qs "^6.5.1"
readable-stream "^2.3.5"

superstruct@^0.6.0, superstruct@~0.6.0, superstruct@~0.6.1:
superstruct@^0.6.0, superstruct@~0.6.1:
version "0.6.1"
resolved "https://registry.yarnpkg.com/superstruct/-/superstruct-0.6.1.tgz#148fc3d627bb59fcfe24aa1bd2a1b8c51b1db072"
integrity sha512-LDbOKL5sNbOJ00Q36iYRhSexKIptZje0/mhNznnz04wT9CmsPDZg/K/UV1dgYuCwNMuOBHTbVROZsGB9EhhK4w==
dependencies:
clone-deep "^2.0.1"
kind-of "^6.0.1"

superstruct@~0.6.0:
version "0.6.2"
resolved "https://registry.yarnpkg.com/superstruct/-/superstruct-0.6.2.tgz#c5eb034806a17ff98d036674169ef85e4c7f6a1c"
integrity sha512-lvA97MFAJng3rfjcafT/zGTSWm6Tbpk++DP6It4Qg7oNaeM+2tdJMuVgGje21/bIpBEs6iQql1PJH6dKTjl4Ig==
dependencies:
clone-deep "^2.0.1"
kind-of "^6.0.1"

supports-color@6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-6.0.0.tgz#76cfe742cf1f41bb9b1c29ad03068c05b4c0e40a"
Expand Down

0 comments on commit 3c04858

Please sign in to comment.