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: d724f183af20643157923b42ef8ca0697de6d091
Choose a head ref
Loading
Showing with 581 additions and 226 deletions.
  1. +17 −6 .aegir.js
  2. +56 −0 .github/workflows/main.yml
  3. +2 −1 .gitignore
  4. +0 −42 .travis.yml
  5. +183 −0 CHANGELOG.md
  6. +33 −9 README.md
  7. +26 −13 package.json
  8. +118 −37 src/index.js
  9. +146 −118 test/index.spec.js
23 changes: 17 additions & 6 deletions .aegir.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
'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)
test: {
before: async () => {
server = createServer({
host: '127.0.0.1',
port: 57583
}, {
type: 'go',
ipfsHttpModule: require('ipfs-http-client'),
ipfsBin: require('go-ipfs').path(),
test: true
})

await server.start()
},
after: () => server.stop()
}
}
56 changes: 56 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: ci
on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: npm install
- run: npx aegir lint
- run: npx aegir dep-check
- run: npx aegir build
test-node:
needs: check
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
node: [16]
fail-fast: true
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}
# modules with pre-built binaries may not have deployed versions for bleeding-edge node so this lets us fall back to building from source
- run: npm install node-pre-gyp -g
- run: npm install
- run: npx nyc --reporter=lcov aegir test -t node -- --bail
- uses: codecov/codecov-action@v1
test-chrome:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: lts/*
- run: npm install
- run: npx aegir test -t browser -t webworker --bail
test-firefox:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: lts/*
- run: npm install
- run: npx aegir test -t browser -t webworker --bail -- --browsers FirefoxHeadless
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/
42 changes: 0 additions & 42 deletions .travis.yml

This file was deleted.

183 changes: 183 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,186 @@
# [0.11.0](https://github.com/libp2p/js-libp2p-delegated-peer-routing/compare/v0.10.0...v0.11.0) (2021-12-02)


### chore

* update peer-id dep ([#47](https://github.com/libp2p/js-libp2p-delegated-peer-routing/issues/47)) ([1664f69](https://github.com/libp2p/js-libp2p-delegated-peer-routing/commit/1664f69b7234e8bc41dc6641ebd70fb8fa1b0129))


### BREAKING CHANGES

* requires node 15



# [0.10.0](https://github.com/libp2p/js-libp2p-delegated-peer-routing/compare/v0.9.0...v0.10.0) (2021-07-07)


### chore

* update to new multiformats ([#46](https://github.com/libp2p/js-libp2p-delegated-peer-routing/issues/46)) ([44cd293](https://github.com/libp2p/js-libp2p-delegated-peer-routing/commit/44cd2933b705285cc5081e7469ddc3c137a539dc))


### BREAKING CHANGES

* uses the CID class from the new multiformats module



# [0.9.0](https://github.com/libp2p/js-libp2p-delegated-peer-routing/compare/v0.8.1...v0.9.0) (2021-04-09)



## [0.8.2](https://github.com/libp2p/js-libp2p-delegated-peer-routing/compare/v0.8.1...v0.8.2) (2020-11-30)



## [0.8.1](https://github.com/libp2p/js-libp2p-delegated-peer-routing/compare/v0.4.0...v0.8.1) (2020-11-27)


### Bug Fixes

* accept http client instance ([#39](https://github.com/libp2p/js-libp2p-delegated-peer-routing/issues/39)) ([bd9ecc3](https://github.com/libp2p/js-libp2p-delegated-peer-routing/commit/bd9ecc311e87604d489cae5e832691bd1dec7429))


### chore

* 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/a1b1b5ec59af97f5ab708c757808940dbcb070d9))
* 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/f49ddc0740963587fc0976c2a627f241bd045abf))


### Features

* add support for api dht/query endpoint ([#37](https://github.com/libp2p/js-libp2p-delegated-peer-routing/issues/37)) ([6fa569c](https://github.com/libp2p/js-libp2p-delegated-peer-routing/commit/6fa569cdaaeca3ca200af8b3c10b2a098faff5c1))


### 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



# [0.8.0](https://github.com/libp2p/js-libp2p-delegated-peer-routing/compare/v0.7.0...v0.8.0) (2020-10-21)



<a name="0.7.0"></a>
# [0.7.0](https://github.com/libp2p/js-libp2p-delegated-peer-routing/compare/v0.6.1...v0.7.0) (2020-08-26)


### Bug Fixes

* accept http client instance ([#39](https://github.com/libp2p/js-libp2p-delegated-peer-routing/issues/39)) ([bd9ecc3](https://github.com/libp2p/js-libp2p-delegated-peer-routing/commit/bd9ecc3))



<a name="0.6.1"></a>
## [0.6.1](https://github.com/libp2p/js-libp2p-delegated-peer-routing/compare/v0.6.0...v0.6.1) (2020-08-14)


### Features

* add support for api dht/query endpoint ([#37](https://github.com/libp2p/js-libp2p-delegated-peer-routing/issues/37)) ([6fa569c](https://github.com/libp2p/js-libp2p-delegated-peer-routing/commit/6fa569c))



<a name="0.6.0"></a>
# [0.6.0](https://github.com/libp2p/js-libp2p-delegated-peer-routing/compare/v0.5.0...v0.6.0) (2020-08-12)



<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)

42 changes: 33 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,49 @@
# js-libp2p-delegated-peer-routing

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

Requires access to `/api/v0/dht/findpeer` and `/api/v0/dht/query` HTTP API endpoints 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 an instance of it as a constructor argument.

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

## Example

```js
const DelegatedPeerRouting = require('libp2p-delegated-routing')
const PeerId = require('peer-id')
const DelegatedPeerRouting = require('libp2p-delegated-peer-routing')
const ipfsHttpClient = require('ipfs-http-client')

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

routing.findPeer('peerid', (err, peerInfo) => {
if (err) {
return console.error(err)
}
const routing = new DelegatedPeerRouting(ipfsHttpClient.create({
// use default api settings
protocol: 'https',
port: 443,
host: 'node0.delegate.ipfs.io'
}))

try {
const { id, multiaddrs } = await routing.findPeer('peerid')

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

const peerId = await PeerId.create({ keyType: 'ed25519' })
for await (const { id, multiaddrs } of routing.getClosestPeers(peerId.id)) {
console.log('found closest peer', id, multiaddrs)
}

console.log('found peer details', peerInfo)
})
```

## License
Loading