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

feat: webrtc by default if supported #793

Merged
merged 1 commit into from
May 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ const node = new IPFS({
// start: false,
EXPERIMENTAL: { // enable experimental features
pubsub: true,
sharding: true // enable dir sharding
sharding: true, // enable dir sharding
wrtcLinuxWindows: true // use unstable wrtc module on Linux or Windows with Node.js
},
config: { // overload the default config
Addresses: {
Expand Down Expand Up @@ -367,6 +368,18 @@ A set of data types are exposed directly from the IPFS instance under `ipfs.type
- [`ipfs.types.multihash`](https://github.com/multiformats/js-multihash)
- [`ipfs.types.CID`](https://github.com/ipld/js-cid)

## FAQ

> Is there WebRTC support for js-ipfs with Node.js?

Yes there is, however, Linux and Windows support is limited/unstable. For Linux users, you need to follow the install the extra packages for Linux listed on the [`wrtc` npm page](http://npmjs.org/wrtc) and then, when doing initing the repo, do:

```sh
> IPFS_WRTC_LINUX_WINDOWS=1 jsipfs init
```

This will create a repo with a config file that contains a WebRTC multiaddr.

## Packages

| Package | Version | Deps | DevDeps | Build |
Expand Down
14 changes: 14 additions & 0 deletions src/core/components/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,20 @@ module.exports = function init (self) {
opts.log('done')
opts.log('peer identity: ' + config.Identity.PeerID)

const isWin = /^win/.test(process.platform)
const isLinux = /^linux/.test(process.platform)
const wrtcLinuxWindows = !process.env.IPFS_WRTC_LINUX_WINDOWS ||
self._options.EXPERIMENTAL.wrtcLinuxWindows

// For the lack of sane WebRTC support on Linux and Windows
if (wrtcLinuxWindows && (isWin || isLinux)) {
console.log('WARNING: Your platform does not have native WebRTC support, it won\' use any WebRTC transport')
const newAddrs = config.Addresses.Swarm.filter((addr) => {
return addr.indexOf('libp2p-webrtc-star') < 0
})
config.Addresses.Swarm = newAddrs
}

self._repo.init(config, cb)
},
(_, cb) => self._repo.open(cb),
Expand Down
8 changes: 5 additions & 3 deletions src/init-files/default-config-browser.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{
"Addresses": {
"Swarm": [],
"API": "/ip4/127.0.0.1/tcp/5002",
"Gateway": "/ip4/127.0.0.1/tcp/9090"
"Swarm": [
"/libp2p-webrtc-star/dns4/star-signal.cloud.ipfs.team/wss"
],
"API": "",
"Gateway": ""
},
"Discovery": {
"MDNS": {
Expand Down
3 changes: 2 additions & 1 deletion src/init-files/default-config-node.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"Addresses": {
"Swarm": [
"/ip4/0.0.0.0/tcp/4002",
"/ip4/127.0.0.1/tcp/4003/ws"
"/ip4/127.0.0.1/tcp/4003/ws",
"/libp2p-webrtc-star/dns4/star-signal.cloud.ipfs.team/wss"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is swarm listen address list. Sure it should be here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep @Kubuxu, WebRTC references the signalling point, not a local server ;)

],
"API": "/ip4/127.0.0.1/tcp/5002",
"Gateway": "/ip4/127.0.0.1/tcp/9090"
Expand Down
7 changes: 6 additions & 1 deletion test/core/bitswap.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ const multiaddr = require('multiaddr')
const isNode = require('detect-node')
const multihashing = require('multihashing-async')
const CID = require('cids')
const Buffer = require('safe-buffer').Buffer

// This gets replaced by '../utils/create-repo-browser.js' in the browser
const createTempRepo = require('../utils/create-repo-node.js')

const IPFS = require('../../src/core')

function makeBlock (cb) {
const d = new Buffer(`IPFS is awesome ${Math.random()}`)
const d = Buffer.from(`IPFS is awesome ${Math.random()}`)

multihashing(d, 'sha2-256', (err, multihash) => {
if (err) {
return cb(err)
Expand Down Expand Up @@ -59,6 +61,9 @@ describe('bitswap', () => {
inProcNode = new IPFS({
repo: repo,
config: {
Addresses: {
Swarm: [ '/ip4/127.0.0.1/tcp/0' ]
},
Discovery: {
MDNS: {
Enabled: false
Expand Down
5 changes: 5 additions & 0 deletions test/core/bootstrap.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ describe('bootstrap', () => {
},
EXPERIMENTAL: {
pubsub: true
},
config: {
Addresses: {
Swarm: ['/ip4/127.0.0.1/tcp/0']
}
}
})

Expand Down
52 changes: 47 additions & 5 deletions test/core/create-node.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ const createTempRepo = require('../utils/create-repo-node.js')
describe('create node', () => {
it('custom repoPath', (done) => {
const node = new IPFS({
repo: '/tmp/ipfs-repo-' + Math.random()
repo: '/tmp/ipfs-repo-' + Math.random(),
config: {
Addresses: {
Swarm: []
}
}
})

node.once('start', (err) => {
Expand All @@ -36,7 +41,12 @@ describe('create node', () => {

it('custom repo', (done) => {
const node = new IPFS({
repo: createTempRepo()
repo: createTempRepo(),
config: {
Addresses: {
Swarm: []
}
}
})

node.once('start', (err) => {
Expand All @@ -53,7 +63,12 @@ describe('create node', () => {

it('IPFS.createNode', (done) => {
const node = IPFS.createNode({
repo: createTempRepo()
repo: createTempRepo(),
config: {
Addresses: {
Swarm: []
}
}
})

node.once('start', (err) => {
Expand All @@ -76,6 +91,11 @@ describe('create node', () => {
repo: createTempRepo(),
init: {
bits: 1024
},
config: {
Addresses: {
Swarm: []
}
}
})

Expand All @@ -94,7 +114,12 @@ describe('create node', () => {
it('init: false errors (start default: true)', (done) => {
const node = new IPFS({
repo: createTempRepo(),
init: false
init: false,
config: {
Addresses: {
Swarm: []
}
}
})
node.once('error', (err) => {
expect(err).to.exist()
Expand All @@ -106,7 +131,12 @@ describe('create node', () => {
const node = new IPFS({
repo: createTempRepo(),
init: false,
start: false
start: false,
config: {
Addresses: {
Swarm: []
}
}
})

let happened = false
Expand All @@ -131,6 +161,9 @@ describe('create node', () => {
init: true,
start: false,
config: {
Addresses: {
Swarm: []
},
Bootstrap: []
}
})
Expand All @@ -148,6 +181,9 @@ describe('create node', () => {
init: true,
start: false,
config: {
Addresses: {
Swarm: []
},
Bootstrap: []
}
})
Expand Down Expand Up @@ -192,6 +228,9 @@ describe('create node', () => {
const node = new IPFS({
repo: createTempRepo(),
config: {
Addresses: {
Swarm: []
},
Bootstrap: []
}
})
Expand All @@ -208,6 +247,9 @@ describe('create node', () => {
const options = {
repo: createTempRepo(),
config: {
Addresses: {
Swarm: []
},
Bootstrap: []
}
}
Expand Down
13 changes: 9 additions & 4 deletions test/core/files-sharding.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)
const pull = require('pull-stream')
const Buffer = require('safe-buffer').Buffer

const IPFS = require('../../src/core')
const createTempRepo = require('../utils/create-repo-node.js')
Expand All @@ -16,7 +17,7 @@ describe('files dir', () => {
for (let i = 0; i < 1005; i++) {
files.push({
path: 'test-folder/' + i,
content: new Buffer('some content ' + i)
content: Buffer.from('some content ' + i)
})
}

Expand All @@ -27,15 +28,16 @@ describe('files dir', () => {
ipfs = new IPFS({
repo: createTempRepo(),
config: {
Addresses: {
Swarm: []
},
Bootstrap: []
}
})
ipfs.once('start', done)
})

after((done) => {
ipfs.stop(done)
})
after((done) => ipfs.stop(done))

it('should be able to add dir without sharding', (done) => {
pull(
Expand Down Expand Up @@ -63,6 +65,9 @@ describe('files dir', () => {
ipfs = new IPFS({
repo: createTempRepo(),
config: {
Addresses: {
Swarm: []
},
Bootstrap: []
},
EXPERIMENTAL: {
Expand Down