Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PoC] libdweb discovery and transport #553

Closed
wants to merge 5 commits into from
Closed
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
3 changes: 2 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"plugins": [
"syntax-async-generators"
"syntax-async-generators",
"syntax-object-rest-spread"
],
"presets": [
[
Expand Down
21 changes: 21 additions & 0 deletions add-on/manifest.firefox-libdweb.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,27 @@
"paths": [["protocol"]],
"script": "../node_modules/libdweb/src/protocol/host.js"
}
},
"ServiceDiscovery": {
"schema": "../node_modules/libdweb/src/ServiceDiscovery/ServiceDiscovery.json",
"child": {
"scopes": ["addon_child"],
"paths": [["ServiceDiscovery"]],
"script": "../node_modules/libdweb/src/ServiceDiscovery/client.js"
},
"parent": {
"scopes": ["addon_parent"],
"paths": [["ServiceDiscovery"]],
"script": "../node_modules/libdweb/src/ServiceDiscovery/host.js"
}
},
"TCPSocket": {
"schema": "../node_modules/libdweb/src/TCPSocket/TCPSocket.json",
"child": {
"scopes": ["addon_child"],
"paths": [["TCPSocket"]],
"script": "../node_modules/libdweb/src/TCPSocket/Socket.js"
}
}
}
}
2 changes: 2 additions & 0 deletions add-on/src/background/background.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict'
/* eslint-env browser, webextensions */

chrome.storage.local.debug = 'libp2p:*'

const createIpfsCompanion = require('../lib/ipfs-companion')

// init add-on after all libs are loaded
Expand Down
16 changes: 14 additions & 2 deletions add-on/src/lib/ipfs-client/embedded.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
'use strict'

const Ipfs = require('ipfs')
const WebExtMdns = require('libp2p-webext-mdns')
const WebExtTcp = require('libp2p-webext-tcp')
const { optionDefaults } = require('../options')

let node = null

exports.init = function init (opts) {
console.log('[ipfs-companion] Embedded ipfs init')

node = new Ipfs(
JSON.parse(opts.ipfsNodeConfig || optionDefaults.ipfsNodeConfig)
const ipfsOpts = Object.assign(
JSON.parse(opts.ipfsNodeConfig || optionDefaults.ipfsNodeConfig),
{
libp2p: {
modules: {
peerDiscovery: [WebExtMdns],
transport: [WebExtTcp]
}
}
}
)

node = new Ipfs(ipfsOpts)

if (node.isOnline()) {
return Promise.resolve(node)
}
Expand Down
6 changes: 3 additions & 3 deletions docs/libdweb.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,18 @@ cd ipfs-companion
# install deps and build
npm run libdweb:build

# run in firefox-nightly
# run in firefox-nightly (linux only)
npm run libdweb:firefox
```

### Manually run with different firefox binary
### Manually run with different firefox binary (or on macOS)

To run your extension in libdweb context:

```
npm run libdweb:build
export MOZ_DISABLE_CONTENT_SANDBOX=1
web-ext run --firefox=/path/to/nightly/firefox-bin --browser-console --url about:debugging
npx web-ext run --firefox="/Applications/Firefox Nightly.app" --browser-console --url about:debugging
```

Additional notes:
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"babel-eslint": "8.2.6",
"babel-loader": "7.1.5",
"babel-plugin-syntax-async-generators": "6.13.0",
"babel-plugin-syntax-object-rest-spread": "6.13.0",
"babel-preset-env": "1.7.0",
"chai": "4.1.2",
"cross-env": "5.2.0",
Expand Down Expand Up @@ -115,6 +116,8 @@
"is-ipfs": "0.4.2",
"is-stream": "1.1.0",
"libdweb": "https://github.com/mozilla/libdweb/tarball/dbb9697a8dd09a9ad61ce5e2204400f72d16157a/libdweb.tar.gz",
"libp2p-webext-mdns": "https://github.com/alanshaw/js-libp2p-webext-mdns/tarball/d08a6e93e6129af92e450681467fb68198d8616f/js-libp2p-webext-mdns.tar.gz",
"libp2p-webext-tcp": "https://github.com/alanshaw/js-libp2p-webext-tcp/tarball/4ae6c06d32f82fadf58e055d9880d46c08513ce5/js-libp2p-webext-tcp.tar.gz",
"lru_map": "0.3.3",
"mime-types": "2.1.19",
"p-queue": "2.4.2",
Expand Down
Loading