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

Commit

Permalink
feat: enable circuit relay
Browse files Browse the repository at this point in the history
  • Loading branch information
dryajov authored and daviddias committed Nov 8, 2017
1 parent b92bdfe commit 9aef6b7
Show file tree
Hide file tree
Showing 48 changed files with 649 additions and 226 deletions.
61 changes: 60 additions & 1 deletion .aegir.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,71 @@
'use strict'

const parallel = require('async/parallel')

const spawnJsNode = require('./test/utils/spawn-tools').spawnJsNode
const spawnGoNode = require('./test/utils/spawn-tools').spawnGoNode
const stopNodes = require('./test/utils/spawn-tools').stopNodes

/*
* spawns a daemon with ports numbers starting in 10 and ending in `num`
*/
const before = (done) => {
parallel([
(cb) => spawnJsNode([
`/ip4/127.0.0.1/tcp/10007`,
`/ip4/127.0.0.1/tcp/20007/ws`
], true, 31007, 32007, cb),
(cb) => spawnJsNode([
`/ip4/127.0.0.1/tcp/10008`,
`/ip4/127.0.0.1/tcp/20008/ws`
], true, 31008, 32008, cb),
(cb) => spawnJsNode([
`/ip4/127.0.0.1/tcp/10012`,
`/ip4/127.0.0.1/tcp/20012/ws`
], true, 31012, 32012, cb),
(cb) => spawnJsNode([
`/ip4/127.0.0.1/tcp/10013`,
`/ip4/127.0.0.1/tcp/20013/ws`
], true, 31013, 32013, cb),
(cb) => spawnJsNode([
`/ip4/127.0.0.1/tcp/10014`,
`/ip4/127.0.0.1/tcp/20014/ws`
], true, 31014, 32014, cb),
(cb) => spawnJsNode([
`/ip4/127.0.0.1/tcp/10015`,
`/ip4/127.0.0.1/tcp/20015/ws`
], true, 31015, 32015, cb),
(cb) => spawnGoNode([
`/ip4/127.0.0.1/tcp/10027`,
`/ip4/127.0.0.1/tcp/20027/ws`
], true, 33027, 44027, cb),
(cb) => spawnGoNode([
`/ip4/127.0.0.1/tcp/10028`,
`/ip4/127.0.0.1/tcp/20028/ws`
], true, 33028, 44028, cb),
(cb) => spawnGoNode([
`/ip4/127.0.0.1/tcp/10031`,
`/ip4/127.0.0.1/tcp/20031/ws`
], true, 33031, 44031, cb),
(cb) => spawnGoNode([
`/ip4/127.0.0.1/tcp/10032`,
`/ip4/127.0.0.1/tcp/20032/ws`
], true, 33032, 44032, cb)
], done)
}

module.exports = {
karma: {
files: [{
pattern: 'node_modules/interface-ipfs-core/test/fixtures/**/*',
watched: false,
served: true,
included: false
included: false,
singleRun: false
}]
},
hooks: {
pre: before,
post: stopNodes
}
}
10 changes: 5 additions & 5 deletions examples/exchange-files-in-browser/public/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function start () {
if (!node) {
updateView('starting', node)

node = new self.Ipfs({repo: 'ipfs-' + Math.random()})
node = new self.Ipfs({ repo: 'ipfs-' + Math.random() })

node.on('start', () => {
node.id().then((id) => {
Expand All @@ -55,7 +55,7 @@ function stop () {
*/

function createFileBlob (data, multihash) {
const file = new window.Blob(data, {type: 'application/octet-binary'})
const file = new window.Blob(data, { type: 'application/octet-binary' })
const fileUrl = window.URL.createObjectURL(file)

const listItem = document.createElement('div')
Expand Down Expand Up @@ -151,7 +151,7 @@ function onDrop (event) {

let myReadableStreamBuffer = new streamBuffers.ReadableStreamBuffer({
// frequency: 10, // in milliseconds.
chunkSize: 32048 // in bytes.
chunkSize: 32048 // in bytes.
})

node.files.createAddStream((err, stream) => {
Expand Down Expand Up @@ -200,8 +200,8 @@ function onDrop (event) {
if (files && files.length) {
$multihashInput.value = files[0].hash
$filesStatus.innerHTML = files
.map((e) => `Added ${e.path} as ${e.hash}`)
.join('<br>')
.map((e) => `Added ${e.path} as ${e.hash}`)
.join('<br>')
}
})
.catch(onError)
Expand Down
2 changes: 1 addition & 1 deletion examples/traverse-ipld-graphs/get-path-accross-formats.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ createNode((err, ipfs) => {

series([
(cb) => {
const someData = new Buffer('capoeira')
const someData = Buffer.from('capoeira')

dagPB.DAGNode.create(someData, (err, node) => {
if (err) {
Expand Down
2 changes: 1 addition & 1 deletion examples/traverse-ipld-graphs/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ createNode((err, ipfs) => {

series([
(cb) => {
const someData = new Buffer('capoeira')
const someData = Buffer.from('capoeira')

dagPB.DAGNode.create(someData, (err, node) => {
if (err) {
Expand Down
64 changes: 0 additions & 64 deletions gulpfile.js

This file was deleted.

43 changes: 22 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,21 @@
"npm": ">=3.0.0"
},
"scripts": {
"lint": "aegir-lint",
"coverage": "gulp coverage",
"test": "gulp test --dom",
"test:node": "npm run test:unit:node",
"test:browser": "npm run test:unit:browser",
"test:unit:node": "gulp test:node",
"test:unit:node:core": "TEST=core npm run test:unit:node",
"test:unit:node:http": "TEST=http npm run test:unit:node",
"test:unit:node:gateway": "TEST=gateway npm run test:unit:node",
"test:unit:node:cli": "TEST=cli npm run test:unit:node",
"test:unit:browser": "gulp test:browser",
"lint": "aegir lint",
"build": "aegir build",
"test": "aegir test --target node --target browser --no-cors",
"test:node": "aegir test --target node",
"test:browser": "aegir test --target browser --target webworker --no-cors",
"release": "aegir release --target node --target browser",
"release-minor": "aegir release --type minor --target node --target browser",
"release-major": "aegir release --type major --target node --target browser",
"coverage": "aegir coverage",
"test:unit:node": "aegir test --target node",
"test:unit:node:core": "aegir test --target node -f test/core/*.js",
"test:unit:node:http": "aegir test --target node -f test/http-api/index.js",
"test:unit:node:gateway": "aegir test --target node -f test/gateway/index.js",
"test:unit:node:cli": "aegir test --target node -f test/cli/index.js",
"test:unit:browser": "aegir test --target browser --no-cors",
"test:interop": "npm run test:interop:node",
"test:interop:node": "mocha -t 60000 test/interop/node.js",
"test:interop:browser": "mocha -t 60000 test/interop/browser.js",
Expand All @@ -38,10 +42,6 @@
"test:benchmark:node:core": "echo \"Error: no benchmarks yet\" && exit 1",
"test:benchmark:node:http": "echo \"Error: no benchmarks yet\" && exit 1",
"test:benchmark:browser": "echo \"Error: no benchmarks yet\" && exit 1",
"build": "gulp build",
"release": "gulp release",
"release-minor": "gulp release --type minor",
"release-major": "gulp release --type major",
"coverage-publish": "aegir-coverage publish"
},
"pre-commit": [
Expand All @@ -62,7 +62,7 @@
},
"homepage": "https://github.com/ipfs/js-ipfs#readme",
"devDependencies": {
"aegir": "^11.0.2",
"aegir": "^12.1.3",
"buffer-loader": "0.0.1",
"chai": "^4.1.2",
"delay": "^2.0.0",
Expand All @@ -74,7 +74,7 @@
"expose-loader": "^0.7.3",
"form-data": "^2.3.1",
"gulp": "^3.9.1",
"interface-ipfs-core": "~0.32.1",
"interface-ipfs-core": "~0.33.1",
"ipfsd-ctl": "~0.24.0",
"left-pad": "^1.1.3",
"lodash": "^4.17.4",
Expand Down Expand Up @@ -109,14 +109,15 @@
"ipfs-block": "~0.6.0",
"ipfs-block-service": "~0.12.0",
"ipfs-multipart": "~0.1.0",
"ipfs-repo": "~0.17.0",
"ipfs-repo": "~0.18.1",
"ipfs-unixfs": "~0.1.13",
"ipfs-unixfs-engine": "~0.22.5",
"ipld-resolver": "~0.13.4",
"is-ipfs": "^0.3.2",
"is-stream": "^1.1.0",
"joi": "^13.0.1",
"libp2p": "~0.12.4",
"libp2p": "~0.13.0",
"libp2p-circuit": "~0.1.4",
"libp2p-floodsub": "~0.11.1",
"libp2p-kad-dht": "~0.5.1",
"libp2p-mdns": "~0.9.1",
Expand All @@ -125,12 +126,12 @@
"libp2p-secio": "~0.8.1",
"libp2p-tcp": "~0.11.1",
"libp2p-webrtc-star": "~0.13.2",
"libp2p-websockets": "~0.10.2",
"libp2p-websockets": "~0.10.4",
"lodash.flatmap": "^4.5.0",
"lodash.get": "^4.4.2",
"lodash.sortby": "^4.7.0",
"lodash.values": "^4.3.0",
"mafmt": "^3.0.1",
"mafmt": "^3.0.2",
"mime-types": "^2.1.17",
"mkdirp": "~0.5.1",
"multiaddr": "^3.0.1",
Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/bitswap/stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = {

stats.Wantlist = stats.Wantlist || []
stats.Wantlist = stats.Wantlist.map((entry) => {
const buf = new Buffer(entry.cid.hash.data)
const buf = Buffer.from(entry.cid.hash.data)
const cid = new CID(entry.cid.version, entry.cid.codec, buf)
return cid.toBaseEncodedString()
})
Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/config/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ module.exports = {

function saveConfig (config, next) {
config = utils.isDaemonOn()
? new Buffer(JSON.stringify(config)) : config
? Buffer.from(JSON.stringify(config)) : config

argv.ipfs.config.replace(config, (err) => {
if (err) {
Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/pubsub/pub.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
builder: {},

handler (argv) {
const data = new Buffer(String(argv.data))
const data = Buffer.from(String(argv.data))

argv.ipfs.pubsub.publish(argv.topic, data, (err) => {
if (err) {
Expand Down
6 changes: 3 additions & 3 deletions src/core/boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ module.exports = (self) => {
// fail the whole process.
// TODO: improve datastore and ipfs-repo implemenations so this error is a bit more unified
if (err.message.match(/not found/) || // indexeddb
err.message.match(/ENOENT/) || // fs
err.message.match(/No value/) // memory
) {
err.message.match(/ENOENT/) || // fs
err.message.match(/No value/) // memory
) {
return cb(null, false)
}
return cb(err)
Expand Down
8 changes: 4 additions & 4 deletions src/core/components/id.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ module.exports = function id (self) {
id: self._peerInfo.id.toB58String(),
publicKey: self._peerInfo.id.pubKey.bytes.toString('base64'),
addresses: self._peerInfo.multiaddrs
.toArray()
.map((ma) => ma.toString())
.filter((ma) => ma.indexOf('ipfs') >= 0)
.sort(),
.toArray()
.map((ma) => ma.toString())
.filter((ma) => ma.indexOf('ipfs') >= 0)
.sort(),
agentVersion: 'js-ipfs',
protocolVersion: '9000'
}))
Expand Down
9 changes: 8 additions & 1 deletion src/core/components/libp2p.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ module.exports = function libp2p (self) {
webRTCStar: get(config, 'Discovery.webRTCStar.Enabled'),
bootstrap: get(config, 'Bootstrap'),
dht: get(self._options, 'EXPERIMENTAL.dht'),
modules: self._libp2pModules
modules: self._libp2pModules,
relay: {
enabled: !get(config, 'EXPERIMENTAL.Swarm.DisableRelay', false),
hop: {
enabled: get(config, 'EXPERIMENTAL.Swarm.EnableRelayHop', false),
active: get(config, 'EXPERIMENTAL.Swarm.RelayHopActive', false)
}
}
}

self._libp2pNode = new Node(self._peerInfo, self._peerInfoBook, options)
Expand Down
6 changes: 3 additions & 3 deletions src/core/components/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function normalizeMultihash (multihash, enc) {
return multihash
}

return new Buffer(multihash, enc)
return Buffer.from(multihash, enc)
} else if (Buffer.isBuffer(multihash)) {
return multihash
} else {
Expand Down Expand Up @@ -49,7 +49,7 @@ function parseJSONBuffer (buf, callback) {
mh.fromB58String(link.Hash || link.hash || link.multihash)
)
})
data = new Buffer(parsed.Data)
data = Buffer.from(parsed.Data)
} catch (err) {
return callback(new Error('failed to parse JSON: ' + err))
}
Expand Down Expand Up @@ -104,7 +104,7 @@ module.exports = function object (self) {
assert(template === 'unixfs-dir', 'unkown template')
data = (new Unixfs('directory')).marshal()
} else {
data = new Buffer(0)
data = Buffer.alloc(0)
}

DAGNode.create(data, (err, node) => {
Expand Down
Loading

0 comments on commit 9aef6b7

Please sign in to comment.