├── packages ├── interface-peer-store │ ├── src │ │ └── tags.ts │ ├── LICENSE │ ├── tsconfig.json │ ├── LICENSE-APACHE │ ├── LICENSE-MIT │ └── README.md ├── interface-transport │ ├── img │ │ ├── badge.png │ │ └── badge.sketch │ ├── LICENSE │ ├── tsconfig.json │ ├── LICENSE-APACHE │ └── LICENSE-MIT ├── interface-connection │ ├── img │ │ ├── badge.png │ │ └── badge.sketch │ ├── src │ │ └── status.ts │ ├── LICENSE │ ├── tsconfig.json │ ├── LICENSE-APACHE │ └── LICENSE-MIT ├── interface-peer-routing │ ├── img │ │ ├── badge.png │ │ └── badge.sketch │ ├── LICENSE │ ├── tsconfig.json │ ├── LICENSE-APACHE │ ├── LICENSE-MIT │ ├── src │ │ └── index.ts │ └── README.md ├── interface-stream-muxer │ ├── img │ │ ├── badge.png │ │ └── badge.sketch │ ├── LICENSE │ ├── tsconfig.json │ ├── LICENSE-APACHE │ ├── LICENSE-MIT │ └── src │ │ └── index.ts ├── interface-peer-discovery │ ├── img │ │ ├── badge.png │ │ └── badge.sketch │ ├── LICENSE │ ├── tsconfig.json │ ├── LICENSE-APACHE │ ├── src │ │ └── index.ts │ └── LICENSE-MIT ├── interface-content-routing │ ├── img │ │ ├── badge.png │ │ └── badge.sketch │ ├── LICENSE │ ├── tsconfig.json │ ├── LICENSE-APACHE │ ├── LICENSE-MIT │ └── src │ │ └── index.ts ├── interfaces │ ├── LICENSE │ ├── tsconfig.json │ ├── LICENSE-APACHE │ ├── src │ │ ├── index.ts │ │ ├── errors.ts │ │ ├── startable.ts │ │ └── events.ts │ ├── LICENSE-MIT │ └── README.md ├── interface-dht │ ├── LICENSE │ ├── tsconfig.json │ ├── LICENSE-APACHE │ ├── LICENSE-MIT │ └── README.md ├── interface-keys │ ├── LICENSE │ ├── tsconfig.json │ ├── LICENSE-APACHE │ ├── LICENSE-MIT │ ├── src │ │ └── index.ts │ └── README.md ├── interface-libp2p │ ├── LICENSE │ ├── LICENSE-APACHE │ ├── tsconfig.json │ ├── LICENSE-MIT │ └── README.md ├── interface-metrics │ ├── LICENSE │ ├── tsconfig.json │ ├── LICENSE-APACHE │ ├── LICENSE-MIT │ └── README.md ├── interface-mocks │ ├── LICENSE │ ├── src │ │ ├── duplex.ts │ │ ├── index.ts │ │ ├── connection-gater.ts │ │ ├── peer-discovery.ts │ │ ├── upgrader.ts │ │ ├── multiaddr-connection.ts │ │ └── registrar.ts │ ├── test │ │ ├── muxer.spec.ts │ │ ├── connection-encrypter.spec.ts │ │ ├── peer-discovery.spec.ts │ │ └── connection.spec.ts │ ├── LICENSE-APACHE │ ├── LICENSE-MIT │ ├── tsconfig.json │ └── README.md ├── interface-peer-id │ ├── LICENSE │ ├── tsconfig.json │ ├── LICENSE-APACHE │ ├── LICENSE-MIT │ ├── src │ │ └── index.ts │ └── README.md ├── interface-pubsub │ ├── LICENSE │ ├── tsconfig.json │ ├── LICENSE-APACHE │ └── LICENSE-MIT ├── interface-record │ ├── LICENSE │ ├── tsconfig.json │ ├── LICENSE-APACHE │ ├── src │ │ └── index.ts │ └── LICENSE-MIT ├── interface-keychain │ ├── LICENSE │ ├── tsconfig.json │ ├── LICENSE-APACHE │ └── LICENSE-MIT ├── interface-peer-info │ ├── LICENSE │ ├── src │ │ └── index.ts │ ├── tsconfig.json │ ├── LICENSE-APACHE │ ├── LICENSE-MIT │ └── README.md ├── interface-registrar │ ├── LICENSE │ ├── tsconfig.json │ ├── LICENSE-APACHE │ ├── LICENSE-MIT │ ├── README.md │ └── src │ │ └── index.ts ├── interface-address-manager │ ├── LICENSE │ ├── tsconfig.json │ ├── LICENSE-APACHE │ ├── LICENSE-MIT │ ├── src │ │ └── index.ts │ └── README.md ├── interface-compliance-tests │ ├── LICENSE │ ├── src │ │ ├── index.ts │ │ └── is-valid-tick.ts │ ├── tsconfig.json │ ├── LICENSE-APACHE │ ├── LICENSE-MIT │ └── README.md ├── interface-connection-gater │ ├── LICENSE │ ├── tsconfig.json │ ├── LICENSE-APACHE │ ├── LICENSE-MIT │ ├── README.md │ └── CHANGELOG.md ├── interface-connection-encrypter │ ├── LICENSE │ ├── tsconfig.json │ ├── LICENSE-APACHE │ ├── src │ │ ├── errors.ts │ │ └── index.ts │ └── LICENSE-MIT ├── interface-connection-manager │ ├── LICENSE │ ├── tsconfig.json │ ├── LICENSE-APACHE │ ├── LICENSE-MIT │ ├── README.md │ └── src │ │ └── index.ts ├── interface-connection-compliance-tests │ ├── LICENSE │ ├── tsconfig.json │ ├── LICENSE-APACHE │ ├── LICENSE-MIT │ └── README.md ├── interface-pubsub-compliance-tests │ ├── LICENSE │ ├── LICENSE-APACHE │ ├── tsconfig.json │ ├── LICENSE-MIT │ ├── src │ │ ├── utils.ts │ │ ├── index.ts │ │ ├── messages.ts │ │ ├── emit-self.ts │ │ └── api.ts │ └── README.md ├── interface-record-compliance-tests │ ├── LICENSE │ ├── tsconfig.json │ ├── LICENSE-APACHE │ ├── src │ │ └── index.ts │ ├── LICENSE-MIT │ └── README.md ├── interface-transport-compliance-tests │ ├── LICENSE │ ├── LICENSE-APACHE │ ├── tsconfig.json │ ├── src │ │ ├── index.ts │ │ └── filter-test.ts │ ├── LICENSE-MIT │ └── README.md ├── interface-peer-discovery-compliance-tests │ ├── LICENSE │ ├── tsconfig.json │ ├── LICENSE-APACHE │ ├── LICENSE-MIT │ ├── README.md │ └── src │ │ └── index.ts ├── interface-stream-muxer-compliance-tests │ ├── LICENSE │ ├── tsconfig.json │ ├── LICENSE-APACHE │ ├── src │ │ ├── index.ts │ │ ├── mega-stress-test.ts │ │ ├── stress-test.ts │ │ └── spawner.ts │ ├── LICENSE-MIT │ └── README.md └── interface-connection-encrypter-compliance-tests │ ├── LICENSE │ ├── tsconfig.json │ ├── LICENSE-APACHE │ ├── src │ ├── utils │ │ └── index.ts │ └── index.ts │ ├── LICENSE-MIT │ └── README.md ├── .gitignore ├── .npmrc ├── LICENSE ├── .github ├── workflows │ ├── stale.yml │ ├── semantic-pull-request.yml │ └── automerge.yml └── dependabot.yml ├── LICENSE-APACHE ├── LICENSE-MIT └── package.json /packages/interface-peer-store/src/tags.ts: -------------------------------------------------------------------------------- 1 | 2 | export const KEEP_ALIVE = 'keep-alive' 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | build 3 | dist 4 | .docs 5 | .coverage 6 | node_modules 7 | package-lock.json 8 | yarn.lock 9 | .vscode 10 | -------------------------------------------------------------------------------- /packages/interface-transport/img/badge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libp2p/js-libp2p-interfaces/HEAD/packages/interface-transport/img/badge.png -------------------------------------------------------------------------------- /packages/interface-connection/img/badge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libp2p/js-libp2p-interfaces/HEAD/packages/interface-connection/img/badge.png -------------------------------------------------------------------------------- /packages/interface-connection/src/status.ts: -------------------------------------------------------------------------------- 1 | 2 | export const OPEN = 'OPEN' 3 | export const CLOSING = 'CLOSING' 4 | export const CLOSED = 'CLOSED' 5 | -------------------------------------------------------------------------------- /packages/interface-peer-routing/img/badge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libp2p/js-libp2p-interfaces/HEAD/packages/interface-peer-routing/img/badge.png -------------------------------------------------------------------------------- /packages/interface-stream-muxer/img/badge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libp2p/js-libp2p-interfaces/HEAD/packages/interface-stream-muxer/img/badge.png -------------------------------------------------------------------------------- /packages/interface-transport/img/badge.sketch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libp2p/js-libp2p-interfaces/HEAD/packages/interface-transport/img/badge.sketch -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | ; package-lock with tarball deps breaks lerna/nx - remove when https://github.com/semantic-release/github/pull/487 is merged 2 | package-lock=false 3 | -------------------------------------------------------------------------------- /packages/interface-connection/img/badge.sketch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libp2p/js-libp2p-interfaces/HEAD/packages/interface-connection/img/badge.sketch -------------------------------------------------------------------------------- /packages/interface-peer-discovery/img/badge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libp2p/js-libp2p-interfaces/HEAD/packages/interface-peer-discovery/img/badge.png -------------------------------------------------------------------------------- /packages/interface-content-routing/img/badge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libp2p/js-libp2p-interfaces/HEAD/packages/interface-content-routing/img/badge.png -------------------------------------------------------------------------------- /packages/interface-peer-discovery/img/badge.sketch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libp2p/js-libp2p-interfaces/HEAD/packages/interface-peer-discovery/img/badge.sketch -------------------------------------------------------------------------------- /packages/interface-peer-routing/img/badge.sketch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libp2p/js-libp2p-interfaces/HEAD/packages/interface-peer-routing/img/badge.sketch -------------------------------------------------------------------------------- /packages/interface-stream-muxer/img/badge.sketch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libp2p/js-libp2p-interfaces/HEAD/packages/interface-stream-muxer/img/badge.sketch -------------------------------------------------------------------------------- /packages/interface-content-routing/img/badge.sketch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libp2p/js-libp2p-interfaces/HEAD/packages/interface-content-routing/img/badge.sketch -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This project is dual licensed under MIT and Apache-2.0. 2 | 3 | MIT: https://www.opensource.org/licenses/mit 4 | Apache-2.0: https://www.apache.org/licenses/license-2.0 5 | -------------------------------------------------------------------------------- /packages/interfaces/LICENSE: -------------------------------------------------------------------------------- 1 | This project is dual licensed under MIT and Apache-2.0. 2 | 3 | MIT: https://www.opensource.org/licenses/mit 4 | Apache-2.0: https://www.apache.org/licenses/license-2.0 5 | -------------------------------------------------------------------------------- /packages/interface-dht/LICENSE: -------------------------------------------------------------------------------- 1 | This project is dual licensed under MIT and Apache-2.0. 2 | 3 | MIT: https://www.opensource.org/licenses/mit 4 | Apache-2.0: https://www.apache.org/licenses/license-2.0 5 | -------------------------------------------------------------------------------- /packages/interface-keys/LICENSE: -------------------------------------------------------------------------------- 1 | This project is dual licensed under MIT and Apache-2.0. 2 | 3 | MIT: https://www.opensource.org/licenses/mit 4 | Apache-2.0: https://www.apache.org/licenses/license-2.0 5 | -------------------------------------------------------------------------------- /packages/interface-libp2p/LICENSE: -------------------------------------------------------------------------------- 1 | This project is dual licensed under MIT and Apache-2.0. 2 | 3 | MIT: https://www.opensource.org/licenses/mit 4 | Apache-2.0: https://www.apache.org/licenses/license-2.0 5 | -------------------------------------------------------------------------------- /packages/interface-metrics/LICENSE: -------------------------------------------------------------------------------- 1 | This project is dual licensed under MIT and Apache-2.0. 2 | 3 | MIT: https://www.opensource.org/licenses/mit 4 | Apache-2.0: https://www.apache.org/licenses/license-2.0 5 | -------------------------------------------------------------------------------- /packages/interface-mocks/LICENSE: -------------------------------------------------------------------------------- 1 | This project is dual licensed under MIT and Apache-2.0. 2 | 3 | MIT: https://www.opensource.org/licenses/mit 4 | Apache-2.0: https://www.apache.org/licenses/license-2.0 5 | -------------------------------------------------------------------------------- /packages/interface-peer-id/LICENSE: -------------------------------------------------------------------------------- 1 | This project is dual licensed under MIT and Apache-2.0. 2 | 3 | MIT: https://www.opensource.org/licenses/mit 4 | Apache-2.0: https://www.apache.org/licenses/license-2.0 5 | -------------------------------------------------------------------------------- /packages/interface-pubsub/LICENSE: -------------------------------------------------------------------------------- 1 | This project is dual licensed under MIT and Apache-2.0. 2 | 3 | MIT: https://www.opensource.org/licenses/mit 4 | Apache-2.0: https://www.apache.org/licenses/license-2.0 5 | -------------------------------------------------------------------------------- /packages/interface-record/LICENSE: -------------------------------------------------------------------------------- 1 | This project is dual licensed under MIT and Apache-2.0. 2 | 3 | MIT: https://www.opensource.org/licenses/mit 4 | Apache-2.0: https://www.apache.org/licenses/license-2.0 5 | -------------------------------------------------------------------------------- /packages/interface-connection/LICENSE: -------------------------------------------------------------------------------- 1 | This project is dual licensed under MIT and Apache-2.0. 2 | 3 | MIT: https://www.opensource.org/licenses/mit 4 | Apache-2.0: https://www.apache.org/licenses/license-2.0 5 | -------------------------------------------------------------------------------- /packages/interface-keychain/LICENSE: -------------------------------------------------------------------------------- 1 | This project is dual licensed under MIT and Apache-2.0. 2 | 3 | MIT: https://www.opensource.org/licenses/mit 4 | Apache-2.0: https://www.apache.org/licenses/license-2.0 5 | -------------------------------------------------------------------------------- /packages/interface-peer-info/LICENSE: -------------------------------------------------------------------------------- 1 | This project is dual licensed under MIT and Apache-2.0. 2 | 3 | MIT: https://www.opensource.org/licenses/mit 4 | Apache-2.0: https://www.apache.org/licenses/license-2.0 5 | -------------------------------------------------------------------------------- /packages/interface-peer-routing/LICENSE: -------------------------------------------------------------------------------- 1 | This project is dual licensed under MIT and Apache-2.0. 2 | 3 | MIT: https://www.opensource.org/licenses/mit 4 | Apache-2.0: https://www.apache.org/licenses/license-2.0 5 | -------------------------------------------------------------------------------- /packages/interface-peer-store/LICENSE: -------------------------------------------------------------------------------- 1 | This project is dual licensed under MIT and Apache-2.0. 2 | 3 | MIT: https://www.opensource.org/licenses/mit 4 | Apache-2.0: https://www.apache.org/licenses/license-2.0 5 | -------------------------------------------------------------------------------- /packages/interface-registrar/LICENSE: -------------------------------------------------------------------------------- 1 | This project is dual licensed under MIT and Apache-2.0. 2 | 3 | MIT: https://www.opensource.org/licenses/mit 4 | Apache-2.0: https://www.apache.org/licenses/license-2.0 5 | -------------------------------------------------------------------------------- /packages/interface-stream-muxer/LICENSE: -------------------------------------------------------------------------------- 1 | This project is dual licensed under MIT and Apache-2.0. 2 | 3 | MIT: https://www.opensource.org/licenses/mit 4 | Apache-2.0: https://www.apache.org/licenses/license-2.0 5 | -------------------------------------------------------------------------------- /packages/interface-transport/LICENSE: -------------------------------------------------------------------------------- 1 | This project is dual licensed under MIT and Apache-2.0. 2 | 3 | MIT: https://www.opensource.org/licenses/mit 4 | Apache-2.0: https://www.apache.org/licenses/license-2.0 5 | -------------------------------------------------------------------------------- /packages/interface-address-manager/LICENSE: -------------------------------------------------------------------------------- 1 | This project is dual licensed under MIT and Apache-2.0. 2 | 3 | MIT: https://www.opensource.org/licenses/mit 4 | Apache-2.0: https://www.apache.org/licenses/license-2.0 5 | -------------------------------------------------------------------------------- /packages/interface-compliance-tests/LICENSE: -------------------------------------------------------------------------------- 1 | This project is dual licensed under MIT and Apache-2.0. 2 | 3 | MIT: https://www.opensource.org/licenses/mit 4 | Apache-2.0: https://www.apache.org/licenses/license-2.0 5 | -------------------------------------------------------------------------------- /packages/interface-compliance-tests/src/index.ts: -------------------------------------------------------------------------------- 1 | 2 | export interface TestSetup> { 3 | setup: (args?: SetupArgs) => Promise 4 | teardown: () => Promise 5 | } 6 | -------------------------------------------------------------------------------- /packages/interface-connection-gater/LICENSE: -------------------------------------------------------------------------------- 1 | This project is dual licensed under MIT and Apache-2.0. 2 | 3 | MIT: https://www.opensource.org/licenses/mit 4 | Apache-2.0: https://www.apache.org/licenses/license-2.0 5 | -------------------------------------------------------------------------------- /packages/interface-content-routing/LICENSE: -------------------------------------------------------------------------------- 1 | This project is dual licensed under MIT and Apache-2.0. 2 | 3 | MIT: https://www.opensource.org/licenses/mit 4 | Apache-2.0: https://www.apache.org/licenses/license-2.0 5 | -------------------------------------------------------------------------------- /packages/interface-keys/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "aegir/src/config/tsconfig.aegir.json", 3 | "compilerOptions": { 4 | "outDir": "dist" 5 | }, 6 | "include": [ 7 | "src" 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /packages/interface-peer-discovery/LICENSE: -------------------------------------------------------------------------------- 1 | This project is dual licensed under MIT and Apache-2.0. 2 | 3 | MIT: https://www.opensource.org/licenses/mit 4 | Apache-2.0: https://www.apache.org/licenses/license-2.0 5 | -------------------------------------------------------------------------------- /packages/interfaces/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "aegir/src/config/tsconfig.aegir.json", 3 | "compilerOptions": { 4 | "outDir": "dist" 5 | }, 6 | "include": [ 7 | "src" 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /packages/interface-connection-encrypter/LICENSE: -------------------------------------------------------------------------------- 1 | This project is dual licensed under MIT and Apache-2.0. 2 | 3 | MIT: https://www.opensource.org/licenses/mit 4 | Apache-2.0: https://www.apache.org/licenses/license-2.0 5 | -------------------------------------------------------------------------------- /packages/interface-connection-manager/LICENSE: -------------------------------------------------------------------------------- 1 | This project is dual licensed under MIT and Apache-2.0. 2 | 3 | MIT: https://www.opensource.org/licenses/mit 4 | Apache-2.0: https://www.apache.org/licenses/license-2.0 5 | -------------------------------------------------------------------------------- /packages/interface-peer-id/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "aegir/src/config/tsconfig.aegir.json", 3 | "compilerOptions": { 4 | "outDir": "dist" 5 | }, 6 | "include": [ 7 | "src" 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /packages/interface-connection-compliance-tests/LICENSE: -------------------------------------------------------------------------------- 1 | This project is dual licensed under MIT and Apache-2.0. 2 | 3 | MIT: https://www.opensource.org/licenses/mit 4 | Apache-2.0: https://www.apache.org/licenses/license-2.0 5 | -------------------------------------------------------------------------------- /packages/interface-pubsub-compliance-tests/LICENSE: -------------------------------------------------------------------------------- 1 | This project is dual licensed under MIT and Apache-2.0. 2 | 3 | MIT: https://www.opensource.org/licenses/mit 4 | Apache-2.0: https://www.apache.org/licenses/license-2.0 5 | -------------------------------------------------------------------------------- /packages/interface-record-compliance-tests/LICENSE: -------------------------------------------------------------------------------- 1 | This project is dual licensed under MIT and Apache-2.0. 2 | 3 | MIT: https://www.opensource.org/licenses/mit 4 | Apache-2.0: https://www.apache.org/licenses/license-2.0 5 | -------------------------------------------------------------------------------- /packages/interface-transport-compliance-tests/LICENSE: -------------------------------------------------------------------------------- 1 | This project is dual licensed under MIT and Apache-2.0. 2 | 3 | MIT: https://www.opensource.org/licenses/mit 4 | Apache-2.0: https://www.apache.org/licenses/license-2.0 5 | -------------------------------------------------------------------------------- /packages/interface-address-manager/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "aegir/src/config/tsconfig.aegir.json", 3 | "compilerOptions": { 4 | "outDir": "dist" 5 | }, 6 | "include": [ 7 | "src" 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /packages/interface-compliance-tests/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "aegir/src/config/tsconfig.aegir.json", 3 | "compilerOptions": { 4 | "outDir": "dist" 5 | }, 6 | "include": [ 7 | "src" 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /packages/interface-peer-discovery-compliance-tests/LICENSE: -------------------------------------------------------------------------------- 1 | This project is dual licensed under MIT and Apache-2.0. 2 | 3 | MIT: https://www.opensource.org/licenses/mit 4 | Apache-2.0: https://www.apache.org/licenses/license-2.0 5 | -------------------------------------------------------------------------------- /packages/interface-stream-muxer-compliance-tests/LICENSE: -------------------------------------------------------------------------------- 1 | This project is dual licensed under MIT and Apache-2.0. 2 | 3 | MIT: https://www.opensource.org/licenses/mit 4 | Apache-2.0: https://www.apache.org/licenses/license-2.0 5 | -------------------------------------------------------------------------------- /.github/workflows/stale.yml: -------------------------------------------------------------------------------- 1 | name: Close and mark stale issue 2 | 3 | on: 4 | schedule: 5 | - cron: '0 0 * * *' 6 | 7 | jobs: 8 | stale: 9 | uses: pl-strflt/.github/.github/workflows/reusable-stale-issue.yml@v0.3 10 | -------------------------------------------------------------------------------- /packages/interface-connection-encrypter-compliance-tests/LICENSE: -------------------------------------------------------------------------------- 1 | This project is dual licensed under MIT and Apache-2.0. 2 | 3 | MIT: https://www.opensource.org/licenses/mit 4 | Apache-2.0: https://www.apache.org/licenses/license-2.0 5 | -------------------------------------------------------------------------------- /packages/interface-peer-info/src/index.ts: -------------------------------------------------------------------------------- 1 | import type { PeerId } from '@libp2p/interface-peer-id' 2 | import type { Multiaddr } from '@multiformats/multiaddr' 3 | 4 | export interface PeerInfo { 5 | id: PeerId 6 | multiaddrs: Multiaddr[] 7 | protocols: string[] 8 | } 9 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: npm 4 | directory: "/" 5 | schedule: 6 | interval: daily 7 | time: "10:00" 8 | open-pull-requests-limit: 10 9 | commit-message: 10 | prefix: "deps" 11 | prefix-development: "deps(dev)" 12 | -------------------------------------------------------------------------------- /.github/workflows/semantic-pull-request.yml: -------------------------------------------------------------------------------- 1 | name: Semantic PR 2 | 3 | on: 4 | pull_request_target: 5 | types: 6 | - opened 7 | - edited 8 | - synchronize 9 | 10 | jobs: 11 | main: 12 | uses: pl-strflt/.github/.github/workflows/reusable-semantic-pull-request.yml@v0.3 13 | -------------------------------------------------------------------------------- /packages/interface-keychain/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "aegir/src/config/tsconfig.aegir.json", 3 | "compilerOptions": { 4 | "outDir": "dist" 5 | }, 6 | "include": [ 7 | "src" 8 | ], 9 | "references": [ 10 | { 11 | "path": "../interface-peer-id" 12 | } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /packages/interface-metrics/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "aegir/src/config/tsconfig.aegir.json", 3 | "compilerOptions": { 4 | "outDir": "dist" 5 | }, 6 | "include": [ 7 | "src" 8 | ], 9 | "references": [ 10 | { 11 | "path": "../interface-connection" 12 | } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /packages/interface-peer-info/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "aegir/src/config/tsconfig.aegir.json", 3 | "compilerOptions": { 4 | "outDir": "dist" 5 | }, 6 | "include": [ 7 | "src" 8 | ], 9 | "references": [ 10 | { 11 | "path": "../interface-peer-id" 12 | } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /packages/interface-peer-store/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "aegir/src/config/tsconfig.aegir.json", 3 | "compilerOptions": { 4 | "outDir": "dist" 5 | }, 6 | "include": [ 7 | "src" 8 | ], 9 | "references": [ 10 | { 11 | "path": "../interface-peer-id" 12 | } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /packages/interface-connection-encrypter/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "aegir/src/config/tsconfig.aegir.json", 3 | "compilerOptions": { 4 | "outDir": "dist" 5 | }, 6 | "include": [ 7 | "src" 8 | ], 9 | "references": [ 10 | { 11 | "path": "../interface-peer-id" 12 | } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /packages/interface-record/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "aegir/src/config/tsconfig.aegir.json", 3 | "compilerOptions": { 4 | "outDir": "dist" 5 | }, 6 | "include": [ 7 | "src", 8 | "test" 9 | ], 10 | "references": [ 11 | { 12 | "path": "../interface-peer-id" 13 | } 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /.github/workflows/automerge.yml: -------------------------------------------------------------------------------- 1 | # File managed by web3-bot. DO NOT EDIT. 2 | # See https://github.com/protocol/.github/ for details. 3 | 4 | name: Automerge 5 | on: [ pull_request ] 6 | 7 | jobs: 8 | automerge: 9 | uses: protocol/.github/.github/workflows/automerge.yml@master 10 | with: 11 | job: 'automerge' 12 | -------------------------------------------------------------------------------- /packages/interface-mocks/src/duplex.ts: -------------------------------------------------------------------------------- 1 | import type { Duplex, Source } from 'it-stream-types' 2 | 3 | export function mockDuplex (): Duplex, Source, Promise> { 4 | return { 5 | source: (async function * () { 6 | yield * [] 7 | }()), 8 | sink: async () => {} 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /packages/interface-connection/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "aegir/src/config/tsconfig.aegir.json", 3 | "compilerOptions": { 4 | "outDir": "dist" 5 | }, 6 | "include": [ 7 | "src" 8 | ], 9 | "references": [ 10 | { 11 | "path": "../interface-peer-id" 12 | }, 13 | { 14 | "path": "../interfaces" 15 | } 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /packages/interface-mocks/test/muxer.spec.ts: -------------------------------------------------------------------------------- 1 | import tests from '@libp2p/interface-stream-muxer-compliance-tests' 2 | import { mockMuxer } from '../src/muxer.js' 3 | 4 | describe('mock stream muxer compliance tests', () => { 5 | tests({ 6 | async setup () { 7 | return mockMuxer() 8 | }, 9 | async teardown () { 10 | 11 | } 12 | }) 13 | }) 14 | -------------------------------------------------------------------------------- /packages/interface-content-routing/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "aegir/src/config/tsconfig.aegir.json", 3 | "compilerOptions": { 4 | "outDir": "dist" 5 | }, 6 | "include": [ 7 | "src" 8 | ], 9 | "references": [ 10 | { 11 | "path": "../interface-peer-info" 12 | }, 13 | { 14 | "path": "../interfaces" 15 | } 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /packages/interface-peer-discovery/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "aegir/src/config/tsconfig.aegir.json", 3 | "compilerOptions": { 4 | "outDir": "dist" 5 | }, 6 | "include": [ 7 | "src" 8 | ], 9 | "references": [ 10 | { 11 | "path": "../interface-peer-info" 12 | }, 13 | { 14 | "path": "../interfaces" 15 | } 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /packages/interface-connection-gater/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "aegir/src/config/tsconfig.aegir.json", 3 | "compilerOptions": { 4 | "outDir": "dist" 5 | }, 6 | "include": [ 7 | "src" 8 | ], 9 | "references": [ 10 | { 11 | "path": "../interface-connection" 12 | }, 13 | { 14 | "path": "../interface-peer-id" 15 | } 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /packages/interface-stream-muxer/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "aegir/src/config/tsconfig.aegir.json", 3 | "compilerOptions": { 4 | "outDir": "dist" 5 | }, 6 | "include": [ 7 | "src", 8 | "test" 9 | ], 10 | "references": [ 11 | { 12 | "path": "../interface-connection" 13 | }, 14 | { 15 | "path": "../interfaces" 16 | } 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /packages/interface-registrar/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "aegir/src/config/tsconfig.aegir.json", 3 | "compilerOptions": { 4 | "outDir": "dist" 5 | }, 6 | "include": [ 7 | "src", 8 | "test" 9 | ], 10 | "references": [ 11 | { 12 | "path": "../interface-connection" 13 | }, 14 | { 15 | "path": "../interface-peer-id" 16 | } 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /packages/interface-record-compliance-tests/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "aegir/src/config/tsconfig.aegir.json", 3 | "compilerOptions": { 4 | "outDir": "dist" 5 | }, 6 | "include": [ 7 | "src", 8 | "test" 9 | ], 10 | "references": [ 11 | { 12 | "path": "../interface-compliance-tests" 13 | }, 14 | { 15 | "path": "../interface-record" 16 | } 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /packages/interface-connection-compliance-tests/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "aegir/src/config/tsconfig.aegir.json", 3 | "compilerOptions": { 4 | "outDir": "dist" 5 | }, 6 | "include": [ 7 | "src", 8 | "test" 9 | ], 10 | "references": [ 11 | { 12 | "path": "../interface-compliance-tests" 13 | }, 14 | { 15 | "path": "../interface-connection" 16 | } 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /packages/interface-pubsub/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "aegir/src/config/tsconfig.aegir.json", 3 | "compilerOptions": { 4 | "outDir": "dist" 5 | }, 6 | "include": [ 7 | "src" 8 | ], 9 | "references": [ 10 | { 11 | "path": "../interface-connection" 12 | }, 13 | { 14 | "path": "../interface-peer-id" 15 | }, 16 | { 17 | "path": "../interfaces" 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /packages/interface-peer-routing/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "aegir/src/config/tsconfig.aegir.json", 3 | "compilerOptions": { 4 | "outDir": "dist" 5 | }, 6 | "include": [ 7 | "src" 8 | ], 9 | "references": [ 10 | { 11 | "path": "../interface-peer-id" 12 | }, 13 | { 14 | "path": "../interface-peer-info" 15 | }, 16 | { 17 | "path": "../interfaces" 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /packages/interface-mocks/test/connection-encrypter.spec.ts: -------------------------------------------------------------------------------- 1 | import tests from '@libp2p/interface-connection-encrypter-compliance-tests' 2 | import { mockConnectionEncrypter } from '../src/connection-encrypter.js' 3 | 4 | describe('mock connection encrypter compliance tests', () => { 5 | tests({ 6 | async setup () { 7 | return mockConnectionEncrypter() 8 | }, 9 | async teardown () { 10 | 11 | } 12 | }) 13 | }) 14 | -------------------------------------------------------------------------------- /packages/interface-connection-manager/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "aegir/src/config/tsconfig.aegir.json", 3 | "compilerOptions": { 4 | "outDir": "dist" 5 | }, 6 | "include": [ 7 | "src" 8 | ], 9 | "references": [ 10 | { 11 | "path": "../interface-connection" 12 | }, 13 | { 14 | "path": "../interface-peer-id" 15 | }, 16 | { 17 | "path": "../interfaces" 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /packages/interface-transport/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "aegir/src/config/tsconfig.aegir.json", 3 | "compilerOptions": { 4 | "outDir": "dist" 5 | }, 6 | "include": [ 7 | "src", 8 | "test" 9 | ], 10 | "references": [ 11 | { 12 | "path": "../interface-connection" 13 | }, 14 | { 15 | "path": "../interface-stream-muxer" 16 | }, 17 | { 18 | "path": "../interfaces" 19 | } 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /packages/interface-compliance-tests/src/is-valid-tick.ts: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * A tick is considered valid if it happened between now 4 | * and `ms` milliseconds ago 5 | */ 6 | export function isValidTick (date?: number, ms: number = 5000): boolean { 7 | if (date == null) { 8 | throw new Error('date must be a number') 9 | } 10 | 11 | const now = Date.now() 12 | 13 | if (date > now - ms && date <= now) { 14 | return true 15 | } 16 | 17 | return false 18 | } 19 | -------------------------------------------------------------------------------- /packages/interface-peer-discovery-compliance-tests/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "aegir/src/config/tsconfig.aegir.json", 3 | "compilerOptions": { 4 | "outDir": "dist" 5 | }, 6 | "include": [ 7 | "src", 8 | "test" 9 | ], 10 | "references": [ 11 | { 12 | "path": "../interface-compliance-tests" 13 | }, 14 | { 15 | "path": "../interface-peer-discovery" 16 | }, 17 | { 18 | "path": "../interfaces" 19 | } 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /packages/interface-stream-muxer-compliance-tests/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "aegir/src/config/tsconfig.aegir.json", 3 | "compilerOptions": { 4 | "outDir": "dist" 5 | }, 6 | "include": [ 7 | "src", 8 | "test" 9 | ], 10 | "references": [ 11 | { 12 | "path": "../interface-compliance-tests" 13 | }, 14 | { 15 | "path": "../interface-connection" 16 | }, 17 | { 18 | "path": "../interface-stream-muxer" 19 | } 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /packages/interface-dht/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "aegir/src/config/tsconfig.aegir.json", 3 | "compilerOptions": { 4 | "outDir": "dist" 5 | }, 6 | "include": [ 7 | "src" 8 | ], 9 | "references": [ 10 | { 11 | "path": "../interface-peer-discovery" 12 | }, 13 | { 14 | "path": "../interface-peer-id" 15 | }, 16 | { 17 | "path": "../interface-peer-info" 18 | }, 19 | { 20 | "path": "../interfaces" 21 | } 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | 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 2 | 3 | http://www.apache.org/licenses/LICENSE-2.0 4 | 5 | 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. 6 | -------------------------------------------------------------------------------- /packages/interface-dht/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | 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 2 | 3 | http://www.apache.org/licenses/LICENSE-2.0 4 | 5 | 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. 6 | -------------------------------------------------------------------------------- /packages/interface-keys/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | 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 2 | 3 | http://www.apache.org/licenses/LICENSE-2.0 4 | 5 | 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. 6 | -------------------------------------------------------------------------------- /packages/interfaces/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | 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 2 | 3 | http://www.apache.org/licenses/LICENSE-2.0 4 | 5 | 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. 6 | -------------------------------------------------------------------------------- /packages/interface-keychain/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | 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 2 | 3 | http://www.apache.org/licenses/LICENSE-2.0 4 | 5 | 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. 6 | -------------------------------------------------------------------------------- /packages/interface-libp2p/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | 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 2 | 3 | http://www.apache.org/licenses/LICENSE-2.0 4 | 5 | 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. 6 | -------------------------------------------------------------------------------- /packages/interface-metrics/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | 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 2 | 3 | http://www.apache.org/licenses/LICENSE-2.0 4 | 5 | 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. 6 | -------------------------------------------------------------------------------- /packages/interface-mocks/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | 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 2 | 3 | http://www.apache.org/licenses/LICENSE-2.0 4 | 5 | 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. 6 | -------------------------------------------------------------------------------- /packages/interface-peer-id/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | 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 2 | 3 | http://www.apache.org/licenses/LICENSE-2.0 4 | 5 | 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. 6 | -------------------------------------------------------------------------------- /packages/interface-peer-info/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | 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 2 | 3 | http://www.apache.org/licenses/LICENSE-2.0 4 | 5 | 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. 6 | -------------------------------------------------------------------------------- /packages/interface-pubsub/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | 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 2 | 3 | http://www.apache.org/licenses/LICENSE-2.0 4 | 5 | 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. 6 | -------------------------------------------------------------------------------- /packages/interface-record/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | 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 2 | 3 | http://www.apache.org/licenses/LICENSE-2.0 4 | 5 | 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. 6 | -------------------------------------------------------------------------------- /packages/interface-registrar/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | 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 2 | 3 | http://www.apache.org/licenses/LICENSE-2.0 4 | 5 | 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. 6 | -------------------------------------------------------------------------------- /packages/interface-transport/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | 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 2 | 3 | http://www.apache.org/licenses/LICENSE-2.0 4 | 5 | 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. 6 | -------------------------------------------------------------------------------- /packages/interface-connection-encrypter-compliance-tests/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "aegir/src/config/tsconfig.aegir.json", 3 | "compilerOptions": { 4 | "outDir": "dist" 5 | }, 6 | "include": [ 7 | "src", 8 | "test" 9 | ], 10 | "references": [ 11 | { 12 | "path": "../interface-compliance-tests" 13 | }, 14 | { 15 | "path": "../interface-connection" 16 | }, 17 | { 18 | "path": "../interface-connection-encrypter" 19 | }, 20 | { 21 | "path": "../interface-peer-id" 22 | } 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /packages/interface-connection/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | 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 2 | 3 | http://www.apache.org/licenses/LICENSE-2.0 4 | 5 | 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. 6 | -------------------------------------------------------------------------------- /packages/interface-peer-discovery/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | 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 2 | 3 | http://www.apache.org/licenses/LICENSE-2.0 4 | 5 | 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. 6 | -------------------------------------------------------------------------------- /packages/interface-peer-routing/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | 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 2 | 3 | http://www.apache.org/licenses/LICENSE-2.0 4 | 5 | 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. 6 | -------------------------------------------------------------------------------- /packages/interface-peer-store/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | 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 2 | 3 | http://www.apache.org/licenses/LICENSE-2.0 4 | 5 | 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. 6 | -------------------------------------------------------------------------------- /packages/interface-stream-muxer/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | 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 2 | 3 | http://www.apache.org/licenses/LICENSE-2.0 4 | 5 | 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. 6 | -------------------------------------------------------------------------------- /packages/interface-address-manager/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | 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 2 | 3 | http://www.apache.org/licenses/LICENSE-2.0 4 | 5 | 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. 6 | -------------------------------------------------------------------------------- /packages/interface-compliance-tests/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | 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 2 | 3 | http://www.apache.org/licenses/LICENSE-2.0 4 | 5 | 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. 6 | -------------------------------------------------------------------------------- /packages/interface-connection-gater/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | 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 2 | 3 | http://www.apache.org/licenses/LICENSE-2.0 4 | 5 | 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. 6 | -------------------------------------------------------------------------------- /packages/interface-connection-manager/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | 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 2 | 3 | http://www.apache.org/licenses/LICENSE-2.0 4 | 5 | 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. 6 | -------------------------------------------------------------------------------- /packages/interface-content-routing/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | 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 2 | 3 | http://www.apache.org/licenses/LICENSE-2.0 4 | 5 | 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. 6 | -------------------------------------------------------------------------------- /packages/interface-connection-encrypter/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | 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 2 | 3 | http://www.apache.org/licenses/LICENSE-2.0 4 | 5 | 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. 6 | -------------------------------------------------------------------------------- /packages/interface-pubsub-compliance-tests/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | 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 2 | 3 | http://www.apache.org/licenses/LICENSE-2.0 4 | 5 | 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. 6 | -------------------------------------------------------------------------------- /packages/interface-record-compliance-tests/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | 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 2 | 3 | http://www.apache.org/licenses/LICENSE-2.0 4 | 5 | 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. 6 | -------------------------------------------------------------------------------- /packages/interface-connection-compliance-tests/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | 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 2 | 3 | http://www.apache.org/licenses/LICENSE-2.0 4 | 5 | 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. 6 | -------------------------------------------------------------------------------- /packages/interface-stream-muxer-compliance-tests/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | 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 2 | 3 | http://www.apache.org/licenses/LICENSE-2.0 4 | 5 | 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. 6 | -------------------------------------------------------------------------------- /packages/interface-transport-compliance-tests/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | 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 2 | 3 | http://www.apache.org/licenses/LICENSE-2.0 4 | 5 | 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. 6 | -------------------------------------------------------------------------------- /packages/interface-peer-discovery-compliance-tests/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | 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 2 | 3 | http://www.apache.org/licenses/LICENSE-2.0 4 | 5 | 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. 6 | -------------------------------------------------------------------------------- /packages/interface-connection-encrypter-compliance-tests/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | 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 2 | 3 | http://www.apache.org/licenses/LICENSE-2.0 4 | 5 | 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. 6 | -------------------------------------------------------------------------------- /packages/interface-mocks/test/peer-discovery.spec.ts: -------------------------------------------------------------------------------- 1 | import tests from '@libp2p/interface-peer-discovery-compliance-tests' 2 | import { MockDiscovery } from '../src/peer-discovery.js' 3 | 4 | describe('mock peer discovery compliance tests', () => { 5 | let intervalId: any 6 | 7 | tests({ 8 | async setup () { 9 | const mockDiscovery = new MockDiscovery({ 10 | discoveryDelay: 1 11 | }) 12 | 13 | intervalId = setInterval(mockDiscovery._discoverPeer, 1000) 14 | 15 | return mockDiscovery 16 | }, 17 | async teardown () { 18 | clearInterval(intervalId) 19 | } 20 | }) 21 | }) 22 | -------------------------------------------------------------------------------- /packages/interface-stream-muxer-compliance-tests/src/index.ts: -------------------------------------------------------------------------------- 1 | import baseTest from './base-test.js' 2 | import closeTest from './close-test.js' 3 | import megaStressTest from './mega-stress-test.js' 4 | import stressTest from './stress-test.js' 5 | import type { TestSetup } from '@libp2p/interface-compliance-tests' 6 | import type { StreamMuxerFactory } from '@libp2p/interface-stream-muxer' 7 | 8 | export default (common: TestSetup): void => { 9 | describe('interface-stream-muxer', () => { 10 | baseTest(common) 11 | closeTest(common) 12 | stressTest(common) 13 | megaStressTest(common) 14 | }) 15 | } 16 | -------------------------------------------------------------------------------- /packages/interface-transport-compliance-tests/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "aegir/src/config/tsconfig.aegir.json", 3 | "compilerOptions": { 4 | "outDir": "dist" 5 | }, 6 | "include": [ 7 | "src", 8 | "test" 9 | ], 10 | "references": [ 11 | { 12 | "path": "../interface-compliance-tests" 13 | }, 14 | { 15 | "path": "../interface-connection" 16 | }, 17 | { 18 | "path": "../interface-mocks" 19 | }, 20 | { 21 | "path": "../interface-registrar" 22 | }, 23 | { 24 | "path": "../interface-transport" 25 | }, 26 | { 27 | "path": "../interfaces" 28 | } 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /packages/interface-stream-muxer-compliance-tests/src/mega-stress-test.ts: -------------------------------------------------------------------------------- 1 | import spawn from './spawner.js' 2 | import type { TestSetup } from '@libp2p/interface-compliance-tests' 3 | import type { StreamMuxer, StreamMuxerFactory, StreamMuxerInit } from '@libp2p/interface-stream-muxer' 4 | 5 | export default (common: TestSetup): void => { 6 | const createMuxer = async (init?: StreamMuxerInit): Promise => { 7 | const factory = await common.setup() 8 | return factory.createStreamMuxer(init) 9 | } 10 | 11 | describe.skip('mega stress test', function () { 12 | it('10,000 streams with 10,000 msg', async () => { await spawn(createMuxer, 10000, 10000, 5000) }) 13 | }) 14 | } 15 | -------------------------------------------------------------------------------- /packages/interface-pubsub-compliance-tests/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "aegir/src/config/tsconfig.aegir.json", 3 | "compilerOptions": { 4 | "outDir": "dist" 5 | }, 6 | "include": [ 7 | "src", 8 | "test" 9 | ], 10 | "references": [ 11 | { 12 | "path": "../interface-compliance-tests" 13 | }, 14 | { 15 | "path": "../interface-connection-manager" 16 | }, 17 | { 18 | "path": "../interface-mocks" 19 | }, 20 | { 21 | "path": "../interface-peer-id" 22 | }, 23 | { 24 | "path": "../interface-pubsub" 25 | }, 26 | { 27 | "path": "../interface-registrar" 28 | }, 29 | { 30 | "path": "../interfaces" 31 | } 32 | ] 33 | } 34 | -------------------------------------------------------------------------------- /packages/interfaces/src/index.ts: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * An object that contains an AbortSignal as 4 | * the optional `signal` property. 5 | * 6 | * @example 7 | * 8 | * ```js 9 | * const controller = new AbortController() 10 | * 11 | * aLongRunningOperation({ 12 | * signal: controller.signal 13 | * }) 14 | * 15 | * // later 16 | * 17 | * controller.abort() 18 | */ 19 | export interface AbortOptions { 20 | signal?: AbortSignal 21 | } 22 | 23 | /** 24 | * Returns a new type with all fields marked optional. 25 | * 26 | * Borrowed from the tsdef module. 27 | */ 28 | export type RecursivePartial = { 29 | [P in keyof T]?: T[P] extends Array ? Array> : T[P] extends (...args: any[]) => any ? T[P] : RecursivePartial 30 | } 31 | -------------------------------------------------------------------------------- /packages/interface-mocks/src/index.ts: -------------------------------------------------------------------------------- 1 | export { mockConnectionEncrypter } from './connection-encrypter.js' 2 | export { mockConnectionGater } from './connection-gater.js' 3 | export { mockConnectionManager, mockNetwork } from './connection-manager.js' 4 | export { mockConnection, mockStream, connectionPair } from './connection.js' 5 | export { mockMultiaddrConnection, mockMultiaddrConnPair } from './multiaddr-connection.js' 6 | export { mockMuxer } from './muxer.js' 7 | export { mockRegistrar } from './registrar.js' 8 | export { mockUpgrader } from './upgrader.js' 9 | export { mockDuplex } from './duplex.js' 10 | export { mockMetrics } from './metrics.js' 11 | export type { MockUpgraderInit } from './upgrader.js' 12 | export type { MockNetworkComponents } from './connection-manager.js' 13 | -------------------------------------------------------------------------------- /packages/interface-transport-compliance-tests/src/index.ts: -------------------------------------------------------------------------------- 1 | import dial from './dial-test.js' 2 | import filter from './filter-test.js' 3 | import listen from './listen-test.js' 4 | import type { TestSetup } from '@libp2p/interface-compliance-tests' 5 | import type { Transport } from '@libp2p/interface-transport' 6 | import type { Multiaddr } from '@multiformats/multiaddr' 7 | 8 | export interface Connector { 9 | delay: (ms: number) => void 10 | restore: () => void 11 | } 12 | 13 | export interface TransportTestFixtures { 14 | addrs: Multiaddr[] 15 | transport: Transport 16 | connector: Connector 17 | } 18 | 19 | export default (common: TestSetup): void => { 20 | describe('interface-transport', () => { 21 | dial(common) 22 | listen(common) 23 | filter(common) 24 | }) 25 | } 26 | -------------------------------------------------------------------------------- /packages/interface-transport-compliance-tests/src/filter-test.ts: -------------------------------------------------------------------------------- 1 | import { expect } from 'aegir/chai' 2 | import type { TransportTestFixtures } from './index.js' 3 | import type { TestSetup } from '@libp2p/interface-compliance-tests' 4 | import type { Transport } from '@libp2p/interface-transport' 5 | import type { Multiaddr } from '@multiformats/multiaddr' 6 | 7 | export default (common: TestSetup): void => { 8 | describe('filter', () => { 9 | let addrs: Multiaddr[] 10 | let transport: Transport 11 | 12 | before(async () => { 13 | ({ addrs, transport } = await common.setup()) 14 | }) 15 | 16 | after(async () => { 17 | await common.teardown() 18 | }) 19 | 20 | it('filters addresses', () => { 21 | const filteredAddrs = transport.filter(addrs) 22 | expect(filteredAddrs).to.eql(addrs) 23 | }) 24 | }) 25 | } 26 | -------------------------------------------------------------------------------- /packages/interface-connection-encrypter-compliance-tests/src/utils/index.ts: -------------------------------------------------------------------------------- 1 | import { multiaddr } from '@multiformats/multiaddr' 2 | import { duplexPair } from 'it-pair/duplex' 3 | import type { MultiaddrConnection } from '@libp2p/interface-connection' 4 | import type { Duplex, Source } from 'it-stream-types' 5 | 6 | export function createMaConnPair (): [MultiaddrConnection, MultiaddrConnection] { 7 | const [local, remote] = duplexPair() 8 | 9 | function duplexToMaConn (duplex: Duplex, Source, Promise>): MultiaddrConnection { 10 | const output: MultiaddrConnection = { 11 | ...duplex, 12 | close: async () => {}, 13 | remoteAddr: multiaddr('/ip4/127.0.0.1/tcp/4001'), 14 | timeline: { 15 | open: Date.now() 16 | } 17 | } 18 | 19 | return output 20 | } 21 | 22 | return [duplexToMaConn(local), duplexToMaConn(remote)] 23 | } 24 | -------------------------------------------------------------------------------- /packages/interface-libp2p/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "aegir/src/config/tsconfig.aegir.json", 3 | "compilerOptions": { 4 | "outDir": "dist" 5 | }, 6 | "include": [ 7 | "src" 8 | ], 9 | "references": [ 10 | { 11 | "path": "../interface-connection" 12 | }, 13 | { 14 | "path": "../interface-content-routing" 15 | }, 16 | { 17 | "path": "../interface-keychain" 18 | }, 19 | { 20 | "path": "../interface-metrics" 21 | }, 22 | { 23 | "path": "../interface-peer-id" 24 | }, 25 | { 26 | "path": "../interface-peer-info" 27 | }, 28 | { 29 | "path": "../interface-peer-routing" 30 | }, 31 | { 32 | "path": "../interface-peer-store" 33 | }, 34 | { 35 | "path": "../interface-registrar" 36 | }, 37 | { 38 | "path": "../interface-transport" 39 | }, 40 | { 41 | "path": "../interfaces" 42 | } 43 | ] 44 | } 45 | -------------------------------------------------------------------------------- /packages/interface-connection-encrypter/src/errors.ts: -------------------------------------------------------------------------------- 1 | 2 | export class UnexpectedPeerError extends Error { 3 | public code: string 4 | 5 | constructor (message = 'Unexpected Peer') { 6 | super(message) 7 | this.code = UnexpectedPeerError.code 8 | } 9 | 10 | static readonly code = 'ERR_UNEXPECTED_PEER' 11 | } 12 | 13 | export class InvalidCryptoExchangeError extends Error { 14 | public code: string 15 | 16 | constructor (message = 'Invalid crypto exchange') { 17 | super(message) 18 | this.code = InvalidCryptoExchangeError.code 19 | } 20 | 21 | static readonly code = 'ERR_INVALID_CRYPTO_EXCHANGE' 22 | } 23 | 24 | export class InvalidCryptoTransmissionError extends Error { 25 | public code: string 26 | 27 | constructor (message = 'Invalid crypto transmission') { 28 | super(message) 29 | this.code = InvalidCryptoTransmissionError.code 30 | } 31 | 32 | static readonly code = 'ERR_INVALID_CRYPTO_TRANSMISSION' 33 | } 34 | -------------------------------------------------------------------------------- /packages/interface-peer-discovery/src/index.ts: -------------------------------------------------------------------------------- 1 | import type { PeerInfo } from '@libp2p/interface-peer-info' 2 | import type { EventEmitter } from '@libp2p/interfaces/events' 3 | 4 | /** 5 | * Any object that implements this Symbol as a property should return a 6 | * PeerDiscovery instance as the property value, similar to how 7 | * `Symbol.Iterable` can be used to return an `Iterable` from an `Iterator`. 8 | * 9 | * @example 10 | * 11 | * ```js 12 | * import { peerDiscovery, PeerDiscovery } from '@libp2p/peer-discovery' 13 | * 14 | * class MyPeerDiscoverer implements PeerDiscovery { 15 | * get [peerDiscovery] () { 16 | * return this 17 | * } 18 | * 19 | * // ...other methods 20 | * } 21 | * ``` 22 | */ 23 | export const peerDiscovery = Symbol.for('@libp2p/peer-discovery') 24 | 25 | export interface PeerDiscoveryEvents { 26 | 'peer': CustomEvent 27 | } 28 | 29 | export interface PeerDiscovery extends EventEmitter {} 30 | -------------------------------------------------------------------------------- /packages/interface-record-compliance-tests/src/index.ts: -------------------------------------------------------------------------------- 1 | import { expect } from 'aegir/chai' 2 | import type { TestSetup } from '@libp2p/interface-compliance-tests' 3 | import type { Record } from '@libp2p/interface-record' 4 | 5 | export default (test: TestSetup): void => { 6 | describe('record', () => { 7 | let record: Record 8 | 9 | beforeEach(async () => { 10 | record = await test.setup() 11 | }) 12 | 13 | afterEach(async () => { 14 | await test.teardown() 15 | }) 16 | 17 | it('has domain and codec', () => { 18 | expect(record.domain).to.exist() 19 | expect(record.codec).to.exist() 20 | }) 21 | 22 | it('is able to marshal', () => { 23 | const rawData = record.marshal() 24 | expect(rawData).to.have.property('byteLength') 25 | }) 26 | 27 | it('is able to compare two records', () => { 28 | const equals = record.equals(record) 29 | expect(equals).to.eql(true) 30 | }) 31 | }) 32 | } 33 | -------------------------------------------------------------------------------- /packages/interface-record/src/index.ts: -------------------------------------------------------------------------------- 1 | import type { PeerId } from '@libp2p/interface-peer-id' 2 | import type { Uint8ArrayList } from 'uint8arraylist' 3 | 4 | /** 5 | * Record is the base implementation of a record that can be used as the payload of a libp2p envelope. 6 | */ 7 | export interface Record { 8 | /** 9 | * signature domain. 10 | */ 11 | domain: string 12 | /** 13 | * identifier of the type of record 14 | */ 15 | codec: Uint8Array 16 | /** 17 | * Marshal a record to be used in an envelope. 18 | */ 19 | marshal: () => Uint8Array 20 | /** 21 | * Verifies if the other provided Record is identical to this one. 22 | */ 23 | equals: (other: Record) => boolean 24 | } 25 | 26 | export interface Envelope { 27 | peerId: PeerId 28 | payloadType: Uint8Array | Uint8ArrayList 29 | payload: Uint8Array 30 | signature: Uint8Array | Uint8ArrayList 31 | 32 | marshal: () => Uint8Array 33 | validate: (domain: string) => Promise 34 | equals: (other: Envelope) => boolean 35 | } 36 | -------------------------------------------------------------------------------- /packages/interfaces/src/errors.ts: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * When this error is thrown it means an operation was aborted, 4 | * usually in response to the `abort` event being emitted by an 5 | * AbortSignal. 6 | */ 7 | export class AbortError extends Error { 8 | public readonly code: string 9 | public readonly type: string 10 | 11 | constructor (message: string = 'The operation was aborted') { 12 | super(message) 13 | this.code = AbortError.code 14 | this.type = AbortError.type 15 | } 16 | 17 | static readonly code = 'ABORT_ERR' 18 | 19 | static readonly type = 'aborted' 20 | } 21 | 22 | export class CodeError = Record> extends Error { 23 | public readonly props: T 24 | 25 | constructor ( 26 | message: string, 27 | public readonly code: string, 28 | props?: T 29 | ) { 30 | super(message) 31 | 32 | this.name = props?.name ?? 'CodeError' 33 | this.props = props ?? {} as T // eslint-disable-line @typescript-eslint/consistent-type-assertions 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /packages/interface-mocks/src/connection-gater.ts: -------------------------------------------------------------------------------- 1 | import type { ConnectionGater } from '@libp2p/interface-connection-gater' 2 | 3 | export function mockConnectionGater (): ConnectionGater { 4 | return { 5 | denyDialPeer: async () => Promise.resolve(false), 6 | denyDialMultiaddr: async () => Promise.resolve(false), 7 | denyInboundConnection: async () => Promise.resolve(false), 8 | denyOutboundConnection: async () => Promise.resolve(false), 9 | denyInboundEncryptedConnection: async () => Promise.resolve(false), 10 | denyOutboundEncryptedConnection: async () => Promise.resolve(false), 11 | denyInboundUpgradedConnection: async () => Promise.resolve(false), 12 | denyOutboundUpgradedConnection: async () => Promise.resolve(false), 13 | denyInboundRelayReservation: async () => Promise.resolve(false), 14 | denyOutboundRelayedConnection: async () => Promise.resolve(false), 15 | denyInboundRelayedConnection: async () => Promise.resolve(false), 16 | filterMultiaddrForPeer: async () => Promise.resolve(true) 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /packages/interfaces/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /packages/interface-dht/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /packages/interface-keys/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /packages/interface-mocks/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /packages/interface-connection/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /packages/interface-keychain/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /packages/interface-libp2p/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /packages/interface-metrics/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /packages/interface-peer-id/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /packages/interface-peer-info/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /packages/interface-peer-store/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /packages/interface-pubsub/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /packages/interface-record/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /packages/interface-registrar/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /packages/interface-transport/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /packages/interface-address-manager/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /packages/interface-content-routing/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /packages/interface-peer-discovery/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /packages/interface-peer-routing/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /packages/interface-stream-muxer/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /packages/interface-compliance-tests/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /packages/interface-connection-encrypter/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /packages/interface-connection-gater/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /packages/interface-connection-manager/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /packages/interface-pubsub-compliance-tests/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /packages/interface-record-compliance-tests/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /packages/interface-connection-compliance-tests/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /packages/interface-stream-muxer-compliance-tests/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /packages/interface-transport-compliance-tests/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /packages/interface-peer-discovery-compliance-tests/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /packages/interface-pubsub-compliance-tests/src/utils.ts: -------------------------------------------------------------------------------- 1 | import { mockConnectionManager, mockRegistrar, mockNetwork } from '@libp2p/interface-mocks' 2 | import { createEd25519PeerId } from '@libp2p/peer-id-factory' 3 | import { pEvent } from 'p-event' 4 | import pWaitFor from 'p-wait-for' 5 | import type { MockNetworkComponents } from '@libp2p/interface-mocks' 6 | import type { PeerId } from '@libp2p/interface-peer-id' 7 | import type { PubSub, SubscriptionChangeData } from '@libp2p/interface-pubsub' 8 | 9 | export async function waitForSubscriptionUpdate (a: PubSub, b: PeerId): Promise { 10 | await pWaitFor(async () => { 11 | const event = await pEvent<'subscription-change', CustomEvent>(a, 'subscription-change') 12 | 13 | return event.detail.peerId.equals(b) 14 | }) 15 | } 16 | 17 | export async function createComponents (): Promise { 18 | const components: any = { 19 | peerId: await createEd25519PeerId(), 20 | registrar: mockRegistrar() 21 | } 22 | components.connectionManager = mockConnectionManager(components) 23 | 24 | mockNetwork.addNode(components) 25 | 26 | return components 27 | } 28 | -------------------------------------------------------------------------------- /packages/interface-connection-encrypter-compliance-tests/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /packages/interface-peer-id/src/index.ts: -------------------------------------------------------------------------------- 1 | import type { CID } from 'multiformats/cid' 2 | import type { MultihashDigest } from 'multiformats/hashes/interface' 3 | 4 | export type PeerIdType = 'RSA' | 'Ed25519' | 'secp256k1' 5 | 6 | interface BasePeerId { 7 | readonly type: PeerIdType 8 | readonly multihash: MultihashDigest 9 | readonly privateKey?: Uint8Array 10 | readonly publicKey?: Uint8Array 11 | 12 | toString: () => string 13 | toCID: () => CID 14 | toBytes: () => Uint8Array 15 | equals: (other: PeerId | Uint8Array | string) => boolean 16 | } 17 | 18 | export interface RSAPeerId extends BasePeerId { 19 | readonly type: 'RSA' 20 | readonly publicKey?: Uint8Array 21 | } 22 | 23 | export interface Ed25519PeerId extends BasePeerId { 24 | readonly type: 'Ed25519' 25 | readonly publicKey: Uint8Array 26 | } 27 | 28 | export interface Secp256k1PeerId extends BasePeerId { 29 | readonly type: 'secp256k1' 30 | readonly publicKey: Uint8Array 31 | } 32 | 33 | export type PeerId = RSAPeerId | Ed25519PeerId | Secp256k1PeerId 34 | 35 | export const symbol = Symbol.for('@libp2p/peer-id') 36 | 37 | export function isPeerId (other: any): other is PeerId { 38 | return other != null && Boolean(other[symbol]) 39 | } 40 | -------------------------------------------------------------------------------- /packages/interface-mocks/test/connection.spec.ts: -------------------------------------------------------------------------------- 1 | import tests from '@libp2p/interface-connection-compliance-tests' 2 | import { createEd25519PeerId } from '@libp2p/peer-id-factory' 3 | import { pipe } from 'it-pipe' 4 | import { connectionPair } from '../src/connection.js' 5 | import { mockRegistrar } from '../src/registrar.js' 6 | import type { Connection } from '@libp2p/interface-connection' 7 | 8 | describe('mock connection compliance tests', () => { 9 | let connections: Connection[] = [] 10 | 11 | tests({ 12 | async setup () { 13 | const componentsA = { 14 | peerId: await createEd25519PeerId(), 15 | registrar: mockRegistrar() 16 | } 17 | const componentsB = { 18 | peerId: await createEd25519PeerId(), 19 | registrar: mockRegistrar() 20 | } 21 | connections = connectionPair(componentsA, componentsB) 22 | 23 | await componentsB.registrar.handle('/echo/0.0.1', (data) => { 24 | void pipe( 25 | data.stream, 26 | data.stream 27 | ) 28 | }) 29 | 30 | return connections[0] 31 | }, 32 | async teardown () { 33 | await Promise.all(connections.map(async conn => { 34 | await conn.close() 35 | })) 36 | } 37 | }) 38 | }) 39 | -------------------------------------------------------------------------------- /packages/interface-keys/src/index.ts: -------------------------------------------------------------------------------- 1 | 2 | export interface PublicKey { 3 | readonly bytes: Uint8Array 4 | verify: (data: Uint8Array, sig: Uint8Array) => Promise 5 | marshal: () => Uint8Array 6 | equals: (key: PublicKey) => boolean 7 | hash: () => Promise 8 | } 9 | 10 | /** 11 | * Generic private key interface 12 | */ 13 | export interface PrivateKey { 14 | readonly public: PublicKey 15 | readonly bytes: Uint8Array 16 | sign: (data: Uint8Array) => Promise 17 | marshal: () => Uint8Array 18 | equals: (key: PrivateKey) => boolean 19 | hash: () => Promise 20 | /** 21 | * Gets the ID of the key. 22 | * 23 | * The key id is the base58 encoding of the SHA-256 multihash of its public key. 24 | * The public key is a protobuf encoding containing a type and the DER encoding 25 | * of the PKCS SubjectPublicKeyInfo. 26 | */ 27 | id: () => Promise 28 | /** 29 | * Exports the password protected key in the format specified. 30 | */ 31 | export: (password: string, format?: 'pkcs-8' | string) => Promise 32 | } 33 | 34 | export const Ed25519 = 'Ed25519' 35 | export const RSA = 'RSA' 36 | export const secp256k1 = 'secp256k1' 37 | 38 | export type KeyType = typeof Ed25519 | typeof RSA | typeof secp256k1 39 | -------------------------------------------------------------------------------- /packages/interface-pubsub-compliance-tests/src/index.ts: -------------------------------------------------------------------------------- 1 | import apiTest from './api.js' 2 | import connectionHandlersTest from './connection-handlers.js' 3 | import emitSelfTest from './emit-self.js' 4 | import messagesTest from './messages.js' 5 | import multipleNodesTest from './multiple-nodes.js' 6 | import twoNodesTest from './two-nodes.js' 7 | import type { TestSetup } from '@libp2p/interface-compliance-tests' 8 | import type { ConnectionManager } from '@libp2p/interface-connection-manager' 9 | import type { PeerId } from '@libp2p/interface-peer-id' 10 | import type { PubSub, PubSubInit } from '@libp2p/interface-pubsub' 11 | import type { Registrar } from '@libp2p/interface-registrar' 12 | 13 | export interface PubSubComponents { 14 | peerId: PeerId 15 | registrar: Registrar 16 | connectionManager: ConnectionManager 17 | pubsub?: PubSub 18 | } 19 | 20 | export interface PubSubArgs { 21 | components: PubSubComponents 22 | init: PubSubInit 23 | } 24 | 25 | export default (common: TestSetup): void => { 26 | describe('interface-pubsub compliance tests', () => { 27 | apiTest(common) 28 | emitSelfTest(common) 29 | messagesTest(common) 30 | connectionHandlersTest(common) 31 | twoNodesTest(common) 32 | multipleNodesTest(common) 33 | }) 34 | } 35 | -------------------------------------------------------------------------------- /packages/interface-address-manager/src/index.ts: -------------------------------------------------------------------------------- 1 | import type { Multiaddr } from '@multiformats/multiaddr' 2 | 3 | export interface AddressManager { 4 | /** 5 | * Get peer listen multiaddrs 6 | */ 7 | getListenAddrs: () => Multiaddr[] 8 | 9 | /** 10 | * Get peer announcing multiaddrs 11 | */ 12 | getAnnounceAddrs: () => Multiaddr[] 13 | 14 | /** 15 | * Get observed multiaddrs - these addresses may not have been confirmed as 16 | * publicly dialable yet 17 | */ 18 | getObservedAddrs: () => Multiaddr[] 19 | 20 | /** 21 | * Signal that we have confidence an observed multiaddr is publicly dialable - 22 | * this will make it appear in the output of getAddresses() 23 | */ 24 | confirmObservedAddr: (addr: Multiaddr) => void 25 | 26 | /** 27 | * Signal that we do not have confidence an observed multiaddr is publicly dialable - 28 | * this will remove it from the output of getObservedAddrs() 29 | */ 30 | removeObservedAddr: (addr: Multiaddr) => void 31 | 32 | /** 33 | * Add peer observed addresses. These will then appear in the output of getObservedAddrs 34 | * but not getAddresses() until their dialability has been confirmed via a call to 35 | * confirmObservedAddr. 36 | */ 37 | addObservedAddr: (addr: Multiaddr) => void 38 | 39 | /** 40 | * Get the current node's addresses 41 | */ 42 | getAddresses: () => Multiaddr[] 43 | } 44 | -------------------------------------------------------------------------------- /packages/interface-connection-encrypter/src/index.ts: -------------------------------------------------------------------------------- 1 | import type { PeerId } from '@libp2p/interface-peer-id' 2 | import type { Duplex, Source } from 'it-stream-types' 3 | 4 | /** 5 | * A libp2p connection encrypter module must be compliant to this interface 6 | * to ensure all exchanged data between two peers is encrypted. 7 | */ 8 | export interface ConnectionEncrypter { 9 | protocol: string 10 | 11 | /** 12 | * Encrypt outgoing data to the remote party. If the remote PeerId is known, 13 | * pass it for extra verification, otherwise it will be determined during 14 | * the handshake. 15 | */ 16 | secureOutbound: (localPeer: PeerId, connection: Duplex, Source, Promise>, remotePeer?: PeerId) => Promise> 17 | 18 | /** 19 | * Decrypt incoming data. If the remote PeerId is known, 20 | * pass it for extra verification, otherwise it will be determined during 21 | * the handshake 22 | */ 23 | secureInbound: (localPeer: PeerId, connection: Duplex, Source, Promise>, remotePeer?: PeerId) => Promise> 24 | } 25 | 26 | export interface SecuredConnection { 27 | conn: Duplex, Source, Promise> 28 | remoteExtensions?: Extension 29 | remotePeer: PeerId 30 | } 31 | -------------------------------------------------------------------------------- /packages/interface-mocks/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "aegir/src/config/tsconfig.aegir.json", 3 | "compilerOptions": { 4 | "outDir": "dist" 5 | }, 6 | "include": [ 7 | "src", 8 | "test" 9 | ], 10 | "references": [ 11 | { 12 | "path": "../interface-connection" 13 | }, 14 | { 15 | "path": "../interface-connection-compliance-tests" 16 | }, 17 | { 18 | "path": "../interface-connection-encrypter" 19 | }, 20 | { 21 | "path": "../interface-connection-encrypter-compliance-tests" 22 | }, 23 | { 24 | "path": "../interface-connection-gater" 25 | }, 26 | { 27 | "path": "../interface-connection-manager" 28 | }, 29 | { 30 | "path": "../interface-libp2p" 31 | }, 32 | { 33 | "path": "../interface-metrics" 34 | }, 35 | { 36 | "path": "../interface-peer-discovery" 37 | }, 38 | { 39 | "path": "../interface-peer-discovery-compliance-tests" 40 | }, 41 | { 42 | "path": "../interface-peer-id" 43 | }, 44 | { 45 | "path": "../interface-peer-info" 46 | }, 47 | { 48 | "path": "../interface-pubsub" 49 | }, 50 | { 51 | "path": "../interface-registrar" 52 | }, 53 | { 54 | "path": "../interface-stream-muxer" 55 | }, 56 | { 57 | "path": "../interface-stream-muxer-compliance-tests" 58 | }, 59 | { 60 | "path": "../interface-transport" 61 | }, 62 | { 63 | "path": "../interfaces" 64 | } 65 | ] 66 | } 67 | -------------------------------------------------------------------------------- /packages/interface-dht/README.md: -------------------------------------------------------------------------------- 1 | # @libp2p/interface-dht 2 | 3 | [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) 4 | [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) 5 | [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-interfaces.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-interfaces) 6 | [![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p-interfaces/js-test-and-release.yml?branch=master\&style=flat-square)](https://github.com/libp2p/js-libp2p-interfaces/actions/workflows/js-test-and-release.yml?query=branch%3Amaster) 7 | 8 | > DHT interface for libp2p 9 | 10 | ## Table of contents 11 | 12 | - [Install](#install) 13 | - [API Docs](#api-docs) 14 | - [License](#license) 15 | - [Contribution](#contribution) 16 | 17 | ## Install 18 | 19 | ```console 20 | $ npm i @libp2p/interface-dht 21 | ``` 22 | 23 | ## API Docs 24 | 25 | - 26 | 27 | ## License 28 | 29 | Licensed under either of 30 | 31 | - Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) 32 | - MIT ([LICENSE-MIT](LICENSE-MIT) / ) 33 | 34 | ## Contribution 35 | 36 | 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. 37 | -------------------------------------------------------------------------------- /packages/interface-libp2p/README.md: -------------------------------------------------------------------------------- 1 | # @libp2p/interface-libp2p 2 | 3 | [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) 4 | [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) 5 | [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-interfaces.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-interfaces) 6 | [![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p-interfaces/js-test-and-release.yml?branch=master\&style=flat-square)](https://github.com/libp2p/js-libp2p-interfaces/actions/workflows/js-test-and-release.yml?query=branch%3Amaster) 7 | 8 | > The interface implemented by a libp2p node 9 | 10 | ## Table of contents 11 | 12 | - [Install](#install) 13 | - [API Docs](#api-docs) 14 | - [License](#license) 15 | - [Contribution](#contribution) 16 | 17 | ## Install 18 | 19 | ```console 20 | $ npm i @libp2p/interface-libp2p 21 | ``` 22 | 23 | ## API Docs 24 | 25 | - 26 | 27 | ## License 28 | 29 | Licensed under either of 30 | 31 | - Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) 32 | - MIT ([LICENSE-MIT](LICENSE-MIT) / ) 33 | 34 | ## Contribution 35 | 36 | 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. 37 | -------------------------------------------------------------------------------- /packages/interface-peer-info/README.md: -------------------------------------------------------------------------------- 1 | # @libp2p/interface-peer-info 2 | 3 | [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) 4 | [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) 5 | [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-interfaces.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-interfaces) 6 | [![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p-interfaces/js-test-and-release.yml?branch=master\&style=flat-square)](https://github.com/libp2p/js-libp2p-interfaces/actions/workflows/js-test-and-release.yml?query=branch%3Amaster) 7 | 8 | > Peer Info interface for libp2p 9 | 10 | ## Table of contents 11 | 12 | - [Install](#install) 13 | - [API Docs](#api-docs) 14 | - [License](#license) 15 | - [Contribution](#contribution) 16 | 17 | ## Install 18 | 19 | ```console 20 | $ npm i @libp2p/interface-peer-info 21 | ``` 22 | 23 | ## API Docs 24 | 25 | - 26 | 27 | ## License 28 | 29 | Licensed under either of 30 | 31 | - Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) 32 | - MIT ([LICENSE-MIT](LICENSE-MIT) / ) 33 | 34 | ## Contribution 35 | 36 | 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. 37 | -------------------------------------------------------------------------------- /packages/interface-registrar/README.md: -------------------------------------------------------------------------------- 1 | # @libp2p/interface-registrar 2 | 3 | [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) 4 | [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) 5 | [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-interfaces.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-interfaces) 6 | [![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p-interfaces/js-test-and-release.yml?branch=master\&style=flat-square)](https://github.com/libp2p/js-libp2p-interfaces/actions/workflows/js-test-and-release.yml?query=branch%3Amaster) 7 | 8 | > Registrar interface for libp2p 9 | 10 | ## Table of contents 11 | 12 | - [Install](#install) 13 | - [API Docs](#api-docs) 14 | - [License](#license) 15 | - [Contribution](#contribution) 16 | 17 | ## Install 18 | 19 | ```console 20 | $ npm i @libp2p/interface-registrar 21 | ``` 22 | 23 | ## API Docs 24 | 25 | - 26 | 27 | ## License 28 | 29 | Licensed under either of 30 | 31 | - Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) 32 | - MIT ([LICENSE-MIT](LICENSE-MIT) / ) 33 | 34 | ## Contribution 35 | 36 | 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. 37 | -------------------------------------------------------------------------------- /packages/interface-stream-muxer-compliance-tests/src/stress-test.ts: -------------------------------------------------------------------------------- 1 | import spawn from './spawner.js' 2 | import type { TestSetup } from '@libp2p/interface-compliance-tests' 3 | import type { StreamMuxerFactory, StreamMuxerInit, StreamMuxer } from '@libp2p/interface-stream-muxer' 4 | 5 | export default (common: TestSetup): void => { 6 | const createMuxer = async (init?: StreamMuxerInit): Promise => { 7 | const factory = await common.setup() 8 | return factory.createStreamMuxer(init) 9 | } 10 | 11 | describe('stress test', function () { 12 | this.timeout(800000) 13 | 14 | it('1 stream with 1 msg', async () => { await spawn(createMuxer, 1, 1) }) 15 | it('1 stream with 10 msg', async () => { await spawn(createMuxer, 1, 10) }) 16 | it('1 stream with 100 msg', async () => { await spawn(createMuxer, 1, 100) }) 17 | it('10 streams with 1 msg', async () => { await spawn(createMuxer, 10, 1) }) 18 | it('10 streams with 10 msg', async () => { await spawn(createMuxer, 10, 10) }) 19 | it('10 streams with 100 msg', async () => { await spawn(createMuxer, 10, 100) }) 20 | it('100 streams with 1 msg', async () => { await spawn(createMuxer, 100, 1) }) 21 | it('100 streams with 10 msg', async () => { await spawn(createMuxer, 100, 10) }) 22 | it('100 streams with 100 msg', async () => { await spawn(createMuxer, 100, 100) }) 23 | it('1000 streams with 1 msg', async () => { await spawn(createMuxer, 1000, 1) }) 24 | it('1000 streams with 10 msg', async () => { await spawn(createMuxer, 1000, 10) }) 25 | it('1000 streams with 100 msg', async () => { await spawn(createMuxer, 1000, 100) }) 26 | }) 27 | } 28 | -------------------------------------------------------------------------------- /packages/interface-connection-gater/README.md: -------------------------------------------------------------------------------- 1 | # @libp2p/interface-connection-gater 2 | 3 | [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) 4 | [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) 5 | [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-interfaces.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-interfaces) 6 | [![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p-interfaces/js-test-and-release.yml?branch=master\&style=flat-square)](https://github.com/libp2p/js-libp2p-interfaces/actions/workflows/js-test-and-release.yml?query=branch%3Amaster) 7 | 8 | > Connection gater interface for libp2p 9 | 10 | ## Table of contents 11 | 12 | - [Install](#install) 13 | - [API Docs](#api-docs) 14 | - [License](#license) 15 | - [Contribution](#contribution) 16 | 17 | ## Install 18 | 19 | ```console 20 | $ npm i @libp2p/interface-connection-gater 21 | ``` 22 | 23 | ## API Docs 24 | 25 | - 26 | 27 | ## License 28 | 29 | Licensed under either of 30 | 31 | - Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) 32 | - MIT ([LICENSE-MIT](LICENSE-MIT) / ) 33 | 34 | ## Contribution 35 | 36 | 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. 37 | -------------------------------------------------------------------------------- /packages/interface-peer-routing/src/index.ts: -------------------------------------------------------------------------------- 1 | import type { PeerId } from '@libp2p/interface-peer-id' 2 | import type { PeerInfo } from '@libp2p/interface-peer-info' 3 | import type { AbortOptions } from '@libp2p/interfaces' 4 | 5 | /** 6 | * Any object that implements this Symbol as a property should return a 7 | * PeerRouting instance as the property value, similar to how 8 | * `Symbol.Iterable` can be used to return an `Iterable` from an `Iterator`. 9 | * 10 | * @example 11 | * 12 | * ```js 13 | * import { peerRouting, PeerRouting } from '@libp2p/peer-routing' 14 | * 15 | * class MyPeerRouter implements PeerRouting { 16 | * get [peerRouting] () { 17 | * return this 18 | * } 19 | * 20 | * // ...other methods 21 | * } 22 | * ``` 23 | */ 24 | export const peerRouting = Symbol.for('@libp2p/peer-routing') 25 | 26 | export interface PeerRouting { 27 | /** 28 | * Searches the network for peer info corresponding to the passed peer id. 29 | * 30 | * @example 31 | * 32 | * ```js 33 | * // ... 34 | * const peer = await peerRouting.findPeer(peerId, options) 35 | * ``` 36 | */ 37 | findPeer: (peerId: PeerId, options?: AbortOptions) => Promise 38 | 39 | /** 40 | * Search the network for peers that are closer to the passed key. Peer 41 | * info should be yielded in ever-increasing closeness to the key. 42 | * 43 | * @example 44 | * 45 | * ```js 46 | * // Iterate over the closest peers found for the given key 47 | * for await (const peer of peerRouting.getClosestPeers(key)) { 48 | * console.log(peer.id, peer.multiaddrs) 49 | * } 50 | * ``` 51 | */ 52 | getClosestPeers: (key: Uint8Array, options?: AbortOptions) => AsyncIterable 53 | } 54 | -------------------------------------------------------------------------------- /packages/interface-mocks/src/peer-discovery.ts: -------------------------------------------------------------------------------- 1 | import { peerDiscovery } from '@libp2p/interface-peer-discovery' 2 | import { EventEmitter } from '@libp2p/interfaces/events' 3 | import * as PeerIdFactory from '@libp2p/peer-id-factory' 4 | import { multiaddr } from '@multiformats/multiaddr' 5 | import type { PeerDiscovery, PeerDiscoveryEvents } from '@libp2p/interface-peer-discovery' 6 | import type { PeerInfo } from '@libp2p/interface-peer-info' 7 | 8 | interface MockDiscoveryInit { 9 | discoveryDelay?: number 10 | } 11 | 12 | /** 13 | * Emits 'peer' events on discovery. 14 | */ 15 | export class MockDiscovery extends EventEmitter implements PeerDiscovery { 16 | public readonly options: MockDiscoveryInit 17 | private _isRunning: boolean 18 | private _timer: any 19 | 20 | constructor (init = {}) { 21 | super() 22 | 23 | this.options = init 24 | this._isRunning = false 25 | } 26 | 27 | readonly [peerDiscovery] = this 28 | 29 | start (): void { 30 | this._isRunning = true 31 | this._discoverPeer() 32 | } 33 | 34 | stop (): void { 35 | clearTimeout(this._timer) 36 | this._isRunning = false 37 | } 38 | 39 | isStarted (): boolean { 40 | return this._isRunning 41 | } 42 | 43 | _discoverPeer (): void { 44 | if (!this._isRunning) return 45 | 46 | PeerIdFactory.createEd25519PeerId() 47 | .then(peerId => { 48 | this._timer = setTimeout(() => { 49 | this.safeDispatchEvent('peer', { 50 | detail: { 51 | id: peerId, 52 | multiaddrs: [multiaddr('/ip4/127.0.0.1/tcp/8000')], 53 | protocols: [] 54 | } 55 | }) 56 | }, this.options.discoveryDelay ?? 1000) 57 | }) 58 | .catch(() => {}) 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /packages/interface-mocks/src/upgrader.ts: -------------------------------------------------------------------------------- 1 | import { mockConnection } from './connection.js' 2 | import type { Connection, MultiaddrConnection } from '@libp2p/interface-connection' 3 | import type { Libp2pEvents } from '@libp2p/interface-libp2p' 4 | import type { Registrar } from '@libp2p/interface-registrar' 5 | import type { Upgrader, UpgraderOptions } from '@libp2p/interface-transport' 6 | import type { EventEmitter } from '@libp2p/interfaces/events' 7 | 8 | export interface MockUpgraderInit { 9 | registrar?: Registrar 10 | events?: EventEmitter 11 | } 12 | 13 | class MockUpgrader implements Upgrader { 14 | private readonly registrar?: Registrar 15 | private readonly events?: EventEmitter 16 | 17 | constructor (init: MockUpgraderInit) { 18 | this.registrar = init.registrar 19 | this.events = init.events 20 | } 21 | 22 | async upgradeOutbound (multiaddrConnection: MultiaddrConnection, opts: UpgraderOptions = {}): Promise { 23 | const connection = mockConnection(multiaddrConnection, { 24 | direction: 'outbound', 25 | registrar: this.registrar, 26 | ...opts 27 | }) 28 | 29 | this.events?.safeDispatchEvent('connection:open', { detail: connection }) 30 | 31 | return connection 32 | } 33 | 34 | async upgradeInbound (multiaddrConnection: MultiaddrConnection, opts: UpgraderOptions = {}): Promise { 35 | const connection = mockConnection(multiaddrConnection, { 36 | direction: 'inbound', 37 | registrar: this.registrar, 38 | ...opts 39 | }) 40 | 41 | this.events?.safeDispatchEvent('connection:open', { detail: connection }) 42 | 43 | return connection 44 | } 45 | } 46 | 47 | export function mockUpgrader (init: MockUpgraderInit = {}): Upgrader { 48 | return new MockUpgrader(init) 49 | } 50 | -------------------------------------------------------------------------------- /packages/interface-metrics/README.md: -------------------------------------------------------------------------------- 1 | # @libp2p/interface-metrics 2 | 3 | [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) 4 | [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) 5 | [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-interfaces.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-interfaces) 6 | [![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p-interfaces/js-test-and-release.yml?branch=master\&style=flat-square)](https://github.com/libp2p/js-libp2p-interfaces/actions/workflows/js-test-and-release.yml?query=branch%3Amaster) 7 | 8 | > Metrics interface for libp2p 9 | 10 | ## Table of contents 11 | 12 | - [Install](#install) 13 | - [Implementations](#implementations) 14 | - [API Docs](#api-docs) 15 | - [License](#license) 16 | - [Contribution](#contribution) 17 | 18 | ## Install 19 | 20 | ```console 21 | $ npm i @libp2p/interface-metrics 22 | ``` 23 | 24 | ## Implementations 25 | 26 | - [@libp2p/prometheus-metrics](https://github.com/libp2p/js-libp2p-prometheus-metrics) 27 | 28 | ## API Docs 29 | 30 | - 31 | 32 | ## License 33 | 34 | Licensed under either of 35 | 36 | - Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) 37 | - MIT ([LICENSE-MIT](LICENSE-MIT) / ) 38 | 39 | ## Contribution 40 | 41 | 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. 42 | -------------------------------------------------------------------------------- /packages/interface-address-manager/README.md: -------------------------------------------------------------------------------- 1 | # @libp2p/interface-address-manager 2 | 3 | [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) 4 | [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) 5 | [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-interfaces.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-interfaces) 6 | [![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p-interfaces/js-test-and-release.yml?branch=master\&style=flat-square)](https://github.com/libp2p/js-libp2p-interfaces/actions/workflows/js-test-and-release.yml?query=branch%3Amaster) 7 | 8 | > Address Manager interface for libp2p 9 | 10 | ## Table of contents 11 | 12 | - [Install](#install) 13 | - [Usage](#usage) 14 | - [API Docs](#api-docs) 15 | - [License](#license) 16 | - [Contribution](#contribution) 17 | 18 | ## Install 19 | 20 | ```console 21 | $ npm i @libp2p/interface-address-manager 22 | ``` 23 | 24 | ## Usage 25 | 26 | ```js 27 | import type { AddressManager } from '@libp2p/interfaces-address-manager' 28 | ``` 29 | 30 | ## API Docs 31 | 32 | - 33 | 34 | ## License 35 | 36 | Licensed under either of 37 | 38 | - Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) 39 | - MIT ([LICENSE-MIT](LICENSE-MIT) / ) 40 | 41 | ## Contribution 42 | 43 | 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. 44 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "js-libp2p-interfaces", 3 | "version": "1.0.0", 4 | "description": "Contains test suites and interfaces you can use to implement the various components of libp2p", 5 | "license": "Apache-2.0 OR MIT", 6 | "homepage": "https://github.com/libp2p/js-libp2p-interfaces#readme", 7 | "repository": { 8 | "type": "git", 9 | "url": "git+https://github.com/libp2p/js-libp2p-interfaces.git" 10 | }, 11 | "bugs": { 12 | "url": "https://github.com/libp2p/js-libp2p-interfaces/issues" 13 | }, 14 | "keywords": [ 15 | "interface", 16 | "libp2p" 17 | ], 18 | "engines": { 19 | "node": ">=16.0.0", 20 | "npm": ">=7.0.0" 21 | }, 22 | "private": true, 23 | "scripts": { 24 | "reset": "aegir run clean && aegir clean ./node_modules ./package-lock.json packages/*/node_modules packages/*/package-lock.json packages/*/dist", 25 | "test": "aegir run test", 26 | "test:node": "aegir run test:node", 27 | "test:chrome": "aegir run test:chrome", 28 | "test:chrome-webworker": "aegir run test:chrome-webworker", 29 | "test:firefox": "aegir run test:firefox", 30 | "test:firefox-webworker": "aegir run test:firefox-webworker", 31 | "test:electron-main": "aegir run test:electron-main", 32 | "test:electron-renderer": "aegir run test:electron-renderer", 33 | "clean": "aegir run clean", 34 | "generate": "aegir run generate", 35 | "build": "aegir run build", 36 | "lint": "aegir run lint", 37 | "docs": "NODE_OPTIONS=--max_old_space_size=4096 aegir docs", 38 | "docs:no-publish": "npm run docs -- --publish false", 39 | "dep-check": "aegir run dep-check", 40 | "release": "npm run docs:no-publish && aegir run release && npm run docs" 41 | }, 42 | "dependencies": { 43 | "aegir": "^39.0.5" 44 | }, 45 | "workspaces": [ 46 | "packages/*" 47 | ] 48 | } 49 | -------------------------------------------------------------------------------- /packages/interface-connection-manager/README.md: -------------------------------------------------------------------------------- 1 | # @libp2p/interface-connection-manager 2 | 3 | [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) 4 | [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) 5 | [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-interfaces.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-interfaces) 6 | [![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p-interfaces/js-test-and-release.yml?branch=master\&style=flat-square)](https://github.com/libp2p/js-libp2p-interfaces/actions/workflows/js-test-and-release.yml?query=branch%3Amaster) 7 | 8 | > Connection Manager interface for libp2p 9 | 10 | ## Table of contents 11 | 12 | - [Install](#install) 13 | - [Usage](#usage) 14 | - [API Docs](#api-docs) 15 | - [License](#license) 16 | - [Contribution](#contribution) 17 | 18 | ## Install 19 | 20 | ```console 21 | $ npm i @libp2p/interface-connection-manager 22 | ``` 23 | 24 | ## Usage 25 | 26 | ```js 27 | import type { ConnectionManager } from '@libp2p/interface-connection-manager' 28 | ``` 29 | 30 | ## API Docs 31 | 32 | - 33 | 34 | ## License 35 | 36 | Licensed under either of 37 | 38 | - Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) 39 | - MIT ([LICENSE-MIT](LICENSE-MIT) / ) 40 | 41 | ## Contribution 42 | 43 | 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. 44 | -------------------------------------------------------------------------------- /packages/interface-stream-muxer-compliance-tests/src/spawner.ts: -------------------------------------------------------------------------------- 1 | import { expect } from 'aegir/chai' 2 | import all from 'it-all' 3 | import drain from 'it-drain' 4 | import { duplexPair } from 'it-pair/duplex' 5 | import { pipe } from 'it-pipe' 6 | import pLimit from 'p-limit' 7 | import { Uint8ArrayList } from 'uint8arraylist' 8 | import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' 9 | import type { StreamMuxer, StreamMuxerInit } from '@libp2p/interface-stream-muxer' 10 | 11 | export default async (createMuxer: (init?: StreamMuxerInit) => Promise, nStreams: number, nMsg: number, limit?: number): Promise => { 12 | const [dialerSocket, listenerSocket] = duplexPair() 13 | 14 | const msg = new Uint8ArrayList(uint8ArrayFromString('simple msg')) 15 | 16 | const listener = await createMuxer({ 17 | direction: 'inbound', 18 | onIncomingStream: (stream) => { 19 | void pipe( 20 | stream, 21 | drain 22 | ).then(() => { 23 | stream.close() 24 | }) 25 | } 26 | }) 27 | const dialer = await createMuxer({ direction: 'outbound' }) 28 | 29 | void pipe(listenerSocket, listener, listenerSocket) 30 | void pipe(dialerSocket, dialer, dialerSocket) 31 | 32 | const spawnStream = async (): Promise => { 33 | const stream = await dialer.newStream() 34 | expect(stream).to.exist // eslint-disable-line 35 | 36 | const res = await pipe( 37 | (async function * () { 38 | for (let i = 0; i < nMsg; i++) { 39 | yield msg 40 | } 41 | }()), 42 | stream, 43 | async (source) => all(source) 44 | ) 45 | 46 | expect(res).to.be.eql([]) 47 | } 48 | 49 | const limiter = pLimit(limit ?? Infinity) 50 | 51 | await Promise.all( 52 | Array.from(Array(nStreams), async () => { await limiter(async () => { await spawnStream() }) }) 53 | ) 54 | } 55 | -------------------------------------------------------------------------------- /packages/interface-stream-muxer/src/index.ts: -------------------------------------------------------------------------------- 1 | import type { Direction, Stream } from '@libp2p/interface-connection' 2 | import type { AbortOptions } from '@libp2p/interfaces' 3 | import type { Duplex, Source } from 'it-stream-types' 4 | import type { Uint8ArrayList } from 'uint8arraylist' 5 | 6 | export interface StreamMuxerFactory { 7 | /** 8 | * The protocol used to select this muxer during connection opening 9 | */ 10 | protocol: string 11 | 12 | /** 13 | * Creates a new stream muxer to be used with a new connection 14 | */ 15 | createStreamMuxer: (init?: StreamMuxerInit) => StreamMuxer 16 | } 17 | 18 | /** 19 | * A libp2p stream muxer 20 | */ 21 | export interface StreamMuxer extends Duplex, Source, Promise> { 22 | /** 23 | * The protocol used to select this muxer during connection opening 24 | */ 25 | protocol: string 26 | 27 | /** 28 | * A list of streams that are currently open. Closed streams will not be returned. 29 | */ 30 | readonly streams: Stream[] 31 | /** 32 | * Initiate a new stream with the given name. If no name is 33 | * provided, the id of the stream will be used. 34 | */ 35 | newStream: (name?: string) => Stream | Promise 36 | 37 | /** 38 | * Close or abort all tracked streams and stop the muxer 39 | */ 40 | close: (err?: Error) => void 41 | } 42 | 43 | export interface StreamMuxerInit extends AbortOptions { 44 | /** 45 | * A callback function invoked every time an incoming stream is opened 46 | */ 47 | onIncomingStream?: (stream: Stream) => void 48 | 49 | /** 50 | * A callback function invoke every time a stream ends 51 | */ 52 | onStreamEnd?: (stream: Stream) => void 53 | 54 | /** 55 | * Outbound stream muxers are opened by the local node, inbound stream muxers are opened by the remote 56 | */ 57 | direction?: Direction 58 | } 59 | -------------------------------------------------------------------------------- /packages/interface-compliance-tests/README.md: -------------------------------------------------------------------------------- 1 | # @libp2p/interface-compliance-tests 2 | 3 | [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) 4 | [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) 5 | [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-interfaces.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-interfaces) 6 | [![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p-interfaces/js-test-and-release.yml?branch=master\&style=flat-square)](https://github.com/libp2p/js-libp2p-interfaces/actions/workflows/js-test-and-release.yml?query=branch%3Amaster) 7 | 8 | > Compliance tests for JS libp2p interfaces 9 | 10 | ## Table of contents 11 | 12 | - [Install](#install) 13 | - [Usage](#usage) 14 | - [API Docs](#api-docs) 15 | - [License](#license) 16 | - [Contribution](#contribution) 17 | 18 | ## Install 19 | 20 | ```console 21 | $ npm i @libp2p/interface-compliance-tests 22 | ``` 23 | 24 | ## Usage 25 | 26 | Each [interface](https://npmjs.org/packages/@libp2p/interfaces) has its documentation on how to use the compliance tests and should be used as the source of truth. 27 | 28 | ## API Docs 29 | 30 | - 31 | 32 | ## License 33 | 34 | Licensed under either of 35 | 36 | - Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) 37 | - MIT ([LICENSE-MIT](LICENSE-MIT) / ) 38 | 39 | ## Contribution 40 | 41 | 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. 42 | -------------------------------------------------------------------------------- /packages/interface-peer-store/README.md: -------------------------------------------------------------------------------- 1 | # @libp2p/interface-peer-store 2 | 3 | [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) 4 | [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) 5 | [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-interfaces.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-interfaces) 6 | [![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p-interfaces/js-test-and-release.yml?branch=master\&style=flat-square)](https://github.com/libp2p/js-libp2p-interfaces/actions/workflows/js-test-and-release.yml?query=branch%3Amaster) 7 | 8 | > Peer Store interface for libp2p 9 | 10 | ## Table of contents 11 | 12 | - [Install](#install) 13 | - [Usage](#usage) 14 | - [Tags](#tags) 15 | - [API Docs](#api-docs) 16 | - [License](#license) 17 | - [Contribution](#contribution) 18 | 19 | ## Install 20 | 21 | ```console 22 | $ npm i @libp2p/interface-peer-store 23 | ``` 24 | 25 | ## Usage 26 | 27 | ### Tags 28 | 29 | Common tags can be imported from the `@libp2p/interface-peer-store/tag` module: 30 | 31 | ```js 32 | import { KEEP_ALIVE } from '@libp2p/interface-peer-store/tags' 33 | 34 | await peerStore.tagPeer(peerId, KEEP_ALIVE) 35 | ``` 36 | 37 | ## API Docs 38 | 39 | - 40 | 41 | ## License 42 | 43 | Licensed under either of 44 | 45 | - Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) 46 | - MIT ([LICENSE-MIT](LICENSE-MIT) / ) 47 | 48 | ## Contribution 49 | 50 | 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. 51 | -------------------------------------------------------------------------------- /packages/interface-pubsub-compliance-tests/src/messages.ts: -------------------------------------------------------------------------------- 1 | import { mockNetwork } from '@libp2p/interface-mocks' 2 | import { start, stop } from '@libp2p/interfaces/startable' 3 | import { expect } from 'aegir/chai' 4 | import { pEvent } from 'p-event' 5 | import sinon from 'sinon' 6 | import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' 7 | import { createComponents } from './utils.js' 8 | import type { PubSubArgs, PubSubComponents } from './index.js' 9 | import type { TestSetup } from '@libp2p/interface-compliance-tests' 10 | import type { Message, PubSub } from '@libp2p/interface-pubsub' 11 | 12 | const topic = 'foo' 13 | const data = uint8ArrayFromString('bar') 14 | 15 | export default (common: TestSetup): void => { 16 | describe('messages', () => { 17 | let pubsub: PubSub 18 | let components: PubSubComponents 19 | 20 | // Create pubsub router 21 | beforeEach(async () => { 22 | mockNetwork.reset() 23 | components = await createComponents() 24 | 25 | pubsub = components.pubsub = await common.setup({ 26 | components, 27 | init: { 28 | emitSelf: true 29 | } 30 | }) 31 | await start(...Object.values(components)) 32 | }) 33 | 34 | afterEach(async () => { 35 | sinon.restore() 36 | await stop(...Object.values(components)) 37 | await common.teardown() 38 | mockNetwork.reset() 39 | }) 40 | 41 | it('should emit normalized signed messages on publish', async () => { 42 | const eventPromise = pEvent<'message', CustomEvent>(pubsub, 'message') 43 | 44 | pubsub.globalSignaturePolicy = 'StrictSign' 45 | pubsub.subscribe(topic) 46 | await pubsub.publish(topic, data) 47 | 48 | const event = await eventPromise 49 | const message = event.detail 50 | 51 | if (message.type === 'signed') { 52 | expect(message.from.toString()).to.equal(components.peerId.toString()) 53 | expect(message.sequenceNumber).to.not.eql(undefined) 54 | expect(message.key).to.not.eql(undefined) 55 | expect(message.signature).to.not.eql(undefined) 56 | } 57 | }) 58 | }) 59 | } 60 | -------------------------------------------------------------------------------- /packages/interface-mocks/README.md: -------------------------------------------------------------------------------- 1 | # @libp2p/interface-mocks 2 | 3 | [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) 4 | [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) 5 | [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-interfaces.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-interfaces) 6 | [![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p-interfaces/js-test-and-release.yml?branch=master\&style=flat-square)](https://github.com/libp2p/js-libp2p-interfaces/actions/workflows/js-test-and-release.yml?query=branch%3Amaster) 7 | 8 | > Mock implementations of several libp2p interfaces 9 | 10 | ## Table of contents 11 | 12 | - [Install](#install) 13 | - [Browser ` 31 | ``` 32 | 33 | ## Usage 34 | 35 | Each [interface](../interfaces) has its documentation on how to use the compliance tests and should be used as the source of truth. 36 | 37 | ## API Docs 38 | 39 | - 40 | 41 | ## License 42 | 43 | Licensed under either of 44 | 45 | - Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) 46 | - MIT ([LICENSE-MIT](LICENSE-MIT) / ) 47 | 48 | ## Contribution 49 | 50 | 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. 51 | -------------------------------------------------------------------------------- /packages/interface-keys/README.md: -------------------------------------------------------------------------------- 1 | # @libp2p/interface-keys 2 | 3 | [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) 4 | [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) 5 | [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-interfaces.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-interfaces) 6 | [![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p-interfaces/js-test-and-release.yml?branch=master\&style=flat-square)](https://github.com/libp2p/js-libp2p-interfaces/actions/workflows/js-test-and-release.yml?query=branch%3Amaster) 7 | 8 | > Keys interface for libp2p 9 | 10 | ## Table of contents 11 | 12 | - [Install](#install) 13 | - [Using the Test Suite](#using-the-test-suite) 14 | - [API Docs](#api-docs) 15 | - [License](#license) 16 | - [Contribution](#contribution) 17 | 18 | ## Install 19 | 20 | ```console 21 | $ npm i @libp2p/interface-keys 22 | ``` 23 | 24 | ## Using the Test Suite 25 | 26 | You can also check out the [internal test suite](../../test/crypto/compliance.spec.js) to see the setup in action. 27 | 28 | ```js 29 | const tests = require('libp2p-interfaces-compliance-tests/keys') 30 | const yourKeys = require('./your-keys') 31 | 32 | tests({ 33 | setup () { 34 | // Set up your keys if needed, then return it 35 | return yourKeys 36 | }, 37 | teardown () { 38 | // Clean up your keys if needed 39 | } 40 | }) 41 | ``` 42 | 43 | ## API Docs 44 | 45 | - 46 | 47 | ## License 48 | 49 | Licensed under either of 50 | 51 | - Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) 52 | - MIT ([LICENSE-MIT](LICENSE-MIT) / ) 53 | 54 | ## Contribution 55 | 56 | 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. 57 | -------------------------------------------------------------------------------- /packages/interface-record-compliance-tests/README.md: -------------------------------------------------------------------------------- 1 | # @libp2p/interface-record-compliance-tests 2 | 3 | [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) 4 | [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) 5 | [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-interfaces.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-interfaces) 6 | [![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p-interfaces/js-test-and-release.yml?branch=master\&style=flat-square)](https://github.com/libp2p/js-libp2p-interfaces/actions/workflows/js-test-and-release.yml?query=branch%3Amaster) 7 | 8 | > Compliance tests for implementations of the libp2p Record interface 9 | 10 | ## Table of contents 11 | 12 | - [Install](#install) 13 | - [Usage](#usage) 14 | - [API Docs](#api-docs) 15 | - [License](#license) 16 | - [Contribution](#contribution) 17 | 18 | ## Install 19 | 20 | ```console 21 | $ npm i @libp2p/interface-record-compliance-tests 22 | ``` 23 | 24 | ## Usage 25 | 26 | ```js 27 | import tests from '@libp2p/interface-record-tests' 28 | 29 | describe('your record implementation', () => { 30 | tests({ 31 | // Options should be passed to your implementation 32 | async setup (options) { 33 | return new YourImplementation() 34 | }, 35 | async teardown () { 36 | // cleanup resources created by setup() 37 | } 38 | }) 39 | }) 40 | ``` 41 | 42 | ## API Docs 43 | 44 | - 45 | 46 | ## License 47 | 48 | Licensed under either of 49 | 50 | - Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) 51 | - MIT ([LICENSE-MIT](LICENSE-MIT) / ) 52 | 53 | ## Contribution 54 | 55 | 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. 56 | -------------------------------------------------------------------------------- /packages/interface-pubsub-compliance-tests/README.md: -------------------------------------------------------------------------------- 1 | # @libp2p/interface-pubsub-compliance-tests 2 | 3 | [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) 4 | [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) 5 | [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-interfaces.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-interfaces) 6 | [![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p-interfaces/js-test-and-release.yml?branch=master\&style=flat-square)](https://github.com/libp2p/js-libp2p-interfaces/actions/workflows/js-test-and-release.yml?query=branch%3Amaster) 7 | 8 | > Compliance tests for implementations of the libp2p PubSub interface 9 | 10 | ## Table of contents 11 | 12 | - [Install](#install) 13 | - [Usage](#usage) 14 | - [API Docs](#api-docs) 15 | - [License](#license) 16 | - [Contribution](#contribution) 17 | 18 | ## Install 19 | 20 | ```console 21 | $ npm i @libp2p/interface-pubsub-compliance-tests 22 | ``` 23 | 24 | ## Usage 25 | 26 | ```js 27 | import tests from '@libp2p/interface-pubsub-compliance-tests' 28 | 29 | describe('your pubsub implementation', () => { 30 | tests({ 31 | // Options should be passed to your implementation 32 | async setup (options) { 33 | return new YourImplementation() 34 | }, 35 | async teardown () { 36 | // cleanup resources created by setup() 37 | } 38 | }) 39 | }) 40 | ``` 41 | 42 | ## API Docs 43 | 44 | - 45 | 46 | ## License 47 | 48 | Licensed under either of 49 | 50 | - Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) 51 | - MIT ([LICENSE-MIT](LICENSE-MIT) / ) 52 | 53 | ## Contribution 54 | 55 | 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. 56 | -------------------------------------------------------------------------------- /packages/interface-connection-encrypter-compliance-tests/README.md: -------------------------------------------------------------------------------- 1 | # @libp2p/interface-connection-encrypter-compliance-tests 2 | 3 | [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) 4 | [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) 5 | [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-interfaces.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-interfaces) 6 | [![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p-interfaces/js-test-and-release.yml?branch=master\&style=flat-square)](https://github.com/libp2p/js-libp2p-interfaces/actions/workflows/js-test-and-release.yml?query=branch%3Amaster) 7 | 8 | > Compliance tests for implementations of the libp2p Connection Encrypter interface 9 | 10 | ## Table of contents 11 | 12 | - [Install](#install) 13 | - [Usage](#usage) 14 | - [API Docs](#api-docs) 15 | - [License](#license) 16 | - [Contribution](#contribution) 17 | 18 | ## Install 19 | 20 | ```console 21 | $ npm i @libp2p/interface-connection-encrypter-compliance-tests 22 | ``` 23 | 24 | ## Usage 25 | 26 | ```js 27 | import tests from '@libp2p/interface-connection-encrypter-compliance-tests' 28 | import yourCrypto from './your-encrypter' 29 | 30 | tests({ 31 | setup () { 32 | // Set up your crypto if needed, then return it 33 | return yourCrypto 34 | }, 35 | teardown () { 36 | // Clean up your crypto if needed 37 | } 38 | }) 39 | ``` 40 | 41 | ## API Docs 42 | 43 | - 44 | 45 | ## License 46 | 47 | Licensed under either of 48 | 49 | - Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) 50 | - MIT ([LICENSE-MIT](LICENSE-MIT) / ) 51 | 52 | ## Contribution 53 | 54 | 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. 55 | -------------------------------------------------------------------------------- /packages/interface-transport-compliance-tests/README.md: -------------------------------------------------------------------------------- 1 | # @libp2p/interface-transport-compliance-tests 2 | 3 | [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) 4 | [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) 5 | [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-interfaces.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-interfaces) 6 | [![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p-interfaces/js-test-and-release.yml?branch=master\&style=flat-square)](https://github.com/libp2p/js-libp2p-interfaces/actions/workflows/js-test-and-release.yml?query=branch%3Amaster) 7 | 8 | > Compliance tests for implementations of the libp2p Transport interface 9 | 10 | ## Table of contents 11 | 12 | - [Install](#install) 13 | - [Usage](#usage) 14 | - [API Docs](#api-docs) 15 | - [License](#license) 16 | - [Contribution](#contribution) 17 | 18 | ## Install 19 | 20 | ```console 21 | $ npm i @libp2p/interface-transport-compliance-tests 22 | ``` 23 | 24 | ## Usage 25 | 26 | ```js 27 | import tests from '@libp2p/interface-transport-compliance-tests' 28 | 29 | describe('your transport implementation', () => { 30 | tests({ 31 | // Options should be passed to your implementation 32 | async setup (options) { 33 | return new YourImplementation() 34 | }, 35 | async teardown () { 36 | // cleanup resources created by setup() 37 | } 38 | }) 39 | }) 40 | ``` 41 | 42 | ## API Docs 43 | 44 | - 45 | 46 | ## License 47 | 48 | Licensed under either of 49 | 50 | - Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) 51 | - MIT ([LICENSE-MIT](LICENSE-MIT) / ) 52 | 53 | ## Contribution 54 | 55 | 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. 56 | -------------------------------------------------------------------------------- /packages/interface-stream-muxer-compliance-tests/README.md: -------------------------------------------------------------------------------- 1 | # @libp2p/interface-stream-muxer-compliance-tests 2 | 3 | [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) 4 | [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) 5 | [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-interfaces.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-interfaces) 6 | [![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p-interfaces/js-test-and-release.yml?branch=master\&style=flat-square)](https://github.com/libp2p/js-libp2p-interfaces/actions/workflows/js-test-and-release.yml?query=branch%3Amaster) 7 | 8 | > Compliance tests for implementations of the libp2p Stream Muxer interface 9 | 10 | ## Table of contents 11 | 12 | - [Install](#install) 13 | - [Usage](#usage) 14 | - [API Docs](#api-docs) 15 | - [License](#license) 16 | - [Contribution](#contribution) 17 | 18 | ## Install 19 | 20 | ```console 21 | $ npm i @libp2p/interface-stream-muxer-compliance-tests 22 | ``` 23 | 24 | ## Usage 25 | 26 | ```js 27 | import tests from '@libp2p/interface-stream-muxer-compliance-tests' 28 | 29 | describe('your stream muxer implementation', () => { 30 | tests({ 31 | // Options should be passed to your implementation 32 | async setup (options) { 33 | return new YourImplementation() 34 | }, 35 | async teardown () { 36 | // cleanup resources created by setup() 37 | } 38 | }) 39 | }) 40 | ``` 41 | 42 | ## API Docs 43 | 44 | - 45 | 46 | ## License 47 | 48 | Licensed under either of 49 | 50 | - Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) 51 | - MIT ([LICENSE-MIT](LICENSE-MIT) / ) 52 | 53 | ## Contribution 54 | 55 | 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. 56 | -------------------------------------------------------------------------------- /packages/interface-peer-discovery-compliance-tests/README.md: -------------------------------------------------------------------------------- 1 | # @libp2p/interface-peer-discovery-compliance-tests 2 | 3 | [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) 4 | [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) 5 | [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-interfaces.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-interfaces) 6 | [![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p-interfaces/js-test-and-release.yml?branch=master\&style=flat-square)](https://github.com/libp2p/js-libp2p-interfaces/actions/workflows/js-test-and-release.yml?query=branch%3Amaster) 7 | 8 | > Compliance tests for implementations of the libp2p Peer Discovery interface 9 | 10 | ## Table of contents 11 | 12 | - [Install](#install) 13 | - [Usage](#usage) 14 | - [API Docs](#api-docs) 15 | - [License](#license) 16 | - [Contribution](#contribution) 17 | 18 | ## Install 19 | 20 | ```console 21 | $ npm i @libp2p/interface-peer-discovery-compliance-tests 22 | ``` 23 | 24 | ## Usage 25 | 26 | ```js 27 | import tests from '@libp2p/interface-peer-discovery-compliance-tests' 28 | 29 | describe('your peer discovery implementation', () => { 30 | tests({ 31 | // Options should be passed to your implementation 32 | async setup (options) { 33 | return new YourImplementation() 34 | }, 35 | async teardown () { 36 | // cleanup resources created by setup() 37 | } 38 | }) 39 | }) 40 | ``` 41 | 42 | ## API Docs 43 | 44 | - 45 | 46 | ## License 47 | 48 | Licensed under either of 49 | 50 | - Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) 51 | - MIT ([LICENSE-MIT](LICENSE-MIT) / ) 52 | 53 | ## Contribution 54 | 55 | 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. 56 | -------------------------------------------------------------------------------- /packages/interface-mocks/src/multiaddr-connection.ts: -------------------------------------------------------------------------------- 1 | import { multiaddr } from '@multiformats/multiaddr' 2 | import { abortableSource } from 'abortable-iterator' 3 | import { duplexPair } from 'it-pair/duplex' 4 | import type { MultiaddrConnection } from '@libp2p/interface-connection' 5 | import type { PeerId } from '@libp2p/interface-peer-id' 6 | import type { Multiaddr } from '@multiformats/multiaddr' 7 | import type { Duplex } from 'it-stream-types' 8 | 9 | export function mockMultiaddrConnection (source: Duplex> & Partial, peerId: PeerId): MultiaddrConnection { 10 | const maConn: MultiaddrConnection = { 11 | async close () { 12 | 13 | }, 14 | timeline: { 15 | open: Date.now() 16 | }, 17 | remoteAddr: multiaddr(`/ip4/127.0.0.1/tcp/4001/p2p/${peerId.toString()}`), 18 | ...source 19 | } 20 | 21 | return maConn 22 | } 23 | 24 | export interface MockMultiaddrConnPairOptions { 25 | addrs: Multiaddr[] 26 | remotePeer: PeerId 27 | } 28 | 29 | /** 30 | * Returns both sides of a mocked MultiaddrConnection 31 | */ 32 | export function mockMultiaddrConnPair (opts: MockMultiaddrConnPairOptions): { inbound: MultiaddrConnection, outbound: MultiaddrConnection } { 33 | const { addrs, remotePeer } = opts 34 | const controller = new AbortController() 35 | const [localAddr, remoteAddr] = addrs 36 | const [inboundStream, outboundStream] = duplexPair() 37 | 38 | const outbound: MultiaddrConnection = { 39 | ...outboundStream, 40 | remoteAddr: remoteAddr.toString().includes(`/p2p/${remotePeer.toString()}`) ? remoteAddr : remoteAddr.encapsulate(`/p2p/${remotePeer.toString()}`), 41 | timeline: { 42 | open: Date.now() 43 | }, 44 | close: async () => { 45 | outbound.timeline.close = Date.now() 46 | controller.abort() 47 | } 48 | } 49 | 50 | const inbound: MultiaddrConnection = { 51 | ...inboundStream, 52 | remoteAddr: localAddr, 53 | timeline: { 54 | open: Date.now() 55 | }, 56 | close: async () => { 57 | inbound.timeline.close = Date.now() 58 | controller.abort() 59 | } 60 | } 61 | 62 | // Make the sources abortable so we can close them easily 63 | inbound.source = abortableSource(inbound.source, controller.signal) 64 | outbound.source = abortableSource(outbound.source, controller.signal) 65 | 66 | return { inbound, outbound } 67 | } 68 | -------------------------------------------------------------------------------- /packages/interface-connection-manager/src/index.ts: -------------------------------------------------------------------------------- 1 | import type { Connection, MultiaddrConnection } from '@libp2p/interface-connection' 2 | import type { PeerId } from '@libp2p/interface-peer-id' 3 | import type { AbortOptions } from '@libp2p/interfaces' 4 | import type { PeerMap } from '@libp2p/peer-collections' 5 | import type { Multiaddr } from '@multiformats/multiaddr' 6 | 7 | export type PendingDialStatus = 'queued' | 'active' | 'error' | 'success' 8 | 9 | export interface PendingDial { 10 | id: string 11 | status: PendingDialStatus 12 | peerId?: PeerId 13 | multiaddrs: Multiaddr[] 14 | } 15 | 16 | export interface ConnectionManager { 17 | /** 18 | * Return connections, optionally filtering by a PeerId 19 | * 20 | * @example 21 | * 22 | * ```js 23 | * const connections = libp2p.connectionManager.get(peerId) 24 | * // [] 25 | * ``` 26 | */ 27 | getConnections: (peerId?: PeerId) => Connection[] 28 | 29 | /** 30 | * Return a map of all connections with their associated PeerIds 31 | * 32 | * @example 33 | * 34 | * ```js 35 | * const connectionsMap = libp2p.connectionManager.getConnectionsMap() 36 | * ``` 37 | */ 38 | getConnectionsMap: () => PeerMap 39 | 40 | /** 41 | * Open a connection to a remote peer 42 | * 43 | * @example 44 | * 45 | * ```js 46 | * const connection = await libp2p.connectionManager.openConnection(peerId) 47 | * ``` 48 | */ 49 | openConnection: (peer: PeerId | Multiaddr | Multiaddr[], options?: AbortOptions) => Promise 50 | 51 | /** 52 | * Close our connections to a peer 53 | */ 54 | closeConnections: (peer: PeerId) => Promise 55 | 56 | /** 57 | * Invoked after an incoming connection is opened but before PeerIds are 58 | * exchanged, this lets the ConnectionManager check we have sufficient 59 | * resources to accept the connection in which case it will return true, 60 | * otherwise it will return false. 61 | */ 62 | acceptIncomingConnection: (maConn: MultiaddrConnection) => Promise 63 | 64 | /** 65 | * Invoked after upgrading a multiaddr connection has finished 66 | */ 67 | afterUpgradeInbound: () => void 68 | 69 | /** 70 | * Return the list of in-progress or queued dials 71 | * 72 | * @example 73 | * 74 | * ```js 75 | * const dials = libp2p.connectionManager.getDialQueue() 76 | * ``` 77 | */ 78 | getDialQueue: () => PendingDial[] 79 | } 80 | -------------------------------------------------------------------------------- /packages/interface-content-routing/src/index.ts: -------------------------------------------------------------------------------- 1 | import type { PeerInfo } from '@libp2p/interface-peer-info' 2 | import type { AbortOptions } from '@libp2p/interfaces' 3 | import type { CID } from 'multiformats/cid' 4 | 5 | /** 6 | * Any object that implements this Symbol as a property should return a 7 | * ContentRouting instance as the property value, similar to how 8 | * `Symbol.Iterable` can be used to return an `Iterable` from an `Iterator`. 9 | * 10 | * @example 11 | * 12 | * ```js 13 | * import { contentRouting, ContentRouting } from '@libp2p/content-routing' 14 | * 15 | * class MyContentRouter implements ContentRouting { 16 | * get [contentRouting] () { 17 | * return this 18 | * } 19 | * 20 | * // ...other methods 21 | * } 22 | * ``` 23 | */ 24 | export const contentRouting = Symbol.for('@libp2p/content-routing') 25 | 26 | export interface ContentRouting { 27 | /** 28 | * The implementation of this method should ensure that network peers know the 29 | * caller can provide content that corresponds to the passed CID. 30 | * 31 | * @example 32 | * 33 | * ```js 34 | * // ... 35 | * await contentRouting.provide(cid) 36 | * ``` 37 | */ 38 | provide: (cid: CID, options?: AbortOptions) => Promise 39 | 40 | /** 41 | * Find the providers of the passed CID. 42 | * 43 | * @example 44 | * 45 | * ```js 46 | * // Iterate over the providers found for the given cid 47 | * for await (const provider of contentRouting.findProviders(cid)) { 48 | * console.log(provider.id, provider.multiaddrs) 49 | * } 50 | * ``` 51 | */ 52 | findProviders: (cid: CID, options?: AbortOptions) => AsyncIterable 53 | 54 | /** 55 | * Puts a value corresponding to the passed key in a way that can later be 56 | * retrieved by another network peer using the get method. 57 | * 58 | * @example 59 | * 60 | * ```js 61 | * // ... 62 | * const key = '/key' 63 | * const value = uint8ArrayFromString('oh hello there') 64 | * 65 | * await contentRouting.put(key, value) 66 | * ``` 67 | */ 68 | put: (key: Uint8Array, value: Uint8Array, options?: AbortOptions) => Promise 69 | 70 | /** 71 | * Retrieves a value from the network corresponding to the passed key. 72 | * 73 | * @example 74 | * 75 | * ```js 76 | * // ... 77 | * 78 | * const key = '/key' 79 | * const value = await contentRouting.get(key) 80 | * ``` 81 | */ 82 | get: (key: Uint8Array, options?: AbortOptions) => Promise 83 | } 84 | -------------------------------------------------------------------------------- /packages/interface-mocks/src/registrar.ts: -------------------------------------------------------------------------------- 1 | import merge from 'merge-options' 2 | import type { Connection } from '@libp2p/interface-connection' 3 | import type { PeerId } from '@libp2p/interface-peer-id' 4 | import type { IncomingStreamData, Registrar, StreamHandler, Topology, StreamHandlerOptions, StreamHandlerRecord } from '@libp2p/interface-registrar' 5 | 6 | export class MockRegistrar implements Registrar { 7 | private readonly topologies = new Map>() 8 | private readonly handlers = new Map() 9 | 10 | getProtocols (): string[] { 11 | return Array.from(this.handlers.keys()).sort() 12 | } 13 | 14 | async handle (protocol: string, handler: StreamHandler, opts?: StreamHandlerOptions): Promise { 15 | const options = merge.bind({ ignoreUndefined: true })({ 16 | maxInboundStreams: 1, 17 | maxOutboundStreams: 1 18 | }, opts) 19 | 20 | if (this.handlers.has(protocol)) { 21 | throw new Error(`Handler already registered for protocol ${protocol}`) 22 | } 23 | 24 | this.handlers.set(protocol, { 25 | handler, 26 | options 27 | }) 28 | } 29 | 30 | async unhandle (protocol: string): Promise { 31 | this.handlers.delete(protocol) 32 | } 33 | 34 | getHandler (protocol: string): StreamHandlerRecord { 35 | const handler = this.handlers.get(protocol) 36 | 37 | if (handler == null) { 38 | throw new Error(`No handler registered for protocol ${protocol}`) 39 | } 40 | 41 | return handler 42 | } 43 | 44 | async register (protocol: string, topology: Topology): Promise { 45 | const id = `topology-id-${Math.random()}` 46 | let topologies = this.topologies.get(protocol) 47 | 48 | if (topologies == null) { 49 | topologies = [] 50 | } 51 | 52 | topologies.push({ 53 | id, 54 | topology 55 | }) 56 | 57 | this.topologies.set(protocol, topologies) 58 | 59 | return id 60 | } 61 | 62 | unregister (id: string | string[]): void { 63 | if (!Array.isArray(id)) { 64 | id = [id] 65 | } 66 | 67 | id.forEach(id => this.topologies.delete(id)) 68 | } 69 | 70 | getTopologies (protocol: string): Topology[] { 71 | return (this.topologies.get(protocol) ?? []).map(t => t.topology) 72 | } 73 | } 74 | 75 | export function mockRegistrar (): Registrar { 76 | return new MockRegistrar() 77 | } 78 | 79 | export async function mockIncomingStreamEvent (protocol: string, conn: Connection, remotePeer: PeerId): Promise { 80 | return { 81 | ...await conn.newStream([protocol]), 82 | // @ts-expect-error incomplete implementation 83 | connection: { 84 | remotePeer 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /packages/interface-peer-discovery-compliance-tests/src/index.ts: -------------------------------------------------------------------------------- 1 | import { start, stop } from '@libp2p/interfaces/startable' 2 | import { isMultiaddr } from '@multiformats/multiaddr' 3 | import { expect } from 'aegir/chai' 4 | import delay from 'delay' 5 | import pDefer from 'p-defer' 6 | import type { TestSetup } from '@libp2p/interface-compliance-tests' 7 | import type { PeerDiscovery } from '@libp2p/interface-peer-discovery' 8 | 9 | export default (common: TestSetup): void => { 10 | describe('interface-peer-discovery compliance tests', () => { 11 | let discovery: PeerDiscovery 12 | 13 | beforeEach(async () => { 14 | discovery = await common.setup() 15 | }) 16 | 17 | afterEach('ensure discovery was stopped', async () => { 18 | await stop(discovery) 19 | 20 | await common.teardown() 21 | }) 22 | 23 | it('can start the service', async () => { 24 | await start(discovery) 25 | }) 26 | 27 | it('can start and stop the service', async () => { 28 | await start(discovery) 29 | await stop(discovery) 30 | }) 31 | 32 | it('should not fail to stop the service if it was not started', async () => { 33 | await stop(discovery) 34 | }) 35 | 36 | it('should not fail to start the service if it is already started', async () => { 37 | await start(discovery) 38 | await start(discovery) 39 | }) 40 | 41 | it('should emit a peer event after start', async () => { 42 | const defer = pDefer() 43 | 44 | discovery.addEventListener('peer', (evt) => { 45 | const { id, multiaddrs } = evt.detail 46 | expect(id).to.exist() 47 | expect(id) 48 | .to.have.property('type') 49 | .that.is.oneOf(['RSA', 'Ed25519', 'secp256k1']) 50 | expect(multiaddrs).to.exist() 51 | 52 | multiaddrs.forEach((m) => expect(isMultiaddr(m)).to.eql(true)) 53 | 54 | defer.resolve() 55 | }) 56 | 57 | await start(discovery) 58 | 59 | await defer.promise 60 | }) 61 | 62 | it('should not receive a peer event before start', async () => { 63 | discovery.addEventListener('peer', () => { 64 | throw new Error('should not receive a peer event before start') 65 | }) 66 | 67 | await delay(2000) 68 | }) 69 | 70 | it('should not receive a peer event after stop', async () => { 71 | const deferStart = pDefer() 72 | 73 | discovery.addEventListener('peer', () => { 74 | deferStart.resolve() 75 | }) 76 | 77 | await start(discovery) 78 | 79 | await deferStart.promise 80 | 81 | await stop(discovery) 82 | 83 | discovery.addEventListener('peer', () => { 84 | throw new Error('should not receive a peer event after stop') 85 | }) 86 | 87 | await delay(2000) 88 | }) 89 | }) 90 | } 91 | -------------------------------------------------------------------------------- /packages/interface-connection-compliance-tests/README.md: -------------------------------------------------------------------------------- 1 | # @libp2p/interface-connection-compliance-tests 2 | 3 | [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) 4 | [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) 5 | [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-interfaces.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-interfaces) 6 | [![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p-interfaces/js-test-and-release.yml?branch=master\&style=flat-square)](https://github.com/libp2p/js-libp2p-interfaces/actions/workflows/js-test-and-release.yml?query=branch%3Amaster) 7 | 8 | > Compliance tests for implementations of the libp2p Connection interface 9 | 10 | ## Table of contents 11 | 12 | - [Install](#install) 13 | - [Usage](#usage) 14 | - [API Docs](#api-docs) 15 | - [License](#license) 16 | - [Contribution](#contribution) 17 | 18 | ## Install 19 | 20 | ```console 21 | $ npm i @libp2p/interface-connection-compliance-tests 22 | ``` 23 | 24 | ## Usage 25 | 26 | This is a test suite and interface you can use to implement a connection. The connection interface contains all the metadata associated with it, as well as an array of the streams opened through this connection. In the same way as the connection, a stream contains properties with its metadata, plus an iterable duplex object that offers a mechanism for writing and reading data, with back pressure. This module and test suite were heavily inspired by abstract-blob-store and interface-stream-muxer. 27 | 28 | The primary goal of this module is to enable developers to pick, swap or upgrade their connection without losing the same API expectations and mechanisms such as back pressure and the ability to half close a connection. 29 | 30 | Publishing a test suite as a module lets multiple modules ensure compatibility since they use the same test suite. 31 | 32 | ```js 33 | import tests from '@libp2p/interface-connection-compliance-tests' 34 | 35 | describe('your connection', () => { 36 | tests({ 37 | // Options should be passed to your connection 38 | async setup (options) { 39 | return YourConnection 40 | }, 41 | async teardown () { 42 | // cleanup resources created by setup() 43 | } 44 | }) 45 | }) 46 | ``` 47 | 48 | ## API Docs 49 | 50 | - 51 | 52 | ## License 53 | 54 | Licensed under either of 55 | 56 | - Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) 57 | - MIT ([LICENSE-MIT](LICENSE-MIT) / ) 58 | 59 | ## Contribution 60 | 61 | 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. 62 | -------------------------------------------------------------------------------- /packages/interfaces/README.md: -------------------------------------------------------------------------------- 1 | # @libp2p/interfaces 2 | 3 | [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) 4 | [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) 5 | [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-interfaces.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-interfaces) 6 | [![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p-interfaces/js-test-and-release.yml?branch=master\&style=flat-square)](https://github.com/libp2p/js-libp2p-interfaces/actions/workflows/js-test-and-release.yml?query=branch%3Amaster) 7 | 8 | > Common code shared by the various libp2p interfaces 9 | 10 | ## Table of contents 11 | 12 | - [Install](#install) 13 | - [Usage](#usage) 14 | - [AbortError](#aborterror) 15 | - [Events](#events) 16 | - [AbortOptions](#abortoptions) 17 | - [Startable](#startable) 18 | - [API Docs](#api-docs) 19 | - [License](#license) 20 | - [Contribution](#contribution) 21 | 22 | ## Install 23 | 24 | ```console 25 | $ npm i @libp2p/interfaces 26 | ``` 27 | 28 | ## Usage 29 | 30 | ### AbortError 31 | 32 | Throw an error with a `.code` property of `'ABORT_ERR'`: 33 | 34 | ```js 35 | import { AbortError } from '@libp2p/interfaces/errors' 36 | 37 | throw new AbortError() 38 | ``` 39 | 40 | ### Events 41 | 42 | Typed events: 43 | 44 | ```js 45 | import { EventEmitter, CustomEvent } from '@libp2p/interfaces/events' 46 | 47 | export interface MyEmitterEvents { 48 | 'some-event': CustomEvent; 49 | } 50 | 51 | class MyEmitter extends EventEmitter { 52 | 53 | } 54 | 55 | // later 56 | const myEmitter = new MyEmitter() 57 | myEmitter.addEventListener('some-event', (evt) => { 58 | const num = evt.detail // <-- inferred as number 59 | }) 60 | ``` 61 | 62 | ### AbortOptions 63 | 64 | ```js 65 | import type { AbortOptions } from '@libp2p/interfaces' 66 | ``` 67 | 68 | ### Startable 69 | 70 | Lifecycles for components 71 | 72 | ```js 73 | import { start, stop, isStartable } from '@libp2p/interfaces/startable' 74 | import type { Startable } from '@libp2p/interfaces/startable' 75 | 76 | class MyStartable implements Startable { 77 | // .. implementation methods 78 | } 79 | 80 | const myStartable = new MyStartable() 81 | 82 | isStartable(myStartable) // returns true 83 | 84 | await start(myStartable) 85 | await stop(myStartable) 86 | ``` 87 | 88 | ## API Docs 89 | 90 | - 91 | 92 | ## License 93 | 94 | Licensed under either of 95 | 96 | - Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) 97 | - MIT ([LICENSE-MIT](LICENSE-MIT) / ) 98 | 99 | ## Contribution 100 | 101 | 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. 102 | -------------------------------------------------------------------------------- /packages/interfaces/src/startable.ts: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Implemented by components that have a lifecycle 4 | */ 5 | export interface Startable { 6 | isStarted: () => boolean 7 | 8 | /** 9 | * If implemented, this method will be invoked before the start method. 10 | * 11 | * It should not assume any other components have been started. 12 | */ 13 | beforeStart?: () => void | Promise 14 | 15 | /** 16 | * This method will be invoked to start the component. 17 | * 18 | * It should not assume that any other components have been started. 19 | */ 20 | start: () => void | Promise 21 | 22 | /** 23 | * If implemented, this method will be invoked after the start method. 24 | * 25 | * All other components will have had their start method invoked before this method is called. 26 | */ 27 | afterStart?: () => void | Promise 28 | 29 | /** 30 | * If implemented, this method will be invoked before the stop method. 31 | * 32 | * Any other components will still be running when this method is called. 33 | */ 34 | beforeStop?: () => void | Promise 35 | 36 | /** 37 | * This method will be invoked to stop the component. 38 | * 39 | * It should not assume any other components are running when it is called. 40 | */ 41 | stop: () => void | Promise 42 | 43 | /** 44 | * If implemented, this method will be invoked after the stop method. 45 | * 46 | * All other components will have had their stop method invoked before this method is called. 47 | */ 48 | afterStop?: () => void | Promise 49 | } 50 | 51 | export function isStartable (obj: any): obj is Startable { 52 | return obj != null && typeof obj.start === 'function' && typeof obj.stop === 'function' 53 | } 54 | 55 | export async function start (...objs: any[]): Promise { 56 | const startables: Startable[] = [] 57 | 58 | for (const obj of objs) { 59 | if (isStartable(obj)) { 60 | startables.push(obj) 61 | } 62 | } 63 | 64 | await Promise.all( 65 | startables.map(async s => { 66 | if (s.beforeStart != null) { 67 | await s.beforeStart() 68 | } 69 | }) 70 | ) 71 | 72 | await Promise.all( 73 | startables.map(async s => { 74 | await s.start() 75 | }) 76 | ) 77 | 78 | await Promise.all( 79 | startables.map(async s => { 80 | if (s.afterStart != null) { 81 | await s.afterStart() 82 | } 83 | }) 84 | ) 85 | } 86 | 87 | export async function stop (...objs: any[]): Promise { 88 | const startables: Startable[] = [] 89 | 90 | for (const obj of objs) { 91 | if (isStartable(obj)) { 92 | startables.push(obj) 93 | } 94 | } 95 | 96 | await Promise.all( 97 | startables.map(async s => { 98 | if (s.beforeStop != null) { 99 | await s.beforeStop() 100 | } 101 | }) 102 | ) 103 | 104 | await Promise.all( 105 | startables.map(async s => { 106 | await s.stop() 107 | }) 108 | ) 109 | 110 | await Promise.all( 111 | startables.map(async s => { 112 | if (s.afterStop != null) { 113 | await s.afterStop() 114 | } 115 | }) 116 | ) 117 | } 118 | -------------------------------------------------------------------------------- /packages/interface-pubsub-compliance-tests/src/emit-self.ts: -------------------------------------------------------------------------------- 1 | import { mockNetwork } from '@libp2p/interface-mocks' 2 | import { start, stop } from '@libp2p/interfaces/startable' 3 | import { expect } from 'aegir/chai' 4 | import sinon from 'sinon' 5 | import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' 6 | import { createComponents } from './utils.js' 7 | import type { PubSubArgs, PubSubComponents } from './index.js' 8 | import type { TestSetup } from '@libp2p/interface-compliance-tests' 9 | import type { PubSub } from '@libp2p/interface-pubsub' 10 | 11 | const topic = 'foo' 12 | const data = uint8ArrayFromString('bar') 13 | const shouldNotHappen = (): void => expect.fail() 14 | 15 | export default (common: TestSetup): void => { 16 | describe('emit self', () => { 17 | describe('enabled', () => { 18 | let pubsub: PubSub 19 | let components: PubSubComponents 20 | 21 | before(async () => { 22 | mockNetwork.reset() 23 | components = await createComponents() 24 | 25 | pubsub = components.pubsub = await common.setup({ 26 | components, 27 | init: { 28 | emitSelf: true 29 | } 30 | }) 31 | 32 | await start(...Object.values(components)) 33 | pubsub.subscribe(topic) 34 | }) 35 | 36 | after(async () => { 37 | sinon.restore() 38 | await stop(...Object.values(components)) 39 | await common.teardown() 40 | mockNetwork.reset() 41 | }) 42 | 43 | it('should emit to self on publish', async () => { 44 | const promise = new Promise((resolve) => { 45 | pubsub.addEventListener('message', (evt) => { 46 | if (evt.detail.topic === topic) { 47 | resolve() 48 | } 49 | }, { 50 | once: true 51 | }) 52 | }) 53 | 54 | const result = await pubsub.publish(topic, data) 55 | 56 | await promise 57 | 58 | expect(result).to.have.property('recipients').with.lengthOf(1) 59 | }) 60 | }) 61 | 62 | describe('disabled', () => { 63 | let pubsub: PubSub 64 | let components: PubSubComponents 65 | 66 | before(async () => { 67 | mockNetwork.reset() 68 | components = await createComponents() 69 | pubsub = components.pubsub = await common.setup({ 70 | components, 71 | init: { 72 | emitSelf: false 73 | } 74 | }) 75 | 76 | await start(...Object.values(components)) 77 | pubsub.subscribe(topic) 78 | }) 79 | 80 | after(async () => { 81 | sinon.restore() 82 | await stop(...Object.values(components)) 83 | await common.teardown() 84 | mockNetwork.reset() 85 | }) 86 | 87 | it('should not emit to self on publish', async () => { 88 | pubsub.addEventListener('message', shouldNotHappen, { 89 | once: true 90 | }) 91 | 92 | await pubsub.publish(topic, data) 93 | 94 | // Wait 1 second to guarantee that self is not noticed 95 | await new Promise((resolve) => setTimeout(resolve, 1000)) 96 | }) 97 | }) 98 | }) 99 | } 100 | -------------------------------------------------------------------------------- /packages/interface-peer-id/README.md: -------------------------------------------------------------------------------- 1 | # @libp2p/interface-peer-id 2 | 3 | [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) 4 | [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) 5 | [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-interfaces.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-interfaces) 6 | [![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p-interfaces/js-test-and-release.yml?branch=master\&style=flat-square)](https://github.com/libp2p/js-libp2p-interfaces/actions/workflows/js-test-and-release.yml?query=branch%3Amaster) 7 | 8 | > Peer Identifier interface for libp2p 9 | 10 | ## Table of contents 11 | 12 | - [Install](#install) 13 | - [Modules that implement the interface](#modules-that-implement-the-interface) 14 | - [Badge](#badge) 15 | - [Usage](#usage) 16 | - [Node.js](#nodejs) 17 | - [API Docs](#api-docs) 18 | - [License](#license) 19 | - [Contribution](#contribution) 20 | 21 | ## Install 22 | 23 | ```console 24 | $ npm i @libp2p/interface-peer-id 25 | ``` 26 | 27 | The primary goal of this module is to enable developers to implement PeerId modules. This module and test suite was heavily inspired by earlier implementation of [PeerId](https://github.com/libp2p/js-peer-id). 28 | 29 | Publishing a test suite as a module lets multiple modules all ensure compatibility since they use the same test suite. 30 | 31 | The API is presented with both Node.js and Go primitives, however, there is not actual limitations for it to be extended for any other language, pushing forward the cross compatibility and interop through different stacks. 32 | 33 | ## Modules that implement the interface 34 | 35 | - [JavaScript libp2p-peer-id](https://github.com/libp2p/js-libp2p-peer-id) 36 | 37 | Send a PR to add a new one if you happen to find or write one. 38 | 39 | ## Badge 40 | 41 | Include this badge in your readme if you make a new module that uses interface-peer-id API. 42 | 43 | ![](/img/badge.png) 44 | 45 | ## Usage 46 | 47 | ### Node.js 48 | 49 | Install `libp2p-interfaces-compliance-tests` as one of the development dependencies of your project and as a test file. Then, using `mocha` (for JavaScript) or a test runner with compatible API, do: 50 | 51 | ```js 52 | const tests = require('libp2p-interfaces-compliance-tests/peer-id') 53 | 54 | describe('your peer id', () => { 55 | // use all of the test suits 56 | tests({ 57 | setup () { 58 | return YourPeerIdFactory 59 | }, 60 | teardown () { 61 | // Clean up any resources created by setup() 62 | } 63 | }) 64 | }) 65 | ``` 66 | 67 | ## API Docs 68 | 69 | - 70 | 71 | ## License 72 | 73 | Licensed under either of 74 | 75 | - Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) 76 | - MIT ([LICENSE-MIT](LICENSE-MIT) / ) 77 | 78 | ## Contribution 79 | 80 | 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. 81 | -------------------------------------------------------------------------------- /packages/interface-registrar/src/index.ts: -------------------------------------------------------------------------------- 1 | import type { Connection, Stream } from '@libp2p/interface-connection' 2 | import type { PeerId } from '@libp2p/interface-peer-id' 3 | 4 | export interface IncomingStreamData { 5 | stream: Stream 6 | connection: Connection 7 | } 8 | 9 | export interface StreamHandler { 10 | (data: IncomingStreamData): void 11 | } 12 | 13 | export interface StreamHandlerOptions { 14 | /** 15 | * How many incoming streams can be open for this protocol at the same time on each connection (default: 32) 16 | */ 17 | maxInboundStreams?: number 18 | 19 | /** 20 | * How many outgoing streams can be open for this protocol at the same time on each connection (default: 64) 21 | */ 22 | maxOutboundStreams?: number 23 | } 24 | 25 | export interface StreamHandlerRecord { 26 | handler: StreamHandler 27 | options: StreamHandlerOptions 28 | } 29 | 30 | export interface Registrar { 31 | /** 32 | * Return the list of protocols with registered handlers 33 | */ 34 | getProtocols: () => string[] 35 | 36 | /** 37 | * Add a protocol handler 38 | */ 39 | handle: (protocol: string, handler: StreamHandler, options?: StreamHandlerOptions) => Promise 40 | 41 | /** 42 | * Remove a protocol handler 43 | */ 44 | unhandle: (protocol: string) => Promise 45 | 46 | /** 47 | * Return the handler for the passed protocol 48 | */ 49 | getHandler: (protocol: string) => StreamHandlerRecord 50 | 51 | /** 52 | * Register a topology handler for a protocol - the topology will be 53 | * invoked when peers are discovered on the network that support the 54 | * passed protocol. 55 | * 56 | * An id will be returned that can later be used to unregister the 57 | * topology. 58 | */ 59 | register: (protocol: string, topology: Topology) => Promise 60 | 61 | /** 62 | * Remove the topology handler with the passed id. 63 | */ 64 | unregister: (id: string) => void 65 | 66 | /** 67 | * Return all topology handlers that wish to be informed about peers 68 | * that support the passed protocol. 69 | */ 70 | getTopologies: (protocol: string) => Topology[] 71 | } 72 | 73 | export interface onConnectHandler { 74 | (peerId: PeerId, conn: Connection): void 75 | } 76 | 77 | export interface onDisconnectHandler { 78 | (peerId: PeerId, conn?: Connection): void 79 | } 80 | 81 | export interface TopologyInit { 82 | /** 83 | * minimum needed connections 84 | */ 85 | min?: number 86 | 87 | /** 88 | * maximum needed connections 89 | */ 90 | max?: number 91 | 92 | /** 93 | * Invoked when a new peer is connects that supports the configured 94 | * protocol 95 | */ 96 | onConnect?: onConnectHandler 97 | 98 | /** 99 | * Invoked when a peer that supports the configured protocol disconnects 100 | */ 101 | onDisconnect?: onDisconnectHandler 102 | } 103 | 104 | export interface Topology { 105 | min: number 106 | max: number 107 | peers: Set 108 | 109 | onConnect: (peerId: PeerId, conn: Connection) => void 110 | onDisconnect: (peerId: PeerId) => void 111 | setRegistrar: (registrar: Registrar) => Promise 112 | } 113 | 114 | export const topologySymbol = Symbol.for('@libp2p/topology') 115 | 116 | export function isTopology (other: any): other is Topology { 117 | return other != null && Boolean(other[topologySymbol]) 118 | } 119 | -------------------------------------------------------------------------------- /packages/interface-peer-routing/README.md: -------------------------------------------------------------------------------- 1 | # @libp2p/interface-peer-routing 2 | 3 | [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) 4 | [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) 5 | [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-interfaces.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-interfaces) 6 | [![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p-interfaces/js-test-and-release.yml?branch=master\&style=flat-square)](https://github.com/libp2p/js-libp2p-interfaces/actions/workflows/js-test-and-release.yml?query=branch%3Amaster) 7 | 8 | > Peer Routing interface for libp2p 9 | 10 | ## Table of contents 11 | 12 | - - [Install](#install) 13 | - [Modules that implement the interface](#modules-that-implement-the-interface) 14 | - [Badge](#badge) 15 | - [How to use the battery of tests](#how-to-use-the-battery-of-tests) 16 | - [Node.js](#nodejs) 17 | - [API](#api) 18 | - - [findPeer](#findpeer) 19 | - [API Docs](#api-docs) 20 | - [License](#license) 21 | - [Contribution](#contribution) 22 | 23 | ## Install 24 | 25 | ```console 26 | $ npm i @libp2p/interface-peer-routing 27 | ``` 28 | 29 | The primary goal of this module is to enable developers to pick and swap their Peer Routing module as they see fit for their libp2p installation, without having to go through shims or compatibility issues. This module and test suite were heavily inspired by abstract-blob-store and interface-stream-muxer. 30 | 31 | Publishing a test suite as a module lets multiple modules all ensure compatibility since they use the same test suite. 32 | 33 | # Modules that implement the interface 34 | 35 | - [JavaScript libp2p-kad-dht](https://github.com/libp2p/js-libp2p-kad-dht) 36 | - [JavaScript libp2p-delegated-peer-routing](https://github.com/libp2p/js-libp2p-delegated-peer-routing) 37 | 38 | # Badge 39 | 40 | Include this badge in your readme if you make a module that is compatible with the interface-record-store API. You can validate this by running the tests. 41 | 42 | ![](img/badge.png) 43 | 44 | # How to use the battery of tests 45 | 46 | ## Node.js 47 | 48 | TBD 49 | 50 | # API 51 | 52 | A valid (read: that follows this abstraction) Peer Routing module must implement the following API. 53 | 54 | ### findPeer 55 | 56 | - `findPeer(peerId)` 57 | 58 | Query the network for all multiaddresses associated with a `PeerId`. 59 | 60 | **Parameters** 61 | 62 | - [peerId](https://github.com/libp2p/js-peer-id). 63 | 64 | **Returns** 65 | 66 | It returns the [peerId](https://github.com/libp2p/js-peer-id) together with the known peers [multiaddrs](https://github.com/multiformats/js-multiaddr), as follows: 67 | 68 | `Promise<{ id: PeerId, multiaddrs: Multiaddr[] }>` 69 | 70 | ## API Docs 71 | 72 | - 73 | 74 | ## License 75 | 76 | Licensed under either of 77 | 78 | - Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) 79 | - MIT ([LICENSE-MIT](LICENSE-MIT) / ) 80 | 81 | ## Contribution 82 | 83 | 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. 84 | -------------------------------------------------------------------------------- /packages/interfaces/src/events.ts: -------------------------------------------------------------------------------- 1 | 2 | export interface EventCallback { (evt: EventType): void } 3 | export interface EventObject { handleEvent: EventCallback } 4 | export type EventHandler = EventCallback | EventObject 5 | 6 | interface Listener { 7 | once: boolean 8 | callback: any 9 | } 10 | 11 | /** 12 | * Adds types to the EventTarget class. Hopefully this won't be necessary forever. 13 | * 14 | * https://github.com/microsoft/TypeScript/issues/28357 15 | * https://github.com/microsoft/TypeScript/issues/43477 16 | * https://github.com/microsoft/TypeScript/issues/299 17 | * etc 18 | */ 19 | export class EventEmitter> extends EventTarget { 20 | #listeners = new Map() 21 | 22 | listenerCount (type: string): number { 23 | const listeners = this.#listeners.get(type) 24 | 25 | if (listeners == null) { 26 | return 0 27 | } 28 | 29 | return listeners.length 30 | } 31 | 32 | addEventListener(type: K, listener: EventHandler | null, options?: boolean | AddEventListenerOptions): void 33 | addEventListener (type: string, listener: EventHandler, options?: boolean | AddEventListenerOptions): void { 34 | super.addEventListener(type, listener, options) 35 | 36 | let list = this.#listeners.get(type) 37 | 38 | if (list == null) { 39 | list = [] 40 | this.#listeners.set(type, list) 41 | } 42 | 43 | list.push({ 44 | callback: listener, 45 | once: (options !== true && options !== false && options?.once) ?? false 46 | }) 47 | } 48 | 49 | removeEventListener(type: K, listener?: EventHandler | null, options?: boolean | EventListenerOptions): void 50 | removeEventListener (type: string, listener?: EventHandler, options?: boolean | EventListenerOptions): void { 51 | super.removeEventListener(type.toString(), listener ?? null, options) 52 | 53 | let list = this.#listeners.get(type) 54 | 55 | if (list == null) { 56 | return 57 | } 58 | 59 | list = list.filter(({ callback }) => callback !== listener) 60 | this.#listeners.set(type, list) 61 | } 62 | 63 | dispatchEvent (event: Event): boolean { 64 | const result = super.dispatchEvent(event) 65 | 66 | let list = this.#listeners.get(event.type) 67 | 68 | if (list == null) { 69 | return result 70 | } 71 | 72 | list = list.filter(({ once }) => !once) 73 | this.#listeners.set(event.type, list) 74 | 75 | return result 76 | } 77 | 78 | safeDispatchEvent(type: keyof EventMap, detail: CustomEventInit): boolean { 79 | return this.dispatchEvent(new CustomEvent(type as string, detail)) 80 | } 81 | } 82 | 83 | /** 84 | * CustomEvent is a standard event but it's not supported by node. 85 | * 86 | * Remove this when https://github.com/nodejs/node/issues/40678 is closed. 87 | * 88 | * Ref: https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent 89 | */ 90 | class CustomEventPolyfill extends Event { 91 | /** Returns any custom data event was created with. Typically used for synthetic events. */ 92 | public detail: T 93 | 94 | constructor (message: string, data?: EventInit & { detail: T }) { 95 | super(message, data) 96 | // @ts-expect-error could be undefined 97 | this.detail = data?.detail 98 | } 99 | } 100 | 101 | export const CustomEvent = globalThis.CustomEvent ?? CustomEventPolyfill 102 | -------------------------------------------------------------------------------- /packages/interface-connection-encrypter-compliance-tests/src/index.ts: -------------------------------------------------------------------------------- 1 | import peers from '@libp2p/interface-compliance-tests/peers' 2 | import { UnexpectedPeerError } from '@libp2p/interface-connection-encrypter/errors' 3 | import * as PeerIdFactory from '@libp2p/peer-id-factory' 4 | import { expect } from 'aegir/chai' 5 | import all from 'it-all' 6 | import { pipe } from 'it-pipe' 7 | import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' 8 | import { createMaConnPair } from './utils/index.js' 9 | import type { TestSetup } from '@libp2p/interface-compliance-tests' 10 | import type { ConnectionEncrypter } from '@libp2p/interface-connection-encrypter' 11 | import type { PeerId } from '@libp2p/interface-peer-id' 12 | 13 | export default (common: TestSetup): void => { 14 | describe('interface-connection-encrypter compliance tests', () => { 15 | let crypto: ConnectionEncrypter 16 | let localPeer: PeerId 17 | let remotePeer: PeerId 18 | let mitmPeer: PeerId 19 | 20 | before(async () => { 21 | [ 22 | crypto, 23 | localPeer, 24 | remotePeer, 25 | mitmPeer 26 | ] = await Promise.all([ 27 | common.setup(), 28 | PeerIdFactory.createFromJSON(peers[0]), 29 | PeerIdFactory.createFromJSON(peers[1]), 30 | PeerIdFactory.createFromJSON(peers[2]) 31 | ]) 32 | }) 33 | 34 | after(async () => { 35 | await common.teardown() 36 | }) 37 | 38 | it('has a protocol string', () => { 39 | expect(crypto.protocol).to.exist() 40 | expect(crypto.protocol).to.be.a('string') 41 | }) 42 | 43 | it('it wraps the provided duplex connection', async () => { 44 | const [localConn, remoteConn] = createMaConnPair() 45 | 46 | const [ 47 | inboundResult, 48 | outboundResult 49 | ] = await Promise.all([ 50 | crypto.secureInbound(remotePeer, localConn), 51 | crypto.secureOutbound(localPeer, remoteConn, remotePeer) 52 | ]) 53 | 54 | // Echo server 55 | void pipe(inboundResult.conn, inboundResult.conn) 56 | 57 | // Send some data and collect the result 58 | const input = uint8ArrayFromString('data to encrypt') 59 | const result = await pipe( 60 | [input], 61 | outboundResult.conn, 62 | async (source) => all(source) 63 | ) 64 | 65 | expect(result).to.eql([input]) 66 | }) 67 | 68 | it('should return the remote peer id', async () => { 69 | const [localConn, remoteConn] = createMaConnPair() 70 | 71 | const [ 72 | inboundResult, 73 | outboundResult 74 | ] = await Promise.all([ 75 | crypto.secureInbound(remotePeer, localConn), 76 | crypto.secureOutbound(localPeer, remoteConn, remotePeer) 77 | ]) 78 | 79 | // Inbound should return the initiator (local) peer 80 | expect(inboundResult.remotePeer.toBytes()).to.equalBytes(localPeer.toBytes()) 81 | // Outbound should return the receiver (remote) peer 82 | expect(outboundResult.remotePeer.toBytes()).to.equalBytes(remotePeer.toBytes()) 83 | }) 84 | 85 | it('inbound connections should verify peer integrity if known', async () => { 86 | const [localConn, remoteConn] = createMaConnPair() 87 | 88 | await Promise.all([ 89 | crypto.secureInbound(remotePeer, localConn, mitmPeer), 90 | crypto.secureOutbound(localPeer, remoteConn, remotePeer) 91 | ]).then(() => expect.fail(), (err) => { 92 | expect(err).to.exist() 93 | expect(err).to.have.property('code', UnexpectedPeerError.code) 94 | }) 95 | }) 96 | }) 97 | } 98 | -------------------------------------------------------------------------------- /packages/interface-connection-gater/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## [@libp2p/interface-connection-gater-v3.0.1](https://github.com/libp2p/js-libp2p-interfaces/compare/@libp2p/interface-connection-gater-v3.0.0...@libp2p/interface-connection-gater-v3.0.1) (2023-05-04) 2 | 3 | 4 | ### Dependencies 5 | 6 | * bump aegir from 38.1.8 to 39.0.5 ([#393](https://github.com/libp2p/js-libp2p-interfaces/issues/393)) ([31f3797](https://github.com/libp2p/js-libp2p-interfaces/commit/31f3797b24f7c23f3f16e9db3a230bd5f7cd5175)) 7 | 8 | ## [@libp2p/interface-connection-gater-v3.0.0](https://github.com/libp2p/js-libp2p-interfaces/compare/@libp2p/interface-connection-gater-v2.0.1...@libp2p/interface-connection-gater-v3.0.0) (2023-04-18) 9 | 10 | 11 | ### ⚠ BREAKING CHANGES 12 | 13 | * bump it-stream-types from 1.0.5 to 2.0.1 (#362) 14 | 15 | ### Dependencies 16 | 17 | * bump it-stream-types from 1.0.5 to 2.0.1 ([#362](https://github.com/libp2p/js-libp2p-interfaces/issues/362)) ([cdc7747](https://github.com/libp2p/js-libp2p-interfaces/commit/cdc774792beead63e0ded96bd6c23de0335a49e3)) 18 | * update sibling dependencies ([2f52a28](https://github.com/libp2p/js-libp2p-interfaces/commit/2f52a284b59c0a88b040f86da1f5d3f044727f2c)) 19 | 20 | ## [@libp2p/interface-connection-gater-v2.0.1](https://github.com/libp2p/js-libp2p-interfaces/compare/@libp2p/interface-connection-gater-v2.0.0...@libp2p/interface-connection-gater-v2.0.1) (2023-04-14) 21 | 22 | 23 | ### Bug Fixes 24 | 25 | * make deny dial multiaddr optional ([#370](https://github.com/libp2p/js-libp2p-interfaces/issues/370)) ([6bf7a7e](https://github.com/libp2p/js-libp2p-interfaces/commit/6bf7a7e9fe2a77a43c5ddf114c26c4978c579d46)) 26 | 27 | ## [@libp2p/interface-connection-gater-v2.0.0](https://github.com/libp2p/js-libp2p-interfaces/compare/@libp2p/interface-connection-gater-v1.0.3...@libp2p/interface-connection-gater-v2.0.0) (2023-04-14) 28 | 29 | 30 | ### ⚠ BREAKING CHANGES 31 | 32 | * the peer id argument has been removed from the `denyDialMultiaddr` method of the connection gater 33 | 34 | ### Bug Fixes 35 | 36 | * remove peer id argument from deny dial multiaddr ([#366](https://github.com/libp2p/js-libp2p-interfaces/issues/366)) ([aa3e000](https://github.com/libp2p/js-libp2p-interfaces/commit/aa3e0008a94d943df961da7756bf4cf6862bd4c1)) 37 | 38 | ## [@libp2p/interface-connection-gater-v1.0.3](https://github.com/libp2p/js-libp2p-interfaces/compare/@libp2p/interface-connection-gater-v1.0.2...@libp2p/interface-connection-gater-v1.0.3) (2023-04-11) 39 | 40 | 41 | ### Dependencies 42 | 43 | * update sibling dependencies ([b034810](https://github.com/libp2p/js-libp2p-interfaces/commit/b0348102e41dc18166e70063f4708a2b3544f4b6)) 44 | 45 | ## [@libp2p/interface-connection-gater-v1.0.2](https://github.com/libp2p/js-libp2p-interfaces/compare/@libp2p/interface-connection-gater-v1.0.1...@libp2p/interface-connection-gater-v1.0.2) (2023-03-17) 46 | 47 | 48 | ### Bug Fixes 49 | 50 | * update project settings ([2aa4f95](https://github.com/libp2p/js-libp2p-interfaces/commit/2aa4f9583fb8ff9b53c51ebb6b81f72d69a1748d)) 51 | 52 | ## [@libp2p/interface-connection-gater-v1.0.1](https://github.com/libp2p/js-libp2p-interfaces/compare/@libp2p/interface-connection-gater-v1.0.0...@libp2p/interface-connection-gater-v1.0.1) (2023-03-17) 53 | 54 | 55 | ### Dependencies 56 | 57 | * update @multiformats/multiaddr to 12.0.0 ([#354](https://github.com/libp2p/js-libp2p-interfaces/issues/354)) ([e0f327b](https://github.com/libp2p/js-libp2p-interfaces/commit/e0f327b5d54e240feabadce21a841629d633ec5e)) 58 | 59 | ## @libp2p/interface-connection-gater-v1.0.0 (2023-03-09) 60 | 61 | 62 | ### Features 63 | 64 | * split connection gater out into module ([#347](https://github.com/libp2p/js-libp2p-interfaces/issues/347)) ([1824744](https://github.com/libp2p/js-libp2p-interfaces/commit/18247442aa64c809d9e101ccbd0067ce48bdb80f)) 65 | -------------------------------------------------------------------------------- /packages/interface-pubsub-compliance-tests/src/api.ts: -------------------------------------------------------------------------------- 1 | import { mockNetwork } from '@libp2p/interface-mocks' 2 | import { isStartable, start, stop } from '@libp2p/interfaces/startable' 3 | import { expect } from 'aegir/chai' 4 | import delay from 'delay' 5 | import pDefer from 'p-defer' 6 | import pWaitFor from 'p-wait-for' 7 | import sinon from 'sinon' 8 | import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' 9 | import { createComponents } from './utils.js' 10 | import type { PubSubArgs, PubSubComponents } from './index.js' 11 | import type { TestSetup } from '@libp2p/interface-compliance-tests' 12 | import type { PubSub } from '@libp2p/interface-pubsub' 13 | 14 | const topic = 'foo' 15 | const data = uint8ArrayFromString('bar') 16 | 17 | export default (common: TestSetup): void => { 18 | describe('pubsub api', () => { 19 | let pubsub: PubSub 20 | let components: PubSubComponents 21 | 22 | // Create pubsub router 23 | beforeEach(async () => { 24 | mockNetwork.reset() 25 | components = await createComponents() 26 | 27 | pubsub = components.pubsub = await common.setup({ 28 | components, 29 | init: { 30 | emitSelf: true 31 | } 32 | }) 33 | }) 34 | 35 | afterEach(async () => { 36 | sinon.restore() 37 | await stop(...Object.values(components)) 38 | await common.teardown() 39 | mockNetwork.reset() 40 | }) 41 | 42 | it('can start correctly', async () => { 43 | if (!isStartable(pubsub)) { 44 | return 45 | } 46 | 47 | sinon.spy(components.registrar, 'register') 48 | 49 | await start(...Object.values(components)) 50 | 51 | expect(pubsub.isStarted()).to.equal(true) 52 | expect(components.registrar.register).to.have.property('callCount', 1) 53 | }) 54 | 55 | it('can stop correctly', async () => { 56 | if (!isStartable(pubsub)) { 57 | return 58 | } 59 | 60 | sinon.spy(components.registrar, 'unregister') 61 | 62 | await start(...Object.values(components)) 63 | await stop(...Object.values(components)) 64 | 65 | expect(pubsub.isStarted()).to.equal(false) 66 | expect(components.registrar.unregister).to.have.property('callCount', 1) 67 | }) 68 | 69 | it('can subscribe and unsubscribe correctly', async () => { 70 | const handler = (): void => { 71 | throw new Error('a message should not be received') 72 | } 73 | 74 | await start(...Object.values(components)) 75 | pubsub.subscribe(topic) 76 | pubsub.addEventListener('message', handler) 77 | 78 | await pWaitFor(() => { 79 | const topics = pubsub.getTopics() 80 | return topics.length === 1 && topics[0] === topic 81 | }) 82 | 83 | pubsub.removeEventListener('message', handler) 84 | pubsub.unsubscribe(topic) 85 | 86 | await pWaitFor(() => pubsub.getTopics().length === 0) 87 | 88 | // Publish to guarantee the handler is not called 89 | await pubsub.publish(topic, data) 90 | 91 | // handlers are called async 92 | await delay(100) 93 | 94 | await stop(...Object.values(components)) 95 | }) 96 | 97 | it('can subscribe and publish correctly', async () => { 98 | const defer = pDefer() 99 | 100 | await start(...Object.values(components)) 101 | 102 | pubsub.subscribe(topic) 103 | pubsub.addEventListener('message', (evt) => { 104 | expect(evt).to.have.nested.property('detail.topic', topic) 105 | expect(evt).to.have.deep.nested.property('detail.data', data) 106 | defer.resolve() 107 | }) 108 | await pubsub.publish(topic, data) 109 | await defer.promise 110 | 111 | await stop(...Object.values(components)) 112 | }) 113 | }) 114 | } 115 | --------------------------------------------------------------------------------