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: 01524ac03ddd875236096fdac25912943d7131f3
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
  • 11 commits
  • 8 files changed
  • 2 contributors

Commits on Apr 9, 2021

  1. chore: remove peer deps (#44)

    * chore: remove peer deps
    
    We added ipfs-http-client as a peer dep to signal to the user
    that they should add the modules they depend on as deps of their project.
    
    Starting with npm7 all peer deps get installed automatically which
    defeats the purpose of our use of peer deps, so let's remove them.
    achingbrain authored Apr 9, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    4612728 View commit details
  2. chore: update deps

    vasco-santos committed Apr 9, 2021
    Copy the full SHA
    541e3cc View commit details
  3. Copy the full SHA
    53fcd78 View commit details
  4. Copy the full SHA
    35e065b View commit details
  5. Copy the full SHA
    f16ca8f View commit details

Commits on Jul 7, 2021

  1. chore: update to new multiformats (#46)

    * chore: update to new multiformats
    
    BREAKING CHANGE: uses the CID class from the new multiformats module
    achingbrain authored Jul 7, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    44cd293 View commit details
  2. Copy the full SHA
    7f2107e View commit details
  3. Copy the full SHA
    974b634 View commit details

Commits on Dec 2, 2021

  1. chore: update peer-id dep (#47)

    BREAKING CHANGE: requires node 15
    achingbrain authored Dec 2, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    1664f69 View commit details
  2. Copy the full SHA
    39d670a View commit details
  3. Copy the full SHA
    d724f18 View commit details
Showing with 131 additions and 90 deletions.
  1. +14 −16 .aegir.js
  2. +56 −0 .github/workflows/main.yml
  3. +0 −42 .travis.yml
  4. +32 −0 CHANGELOG.md
  5. +1 −1 README.md
  6. +10 −12 package.json
  7. +4 −5 src/index.js
  8. +14 −14 test/index.spec.js
30 changes: 14 additions & 16 deletions .aegir.js
Original file line number Diff line number Diff line change
@@ -4,22 +4,20 @@ const { createServer } = require('ipfsd-ctl')
let server

module.exports = {
hooks: {
browser: {
pre: async () => {
server = createServer({
host: '127.0.0.1',
port: 57483
}, {
type: 'go',
ipfsHttpModule: require('ipfs-http-client'),
ipfsBin: require('go-ipfs').path(),
test: true
})
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()
},
post: () => server.stop()
}
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
42 changes: 0 additions & 42 deletions .travis.yml

This file was deleted.

32 changes: 32 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
# [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)


2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ const DelegatedPeerRouting = require('libp2p-delegated-peer-routing')
const ipfsHttpClient = require('ipfs-http-client')

// default is to use ipfs.io
const routing = new DelegatedPeerRouting(ipfsHttpClient({
const routing = new DelegatedPeerRouting(ipfsHttpClient.create({
// use default api settings
protocol: 'https',
port: 443,
22 changes: 10 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "libp2p-delegated-peer-routing",
"version": "0.8.2",
"version": "0.11.0",
"description": "Leverage other peers in the libp2p network to perform Peer Routing calls.",
"leadMaintainer": "Jacob Heun <jacobheun@gmail.com>",
"main": "src/index.js",
@@ -13,6 +13,7 @@
],
"scripts": {
"lint": "aegir lint",
"prepare": "npm run build",
"build": "aegir build",
"test": "aegir test -f test/**/*.spec.js",
"test:node": "aegir test -t node -f test/**/*.spec.js",
@@ -22,22 +23,19 @@
"coverage": "aegir coverage"
},
"devDependencies": {
"aegir": "^29.1.0",
"go-ipfs": "^0.7.0",
"ipfs-http-client": "^48.1.2",
"ipfs-utils": "^5.0.1",
"ipfsd-ctl": "^7.0.0",
"aegir": "^36.0.2",
"go-ipfs": "^0.10.0",
"ipfs-http-client": "^54.0.2",
"ipfs-utils": "^9.0.2",
"ipfsd-ctl": "^10.0.5",
"it-all": "^1.0.2"
},
"dependencies": {
"cids": "^1.0.0",
"debug": "^4.1.1",
"debug": "^4.3.1",
"multiformats": "^9.0.2",
"p-defer": "^3.0.0",
"p-queue": "^6.3.0",
"peer-id": "^0.14.0"
},
"peerDependencies": {
"ipfs-http-client": "*"
"peer-id": "^0.16.0"
},
"browser": {
"go-ipfs": false
9 changes: 4 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const PeerId = require('peer-id')
const CID = require('cids')
const { base58btc } = require('multiformats/bases/base58')
const { default: PQueue } = require('p-queue')
const defer = require('p-defer')
const debug = require('debug')
@@ -89,8 +89,7 @@ class DelegatedPeerRouting {
* @returns {AsyncIterable<{ id: PeerId, multiaddrs: Multiaddr[] }>}
*/
async * getClosestPeers (key, options = {}) {
key = new CID(key)
const keyStr = key.toString()
const keyStr = base58btc.encode(key).substring(1)

log('getClosestPeers starts:', keyStr)
options.timeout = options.timeout || DEFAULT_TIMEOUT
@@ -116,14 +115,14 @@ class DelegatedPeerRouting {
// Track the addresses, so we can yield them when done
result.responses.forEach(response => {
peers.set(response.id, {
id: PeerId.createFromCID(response.id),
id: PeerId.parse(response.id),
multiaddrs: response.addrs
})
})
break
case 2: // Final Peer
yield peers.get(result.id.string) || {
id: PeerId.createFromCID(result.id),
id: PeerId.parse(result.id),
multiaddrs: []
}
break
28 changes: 14 additions & 14 deletions test/index.spec.js
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ const factory = createFactory({
ipfsBin: isNode ? require('go-ipfs').path() : undefined,
test: true,
disposable: true,
endpoint: 'http://localhost:57483'
endpoint: 'http://localhost:57583'
})

async function spawnNode (bootstrap = []) {
@@ -74,7 +74,7 @@ describe('DelegatedPeerRouting', function () {
})

it('should accept an http api client instance at construction time', () => {
const client = ipfsHttpClient({
const client = ipfsHttpClient.create({
protocol: 'http',
port: 8000,
host: 'localhost'
@@ -97,7 +97,7 @@ describe('DelegatedPeerRouting', function () {
it('should be able to find peers via the delegate with a peer id string', async () => {
const opts = delegatedNode.apiAddr.toOptions()

const router = new DelegatedPeerRouting(ipfsHttpClient({
const router = new DelegatedPeerRouting(ipfsHttpClient.create({
protocol: 'http',
port: opts.port,
host: opts.host
@@ -114,13 +114,13 @@ describe('DelegatedPeerRouting', function () {

it('should be able to find peers via the delegate with a peerid', async () => {
const opts = delegatedNode.apiAddr.toOptions()
const router = new DelegatedPeerRouting(ipfsHttpClient({
const router = new DelegatedPeerRouting(ipfsHttpClient.create({
protocol: 'http',
port: opts.port,
host: opts.host
}))

const peer = await router.findPeer(PeerID.createFromB58String(peerIdToFind.id))
const peer = await router.findPeer(PeerID.parse(peerIdToFind.id))
expect(peer).to.be.ok()

const { id, multiaddrs } = peer
@@ -132,13 +132,13 @@ describe('DelegatedPeerRouting', function () {

it('should be able to specify a timeout', async () => {
const opts = delegatedNode.apiAddr.toOptions()
const router = new DelegatedPeerRouting(ipfsHttpClient({
const router = new DelegatedPeerRouting(ipfsHttpClient.create({
protocol: 'http',
port: opts.port,
host: opts.host
}))

const peer = await router.findPeer(PeerID.createFromB58String(peerIdToFind.id), { timeout: 2000 })
const peer = await router.findPeer(PeerID.parse(peerIdToFind.id), { timeout: 2000 })
expect(peer).to.be.ok()

const { id, multiaddrs } = peer
@@ -150,7 +150,7 @@ describe('DelegatedPeerRouting', function () {

it('should not be able to find peers not on the network', async () => {
const opts = delegatedNode.apiAddr.toOptions()
const router = new DelegatedPeerRouting(ipfsHttpClient({
const router = new DelegatedPeerRouting(ipfsHttpClient.create({
protocol: 'http',
port: opts.port,
host: opts.host
@@ -167,16 +167,16 @@ describe('DelegatedPeerRouting', function () {
it('should be able to query for the closest peers', async () => {
const opts = delegatedNode.apiAddr.toOptions()

const router = new DelegatedPeerRouting(ipfsHttpClient({
const router = new DelegatedPeerRouting(ipfsHttpClient.create({
protocol: 'http',
port: opts.port,
host: opts.host
}))

const nodeId = await delegatedNode.api.id()
const delegatePeerId = PeerID.createFromCID(nodeId.id)
const delegatePeerId = PeerID.parse(nodeId.id)

const key = PeerID.createFromB58String(peerIdToFind.id).id
const key = PeerID.parse(peerIdToFind.id).id
const results = await concat(router.getClosestPeers(key))

// we should be closest to the 2 other peers
@@ -188,17 +188,17 @@ describe('DelegatedPeerRouting', function () {
})
})

it('should find closest peers even if the peer doesnt exist', async () => {
it('should find closest peers even if the peer does not exist', async () => {
const opts = delegatedNode.apiAddr.toOptions()

const router = new DelegatedPeerRouting(ipfsHttpClient({
const router = new DelegatedPeerRouting(ipfsHttpClient.create({
protocol: 'http',
port: opts.port,
host: opts.host
}))

const nodeId = await delegatedNode.api.id()
const delegatePeerId = PeerID.createFromCID(nodeId.id)
const delegatePeerId = PeerID.parse(nodeId.id)

const peerId = await PeerID.create({ keyType: 'ed25519' })
const results = await concat(router.getClosestPeers(peerId.id))