Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: libp2p/js-libp2p-delegated-peer-routing
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: cf98420fc493268109384cc383acd9f5a4b37be9
Choose a base ref
...
head repository: libp2p/js-libp2p-delegated-peer-routing
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 38d284803094a8847b03d7848c170c4acdd4a3ae
Choose a head ref

Commits on Jul 12, 2019

  1. feat: refactor to use async/await (#8)

    BREAKING CHANGE: API refactored to use async/await
    
    Also upgrades all the deps, moves from `ipfs-api` to `ipfs-http-client`
    and removes a lot of results massaging that is now done in the
    http client.
    achingbrain authored and jacobheun committed Jul 12, 2019
    Copy the full SHA
    1827328 View commit details
  2. chore: update contributors

    jacobheun committed Jul 12, 2019
    Copy the full SHA
    5de9747 View commit details
  3. chore: release version v0.3.0

    License: MIT
    Signed-off-by: Jacob Heun <jacobheun@gmail.com>
    jacobheun committed Jul 12, 2019
    Copy the full SHA
    d1d1163 View commit details

Commits on Jul 22, 2019

  1. Copy the full SHA
    f09bf3d View commit details

Commits on Jul 24, 2019

  1. fix: limit concurrent HTTP requests (#12)

    All HTTP requests made by this module are sent to the same delegate
    host. Browsers throttle the number of concurrent requests per hostname,
    right now it is 6 per host, which suffocates the use of delegate and
    blocking it from being used for preload or delegated content routing.
    
    This introduces a task queue that limits the number of concurrent
    requests, making it safe to run in browser context.
    
    See also:
    libp2p/js-libp2p-delegated-content-routing#12
    
    License: MIT
    Signed-off-by: Marcin Rataj <lidel@lidel.org>
    lidel authored and jacobheun committed Jul 24, 2019
    Copy the full SHA
    e844d30 View commit details
  2. chore: update contributors

    jacobheun committed Jul 24, 2019
    Copy the full SHA
    78769e2 View commit details
  3. chore: release version v0.3.1

    License: MIT
    Signed-off-by: Jacob Heun <jacobheun@gmail.com>
    jacobheun committed Jul 24, 2019
    Copy the full SHA
    ce9543f View commit details

Commits on Nov 29, 2019

  1. chore: rename timeout option (#14)

    BREAKING CHANGE: maxTimeout option renamed to timeout
    vasco-santos authored and jacobheun committed Nov 29, 2019
    Copy the full SHA
    36d852f View commit details
  2. chore: update contributors

    jacobheun committed Nov 29, 2019
    Copy the full SHA
    1510fde View commit details
  3. chore: release version v0.4.0

    License: MIT
    Signed-off-by: Jacob Heun <jacobheun@gmail.com>
    jacobheun committed Nov 29, 2019
    Copy the full SHA
    9a46c6b View commit details

Commits on Jan 17, 2020

  1. docs: document required API endpoint (#15)

    Alan Shaw authored and jacobheun committed Jan 17, 2020
    Copy the full SHA
    949c0c0 View commit details

Commits on Feb 4, 2020

  1. chore: update ipfs-http-client dep (#17)

    * chore: update ipfs-http-client dep
    
    TODO: use official release
    
    * perf: smaller bundle
    
    * chore: update ipfs-http-client dep
    Alan Shaw authored Feb 4, 2020
    Copy the full SHA
    afbc877 View commit details
  2. chore: update contributors

    jacobheun committed Feb 4, 2020
    Copy the full SHA
    ee2128e View commit details
  3. Copy the full SHA
    00296ba View commit details

Commits on Feb 18, 2020

  1. chore(deps-dev): bump aegir from 20.6.1 to 21.0.2

    Bumps [aegir](https://github.com/ipfs/aegir) from 20.6.1 to 21.0.2.
    - [Release notes](https://github.com/ipfs/aegir/releases)
    - [Changelog](https://github.com/ipfs/aegir/blob/master/CHANGELOG.md)
    - [Commits](ipfs/aegir@v20.6.1...v21.0.2)
    
    Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
    dependabot-preview[bot] authored and jacobheun committed Feb 18, 2020
    Copy the full SHA
    c777434 View commit details

Commits on Apr 9, 2020

  1. chore: update ipfs-http-client to the latest version (#23)

    * chore: update ipfs-http-client to the latest version
    
    * chore: specify minimum http client version
    achingbrain authored Apr 9, 2020
    Copy the full SHA
    67536b4 View commit details
  2. chore: update contributors

    jacobheun committed Apr 9, 2020
    Copy the full SHA
    46658e0 View commit details
  3. Copy the full SHA
    bdb89b6 View commit details

Commits on Apr 16, 2020

  1. chore: update deps (#30)

    * chore: update deps
    
    * refactor: simplify timeout option
    
    * fix: pass correct timeout option
    
    * chore: update http client
    jacobheun authored Apr 16, 2020
    Copy the full SHA
    528adf3 View commit details
  2. chore: update contributors

    jacobheun committed Apr 16, 2020
    Copy the full SHA
    e90430c View commit details
  3. Copy the full SHA
    3255b6f View commit details

Commits on Apr 22, 2020

  1. chore(deps-dev): bump ipfsd-ctl from 3.1.0 to 4.0.1 (#31)

    Bumps [ipfsd-ctl](https://github.com/ipfs/js-ipfsd-ctl) from 3.1.0 to 4.0.1.
    - [Release notes](https://github.com/ipfs/js-ipfsd-ctl/releases)
    - [Changelog](https://github.com/ipfs/js-ipfsd-ctl/blob/master/CHANGELOG.md)
    - [Commits](ipfs/js-ipfsd-ctl@v3.1.0...v4.0.1)
    
    Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
    
    Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
    dependabot-preview[bot] authored Apr 22, 2020
    Copy the full SHA
    4e76474 View commit details

Commits on Apr 23, 2020

  1. chore: remove-peer-info-from-api (#25)

    * chore: remove-peer-info-from-api
    
    BREAKING CHANGE: findPeer returns id and addrs properties instead of peer-info instance
    
    * chore: address review
    vasco-santos authored Apr 23, 2020
    Copy the full SHA
    f49ddc0 View commit details
  2. chore: make ipfs-http-client a peer dependency (#32)

    BREAKING CHANGE: The ipfs-http-client must now be installed
    as a peer dependency. It is no longer included as a dependency
    of this module.
    
    The reason the http-client should be a peerDependency and
    not a dependency is that its API requires knowledge of the
    http-client (we pass in the api endpoint details).
    jacobheun authored Apr 23, 2020
    Copy the full SHA
    a1b1b5e View commit details
  3. chore: update contributors

    jacobheun committed Apr 23, 2020
    Copy the full SHA
    1bb207a View commit details
  4. Copy the full SHA
    38d2848 View commit details
Showing with 251 additions and 140 deletions.
  1. +18 −5 .aegir.js
  2. +2 −1 .gitignore
  3. +84 −0 CHANGELOG.md
  4. +18 −7 README.md
  5. +18 −11 package.json
  6. +43 −32 src/index.js
  7. +68 −84 test/index.spec.js
23 changes: 18 additions & 5 deletions .aegir.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
'use strict'

const createServer = require('ipfsd-ctl').createServer

const server = createServer()
const { createServer } = require('ipfsd-ctl')
let server

module.exports = {
hooks: {
pre: server.start.bind(server),
post: server.stop.bind(server)
browser: {
pre: async () => {
server = createServer({
host: '127.0.0.1',
port: 57483
}, {
type: 'go',
ipfsHttpModule: require('ipfs-http-client'),
ipfsBin: require('go-ipfs-dep').path(),
test: true
})

await server.start()
},
post: () => server.stop()
}
}
}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -61,4 +61,5 @@ docs
.env

yarn.lock
package-lock.json
package-lock.json
dist/
84 changes: 84 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,87 @@
<a name="0.5.0"></a>
# [0.5.0](https://github.com/libp2p/js-libp2p-delegated-peer-routing/compare/v0.4.3...v0.5.0) (2020-04-23)


### Chores

* make ipfs-http-client a peer dependency ([#32](https://github.com/libp2p/js-libp2p-delegated-peer-routing/issues/32)) ([a1b1b5e](https://github.com/libp2p/js-libp2p-delegated-peer-routing/commit/a1b1b5e))
* remove-peer-info-from-api ([#25](https://github.com/libp2p/js-libp2p-delegated-peer-routing/issues/25)) ([f49ddc0](https://github.com/libp2p/js-libp2p-delegated-peer-routing/commit/f49ddc0))


### BREAKING CHANGES

* The ipfs-http-client must now be installed
as a peer dependency. It is no longer included as a dependency
of this module.

The reason the http-client should be a peerDependency and
not a dependency is that its API requires knowledge of the
http-client (we pass in the api endpoint details).
* findPeer returns id and addrs properties instead of peer-info instance

* chore: address review



<a name="0.4.3"></a>
## [0.4.3](https://github.com/libp2p/js-libp2p-delegated-peer-routing/compare/v0.4.2...v0.4.3) (2020-04-16)



<a name="0.4.2"></a>
## [0.4.2](https://github.com/libp2p/js-libp2p-delegated-peer-routing/compare/v0.4.1...v0.4.2) (2020-04-09)



<a name="0.4.1"></a>
## [0.4.1](https://github.com/libp2p/js-libp2p-delegated-peer-routing/compare/v0.4.0...v0.4.1) (2020-02-04)



<a name="0.4.0"></a>
# [0.4.0](https://github.com/libp2p/js-libp2p-delegated-peer-routing/compare/v0.3.1...v0.4.0) (2019-11-29)


### Chores

* rename timeout option ([#14](https://github.com/libp2p/js-libp2p-delegated-peer-routing/issues/14)) ([36d852f](https://github.com/libp2p/js-libp2p-delegated-peer-routing/commit/36d852f))


### BREAKING CHANGES

* maxTimeout option renamed to timeout



<a name="0.3.1"></a>
## [0.3.1](https://github.com/libp2p/js-libp2p-delegated-peer-routing/compare/v0.3.0...v0.3.1) (2019-07-24)


### Bug Fixes

* limit concurrent HTTP requests ([#12](https://github.com/libp2p/js-libp2p-delegated-peer-routing/issues/12)) ([e844d30](https://github.com/libp2p/js-libp2p-delegated-peer-routing/commit/e844d30))



<a name="0.3.0"></a>
# [0.3.0](https://github.com/libp2p/js-libp2p-delegated-peer-routing/compare/v0.2.3...v0.3.0) (2019-07-12)


### Features

* refactor to use async/await ([#8](https://github.com/libp2p/js-libp2p-delegated-peer-routing/issues/8)) ([1827328](https://github.com/libp2p/js-libp2p-delegated-peer-routing/commit/1827328))


### BREAKING CHANGES

* API refactored to use async/await

Also upgrades all the deps, moves from `ipfs-api` to `ipfs-http-client`
and removes a lot of results massaging that is now done in the
http client.



<a name="0.2.3"></a>
## [0.2.3](https://github.com/libp2p/js-libp2p-delegated-peer-routing/compare/v0.2.2...v0.2.3) (2019-07-10)

25 changes: 18 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,36 @@
# js-libp2p-delegated-peer-routing

Leverage other peers in the network to perform Peer Routing calls.

Requires access to `/api/v0/dht/findpeer` HTTP API endpoint of the delegate node.

## Lead Maintainer

[Jacob Heun](https://github.com/jacobheun)

## Requirements

`libp2p-delegated-peer-routing` leverages the `ipfs-http-client` library and requires it as a peer dependency, as such, both must be installed in order for this module to work properly.

```sh
npm install ipfs-http-client libp2p-delegated-peer-routing
```

## Example

```js
const DelegatedPeerRouting = require('libp2p-delegated-routing')
const DelegatedPeerRouting = require('libp2p-delegated-peer-routing')

// default is to use ipfs.io
const routing = new DelegatedPeerRouing()

routing.findPeer('peerid', (err, peerInfo) => {
if (err) {
return console.error(err)
}
try {
const { id, multiaddrs } = await routing.findPeer('peerid')

console.log('found peer details', peerInfo)
})
console.log('found peer details', id, multiaddrs)
} catch (err) {
console.error(err)
}
```

## License
29 changes: 18 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "libp2p-delegated-peer-routing",
"version": "0.2.3",
"version": "0.5.0",
"description": "Leverage other peers in the libp2p network to perform Peer Routing calls.",
"leadMaintainer": "Jacob Heun <jacobheun@gmail.com>",
"main": "src/index.js",
@@ -18,23 +18,30 @@
"coverage": "aegir coverage"
},
"devDependencies": {
"aegir": "^19.0.5",
"async": "^3.1.0",
"aegir": "^21.7.0",
"chai": "^4.2.0",
"dirty-chai": "^2.0.1",
"go-ipfs-dep": "^0.4.21",
"ipfsd-ctl": "^0.43.0"
"go-ipfs-dep": "0.4.23-3",
"ipfs-utils": "^2.2.0",
"ipfs-http-client": "^44.0.0",
"ipfsd-ctl": "^4.0.1"
},
"peerDependencies": {
"ipfs-http-client": "^44.0.0"
},
"dependencies": {
"ipfs-http-client": "^33.0.1",
"peer-id": "^0.12.2",
"peer-info": "^0.15.1"
"debug": "^4.1.1",
"p-queue": "^6.3.0",
"peer-id": "^0.13.11"
},
"contributors": [
"Jacob Heun <jacobheun@gmail.com>",
"Alan Shaw <alan.shaw@protocol.ai>",
"David Dias <daviddias.p@gmail.com>",
"Vasco Santos <vasco.santos@moxy.studio>",
"Alex Potsides <alex@achingbrain.net>",
"Friedel Ziegelmayer <dignifiedquire@gmail.com>",
"Jacob Heun <jacobheun@gmail.com>",
"Maciej Krüger <mkg20001@gmail.com>"
"Maciej Krüger <mkg20001@gmail.com>",
"Marcin Rataj <lidel@lidel.org>",
"David Dias <daviddias.p@gmail.com>"
]
}
75 changes: 43 additions & 32 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,61 +1,72 @@
'use strict'

const PeerId = require('peer-id')
const dht = require('ipfs-http-client/src/dht')
const defaultConfig = require('ipfs-http-client/src/utils/default-config')
const createFindPeer = require('ipfs-http-client/src/dht/find-peer')
const { default: PQueue } = require('p-queue')
const debug = require('debug')

const DEFAULT_MAX_TIMEOUT = 30e3 // 30 second default
const log = debug('libp2p-delegated-peer-routing')
log.error = debug('libp2p-delegated-peer-routing:error')

const DEFAULT_TIMEOUT = 30e3 // 30 second default
const DEFAULT_IPFS_API = {
protocol: 'https',
port: 443,
host: 'ipfs.io'
host: 'node0.delegate.ipfs.io'
}
const CONCURRENT_HTTP_REQUESTS = 4

class DelegatedPeerRouting {
constructor (api) {
this.api = Object.assign({}, defaultConfig(), DEFAULT_IPFS_API, api)
this.dht = dht(this.api)
this.api = Object.assign({}, DEFAULT_IPFS_API, api)
this.dht = { findPeer: createFindPeer(this.api) }

// limit concurrency to avoid request flood in web browser
// https://github.com/libp2p/js-libp2p-delegated-content-routing/issues/12
this._httpQueue = new PQueue({
concurrency: CONCURRENT_HTTP_REQUESTS
})
log(`enabled DelegatedPeerRouting via ${this.api.protocol}://${this.api.host}:${this.api.port}`)
}

/**
* Attempts to find the given peer
*
* @param {PeerID} id
* @param {object} options
* @param {number} options.maxTimeout How long the query can take. Defaults to 30 seconds
* @param {function(Error, PeerInfo)} callback
* @returns {void}
* @param {number} options.timeout How long the query can take. Defaults to 30 seconds
* @returns {Promise<{ id: PeerId, multiaddrs: Multiaddr[] }>}
*/
findPeer (id, options, callback) {
if (typeof options === 'function') {
callback = options
options = {}
} else if (typeof options === 'number') { // This will be deprecated in a next release
options = {
maxTimeout: options
}
} else {
options = options || {}
async findPeer (id, options = {}) {
let idStr = id
if (PeerId.isPeerId(idStr)) {
idStr = id.toB58String()
}

if (PeerId.isPeerId(id)) {
id = id.toB58String()
}
log('findPeer starts: ' + id)

options.timeout = options.timeout || DEFAULT_TIMEOUT

options.maxTimeout = options.maxTimeout || DEFAULT_MAX_TIMEOUT
try {
return await this._httpQueue.add(async () => {
const { addrs } = await this.dht.findPeer(idStr, {
timeout: options.timeout
})

this.dht.findPeer(id, {
timeout: `${options.maxTimeout}ms`// The api requires specification of the time unit (s/ms)
}, (err, info) => {
if (err) {
if (err.message.includes('not found')) {
return callback()
return {
id,
multiaddrs: addrs
}
return callback(err)
})
} catch (err) {
if (err.message.includes('not found')) {
return undefined
}

callback(null, info)
})
throw err
} finally {
log('findPeer finished: ' + id)
}
}
}

Loading