Skip to content

Commit

Permalink
feat: add libp2p-webext-mdns discovery
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Alan Shaw <[email protected]>
  • Loading branch information
alanshaw committed Aug 8, 2018
1 parent 0a0b685 commit 8bb39e7
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 14 deletions.
13 changes: 13 additions & 0 deletions add-on/manifest.firefox-libdweb.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@
"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"
}
}
}
}
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:webext-mdns*'

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

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

const Ipfs = require('ipfs')
const WebExtMdns = require('libp2p-webext-mdns')
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]
}
}
}
)

node = new Ipfs(ipfsOpts)

if (node.isOnline()) {
return Promise.resolve(node)
}
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"cross-env": "5.2.0",
"fakefile": "0.0.9",
"fs-promise": "2.0.3",
"get-firefox": "2.1.1",
"get-firefox": "2.2.0",
"husky": "0.14.3",
"ignore-styles": "5.0.1",
"json": "9.0.6",
Expand Down Expand Up @@ -115,7 +115,8 @@
"is-ipfs": "0.4.2",
"is-stream": "1.1.0",
"is-svg": "3.0.0",
"libdweb": "mozilla/libdweb.git#fbff435b33542b02bc35c0bb8c27bc203e6d4e6e",
"libdweb": "mozilla/libdweb.git#1ee7977a2352950ecf7fa46a13ae45aa500c9b32",
"libp2p-webext-mdns": "github:alanshaw/js-libp2p-webext-mdns#661e03745450c3303e4fa0c2600c28dd0a4a3ba5",
"lru_map": "0.3.3",
"mime-types": "2.1.18",
"p-queue": "2.4.2",
Expand Down
31 changes: 21 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4249,19 +4249,20 @@ get-caller-file@^1.0.1:
version "1.0.3"
resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-1.0.3.tgz#f978fa4c90d1dfe7ff2d6beda2a515e713bdcf4a"

get-firefox@2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/get-firefox/-/get-firefox-2.1.1.tgz#1dbafe1e357fb292e816d4c64b6fc7a5153bf7a7"
get-firefox@2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/get-firefox/-/get-firefox-2.2.0.tgz#7ea8fc874bb952295de33705aea21db14ce2a55e"
dependencies:
chalk "^2.4.1"
decompress "^4.2.0"
is-ci "^1.1.0"
listr "^0.14.0"
meow "^5.0.0"
moz-download-url "^2.0.0"
node-fetch "^2.1.2"
node-fetch "^2.2.0"
sha "^2.0.1"
stream-to-promise "^2.2.0"
taskcluster-client "^11.0.0"
taskcluster-client "^11.0.3"

get-folder-size@^2.0.0:
version "2.0.0"
Expand Down Expand Up @@ -5497,7 +5498,7 @@ is-callable@^1.1.1, is-callable@^1.1.3:
version "1.1.4"
resolved "https://registry.yarnpkg.com/is-callable/-/is-callable-1.1.4.tgz#1e1adf219e1eeb684d691f9d6a05ff0d30a24d75"

is-ci@^1.0.10:
is-ci@^1.0.10, is-ci@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/is-ci/-/is-ci-1.1.0.tgz#247e4162e7860cebbdaf30b774d6b0ac7dcfe7a5"
dependencies:
Expand Down Expand Up @@ -6255,9 +6256,9 @@ levn@^0.3.0, levn@~0.3.0:
prelude-ls "~1.1.2"
type-check "~0.3.2"

libdweb@mozilla/libdweb.git#fbff435b33542b02bc35c0bb8c27bc203e6d4e6e:
libdweb@mozilla/libdweb.git#1ee7977a2352950ecf7fa46a13ae45aa500c9b32:
version "0.0.0"
resolved "https://codeload.github.com/mozilla/libdweb/tar.gz/fbff435b33542b02bc35c0bb8c27bc203e6d4e6e"
resolved "https://codeload.github.com/mozilla/libdweb/tar.gz/1ee7977a2352950ecf7fa46a13ae45aa500c9b32"

libp2p-bootstrap@~0.9.3:
version "0.9.3"
Expand Down Expand Up @@ -6506,6 +6507,16 @@ libp2p-tcp@~0.12.0:
once "^1.4.0"
stream-to-pull-stream "^1.7.2"

"libp2p-webext-mdns@github:alanshaw/js-libp2p-webext-mdns#661e03745450c3303e4fa0c2600c28dd0a4a3ba5":
version "0.1.0"
resolved "https://codeload.github.com/alanshaw/js-libp2p-webext-mdns/tar.gz/661e03745450c3303e4fa0c2600c28dd0a4a3ba5"
dependencies:
async "^2.6.1"
libp2p-tcp "~0.12.0"
multiaddr "^5.0.0"
peer-id "~0.11.0"
peer-info "~0.14.1"

libp2p-webrtc-star@~0.15.3:
version "0.15.3"
resolved "https://registry.yarnpkg.com/libp2p-webrtc-star/-/libp2p-webrtc-star-0.15.3.tgz#370b09c2871a12dadc44ed66dfd31060af671b52"
Expand Down Expand Up @@ -7718,7 +7729,7 @@ node-abi@^2.2.0:
dependencies:
semver "^5.4.1"

node-fetch@^2.1.2:
node-fetch@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.2.0.tgz#4ee79bde909262f9775f731e3656d0db55ced5b5"

Expand Down Expand Up @@ -10518,7 +10529,7 @@ tar@^4:
safe-buffer "^5.1.2"
yallist "^3.0.2"

taskcluster-client@^11.0.0:
taskcluster-client@^11.0.3:
version "11.0.3"
resolved "https://registry.yarnpkg.com/taskcluster-client/-/taskcluster-client-11.0.3.tgz#f71fd2d75dc4912ecc6c69fc56994eae088265aa"
dependencies:
Expand Down

0 comments on commit 8bb39e7

Please sign in to comment.