Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Commit

Permalink
feat: ipns over pubsub (#846)
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos authored and Alan Shaw committed Oct 24, 2018
1 parent 14a4471 commit ef49e95
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ const ipfs = IpfsApi({

- [name](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/NAME.md)
- [`ipfs.name.publish(addr, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/NAME.md#namepublish)
- [`ipfs.name.pubsub.cancel(arg, [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/NAME.md#namepubsubcancel)
- [`ipfs.name.pubsub.state([callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/NAME.md#namepubsubstate)
- [`ipfs.name.pubsub.subs([callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/NAME.md#namepubsubsubs)
- [`ipfs.name.resolve(addr, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/NAME.md#nameresolve)

#### Node Management
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"eslint-plugin-react": "^7.10.0",
"go-ipfs-dep": "~0.4.17",
"gulp": "^3.9.1",
"interface-ipfs-core": "~0.78.0",
"interface-ipfs-core": "~0.80.0",
"ipfsd-ctl": "~0.39.0",
"pull-stream": "^3.6.8",
"socket.io": "^2.1.1",
Expand Down
3 changes: 2 additions & 1 deletion src/name/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports = (arg) => {

return {
publish: require('./publish')(send),
resolve: require('./resolve')(send)
resolve: require('./resolve')(send),
pubsub: require('./pubsub')(send)
}
}
24 changes: 24 additions & 0 deletions src/name/pubsub/cancel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict'

const promisify = require('promisify-es6')

const transform = function (res, callback) {
callback(null, {
canceled: res.Canceled === undefined || res.Canceled === true
})
}

module.exports = (send) => {
return promisify((args, opts, callback) => {
if (typeof (opts) === 'function') {
callback = opts
opts = {}
}

send.andTransform({
path: 'name/pubsub/cancel',
args: args,
qs: opts
}, transform, callback)
})
}
7 changes: 7 additions & 0 deletions src/name/pubsub/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict'

module.exports = (send) => ({
cancel: require('./cancel')(send),
state: require('./state')(send),
subs: require('./subs')(send)
})
23 changes: 23 additions & 0 deletions src/name/pubsub/state.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict'

const promisify = require('promisify-es6')

const transform = function (res, callback) {
callback(null, {
enabled: res.Enabled
})
}

module.exports = (send) => {
return promisify((opts, callback) => {
if (typeof (opts) === 'function') {
callback = opts
opts = {}
}

send.andTransform({
path: 'name/pubsub/state',
qs: opts
}, transform, callback)
})
}
21 changes: 21 additions & 0 deletions src/name/pubsub/subs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict'

const promisify = require('promisify-es6')

const transform = function (res, callback) {
callback(null, res.Strings || [])
}

module.exports = (send) => {
return promisify((opts, callback) => {
if (typeof (opts) === 'function') {
callback = opts
opts = {}
}

send.andTransform({
path: 'name/pubsub/subs',
qs: opts
}, transform, callback)
})
}
21 changes: 21 additions & 0 deletions test/interface.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,27 @@ describe('interface-ipfs-core tests', () => {
]
})

// TODO: uncomment after https://github.com/ipfs/interface-ipfs-core/pull/361 being merged and a new release
tests.namePubsub(CommonFactory.create({
spawnOptions: {
args: ['--enable-namesys-pubsub'],
initOptions: { bits: 1024 }
}
}), {
skip: [
// name.pubsub.cancel
{
name: 'should cancel a subscription correctly returning true',
reason: 'go-ipfs is really slow for publishing and resolving ipns records, unless in offline mode'
},
// name.pubsub.subs
{
name: 'should get the list of subscriptions updated after a resolve',
reason: 'go-ipfs is really slow for publishing and resolving ipns records, unless in offline mode'
}
]
})

tests.object(defaultCommonFactory)

tests.pin(defaultCommonFactory)
Expand Down

0 comments on commit ef49e95

Please sign in to comment.