From 8bc0ae937a319c99aa10042aaaecb46afabe60de Mon Sep 17 00:00:00 2001 From: achingbrain Date: Sat, 15 Apr 2023 15:59:09 +0200 Subject: [PATCH] feat: initial import --- .aegir.js | 34 ++++ .github/dependabot.yml | 11 ++ .github/workflows/automerge.yml | 8 + .github/workflows/js-test-and-release.yml | 181 ++++++++++++++++++++ .github/workflows/semantic-pull-request.yml | 40 +++++ .github/workflows/stale.yml | 26 +++ .gitignore | 9 + LICENSE | 4 + LICENSE-APACHE | 5 + LICENSE-MIT | 19 ++ README.md | 65 +++++++ package.json | 157 +++++++++++++++++ src/index.ts | 158 +++++++++++++++++ test/index.spec.ts | 50 ++++++ tsconfig.json | 10 ++ 15 files changed, 777 insertions(+) create mode 100644 .aegir.js create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/automerge.yml create mode 100644 .github/workflows/js-test-and-release.yml create mode 100644 .github/workflows/semantic-pull-request.yml create mode 100644 .github/workflows/stale.yml create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 LICENSE-APACHE create mode 100644 LICENSE-MIT create mode 100644 README.md create mode 100644 package.json create mode 100644 src/index.ts create mode 100644 test/index.spec.ts create mode 100644 tsconfig.json diff --git a/.aegir.js b/.aegir.js new file mode 100644 index 0000000..07040ea --- /dev/null +++ b/.aegir.js @@ -0,0 +1,34 @@ +import EchoServer from 'aegir/echo-server' +import body from 'body-parser' + +export default { + test: { + before: async () => { + const providers = new Map() + const echoServer = new EchoServer() + echoServer.polka.use(body.text()) + echoServer.polka.post('/add-providers/:cid', (req, res) => { + providers.set(req.params.cid, req.body) + res.end() + }) + echoServer.polka.get('/cid/:cid', (req, res) => { + const provs = providers.get(req.params.cid) ?? '[]' + providers.delete(req.params.cid) + + res.end(provs) + }) + + await echoServer.start() + + return { + env: { + ECHO_SERVER: `http://${echoServer.host}:${echoServer.port}` + }, + echoServer + } + }, + after: async (options, beforeResult) => { + await beforeResult.echoServer.stop() + } + } +} diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..0bc3b42 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,11 @@ +version: 2 +updates: +- package-ecosystem: npm + directory: "/" + schedule: + interval: daily + time: "10:00" + open-pull-requests-limit: 10 + commit-message: + prefix: "deps" + prefix-development: "deps(dev)" diff --git a/.github/workflows/automerge.yml b/.github/workflows/automerge.yml new file mode 100644 index 0000000..d57c2a0 --- /dev/null +++ b/.github/workflows/automerge.yml @@ -0,0 +1,8 @@ +name: Automerge +on: [ pull_request ] + +jobs: + automerge: + uses: protocol/.github/.github/workflows/automerge.yml@master + with: + job: 'automerge' diff --git a/.github/workflows/js-test-and-release.yml b/.github/workflows/js-test-and-release.yml new file mode 100644 index 0000000..5168641 --- /dev/null +++ b/.github/workflows/js-test-and-release.yml @@ -0,0 +1,181 @@ +name: test & maybe release +on: + push: + branches: + - main + pull_request: + +jobs: + + check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: lts/* + - uses: ipfs/aegir/actions/cache-node-modules@master + - run: npm run --if-present lint + - run: npm run --if-present dep-check + + test-node: + needs: check + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [windows-latest, ubuntu-latest, macos-latest] + node: [lts/*] + fail-fast: true + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node }} + - uses: ipfs/aegir/actions/cache-node-modules@master + - run: npm run --if-present test:node + - uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1 + with: + flags: node + + test-chrome: + needs: check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: lts/* + - uses: ipfs/aegir/actions/cache-node-modules@master + - run: npm run --if-present test:chrome + - uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1 + with: + flags: chrome + + test-chrome-webworker: + needs: check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: lts/* + - uses: ipfs/aegir/actions/cache-node-modules@master + - run: npm run --if-present test:chrome-webworker + - uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1 + with: + flags: chrome-webworker + + test-firefox: + needs: check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: lts/* + - uses: ipfs/aegir/actions/cache-node-modules@master + - run: npm run --if-present test:firefox + - uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1 + with: + flags: firefox + + test-firefox-webworker: + needs: check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: lts/* + - uses: ipfs/aegir/actions/cache-node-modules@master + - run: npm run --if-present test:firefox-webworker + - uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1 + with: + flags: firefox-webworker + + test-webkit: + needs: check + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macos-latest] + node: [lts/*] + fail-fast: true + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: lts/* + - uses: ipfs/aegir/actions/cache-node-modules@master + - run: npm run --if-present test:webkit + - uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1 + with: + flags: webkit + + test-webkit-webworker: + needs: check + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macos-latest] + node: [lts/*] + fail-fast: true + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: lts/* + - uses: ipfs/aegir/actions/cache-node-modules@master + - run: npm run --if-present test:webkit-webworker + - uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1 + with: + flags: webkit-webworker + + test-electron-main: + needs: check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: lts/* + - uses: ipfs/aegir/actions/cache-node-modules@master + - run: npx xvfb-maybe npm run --if-present test:electron-main + - uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1 + with: + flags: electron-main + + test-electron-renderer: + needs: check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: lts/* + - uses: ipfs/aegir/actions/cache-node-modules@master + - run: npx xvfb-maybe npm run --if-present test:electron-renderer + - uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1 + with: + flags: electron-renderer + + release: + needs: [test-node, test-chrome, test-chrome-webworker, test-firefox, test-firefox-webworker, test-webkit, test-webkit-webworker, test-electron-main, test-electron-renderer] + runs-on: ubuntu-latest + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - uses: actions/setup-node@v3 + with: + node-version: lts/* + - uses: ipfs/aegir/actions/cache-node-modules@master + - uses: ipfs/aegir/actions/docker-login@master + with: + docker-token: ${{ secrets.DOCKER_TOKEN }} + docker-username: ${{ secrets.DOCKER_USERNAME }} + - run: npm run --if-present release + env: + GITHUB_TOKEN: ${{ secrets.UCI_GITHUB_TOKEN || github.token }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/semantic-pull-request.yml b/.github/workflows/semantic-pull-request.yml new file mode 100644 index 0000000..4f9798c --- /dev/null +++ b/.github/workflows/semantic-pull-request.yml @@ -0,0 +1,40 @@ +name: "Semantic PR" + +on: + pull_request_target: + types: + - opened + - edited + - synchronize + +jobs: + main: + name: Validate PR title + runs-on: ubuntu-latest + steps: + - uses: amannn/action-semantic-pull-request@b6bca70dcd3e56e896605356ce09b76f7e1e0d39 # v5.1.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + # Configure which types are allowed (newline delimited). + types: | + feat + fix + chore + docs + deps + test + refactor + ci + requireScope: false + + - name: Check PR title length + env: + TITLE: ${{ github.event.pull_request.title }} + run: | + title_length=${#TITLE} + if [ $title_length -gt 72 ] + then + echo "PR title is too long (greater than 72 characters)" + exit 1 + fi diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml new file mode 100644 index 0000000..6f6d895 --- /dev/null +++ b/.github/workflows/stale.yml @@ -0,0 +1,26 @@ +name: Close and mark stale issue + +on: + schedule: + - cron: '0 0 * * *' + +jobs: + stale: + + runs-on: ubuntu-latest + permissions: + issues: write + pull-requests: write + + steps: + - uses: actions/stale@v3 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + stale-issue-message: 'Oops, seems like we needed more information for this issue, please comment with more details or this issue will be closed in 7 days.' + close-issue-message: 'This issue was closed because it is missing author input.' + stale-issue-label: 'kind/stale' + any-of-labels: 'need/author-input' + exempt-issue-labels: 'need/triage,need/community-input,need/maintainer-input,need/maintainers-input,need/analysis,status/blocked,status/in-progress,status/ready,status/deferred,status/inactive' + days-before-issue-stale: 6 + days-before-issue-close: 7 + enable-statistics: true diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7ad9e67 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +node_modules +build +dist +.docs +.coverage +node_modules +package-lock.json +yarn.lock +.vscode diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..20ce483 --- /dev/null +++ b/LICENSE @@ -0,0 +1,4 @@ +This project is dual licensed under MIT and Apache-2.0. + +MIT: https://www.opensource.org/licenses/mit +Apache-2.0: https://www.apache.org/licenses/license-2.0 diff --git a/LICENSE-APACHE b/LICENSE-APACHE new file mode 100644 index 0000000..14478a3 --- /dev/null +++ b/LICENSE-APACHE @@ -0,0 +1,5 @@ +Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. diff --git a/LICENSE-MIT b/LICENSE-MIT new file mode 100644 index 0000000..72dc60d --- /dev/null +++ b/LICENSE-MIT @@ -0,0 +1,19 @@ +The MIT License (MIT) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..39a1417 --- /dev/null +++ b/README.md @@ -0,0 +1,65 @@ +# @libp2p/ipni-content-routing + +[![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) +[![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) +[![codecov](https://img.shields.io/codecov/c/github/libp2p/js-ipni-content-routing.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-ipni-content-routing) +[![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-ipni-content-routing/js-test-and-release.yml?branch=main\&style=flat-square)](https://github.com/libp2p/js-ipni-content-routing/actions/workflows/js-test-and-release.yml?query=branch%3Amain) + +> Use an IPNI service to discover content providers + +## Table of contents + +- [Install](#install) + - [Browser ` +``` + +## Example + +```js +import { createLibp2p } from 'libp2p' +import { ipniContentRouting } from '@libp2p/ipni-content-routing' + +const node = await createLibp2p({ + peerRouting: [ + ipniContentRouting(new URL('https://cid.contact')) + ] + //.. other config +}) +await node.start() + +for await (const provider of node.contentRouting.findProviders('cid')) { + console.log('provider', provider) +} +``` + +## API Docs + +- + +## License + +Licensed under either of + +- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) +- MIT ([LICENSE-MIT](LICENSE-MIT) / ) + +## Contribution + +Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. diff --git a/package.json b/package.json new file mode 100644 index 0000000..865f293 --- /dev/null +++ b/package.json @@ -0,0 +1,157 @@ +{ + "name": "@libp2p/ipni-content-routing", + "version": "0.0.0", + "description": "Use an IPNI service to discover content providers", + "license": "Apache-2.0 OR MIT", + "homepage": "https://github.com/libp2p/js-ipni-content-routing#readme", + "repository": { + "type": "git", + "url": "git+https://github.com/libp2p/js-ipni-content-routing.git" + }, + "bugs": { + "url": "https://github.com/libp2p/js-ipni-content-routing/issues" + }, + "engines": { + "node": ">=16.0.0", + "npm": ">=7.0.0" + }, + "type": "module", + "types": "./dist/src/index.d.ts", + "files": [ + "src", + "dist", + "!dist/test", + "!**/*.tsbuildinfo" + ], + "exports": { + ".": { + "types": "./src/index.d.ts", + "import": "./dist/src/index.js" + } + }, + "eslintConfig": { + "extends": "ipfs", + "parserOptions": { + "sourceType": "module" + } + }, + "release": { + "branches": [ + "main" + ], + "plugins": [ + [ + "@semantic-release/commit-analyzer", + { + "preset": "conventionalcommits", + "releaseRules": [ + { + "breaking": true, + "release": "major" + }, + { + "revert": true, + "release": "patch" + }, + { + "type": "feat", + "release": "minor" + }, + { + "type": "fix", + "release": "patch" + }, + { + "type": "docs", + "release": "patch" + }, + { + "type": "test", + "release": "patch" + }, + { + "type": "deps", + "release": "patch" + }, + { + "scope": "no-release", + "release": false + } + ] + } + ], + [ + "@semantic-release/release-notes-generator", + { + "preset": "conventionalcommits", + "presetConfig": { + "types": [ + { + "type": "feat", + "section": "Features" + }, + { + "type": "fix", + "section": "Bug Fixes" + }, + { + "type": "chore", + "section": "Trivial Changes" + }, + { + "type": "docs", + "section": "Documentation" + }, + { + "type": "deps", + "section": "Dependencies" + }, + { + "type": "test", + "section": "Tests" + } + ] + } + } + ], + "@semantic-release/changelog", + "@semantic-release/npm", + "@semantic-release/github", + "@semantic-release/git" + ] + }, + "scripts": { + "clean": "aegir clean", + "lint": "aegir lint", + "dep-check": "aegir dep-check", + "build": "aegir build", + "test": "aegir test", + "test:chrome": "aegir test -t browser --cov", + "test:chrome-webworker": "aegir test -t webworker", + "test:firefox": "aegir test -t browser -- --browser firefox", + "test:firefox-webworker": "aegir test -t webworker -- --browser firefox", + "test:node": "aegir test -t node --cov", + "test:electron-main": "aegir test -t electron-main", + "release": "aegir release", + "docs": "aegir docs" + }, + "dependencies": { + "@libp2p/interface-content-routing": "^2.0.2", + "@libp2p/interface-peer-info": "^1.0.9", + "@libp2p/interfaces": "^3.3.1", + "@libp2p/logger": "^2.0.7", + "@libp2p/peer-id": "^2.0.3", + "any-signal": "^4.1.1", + "browser-readablestream-to-it": "^2.0.2", + "iterable-ndjson": "^1.1.0", + "multiformats": "^11.0.2", + "p-defer": "^4.0.0", + "p-queue": "^7.3.4" + }, + "devDependencies": { + "@libp2p/peer-id-factory": "^2.0.3", + "aegir": "^38.1.2", + "body-parser": "^1.20.2", + "it-all": "^3.0.1" + } +} diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..df635f0 --- /dev/null +++ b/src/index.ts @@ -0,0 +1,158 @@ +import PQueue from 'p-queue' +import type { AbortOptions } from '@libp2p/interfaces' +import type { ContentRouting } from '@libp2p/interface-content-routing' +import type { PeerInfo } from '@libp2p/interface-peer-info' +import type { Startable } from '@libp2p/interfaces/startable' +import type { CID } from 'multiformats/cid' +import { peerIdFromString } from '@libp2p/peer-id' +import { multiaddr } from '@multiformats/multiaddr' +import { logger } from '@libp2p/logger' +import defer from 'p-defer' +import { anySignal } from 'any-signal' +import type { Multiaddr } from '@multiformats/multiaddr' +import { CodeError } from '@libp2p/interfaces/errors' +import toIt from 'browser-readablestream-to-it' +// @ts-expect-error no types +import ndjson from 'iterable-ndjson' + +const log = logger('ipni-content-routing') + +export interface IpniResponseItem { + Metadata: string // gBI= means bitswap + ContextID: string + Provider: { + ID: string + Addrs: Multiaddr[] + } +} + +export interface IpniContentRoutingInit { + /** + * A concurrency limit to avoid request flood in web browser (default: 4) + * @see https://github.com/libp2p/js-libp2p-delegated-content-routing/issues/12 + */ + concurrentRequests?: number + + /** + * How long a request is allowed to take in ms (default: 30 seconds) + */ + timeout?: number +} + +const defaultValues = { + concurrentRequests: 4, + timeout: 30e3 +} + +/** + * An implementation of content routing, using a delegated peer + */ +class IpniContentRouting implements ContentRouting, Startable { + private started: boolean + private readonly httpQueue: PQueue + private shutDownController: AbortController + private clientUrl: URL + private timeout: number + + /** + * Create a new DelegatedContentRouting instance + */ + constructor (url: URL, init: IpniContentRoutingInit = {}) { + log('enabled IPNI routing via', url) + this.started = false + this.shutDownController = new AbortController() + this.httpQueue = new PQueue({ + concurrency: init.concurrentRequests ?? defaultValues.concurrentRequests + }) + this.clientUrl = url + this.timeout = init.timeout ?? defaultValues.timeout + } + + isStarted (): boolean { + return this.started + } + + start (): void { + this.started = true + } + + stop (): void { + this.httpQueue.clear() + this.shutDownController.abort() + this.started = false + } + + async * findProviders (key: CID, options: AbortOptions = {}): AsyncIterable { + log('findProviders starts: %c', key) + + const signal = anySignal([this.shutDownController.signal, options.signal, AbortSignal.timeout(this.timeout)]) + const onStart = defer() + const onFinish = defer() + + void this.httpQueue.add(async () => { + onStart.resolve() + return await onFinish.promise + }) + + try { + await onStart.promise + + const resource = `${this.clientUrl}cid/${key.toString()}?cascade=ipfs-dht` + const getOptions = { headers: { Accept: 'application/x-ndjson' }, signal } + const a = await fetch(resource, getOptions) + + if (a.body == null) { + throw new CodeError('IPNI response had no body', 'ERR_BAD_RESPONSE') + } + + for await (const event of ndjson(toIt(a.body))) { + if (event.Metadata !== 'gBI=') { + continue + } + + yield this.mapEvent(event) + } + } catch (err) { + log.error('findProviders errored:', err) + throw err + } finally { + signal.clear() + onFinish.resolve() + log('findProviders finished: %c', key) + } + } + + private mapEvent (event: IpniResponseItem): PeerInfo { + const peer = peerIdFromString(event.Provider.ID) + const ma: Multiaddr[] = [] + + for (const strAddr of event.Provider.Addrs) { + const addr = multiaddr(strAddr) + ma.push(addr) + } + + const pi = { + id: peer, + multiaddrs: ma, + protocols: [] + } + + return pi + } + + async provide (): Promise { + // noop + } + + async put (): Promise { + // noop + } + + async get (): Promise { + throw new CodeError('Not found', 'ERR_NOT_FOUND') + } +} + +export function ipniContentRouting (url: URL, init: IpniContentRoutingInit = {}): () => ContentRouting { + return () => new IpniContentRouting(url, init) +} diff --git a/test/index.spec.ts b/test/index.spec.ts new file mode 100644 index 0000000..284f408 --- /dev/null +++ b/test/index.spec.ts @@ -0,0 +1,50 @@ +/* eslint-env mocha */ + +import { expect } from 'aegir/chai' +import { createEd25519PeerId } from '@libp2p/peer-id-factory' +import { ipniContentRouting } from '../src/index.js' +import { CID } from 'multiformats/cid' +import all from 'it-all' + +describe('IPNIContentRouting', function () { + it('should find providers', async () => { + if (process.env.ECHO_SERVER == null) { + throw new Error('Echo server not configured correctly') + } + + const providers = [{ + Metadata: 'gBI=', + ContextID: '', + Provider: { + ID: (await createEd25519PeerId()).toString(), + Addrs: ['/ip4/41.41.41.41/tcp/1234'] + } + }, { + Metadata: 'gBI=', + ContextID: '', + Provider: { + ID: (await createEd25519PeerId()).toString(), + Addrs: ['/ip4/42.42.42.42/tcp/1234'] + } + }] + + const cid = CID.parse('QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn') + + // load providers for the router to fetch + await fetch(`${process.env.ECHO_SERVER}/add-providers/${cid.toString()}`, { + method: 'POST', + body: providers.map(prov => JSON.stringify(prov)).join('\n') + }) + + const routing = ipniContentRouting(new URL(process.env.ECHO_SERVER))() + + const provs = await all(routing.findProviders(cid)) + expect(provs.map(prov => ({ + id: prov.id.toString(), + addrs: prov.multiaddrs.map(ma => ma.toString()) + }))).to.deep.equal(providers.map(prov => ({ + id: prov.Provider.ID, + addrs: prov.Provider.Addrs + }))) + }) +}) diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..13a3599 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "aegir/src/config/tsconfig.aegir.json", + "compilerOptions": { + "outDir": "dist" + }, + "include": [ + "src", + "test" + ] +}