diff --git a/packages/libp2p-daemon-client/.aegir.js b/packages/libp2p-daemon-client/.aegir.js deleted file mode 100644 index 135a6a2211..0000000000 --- a/packages/libp2p-daemon-client/.aegir.js +++ /dev/null @@ -1,8 +0,0 @@ - -export default { - build: { - config: { - platform: 'node' - } - } -} diff --git a/packages/libp2p-daemon-client/API.md b/packages/libp2p-daemon-client/API.md deleted file mode 100644 index 67732fea6d..0000000000 --- a/packages/libp2p-daemon-client/API.md +++ /dev/null @@ -1,500 +0,0 @@ -# API - -* [Getting started](#getting-started) -* [`close`](#close) -* [`connect`](#connect) -* [`identify`](#identify) -* [`listPeers`](#listPeers) -* [`openStream`](#openStream) -* [`registerStream`](#registerStream) -* [`dht.put`](#dht.put) -* [`dht.get`](#dht.get) -* [`dht.findPeer`](#dht.findPeer) -* [`dht.provide`](#dht.provide) -* [`dht.findProviders`](#dht.findProviders) -* [`dht.getClosestPeers`](#dht.getClosestPeers) -* [`dht.getPublicKey`](#dht.getPublicKey) -* [`pubsub.getTopics`](#pubsub.getTopics) -* [`pubsub.publish`](#pubsub.publish) -* [`pubsub.subscribe`](#pubsub.subscribe) - -## Getting started - -Create a new daemon client, using a unix socket. - -### `Client(socketPath)` - -#### Parameters - -| Name | Type | Description | -|------|------|-------------| -| socketPath | `String` | unix socket path | - -#### Returns - -Client instance - -#### Example - -```js -const Client = require('libp2p-daemon-client') - -const defaultSock = '/tmp/p2pd.sock' -const client = new Client(defaultSock) - -// client.{} -``` - -## close - -Closes the socket. - -### `client.close()` - -#### Returns - -| Type | Description | -|------|-------------| -| `Promise` | Promise resolves when socket is closed | - -#### Example - -```js -const Client = require('libp2p-daemon-client') - -const defaultSock = '/tmp/p2pd.sock' -const client = new Client(defaultSock) - -// close the socket -await client.close() -``` - -## connect - -Requests a connection to a known peer on a given set of addresses. - -### `client.connect(peerId, addrs)` - -#### Parameters - -| Name | Type | Description | -|------|------|-------------| -| peerId | [`PeerId`](https://github.com/libp2p/js-peer-id) | peer ID to connect | -| options | `Object` | set of addresses to connect | - -#### Example - -```js -const client = new Client(defaultSock) - -try { - await client.connect(peerId, addrs) -} catch (err) { - // -} -``` - -## identify - -Query the daemon for its peer ID and listen addresses. - -### `client.identify()` - -#### Returns - -| Type | Description | -|------|-------------| -| `Object` | Identify response | -| `Object.peerId` | Peer id of the daemon | -| `Object.addrs` | Addresses of the daemon | - -#### Example - -```js -const client = new Client(defaultSock) - -let identify - -try { - identify = await client.identify() -} catch (err) { - // -} -``` - -## listPeers - -Get a list of IDs of peers the node is connected to. - -### `client.listPeers()` - -#### Returns - -| Type | Description | -|------|-------------| -| `Array` | array of peer id's | -| `Array.` | Peer id of a node | - -#### Example - -```js -const client = new Client(defaultSock) - -let identify - -try { - identify = await client.identify() -} catch (err) { - // -} -``` - -## openStream - -Initiate an outbound stream to a peer on one of a set of protocols. - -### `client.openStream(peerId, protocol)` - -#### Parameters - -| Name | Type | Description | -|------|------|-------------| -| peerId | [`PeerId`](https://github.com/libp2p/js-peer-id) | peer ID to connect | -| protocol | `string` | protocol to use | - -#### Returns - -| Type | Description | -|------|-------------| -| `Socket` | socket to write data | - -#### Example - -```js -const protocol = '/protocol/1.0.0' -const client = new Client(defaultSock) - -let socket - -try { - socket = await client.openStream(peerId, protocol) -} catch (err) { - // -} - -socket.write(uint8ArrayFromString('data')) -``` - -## registerStreamHandler - -Register a handler for inbound streams on a given protocol. - -### `client.registerStreamHandler(path, protocol)` - -#### Parameters - -| Name | Type | Description | -|------|------|-------------| -| path | `string` | socket path | -| protocol | `string` | protocol to use | - -#### Example - -```js -const protocol = '/protocol/1.0.0' -const client = new Client(defaultSock) - -await client.registerStreamHandler(path, protocol) -``` - -## dht.put - -Write a value to a key in the DHT. - -### `client.dht.put(key, value)` - -#### Parameters - -| Name | Type | Description | -|------|------|-------------| -| key | `Uint8Array` | key to add to the dht | -| value | `Uint8Array` | value to add to the dht | - -#### Example - -```js -const client = new Client(defaultSock) - -const key = '/key' -const value = uint8ArrayFromString('oh hello there') - -try { - await client.dht.put(key, value) -} catch (err) { - // -} -``` - -## dht.get - -Query the DHT for a value stored through a key in the DHT. - -### `client.dht.get(key)` - -#### Parameters - -| Name | Type | Description | -|------|------|-------------| -| key | `Uint8Array` | key to get from the dht | - -#### Returns - -| Type | Description | -|------|-------------| -| `Uint8Array` | Value obtained from the DHT | - -#### Example - -```js -const client = new Client(defaultSock) - -const key = '/key' -let value - -try { - value = await client.dht.get(key, value) -} catch (err) { - // -} -``` - -## dht.findPeer - -Query the DHT for a given peer's known addresses. - -### `client.dht.findPeer(peerId)` - -#### Parameters - -| Name | Type | Description | -|------|------|-------------| -| peerId | [`PeerId`](https://github.com/libp2p/js-peer-id) | ID of the peer to find | - -#### Returns - -| Type | Description | -|------|-------------| -| `PeerInfo` | Peer info of a known peer | - -#### Example - -```js -const client = new Client(defaultSock) - -let peerInfo - -try { - peerInfo = await client.dht.findPeer(peerId) -} catch (err) { - // -} -``` - -## dht.provide - -Announce that have data addressed by a given CID. - -### `client.dht.provide(cid)` - -#### Parameters - -| Name | Type | Description | -|------|------|-------------| -| cid | [`CID`](https://github.com/multiformats/js-cid) | cid to provide | - -#### Example - -```js -const client = new Client(defaultSock) - -try { - await client.dht.provide(cid) -} catch (err) { - // -} -``` - -## dht.findProviders - -Query the DHT for peers that have a piece of content, identified by a CID. - -### `client.dht.findProviders(cid, [count])` - -#### Parameters - -| Name | Type | Description | -|------|------|-------------| -| cid | [`CID`](https://github.com/multiformats/js-cid) | cid to find | -| count | `number` | number or results aimed | - -#### Returns - -| Type | Description | -|------|-------------| -| `Array` | array of peer info | -| `Array.` | Peer info of a node | - -#### Example - -```js -const client = new Client(defaultSock) - -let peerInfos - -try { - peerInfos = await client.dht.findProviders(cid) -} catch (err) { - // -} -``` - -## dht.getClosestPeers - -Query the DHT routing table for peers that are closest to a provided key. - -### `client.dht.getClosestPeers(key)` - -#### Parameters - -| Name | Type | Description | -|------|------|-------------| -| key | `Uint8Array` | key to get from the dht | - -#### Returns - -| Type | Description | -|------|-------------| -| `Array` | array of peer info | -| `Array.` | Peer info of a node | - -#### Example - -```js -const client = new Client(defaultSock) - -let peerInfos - -try { - peerInfos = await client.dht.getClosestPeers(key) -} catch (err) { - // -} -``` - -## dht.getPublicKey - -Query the DHT routing table for a given peer's public key. - -### `client.dht.getPublicKey(peerId)` - -#### Parameters - -| Name | Type | Description | -|------|------|-------------| -| peerId | [`PeerId`](https://github.com/libp2p/js-peer-id) | ID of the peer to find | - -#### Returns - -| Type | Description | -|------|-------------| -| `PublicKey` | public key of the peer | - -#### Example - -```js -const client = new Client(defaultSock) - -let publicKey - -try { - publicKey = await client.dht.getPublicKey(peerId) -} catch (err) { - // -} -``` - -### `client.pubsub.getTopics()` - -#### Returns - -| Type | Description | -|------|-------------| -| `Array` | topics the node is subscribed to | - -#### Example - -```js -const client = new Client(defaultSock) - -let topics - -try { - topics = await client.pubsub.getTopics() -} catch (err) { - // -} -``` - -### `client.pubsub.publish()` - -#### Parameters - -| Name | Type | Description | -|------|------|-------------| -| topic | `string` | topic to publish | -| data | `Uint8Array` | data to publish | - -#### Returns - -| Type | Description | -|------|-------------| -| `Promise` | publish success | - -#### Example - -```js -const topic = 'topic' -const data = uint8ArrayFromString('data') -const client = new Client(defaultSock) - -try { - await client.pubsub.publish(topic, data) -} catch (err) { - // -} -``` - -### `client.pubsub.subscribe()` - -#### Parameters - -| Name | Type | Description | -|------|------|-------------| -| topic | `string` | topic to subscribe | - -#### Returns - -| Type | Description | -|------|-------------| -| `AsyncIterator` | data published | - -#### Example - -```js -const topic = 'topic' -const client = new Client(defaultSock) - -for await (const msg of client.pubsub.subscribe(topic)) { - // msg.data - pubsub data received -} -``` diff --git a/packages/libp2p-daemon-client/CHANGELOG.md b/packages/libp2p-daemon-client/CHANGELOG.md deleted file mode 100644 index 2b00f16859..0000000000 --- a/packages/libp2p-daemon-client/CHANGELOG.md +++ /dev/null @@ -1,463 +0,0 @@ -## [@libp2p/daemon-client-v6.0.3](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-client-v6.0.2...@libp2p/daemon-client-v6.0.3) (2023-04-27) - - -### Bug Fixes - -* use interface-libp2p to ensure the correct services are set ([#203](https://github.com/libp2p/js-libp2p-daemon/issues/203)) ([8602a70](https://github.com/libp2p/js-libp2p-daemon/commit/8602a704e45cfa768ad55974d025b2d4be6f42a9)) - -## [@libp2p/daemon-client-v6.0.2](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-client-v6.0.1...@libp2p/daemon-client-v6.0.2) (2023-04-24) - - -### Dependencies - -* bump @libp2p/interface-peer-store from 1.2.9 to 2.0.0 ([#201](https://github.com/libp2p/js-libp2p-daemon/issues/201)) ([9b146a8](https://github.com/libp2p/js-libp2p-daemon/commit/9b146a8c38c30a13401be6da5259cd9da6bdc25c)) - -## [@libp2p/daemon-client-v6.0.1](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-client-v6.0.0...@libp2p/daemon-client-v6.0.1) (2023-04-24) - - -### Dependencies - -* **dev:** bump @libp2p/interface-mocks from 10.0.3 to 11.0.0 ([#199](https://github.com/libp2p/js-libp2p-daemon/issues/199)) ([76f7b6f](https://github.com/libp2p/js-libp2p-daemon/commit/76f7b6fdd1af129ac278c5d2313d466db3e28a78)) - -## [@libp2p/daemon-client-v6.0.0](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-client-v5.0.3...@libp2p/daemon-client-v6.0.0) (2023-04-19) - - -### ⚠ BREAKING CHANGES - -* the type of the source/sink properties have changed - -### Dependencies - -* update it-stream-types to 2.x.x ([#196](https://github.com/libp2p/js-libp2p-daemon/issues/196)) ([a09f6d5](https://github.com/libp2p/js-libp2p-daemon/commit/a09f6d58942033b08b579735aaa1537b3a324776)) -* update sibling dependencies ([db50405](https://github.com/libp2p/js-libp2p-daemon/commit/db50405ddec3a68ad265c3d3233595187bc4895d)) -* update sibling dependencies ([e0ec5ec](https://github.com/libp2p/js-libp2p-daemon/commit/e0ec5ecf5bfd7f801274d37d51c3dcce652de2ba)) - -## [@libp2p/daemon-client-v5.0.3](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-client-v5.0.2...@libp2p/daemon-client-v5.0.3) (2023-04-12) - - -### Dependencies - -* bump @libp2p/interface-connection from 3.1.1 to 4.0.0 ([#195](https://github.com/libp2p/js-libp2p-daemon/issues/195)) ([798ecc5](https://github.com/libp2p/js-libp2p-daemon/commit/798ecc594bc64c8e34aad13e1b9884011f0b1f29)) - -## [@libp2p/daemon-client-v5.0.2](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-client-v5.0.1...@libp2p/daemon-client-v5.0.2) (2023-04-03) - - -### Dependencies - -* update all it-* deps to the latest versions ([#193](https://github.com/libp2p/js-libp2p-daemon/issues/193)) ([cb0aa85](https://github.com/libp2p/js-libp2p-daemon/commit/cb0aa85bbbad651db088594622a9438a127d2a10)) - -## [@libp2p/daemon-client-v5.0.1](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-client-v5.0.0...@libp2p/daemon-client-v5.0.1) (2023-03-17) - - -### Dependencies - -* bump @multiformats/multiaddr from 11.6.1 to 12.0.0 ([#189](https://github.com/libp2p/js-libp2p-daemon/issues/189)) ([aaf7e2e](https://github.com/libp2p/js-libp2p-daemon/commit/aaf7e2e37423cae78cd16d8e16e06db40fdcd1e3)) - -## [@libp2p/daemon-client-v5.0.0](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-client-v4.1.0...@libp2p/daemon-client-v5.0.0) (2023-02-24) - - -### ⚠ BREAKING CHANGES - -* update pubsub subscribe method to return subscription (#186) - -### Bug Fixes - -* update pubsub subscribe method to return subscription ([#186](https://github.com/libp2p/js-libp2p-daemon/issues/186)) ([88e4bf5](https://github.com/libp2p/js-libp2p-daemon/commit/88e4bf54ee5189e808cee451f08467c7db302b8d)) - -## [@libp2p/daemon-client-v4.1.0](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-client-v4.0.3...@libp2p/daemon-client-v4.1.0) (2023-02-23) - - -### Features - -* add get subscribers for pubsub topics ([#184](https://github.com/libp2p/js-libp2p-daemon/issues/184)) ([c8be43e](https://github.com/libp2p/js-libp2p-daemon/commit/c8be43e5acd6a74cfdd01857343af6f6d8210d5d)) - -## [@libp2p/daemon-client-v4.0.3](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-client-v4.0.2...@libp2p/daemon-client-v4.0.3) (2023-02-22) - - -### Dependencies - -* bump aegir from 37.12.1 to 38.1.6 ([#183](https://github.com/libp2p/js-libp2p-daemon/issues/183)) ([6725a0a](https://github.com/libp2p/js-libp2p-daemon/commit/6725a0aeba9acb56a7530dece6c65a0f3eadfec5)) - -## [@libp2p/daemon-client-v4.0.2](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-client-v4.0.1...@libp2p/daemon-client-v4.0.2) (2023-02-22) - - -### Trivial Changes - -* remove lerna ([#171](https://github.com/libp2p/js-libp2p-daemon/issues/171)) ([367f912](https://github.com/libp2p/js-libp2p-daemon/commit/367f9122f2fe1c31c8de7a136cda18d024ff08d7)) -* replace err-code with CodeError ([#172](https://github.com/libp2p/js-libp2p-daemon/issues/172)) ([c330fd5](https://github.com/libp2p/js-libp2p-daemon/commit/c330fd5fabac7efb016d1f23e781ce88c38a3b37)), closes [#1269](https://github.com/libp2p/js-libp2p-daemon/issues/1269) - - -### Dependencies - -* **dev:** bump sinon from 14.0.2 to 15.0.1 ([#166](https://github.com/libp2p/js-libp2p-daemon/issues/166)) ([1702efb](https://github.com/libp2p/js-libp2p-daemon/commit/1702efb4248bea4cb9ec19c694c1caae1c0ff16d)) - -## [@libp2p/daemon-client-v4.0.1](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-client-v4.0.0...@libp2p/daemon-client-v4.0.1) (2023-01-07) - - -### Dependencies - -* bump @libp2p/tcp from 5.0.2 to 6.0.8 ([#165](https://github.com/libp2p/js-libp2p-daemon/issues/165)) ([fb676ab](https://github.com/libp2p/js-libp2p-daemon/commit/fb676ab66348b3c704d2385b4da0d7173bc4a04d)) - -## [@libp2p/daemon-client-v4.0.0](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-client-v3.0.6...@libp2p/daemon-client-v4.0.0) (2023-01-07) - - -### ⚠ BREAKING CHANGES - -* Update multiformats and related dependencies (#170) - -### Dependencies - -* Update multiformats and related dependencies ([#170](https://github.com/libp2p/js-libp2p-daemon/issues/170)) ([06744a7](https://github.com/libp2p/js-libp2p-daemon/commit/06744a77006dc77dcfb7bd860e4dc6f36a535603)) -* update sibling dependencies ([775bd83](https://github.com/libp2p/js-libp2p-daemon/commit/775bd83a63ae99c4b892f0169f76dbe39163e2d4)) - -## [@libp2p/daemon-client-v3.0.6](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-client-v3.0.5...@libp2p/daemon-client-v3.0.6) (2022-10-17) - - -### Dependencies - -* **dev:** bump it-all from 1.0.6 to 2.0.0 ([#148](https://github.com/libp2p/js-libp2p-daemon/issues/148)) ([1caa500](https://github.com/libp2p/js-libp2p-daemon/commit/1caa5006157e864bcbe4efb8f9474328b08821c3)) - -## [@libp2p/daemon-client-v3.0.5](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-client-v3.0.4...@libp2p/daemon-client-v3.0.5) (2022-10-14) - - -### Bug Fixes - -* handle empty responses ([#145](https://github.com/libp2p/js-libp2p-daemon/issues/145)) ([0dfb823](https://github.com/libp2p/js-libp2p-daemon/commit/0dfb8236a0ab57a55fa0ebb91ac7a776a9f709da)) - -## [@libp2p/daemon-client-v3.0.4](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-client-v3.0.3...@libp2p/daemon-client-v3.0.4) (2022-10-14) - - -### Dependencies - -* **dev:** bump sinon-ts from 0.0.2 to 1.0.0 ([#144](https://github.com/libp2p/js-libp2p-daemon/issues/144)) ([cfc8755](https://github.com/libp2p/js-libp2p-daemon/commit/cfc8755aa1280ac4fc2aae67cf47d7b0b93f605d)) - -## [@libp2p/daemon-client-v3.0.3](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-client-v3.0.2...@libp2p/daemon-client-v3.0.3) (2022-10-13) - - -### Dependencies - -* update uint8arrays, protons and multiformats ([#143](https://github.com/libp2p/js-libp2p-daemon/issues/143)) ([661139c](https://github.com/libp2p/js-libp2p-daemon/commit/661139c674c9994724e32227d7d9ae2c5da1cea2)) - -## [@libp2p/daemon-client-v3.0.2](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-client-v3.0.1...@libp2p/daemon-client-v3.0.2) (2022-10-07) - - -### Dependencies - -* bump @libp2p/tcp from 3.0.0 to 4.0.1 ([4e64dce](https://github.com/libp2p/js-libp2p-daemon/commit/4e64dce5e6d18dadaa54a20fff7b2da8bbca11ae)) -* **dev:** bump @libp2p/components from 2.1.1 to 3.0.1 ([#133](https://github.com/libp2p/js-libp2p-daemon/issues/133)) ([6d75a57](https://github.com/libp2p/js-libp2p-daemon/commit/6d75a5742040a594c02aa92ee6acf4ef9080ebac)) -* **dev:** bump @libp2p/interface-mocks from 4.0.3 to 6.0.0 ([#130](https://github.com/libp2p/js-libp2p-daemon/issues/130)) ([3807d1d](https://github.com/libp2p/js-libp2p-daemon/commit/3807d1dd9b037938dbe3dd9e9fb2560489d5d603)) - -## [@libp2p/daemon-client-v3.0.1](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-client-v3.0.0...@libp2p/daemon-client-v3.0.1) (2022-09-21) - - -### Dependencies - -* update @multiformats/multiaddr to 11.0.0 ([#128](https://github.com/libp2p/js-libp2p-daemon/issues/128)) ([885d901](https://github.com/libp2p/js-libp2p-daemon/commit/885d9013d82a62e6756b06350932df1242a13296)) - -## [@libp2p/daemon-client-v3.0.0](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-client-v2.0.4...@libp2p/daemon-client-v3.0.0) (2022-09-09) - - -### ⚠ BREAKING CHANGES - -* the stream type returned by `client.openStream` has changed - -### Bug Fixes - -* allow opening remote streams ([#126](https://github.com/libp2p/js-libp2p-daemon/issues/126)) ([361cc57](https://github.com/libp2p/js-libp2p-daemon/commit/361cc5750de505ab0381ae43609c67d5d4f659a7)) - - -### Dependencies - -* update sibling dependencies ([56711c4](https://github.com/libp2p/js-libp2p-daemon/commit/56711c4f14b0cf2370b8612fe07d42ed2ac8363c)) -* update sibling dependencies ([c3ebd58](https://github.com/libp2p/js-libp2p-daemon/commit/c3ebd588abc36ef45667e8e4e4c0e220303b7510)) - -## [@libp2p/daemon-client-v2.0.4](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-client-v2.0.3...@libp2p/daemon-client-v2.0.4) (2022-08-10) - - -### Bug Fixes - -* update all deps ([#124](https://github.com/libp2p/js-libp2p-daemon/issues/124)) ([5e46e1e](https://github.com/libp2p/js-libp2p-daemon/commit/5e46e1e26c23428046a6007ab158420d3d830145)) - -## [@libp2p/daemon-client-v2.0.3](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-client-v2.0.2...@libp2p/daemon-client-v2.0.3) (2022-07-31) - - -### Trivial Changes - -* update project config ([#111](https://github.com/libp2p/js-libp2p-daemon/issues/111)) ([345e663](https://github.com/libp2p/js-libp2p-daemon/commit/345e663e34278e780fc2f3a6b595294f925c4521)) - - -### Dependencies - -* update uint8arraylist and protons deps ([#115](https://github.com/libp2p/js-libp2p-daemon/issues/115)) ([34a8334](https://github.com/libp2p/js-libp2p-daemon/commit/34a83340ba855a9c08319ae1cd735dfa8b71c248)) - -## [@libp2p/daemon-client-v2.0.2](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-client-v2.0.1...@libp2p/daemon-client-v2.0.2) (2022-06-17) - - -### Trivial Changes - -* update deps ([#105](https://github.com/libp2p/js-libp2p-daemon/issues/105)) ([0bdab0e](https://github.com/libp2p/js-libp2p-daemon/commit/0bdab0ee254e32d6dca0e5fe239d4ef16db41b87)) - -## [@libp2p/daemon-client-v2.0.1](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-client-v2.0.0...@libp2p/daemon-client-v2.0.1) (2022-06-15) - - -### Trivial Changes - -* update deps ([#103](https://github.com/libp2p/js-libp2p-daemon/issues/103)) ([2bfaa37](https://github.com/libp2p/js-libp2p-daemon/commit/2bfaa37e2f056dcd5de5a3882b77f52553c595d4)) - -## [@libp2p/daemon-client-v2.0.0](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-client-v1.0.5...@libp2p/daemon-client-v2.0.0) (2022-06-15) - - -### ⚠ BREAKING CHANGES - -* uses new single-issue libp2p interface modules - -### Features - -* update to latest libp2p interfaces ([#102](https://github.com/libp2p/js-libp2p-daemon/issues/102)) ([f5e9121](https://github.com/libp2p/js-libp2p-daemon/commit/f5e91210654ab3c411e316c1c657356c037a0f6a)) - -## [@libp2p/daemon-client-v1.0.5](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-client-v1.0.4...@libp2p/daemon-client-v1.0.5) (2022-05-25) - - -### Trivial Changes - -* update docs ([#91](https://github.com/libp2p/js-libp2p-daemon/issues/91)) ([5b072ff](https://github.com/libp2p/js-libp2p-daemon/commit/5b072ff89f30fd6cf55a3387bf0961c8ad78a22f)), closes [#83](https://github.com/libp2p/js-libp2p-daemon/issues/83) - -## [@libp2p/daemon-client-v1.0.4](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-client-v1.0.3...@libp2p/daemon-client-v1.0.4) (2022-05-23) - - -### Bug Fixes - -* update deps ([#90](https://github.com/libp2p/js-libp2p-daemon/issues/90)) ([b50eba3](https://github.com/libp2p/js-libp2p-daemon/commit/b50eba3770e47969dbc30cbcf87c41672cd9c175)) - -## [@libp2p/daemon-client-v1.0.3](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-client-v1.0.2...@libp2p/daemon-client-v1.0.3) (2022-05-10) - - -### Bug Fixes - -* encode enums correctly ([#86](https://github.com/libp2p/js-libp2p-daemon/issues/86)) ([6ce4633](https://github.com/libp2p/js-libp2p-daemon/commit/6ce4633f3db41ab66f9b8b1abbe84955dde3e9be)) - -## [@libp2p/daemon-client-v1.0.2](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-client-v1.0.1...@libp2p/daemon-client-v1.0.2) (2022-04-20) - - -### Bug Fixes - -* update interfaces and deps ([#84](https://github.com/libp2p/js-libp2p-daemon/issues/84)) ([25173d5](https://github.com/libp2p/js-libp2p-daemon/commit/25173d5b2edf0e9dd9132707d349cdc862caecdb)) - -## [@libp2p/daemon-client-v1.0.1](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-client-v1.0.0...@libp2p/daemon-client-v1.0.1) (2022-04-07) - - -### Bug Fixes - -* remove protobufjs and replace with protons ([#81](https://github.com/libp2p/js-libp2p-daemon/issues/81)) ([78dd02a](https://github.com/libp2p/js-libp2p-daemon/commit/78dd02a679e55f22c7e24c1ee2b6f92a4679a0b9)) - - -### Trivial Changes - -* update aegir to latest version ([#80](https://github.com/libp2p/js-libp2p-daemon/issues/80)) ([3a98959](https://github.com/libp2p/js-libp2p-daemon/commit/3a98959617d9c19bba9fb064defee3d51acfcc29)) - -## @libp2p/daemon-client-v1.0.0 (2022-03-28) - - -### ⚠ BREAKING CHANGES - -* This module is now ESM only - -### Features - -* convert to typescript ([#78](https://github.com/libp2p/js-libp2p-daemon/issues/78)) ([f18b2a4](https://github.com/libp2p/js-libp2p-daemon/commit/f18b2a45871a2704db51b03e8583eefdcd13554c)) - -# [0.11.0](https://github.com/libp2p/js-libp2p-daemon-client/compare/v0.10.0...v0.11.0) (2022-01-17) - - -### Features - -* async peerstore ([#110](https://github.com/libp2p/js-libp2p-daemon-client/issues/110)) ([41dc8a5](https://github.com/libp2p/js-libp2p-daemon-client/commit/41dc8a59ce14447b9b5ab7ba9930f4140bda3652)) - - -### BREAKING CHANGES - -* peerstore methods are now all async - - - -# [0.10.0](https://github.com/libp2p/js-libp2p-daemon-client/compare/v0.9.0...v0.10.0) (2021-12-29) - - -### chore - -* update deps ([#103](https://github.com/libp2p/js-libp2p-daemon-client/issues/103)) ([cdbc4b2](https://github.com/libp2p/js-libp2p-daemon-client/commit/cdbc4b22f3599f33911be1b406b02d06515389b8)) - - -### BREAKING CHANGES - -* only node15+ is supported - - - -# [0.9.0](https://github.com/libp2p/js-libp2p-daemon-client/compare/v0.7.0...v0.9.0) (2021-11-18) - - - -# [0.7.0](https://github.com/libp2p/js-libp2p-daemon-client/compare/v0.6.0...v0.7.0) (2021-07-30) - - - -# [0.6.0](https://github.com/libp2p/js-libp2p-daemon-client/compare/v0.5.0...v0.6.0) (2021-05-04) - - - - -# [0.5.0](https://github.com/libp2p/js-libp2p-daemon-client/compare/v0.4.0...v0.5.0) (2020-08-23) - - -### Bug Fixes - -* replace node buffers with uint8arrays ([#42](https://github.com/libp2p/js-libp2p-daemon-client/issues/42)) ([33be887](https://github.com/libp2p/js-libp2p-daemon-client/commit/33be887)) - - -### BREAKING CHANGES - -* - All deps of this module now use uint8arrays in place of node buffers -- DHT keys/values are Uint8Arrays, not Strings or Buffers - -* chore: bump daemon dep - -Co-authored-by: Jacob Heun - - - - -# [0.4.0](https://github.com/libp2p/js-libp2p-daemon-client/compare/v0.3.1...v0.4.0) (2020-06-08) - - - - -## [0.3.1](https://github.com/libp2p/js-libp2p-daemon-client/compare/v0.3.0...v0.3.1) (2020-04-20) - - - - -# [0.3.0](https://github.com/libp2p/js-libp2p-daemon-client/compare/v0.2.2...v0.3.0) (2020-01-31) - - -### Chores - -* update deps ([#18](https://github.com/libp2p/js-libp2p-daemon-client/issues/18)) ([61813b9](https://github.com/libp2p/js-libp2p-daemon-client/commit/61813b9)) - - -### BREAKING CHANGES - -* api changed as attach is not needed anymore - -* chore: apply suggestions from code review - -Co-Authored-By: Jacob Heun - -* chore: update aegir - -* chore: update daemon version - -Co-authored-by: Jacob Heun - - - - -## [0.2.2](https://github.com/libp2p/js-libp2p-daemon-client/compare/v0.2.1...v0.2.2) (2019-09-05) - - - - -## [0.2.1](https://github.com/libp2p/js-libp2p-daemon-client/compare/v0.2.0...v0.2.1) (2019-07-09) - - -### Bug Fixes - -* **client.connect:** handle empty response ([#13](https://github.com/libp2p/js-libp2p-daemon-client/issues/13)) ([ace789d](https://github.com/libp2p/js-libp2p-daemon-client/commit/ace789d)) -* **client.connect:** handle unspecified error in response ([#12](https://github.com/libp2p/js-libp2p-daemon-client/issues/12)) ([7db681b](https://github.com/libp2p/js-libp2p-daemon-client/commit/7db681b)) - - - - -# [0.2.0](https://github.com/libp2p/js-libp2p-daemon-client/compare/v0.1.2...v0.2.0) (2019-07-09) - - -### Bug Fixes - -* use error as field name instead of ErrorResponse ([#14](https://github.com/libp2p/js-libp2p-daemon-client/issues/14)) ([0ff9eda](https://github.com/libp2p/js-libp2p-daemon-client/commit/0ff9eda)) - - -### BREAKING CHANGES - -* errors property name is now `error` instead of `ErrorResponse` - - - - -## [0.1.2](https://github.com/libp2p/js-libp2p-daemon-client/compare/v0.1.1...v0.1.2) (2019-03-29) - - -### Bug Fixes - -* dht find providers stream ([24eb727](https://github.com/libp2p/js-libp2p-daemon-client/commit/24eb727)) - - - - -## [0.1.1](https://github.com/libp2p/js-libp2p-daemon-client/compare/v0.1.0...v0.1.1) (2019-03-25) - - -### Bug Fixes - -* code review feedback ([7fd02d9](https://github.com/libp2p/js-libp2p-daemon-client/commit/7fd02d9)) - - -### Features - -* pubsub ([c485f50](https://github.com/libp2p/js-libp2p-daemon-client/commit/c485f50)) - - - - -# [0.1.0](https://github.com/libp2p/js-libp2p-daemon-client/compare/v0.0.4...v0.1.0) (2019-03-22) - - -### Bug Fixes - -* update code to work with latest daemon ([#6](https://github.com/libp2p/js-libp2p-daemon-client/issues/6)) ([0ada86c](https://github.com/libp2p/js-libp2p-daemon-client/commit/0ada86c)) - - - - -## [0.0.4](https://github.com/libp2p/js-libp2p-daemon-client/compare/0.0.3...v0.0.4) (2019-03-15) - - -### Features - -* streams ([7cefefd](https://github.com/libp2p/js-libp2p-daemon-client/commit/7cefefd)) - - - - -## [0.0.3](https://github.com/libp2p/js-libp2p-daemon-client/compare/0.0.2...0.0.3) (2019-02-13) - - -### Bug Fixes - -* connect should use peer id in bytes ([b9e4e44](https://github.com/libp2p/js-libp2p-daemon-client/commit/b9e4e44)) - - - - -## [0.0.2](https://github.com/libp2p/js-libp2p-daemon-client/compare/e748b7c...0.0.2) (2019-02-11) - - -### Bug Fixes - -* code review ([6ae7ce0](https://github.com/libp2p/js-libp2p-daemon-client/commit/6ae7ce0)) -* code review ([80e3d62](https://github.com/libp2p/js-libp2p-daemon-client/commit/80e3d62)) -* main on package.json ([8fcc62b](https://github.com/libp2p/js-libp2p-daemon-client/commit/8fcc62b)) - - -### Features - -* initial implementation ([e748b7c](https://github.com/libp2p/js-libp2p-daemon-client/commit/e748b7c)) diff --git a/packages/libp2p-daemon-client/LICENSE b/packages/libp2p-daemon-client/LICENSE deleted file mode 100644 index 20ce483c86..0000000000 --- a/packages/libp2p-daemon-client/LICENSE +++ /dev/null @@ -1,4 +0,0 @@ -This project is dual licensed under MIT and Apache-2.0. - -MIT: https://www.opensource.org/licenses/mit -Apache-2.0: https://www.apache.org/licenses/license-2.0 diff --git a/packages/libp2p-daemon-client/LICENSE-APACHE b/packages/libp2p-daemon-client/LICENSE-APACHE deleted file mode 100644 index 14478a3b60..0000000000 --- a/packages/libp2p-daemon-client/LICENSE-APACHE +++ /dev/null @@ -1,5 +0,0 @@ -Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - -http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. diff --git a/packages/libp2p-daemon-client/LICENSE-MIT b/packages/libp2p-daemon-client/LICENSE-MIT deleted file mode 100644 index 72dc60d84b..0000000000 --- a/packages/libp2p-daemon-client/LICENSE-MIT +++ /dev/null @@ -1,19 +0,0 @@ -The MIT License (MIT) - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. diff --git a/packages/libp2p-daemon-client/README.md b/packages/libp2p-daemon-client/README.md deleted file mode 100644 index 996f69192b..0000000000 --- a/packages/libp2p-daemon-client/README.md +++ /dev/null @@ -1,87 +0,0 @@ -# @libp2p/daemon-client - -[![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) -[![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) -[![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p) -[![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p/main.yml?branch=master\&style=flat-square)](https://github.com/libp2p/js-libp2p/actions/workflows/main.yml?query=branch%3Amaster) - -> libp2p-daemon client implementation - -## Table of contents - -- [Install](#install) -- [Specs](#specs) -- [Usage](#usage) - - [Run a daemon process](#run-a-daemon-process) - - [Interact with the daemon process using the client](#interact-with-the-daemon-process-using-the-client) -- [API](#api) -- [License](#license) -- [Contribution](#contribution) - -## Install - -```console -$ npm i @libp2p/daemon-client -``` - -## Specs - -The specs for the daemon are currently housed in the go implementation. You can read them at [libp2p/go-libp2p-daemon](https://github.com/libp2p/go-libp2p-daemon/blob/master/specs/README.md) - -## Usage - -### Run a daemon process - -There are currently two implementations of the `libp2p-daemon`: - -- [js-libp2p-daemon](https://github.com/libp2p/js-libp2p-daemon) -- [go-libp2p-daemon](https://github.com/libp2p/go-libp2p-daemon) - -### Interact with the daemon process using the client - -```js -import { createClient } from '@libp2p/daemon-client' -import { multiaddr } from '@multiformats/multiaddr' - -const serverAddr = multiaddr('/ip4/127.0.0.1/tcp/1234') -const client = createClient(serverAddr) - -// interact with the daemon -let identify -try { - identify = await client.identify() -} catch (err) { - // ... -} - -// close the socket -await client.close() -``` - -## API - -- [Getting started](API.md#getting-started) -- [`close`](API.md#close) -- [`connect`](API.md#connect) -- [`identify`](API.md#identify) -- [`listPeers`](API.md#listPeers) -- [`openStream`](API.md#openStream) -- [`registerStream`](API.md#registerStream) -- [`dht.put`](API.md#dht.put) -- [`dht.get`](API.md#dht.get) -- [`dht.findPeer`](API.md#dht.findPeer) -- [`dht.provide`](API.md#dht.provide) -- [`dht.findProviders`](API.md#dht.findProviders) -- [`dht.getClosestPeers`](API.md#dht.getClosestPeers) -- [`dht.getPublicKey`](API.md#dht.getPublicKey) - -## License - -Licensed under either of - -- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) -- MIT ([LICENSE-MIT](LICENSE-MIT) / ) - -## Contribution - -Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. diff --git a/packages/libp2p-daemon-client/package.json b/packages/libp2p-daemon-client/package.json deleted file mode 100644 index a5f80aa2de..0000000000 --- a/packages/libp2p-daemon-client/package.json +++ /dev/null @@ -1,70 +0,0 @@ -{ - "name": "@libp2p/daemon-client", - "version": "6.0.3", - "description": "libp2p-daemon client implementation", - "license": "Apache-2.0 OR MIT", - "homepage": "https://github.com/libp2p/js-libp2p/tree/master/packages/libp2p-daemon-client#readme", - "repository": { - "type": "git", - "url": "git+https://github.com/libp2p/js-libp2p.git" - }, - "bugs": { - "url": "https://github.com/libp2p/js-libp2p/issues" - }, - "keywords": [ - "libp2p" - ], - "type": "module", - "types": "./dist/src/index.d.ts", - "files": [ - "src", - "dist", - "!dist/test", - "!**/*.tsbuildinfo" - ], - "exports": { - ".": { - "types": "./src/index.d.ts", - "import": "./dist/src/index.js" - } - }, - "eslintConfig": { - "extends": "ipfs", - "parserOptions": { - "sourceType": "module" - } - }, - "scripts": { - "clean": "aegir clean", - "lint": "aegir lint", - "dep-check": "aegir dep-check", - "build": "aegir build", - "pretest": "npm run build", - "test": "aegir test -t node", - "test:node": "aegir test -t node" - }, - "dependencies": { - "@chainsafe/libp2p-gossipsub": "^9.0.0", - "@libp2p/daemon-protocol": "^4.0.0", - "@libp2p/interface": "^0.1.0", - "@libp2p/kad-dht": "^10.0.0", - "@libp2p/logger": "^3.0.0", - "@libp2p/peer-id": "^3.0.0", - "@libp2p/tcp": "^8.0.0", - "@multiformats/multiaddr": "^12.1.3", - "it-stream-types": "^2.0.1", - "multiformats": "^12.0.1", - "uint8arraylist": "^2.4.3" - }, - "devDependencies": { - "@libp2p/daemon-server": "^5.0.0", - "@libp2p/interface-compliance-tests": "^4.0.0", - "aegir": "^40.0.1", - "it-all": "^3.0.1", - "it-pipe": "^3.0.1", - "sinon": "^15.1.2", - "sinon-ts": "^1.0.0", - "uint8arrays": "^4.0.4" - }, - "private": true -} diff --git a/packages/libp2p-daemon-client/src/dht.ts b/packages/libp2p-daemon-client/src/dht.ts deleted file mode 100644 index 9511eaacad..0000000000 --- a/packages/libp2p-daemon-client/src/dht.ts +++ /dev/null @@ -1,326 +0,0 @@ -import { - Request, - Response, - DHTRequest, - DHTResponse -} from '@libp2p/daemon-protocol' -import { CodeError } from '@libp2p/interface/errors' -import { isPeerId, type PeerId } from '@libp2p/interface/peer-id' -import { peerIdFromBytes } from '@libp2p/peer-id' -import { multiaddr } from '@multiformats/multiaddr' -import { CID } from 'multiformats/cid' -import type { DaemonClient } from './index.js' -import type { PeerInfo } from '@libp2p/interface/peer-info' - -export class DHT { - private readonly client: DaemonClient - - constructor (client: DaemonClient) { - this.client = client - } - - /** - * Write a value to a key in the DHT - */ - async put (key: Uint8Array, value: Uint8Array): Promise { - if (!(key instanceof Uint8Array)) { - throw new CodeError('invalid key received', 'ERR_INVALID_KEY') - } - - if (!(value instanceof Uint8Array)) { - throw new CodeError('value received is not a Uint8Array', 'ERR_INVALID_VALUE') - } - - const sh = await this.client.send({ - type: Request.Type.DHT, - dht: { - type: DHTRequest.Type.PUT_VALUE, - key, - value - } - }) - - const message = await sh.read() - - if (message == null) { - throw new CodeError('Empty response from remote', 'ERR_EMPTY_RESPONSE') - } - - const response = Response.decode(message) - - await sh.close() - - if (response.type !== Response.Type.OK) { - throw new CodeError(response.error?.msg ?? 'DHT put failed', 'ERR_DHT_PUT_FAILED') - } - } - - /** - * Query the DHT for a value stored at a key in the DHT - */ - async get (key: Uint8Array): Promise { - if (!(key instanceof Uint8Array)) { - throw new CodeError('invalid key received', 'ERR_INVALID_KEY') - } - - const sh = await this.client.send({ - type: Request.Type.DHT, - dht: { - type: DHTRequest.Type.GET_VALUE, - key - } - }) - - const message = await sh.read() - - if (message == null) { - throw new CodeError('Empty response from remote', 'ERR_EMPTY_RESPONSE') - } - - const response = Response.decode(message) - - await sh.close() - - if (response.type !== Response.Type.OK) { - throw new CodeError(response.error?.msg ?? 'DHT get failed', 'ERR_DHT_GET_FAILED') - } - - if (response.dht == null || response.dht.value == null) { - throw new CodeError('Invalid DHT get response', 'ERR_DHT_GET_FAILED') - } - - return response.dht.value - } - - /** - * Query the DHT for a given peer's known addresses. - */ - async findPeer (peerId: PeerId): Promise { - if (!isPeerId(peerId)) { - throw new CodeError('invalid peer id received', 'ERR_INVALID_PEER_ID') - } - - const sh = await this.client.send({ - type: Request.Type.DHT, - dht: { - type: DHTRequest.Type.FIND_PEER, - peer: peerId.toBytes() - } - }) - - const message = await sh.read() - - if (message == null) { - throw new CodeError('Empty response from remote', 'ERR_EMPTY_RESPONSE') - } - - const response = Response.decode(message) - - await sh.close() - - if (response.type !== Response.Type.OK) { - throw new CodeError(response.error?.msg ?? 'DHT find peer failed', 'ERR_DHT_FIND_PEER_FAILED') - } - - if (response.dht == null || response.dht.peer == null || response.dht.peer.addrs == null) { - throw new CodeError('Invalid response', 'ERR_DHT_FIND_PEER_FAILED') - } - - return { - id: peerIdFromBytes(response.dht.peer.id), - multiaddrs: response.dht.peer.addrs.map((a) => multiaddr(a)), - protocols: [] - } - } - - /** - * Announce to the network that the peer have data addressed by the provided CID - */ - async provide (cid: CID): Promise { - if (cid == null || CID.asCID(cid) == null) { - throw new CodeError('invalid cid received', 'ERR_INVALID_CID') - } - - const sh = await this.client.send({ - type: Request.Type.DHT, - dht: { - type: DHTRequest.Type.PROVIDE, - cid: cid.bytes - } - }) - - const message = await sh.read() - - if (message == null) { - throw new CodeError('Empty response from remote', 'ERR_EMPTY_RESPONSE') - } - - const response = Response.decode(message) - - await sh.close() - - if (response.type !== Response.Type.OK) { - throw new CodeError(response.error?.msg ?? 'DHT provide failed', 'ERR_DHT_PROVIDE_FAILED') - } - } - - /** - * Query the DHT for peers that have a piece of content, identified by a CID - */ - async * findProviders (cid: CID, count: number = 1): AsyncIterable { - if (cid == null || CID.asCID(cid) == null) { - throw new CodeError('invalid cid received', 'ERR_INVALID_CID') - } - - const sh = await this.client.send({ - type: Request.Type.DHT, - dht: { - type: DHTRequest.Type.FIND_PROVIDERS, - cid: cid.bytes, - count - } - }) - - let message = await sh.read() - - if (message == null) { - throw new CodeError('Empty response from remote', 'ERR_EMPTY_RESPONSE') - } - - // stream begin message - const response = Response.decode(message) - - if (response.type !== Response.Type.OK) { - await sh.close() - throw new CodeError(response.error?.msg ?? 'DHT find providers failed', 'ERR_DHT_FIND_PROVIDERS_FAILED') - } - - while (true) { - message = await sh.read() - - if (message == null) { - throw new CodeError('Empty response from remote', 'ERR_EMPTY_RESPONSE') - } - - const response = DHTResponse.decode(message) - - // Stream end - if (response.type === DHTResponse.Type.END) { - await sh.close() - return - } - - // Stream values - if (response.type === DHTResponse.Type.VALUE && response.peer != null && response.peer?.addrs != null) { - yield { - id: peerIdFromBytes(response.peer.id), - multiaddrs: response.peer.addrs.map((a) => multiaddr(a)), - protocols: [] - } - } else { - // Unexpected message received - await sh.close() - throw new CodeError('unexpected message received', 'ERR_UNEXPECTED_MESSAGE_RECEIVED') - } - } - } - - /** - * Query the DHT routing table for peers that are closest to a provided key. - */ - async * getClosestPeers (key: Uint8Array): AsyncIterable { - if (!(key instanceof Uint8Array)) { - throw new CodeError('invalid key received', 'ERR_INVALID_KEY') - } - - const sh = await this.client.send({ - type: Request.Type.DHT, - dht: { - type: DHTRequest.Type.GET_CLOSEST_PEERS, - key - } - }) - - // stream begin message - let message = await sh.read() - - if (message == null) { - throw new CodeError('Empty response from remote', 'ERR_EMPTY_RESPONSE') - } - - const response = Response.decode(message) - - if (response.type !== Response.Type.OK) { - await sh.close() - throw new CodeError(response.error?.msg ?? 'DHT find providers failed', 'ERR_DHT_FIND_PROVIDERS_FAILED') - } - - while (true) { - message = await sh.read() - - if (message == null) { - throw new CodeError('Empty response from remote', 'ERR_EMPTY_RESPONSE') - } - - const response = DHTResponse.decode(message) - - // Stream end - if (response.type === DHTResponse.Type.END) { - await sh.close() - return - } - - // Stream values - if (response.type === DHTResponse.Type.VALUE && response.value != null) { - const peerId = peerIdFromBytes(response.value) - - yield { - id: peerId, - multiaddrs: [], - protocols: [] - } - } else { - // Unexpected message received - await sh.close() - throw new CodeError('unexpected message received', 'ERR_UNEXPECTED_MESSAGE_RECEIVED') - } - } - } - - /** - * Query the DHT routing table for a given peer's public key. - */ - async getPublicKey (peerId: PeerId): Promise { - if (!isPeerId(peerId)) { - throw new CodeError('invalid peer id received', 'ERR_INVALID_PEER_ID') - } - - const sh = await this.client.send({ - type: Request.Type.DHT, - dht: { - type: DHTRequest.Type.GET_PUBLIC_KEY, - peer: peerId.toBytes() - } - }) - - const message = await sh.read() - - if (message == null) { - throw new CodeError('Empty response from remote', 'ERR_EMPTY_RESPONSE') - } - - const response = Response.decode(message) - - await sh.close() - - if (response.type !== Response.Type.OK) { - throw new CodeError(response.error?.msg ?? 'DHT get public key failed', 'ERR_DHT_GET_PUBLIC_KEY_FAILED') - } - - if (response.dht == null) { - throw new CodeError('Invalid response', 'ERR_DHT_GET_PUBLIC_KEY_FAILED') - } - - return response.dht.value - } -} diff --git a/packages/libp2p-daemon-client/src/index.ts b/packages/libp2p-daemon-client/src/index.ts deleted file mode 100644 index 3ecb5ed785..0000000000 --- a/packages/libp2p-daemon-client/src/index.ts +++ /dev/null @@ -1,323 +0,0 @@ -import { type PSMessage, Request, Response, StreamInfo } from '@libp2p/daemon-protocol' -import { StreamHandler } from '@libp2p/daemon-protocol/stream-handler' -import { passThroughUpgrader } from '@libp2p/daemon-protocol/upgrader' -import { CodeError } from '@libp2p/interface/errors' -import { isPeerId, type PeerId } from '@libp2p/interface/peer-id' -import { logger } from '@libp2p/logger' -import { peerIdFromBytes } from '@libp2p/peer-id' -import { tcp } from '@libp2p/tcp' -import { multiaddr, isMultiaddr } from '@multiformats/multiaddr' -import { DHT } from './dht.js' -import { Pubsub } from './pubsub.js' -import type { MultiaddrConnection } from '@libp2p/interface/connection' -import type { PeerInfo } from '@libp2p/interface/peer-info' -import type { Transport } from '@libp2p/interface/transport' -import type { Multiaddr } from '@multiformats/multiaddr' -import type { Duplex, Source } from 'it-stream-types' -import type { CID } from 'multiformats/cid' -import type { Uint8ArrayList } from 'uint8arraylist' - -const log = logger('libp2p:daemon-client') - -class Client implements DaemonClient { - private readonly multiaddr: Multiaddr - public dht: DHT - public pubsub: Pubsub - private readonly tcp: Transport - - constructor (addr: Multiaddr) { - this.multiaddr = addr - this.tcp = tcp()() - this.dht = new DHT(this) - this.pubsub = new Pubsub(this) - } - - /** - * Connects to a daemon at the unix socket path the daemon - * was created with - * - * @async - * @returns {MultiaddrConnection} - */ - async connectDaemon (): Promise { - // @ts-expect-error because we use a passthrough upgrader, - // this is actually a MultiaddrConnection and not a Connection - return this.tcp.dial(this.multiaddr, { - upgrader: passThroughUpgrader - }) - } - - /** - * Sends the request to the daemon and returns a stream. This - * should only be used when sending daemon requests. - */ - async send (request: Request): Promise { - const maConn = await this.connectDaemon() - - const subtype = request.pubsub?.type ?? request.dht?.type ?? request.peerStore?.type ?? '' - log('send', request.type, subtype) - - const streamHandler = new StreamHandler({ stream: maConn }) - streamHandler.write(Request.encode(request)) - return streamHandler - } - - /** - * Connect requests a connection to a known peer on a given set of addresses - */ - async connect (peerId: PeerId, addrs: Multiaddr[]): Promise { - if (!isPeerId(peerId)) { - throw new CodeError('invalid peer id received', 'ERR_INVALID_PEER_ID') - } - - if (!Array.isArray(addrs)) { - throw new CodeError('addrs received are not in an array', 'ERR_INVALID_ADDRS_TYPE') - } - - addrs.forEach((addr) => { - if (!isMultiaddr(addr)) { - throw new CodeError('received an address that is not a multiaddr', 'ERR_NO_MULTIADDR_RECEIVED') - } - }) - - const sh = await this.send({ - type: Request.Type.CONNECT, - connect: { - peer: peerId.toBytes(), - addrs: addrs.map((a) => a.bytes) - } - }) - - const message = await sh.read() - if (message == null) { - throw new CodeError('unspecified', 'ERR_CONNECT_FAILED') - } - - const response = Response.decode(message) - if (response.type !== Response.Type.OK) { - const errResponse = response.error ?? { msg: 'unspecified' } - throw new CodeError(errResponse.msg ?? 'unspecified', 'ERR_CONNECT_FAILED') - } - - await sh.close() - } - - /** - * @typedef {object} IdentifyResponse - * @property {PeerId} peerId - * @property {Array.} addrs - */ - - /** - * Identify queries the daemon for its peer ID and listen addresses. - */ - async identify (): Promise { - const sh = await this.send({ - type: Request.Type.IDENTIFY - }) - - const message = await sh.read() - - if (message == null) { - throw new CodeError('Empty response from remote', 'ERR_EMPTY_RESPONSE') - } - - const response = Response.decode(message) - - if (response.type !== Response.Type.OK) { - throw new CodeError(response.error?.msg ?? 'Identify failed', 'ERR_IDENTIFY_FAILED') - } - - if (response.identify == null || response.identify.addrs == null) { - throw new CodeError('Invalid response', 'ERR_IDENTIFY_FAILED') - } - - const peerId = peerIdFromBytes(response.identify?.id) - const addrs = response.identify.addrs.map((a) => multiaddr(a)) - - await sh.close() - - return ({ peerId, addrs }) - } - - /** - * Get a list of IDs of peers the node is connected to - */ - async listPeers (): Promise { - const sh = await this.send({ - type: Request.Type.LIST_PEERS - }) - - const message = await sh.read() - - if (message == null) { - throw new CodeError('Empty response from remote', 'ERR_EMPTY_RESPONSE') - } - - const response = Response.decode(message) - - if (response.type !== Response.Type.OK) { - throw new CodeError(response.error?.msg ?? 'List peers failed', 'ERR_LIST_PEERS_FAILED') - } - - await sh.close() - - return response.peers.map((peer) => peerIdFromBytes(peer.id)) - } - - /** - * Initiate an outbound stream to a peer on one of a set of protocols. - */ - async openStream (peerId: PeerId, protocol: string): Promise, Source, Promise>> { - if (!isPeerId(peerId)) { - throw new CodeError('invalid peer id received', 'ERR_INVALID_PEER_ID') - } - - if (typeof protocol !== 'string') { - throw new CodeError('invalid protocol received', 'ERR_INVALID_PROTOCOL') - } - - const sh = await this.send({ - type: Request.Type.STREAM_OPEN, - streamOpen: { - peer: peerId.toBytes(), - proto: [protocol] - } - }) - - const message = await sh.read() - - if (message == null) { - throw new CodeError('Empty response from remote', 'ERR_EMPTY_RESPONSE') - } - - const response = Response.decode(message) - - if (response.type !== Response.Type.OK) { - await sh.close() - throw new CodeError(response.error?.msg ?? 'Open stream failed', 'ERR_OPEN_STREAM_FAILED') - } - - return sh.rest() - } - - /** - * Register a handler for inbound streams on a given protocol - */ - async registerStreamHandler (protocol: string, handler: StreamHandlerFunction): Promise { - if (typeof protocol !== 'string') { - throw new CodeError('invalid protocol received', 'ERR_INVALID_PROTOCOL') - } - - // open a tcp port, pipe any data from it to the handler function - const listener = this.tcp.createListener({ - upgrader: passThroughUpgrader, - handler: (connection) => { - Promise.resolve() - .then(async () => { - const sh = new StreamHandler({ - // @ts-expect-error because we are using a passthrough upgrader, this is a MultiaddrConnection - stream: connection - }) - const message = await sh.read() - - if (message == null) { - throw new CodeError('Could not read open stream response', 'ERR_OPEN_STREAM_FAILED') - } - - const response = StreamInfo.decode(message) - - if (response.proto !== protocol) { - throw new CodeError('Incorrect protocol', 'ERR_OPEN_STREAM_FAILED') - } - - await handler(sh.rest()) - }) - .finally(() => { - connection.close() - .catch(err => { - log.error(err) - }) - listener.close() - .catch(err => { - log.error(err) - }) - }) - } - }) - await listener.listen(multiaddr('/ip4/127.0.0.1/tcp/0')) - const address = listener.getAddrs()[0] - - if (address == null) { - throw new CodeError('Could not listen on port', 'ERR_REGISTER_STREAM_HANDLER_FAILED') - } - - const sh = await this.send({ - type: Request.Type.STREAM_HANDLER, - streamHandler: { - addr: address.bytes, - proto: [protocol] - } - }) - - const message = await sh.read() - - if (message == null) { - throw new CodeError('Empty response from remote', 'ERR_EMPTY_RESPONSE') - } - - const response = Response.decode(message) - - await sh.close() - - if (response.type !== Response.Type.OK) { - throw new CodeError(response.error?.msg ?? 'Register stream handler failed', 'ERR_REGISTER_STREAM_HANDLER_FAILED') - } - } -} - -export interface IdentifyResult { - peerId: PeerId - addrs: Multiaddr[] -} - -export interface StreamHandlerFunction { - (stream: Duplex, Source, Promise>): Promise -} - -export interface DHTClient { - put: (key: Uint8Array, value: Uint8Array) => Promise - get: (key: Uint8Array) => Promise - provide: (cid: CID) => Promise - findProviders: (cid: CID, count?: number) => AsyncIterable - findPeer: (peerId: PeerId) => Promise - getClosestPeers: (key: Uint8Array) => AsyncIterable -} - -export interface Subscription { - messages: () => AsyncIterable - cancel: () => Promise -} - -export interface PubSubClient { - publish: (topic: string, data: Uint8Array) => Promise - subscribe: (topic: string) => Promise - getTopics: () => Promise - getSubscribers: (topic: string) => Promise -} - -export interface DaemonClient { - identify: () => Promise - listPeers: () => Promise - connect: (peerId: PeerId, addrs: Multiaddr[]) => Promise - dht: DHTClient - pubsub: PubSubClient - - send: (request: Request) => Promise - openStream: (peerId: PeerId, protocol: string) => Promise, Source, Promise>> - registerStreamHandler: (protocol: string, handler: StreamHandlerFunction) => Promise -} - -export function createClient (multiaddr: Multiaddr): DaemonClient { - return new Client(multiaddr) -} diff --git a/packages/libp2p-daemon-client/src/pubsub.ts b/packages/libp2p-daemon-client/src/pubsub.ts deleted file mode 100644 index a6f56cdaf8..0000000000 --- a/packages/libp2p-daemon-client/src/pubsub.ts +++ /dev/null @@ -1,173 +0,0 @@ -import { - Request, - Response, - PSRequest, - PSMessage -} from '@libp2p/daemon-protocol' -import { CodeError } from '@libp2p/interface/errors' -import { peerIdFromBytes } from '@libp2p/peer-id' -import type { DaemonClient, Subscription } from './index.js' -import type { PeerId } from '@libp2p/interface/peer-id' - -export class Pubsub { - private readonly client: DaemonClient - - constructor (client: DaemonClient) { - this.client = client - } - - /** - * Get a list of topics the node is subscribed to. - * - * @returns {Array} topics - */ - async getTopics (): Promise { - const sh = await this.client.send({ - type: Request.Type.PUBSUB, - pubsub: { - type: PSRequest.Type.GET_TOPICS - } - }) - - const message = await sh.read() - - if (message == null) { - throw new CodeError('Empty response from remote', 'ERR_EMPTY_RESPONSE') - } - - const response = Response.decode(message) - - await sh.close() - - if (response.type !== Response.Type.OK) { - throw new CodeError(response.error?.msg ?? 'Pubsub get topics failed', 'ERR_PUBSUB_GET_TOPICS_FAILED') - } - - if (response.pubsub == null || response.pubsub.topics == null) { - throw new CodeError('Invalid response', 'ERR_PUBSUB_GET_TOPICS_FAILED') - } - - return response.pubsub.topics - } - - /** - * Publish data under a topic - */ - async publish (topic: string, data: Uint8Array): Promise { - if (typeof topic !== 'string') { - throw new CodeError('invalid topic received', 'ERR_INVALID_TOPIC') - } - - if (!(data instanceof Uint8Array)) { - throw new CodeError('data received is not a Uint8Array', 'ERR_INVALID_DATA') - } - - const sh = await this.client.send({ - type: Request.Type.PUBSUB, - pubsub: { - type: PSRequest.Type.PUBLISH, - topic, - data - } - }) - - const message = await sh.read() - - if (message == null) { - throw new CodeError('Empty response from remote', 'ERR_EMPTY_RESPONSE') - } - - const response = Response.decode(message) - - await sh.close() - - if (response.type !== Response.Type.OK) { - throw new CodeError(response.error?.msg ?? 'Pubsub publish failed', 'ERR_PUBSUB_PUBLISH_FAILED') - } - } - - /** - * Request to subscribe a certain topic - */ - async subscribe (topic: string): Promise { - if (typeof topic !== 'string') { - throw new CodeError('invalid topic received', 'ERR_INVALID_TOPIC') - } - - const sh = await this.client.send({ - type: Request.Type.PUBSUB, - pubsub: { - type: PSRequest.Type.SUBSCRIBE, - topic - } - }) - - let message = await sh.read() - - if (message == null) { - throw new CodeError('Empty response from remote', 'ERR_EMPTY_RESPONSE') - } - - const response = Response.decode(message) - - if (response.type !== Response.Type.OK) { - throw new CodeError(response.error?.msg ?? 'Pubsub publish failed', 'ERR_PUBSUB_PUBLISH_FAILED') - } - - let subscribed = true - - const subscription: Subscription = { - async * messages () { - while (subscribed) { // eslint-disable-line no-unmodified-loop-condition - message = await sh.read() - - if (message == null) { - throw new CodeError('Empty response from remote', 'ERR_EMPTY_RESPONSE') - } - - yield PSMessage.decode(message) - } - }, - async cancel () { - subscribed = false - await sh.close() - } - } - - return subscription - } - - async getSubscribers (topic: string): Promise { - if (typeof topic !== 'string') { - throw new CodeError('invalid topic received', 'ERR_INVALID_TOPIC') - } - - const sh = await this.client.send({ - type: Request.Type.PUBSUB, - pubsub: { - type: PSRequest.Type.LIST_PEERS, - topic - } - }) - - const message = await sh.read() - - if (message == null) { - throw new CodeError('Empty response from remote', 'ERR_EMPTY_RESPONSE') - } - - const response = Response.decode(message) - - await sh.close() - - if (response.type !== Response.Type.OK) { - throw new CodeError(response.error?.msg ?? 'Pubsub get subscribers failed', 'ERR_PUBSUB_GET_SUBSCRIBERS_FAILED') - } - - if (response.pubsub == null || response.pubsub.topics == null) { - throw new CodeError('Invalid response', 'ERR_PUBSUB_GET_SUBSCRIBERS_FAILED') - } - - return response.pubsub.peerIDs.map(buf => peerIdFromBytes(buf)) - } -} diff --git a/packages/libp2p-daemon-client/test/dht.spec.ts b/packages/libp2p-daemon-client/test/dht.spec.ts deleted file mode 100644 index 9d1e5e0d8f..0000000000 --- a/packages/libp2p-daemon-client/test/dht.spec.ts +++ /dev/null @@ -1,242 +0,0 @@ -/* eslint-env mocha */ - -import { createServer, type Libp2pServer } from '@libp2p/daemon-server' -import { type DualKadDHT, type ValueEvent, type FinalPeerEvent, type PeerResponseEvent, MessageType, EventTypes, type KadDHT } from '@libp2p/kad-dht' -import { peerIdFromString } from '@libp2p/peer-id' -import { multiaddr } from '@multiformats/multiaddr' -import { expect } from 'aegir/chai' -import all from 'it-all' -import { CID } from 'multiformats/cid' -import sinon from 'sinon' -import { type StubbedInstance, stubInterface } from 'sinon-ts' -import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' -import { createClient, type DaemonClient } from '../src/index.js' -import type { GossipSub } from '@chainsafe/libp2p-gossipsub' -import type { Libp2p } from '@libp2p/interface' - -const defaultMultiaddr = multiaddr('/ip4/0.0.0.0/tcp/12345') - -function match (cid: CID): sinon.SinonMatcher { - return sinon.match((c: CID) => c.toString() === cid.toString(), 'cid') -} - -describe('daemon dht client', function () { - this.timeout(30e3) - - let libp2p: StubbedInstance> - let server: Libp2pServer - let client: DaemonClient - let dht: StubbedInstance - - beforeEach(async function () { - dht = stubInterface() - libp2p = stubInterface>() - libp2p.services.dht = dht - - server = createServer(defaultMultiaddr, libp2p) - - await server.start() - - client = createClient(server.getMultiaddr()) - }) - - afterEach(async () => { - if (server != null) { - await server.stop() - } - - sinon.restore() - }) - - describe('put', () => { - const key = uint8ArrayFromString('/key') - const value = uint8ArrayFromString('oh hello there') - - it('should be able to put a value to the dht', async function () { - dht.put.returns(async function * () {}()) - - await client.dht.put(key, value) - - expect(dht.put.calledWith(key, value)).to.be.true() - }) - - it('should error if receive an error message', async () => { - dht.put.returns(async function * () { // eslint-disable-line require-yield - throw new Error('Urk!') - }()) - - await expect(client.dht.put(key, value)).to.eventually.be.rejectedWith(/Urk!/) - }) - }) - - describe('get', () => { - it('should be able to get a value from the dht', async function () { - const key = uint8ArrayFromString('/key') - const value = uint8ArrayFromString('oh hello there') - - dht.get.withArgs(key).returns(async function * () { - const event: ValueEvent = { - name: 'VALUE', - type: EventTypes.VALUE, - value, - from: peerIdFromString('12D3KooWJKCJW8Y26pRFNv78TCMGLNTfyN8oKaFswMRYXTzSbSsa') - } - - yield event - }()) - - const result = await client.dht.get(key) - - expect(result).to.equalBytes(value) - }) - - it('should error if receive an error message', async function () { - const key = uint8ArrayFromString('/key') - - dht.get.returns(async function * () { // eslint-disable-line require-yield - throw new Error('Urk!') - }()) - - await expect(client.dht.get(key)).to.eventually.be.rejectedWith(/Urk!/) - }) - }) - - describe('findPeer', () => { - it('should be able to find a peer', async () => { - const id = peerIdFromString('12D3KooWJKCJW8Y26pRFNv78TCMGLNTfyN8oKaFswMRYXTzSbSsa') - - dht.findPeer.withArgs(id).returns(async function * () { - const event: FinalPeerEvent = { - name: 'FINAL_PEER', - type: EventTypes.FINAL_PEER, - peer: { - id, - multiaddrs: [], - protocols: [] - }, - from: peerIdFromString('12D3KooWJKCJW8Y26pRFNv78TCMGLNTfyN8oKaFswMRYXTzSbSsa') - } - - yield event - }()) - - const result = await client.dht.findPeer(id) - - expect(result.id.equals(id)).to.be.true() - }) - - it('should error if receive an error message', async () => { - const id = peerIdFromString('12D3KooWJKCJW8Y26pRFNv78TCMGLNTfyN8oKaFswMRYXTzSbSsa') - - dht.findPeer.returns(async function * () { // eslint-disable-line require-yield - throw new Error('Urk!') - }()) - - await expect(client.dht.findPeer(id)).to.eventually.be.rejectedWith(/Urk!/) - }) - }) - - describe('provide', () => { - it('should be able to provide', async () => { - const cid = CID.parse('QmVzw6MPsF96TyXBSRs1ptLoVMWRv5FCYJZZGJSVB2Hp38') - - dht.provide.returns(async function * () {}()) - - await client.dht.provide(cid) - - expect(dht.provide.calledWith(match(cid))).to.be.true() - }) - - it('should error if receive an error message', async () => { - const cid = CID.parse('QmVzw6MPsF96TyXBSRs1ptLoVMWRv5FCYJZZGJSVB2Hp38') - - dht.provide.returns(async function * () { // eslint-disable-line require-yield - throw new Error('Urk!') - }()) - - await expect(client.dht.provide(cid)).to.eventually.be.rejectedWith(/Urk!/) - }) - }) - - describe('findProviders', () => { - it('should be able to find providers', async () => { - const cid = CID.parse('QmVzw6MPsF96TyXBSRs1ptLoVMWRv5FCYJZZGJSVB2Hp38') - const id = peerIdFromString('12D3KooWJKCJW8Y26pRFNv78TCMGLNTfyN8oKaFswMRYXTzSbSsa') - - dht.findProviders.withArgs(match(cid)).returns(async function * () { - const event: PeerResponseEvent = { - name: 'PEER_RESPONSE', - type: EventTypes.PEER_RESPONSE, - providers: [{ - id, - multiaddrs: [], - protocols: [] - }], - closer: [], - from: id, - messageName: 'GET_PROVIDERS', - messageType: MessageType.GET_PROVIDERS - } - - yield event - }()) - - const result = await all(client.dht.findProviders(cid)) - - expect(result).to.have.lengthOf(1) - expect(result[0].id.equals(id)).to.be.true() - }) - - // skipped because the protocol doesn't handle streaming errors - it.skip('should error if receive an error message', async () => { - const cid = CID.parse('QmVzw6MPsF96TyXBSRs1ptLoVMWRv5FCYJZZGJSVB2Hp38') - - dht.findProviders.returns(async function * () { // eslint-disable-line require-yield - throw new Error('Urk!') - }()) - - await expect(all(client.dht.findProviders(cid))).to.eventually.be.rejectedWith(/Urk!/) - }) - }) - - describe('getClosestPeers', () => { - it('should be able to get the closest peers', async () => { - const cid = CID.parse('QmVzw6MPsF96TyXBSRs1ptLoVMWRv5FCYJZZGJSVB2Hp38') - const id = peerIdFromString('12D3KooWJKCJW8Y26pRFNv78TCMGLNTfyN8oKaFswMRYXTzSbSsa') - - dht.getClosestPeers.returns(async function * () { - const event: PeerResponseEvent = { - name: 'PEER_RESPONSE', - type: EventTypes.PEER_RESPONSE, - providers: [], - closer: [{ - id, - multiaddrs: [], - protocols: [] - }], - from: id, - messageName: 'GET_PROVIDERS', - messageType: MessageType.GET_PROVIDERS - } - - yield event - }()) - - const result = await all(client.dht.getClosestPeers(cid.bytes)) - - expect(result).to.have.lengthOf(1) - expect(result[0].id.equals(id)).to.be.true() - }) - - // skipped because the protocol doesn't handle streaming errors - it.skip('should error if it gets an invalid key', async () => { - const cid = CID.parse('QmVzw6MPsF96TyXBSRs1ptLoVMWRv5FCYJZZGJSVB2Hp38') - - dht.getClosestPeers.returns(async function * () { // eslint-disable-line require-yield - throw new Error('Urk!') - }()) - - await expect(all(client.dht.getClosestPeers(cid.bytes))).to.eventually.be.rejectedWith(/Urk!/) - }) - }) -}) diff --git a/packages/libp2p-daemon-client/test/index.spec.ts b/packages/libp2p-daemon-client/test/index.spec.ts deleted file mode 100644 index 0074446a83..0000000000 --- a/packages/libp2p-daemon-client/test/index.spec.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* eslint-env mocha */ - -import { createServer, type Libp2pServer } from '@libp2p/daemon-server' -import { isPeerId } from '@libp2p/interface/peer-id' -import { mockConnection, mockDuplex, mockMultiaddrConnection } from '@libp2p/interface-compliance-tests/mocks' -import { peerIdFromString } from '@libp2p/peer-id' -import { multiaddr } from '@multiformats/multiaddr' -import { expect } from 'aegir/chai' -import sinon from 'sinon' -import { type StubbedInstance, stubInterface } from 'sinon-ts' -import { createClient, type DaemonClient } from '../src/index.js' -import type { GossipSub } from '@chainsafe/libp2p-gossipsub' -import type { Libp2p } from '@libp2p/interface' -import type { PeerStore } from '@libp2p/interface/peer-store' -import type { KadDHT } from '@libp2p/kad-dht' - -const defaultMultiaddr = multiaddr('/ip4/0.0.0.0/tcp/0') - -describe('daemon client', function () { - this.timeout(30e3) - - let libp2p: StubbedInstance> - let server: Libp2pServer - let client: DaemonClient - - beforeEach(async function () { - libp2p = stubInterface>() - libp2p.peerStore = stubInterface() - - server = createServer(defaultMultiaddr, libp2p) - - await server.start() - - client = createClient(server.getMultiaddr()) - }) - - afterEach(async () => { - if (server != null) { - await server.stop() - } - - sinon.restore() - }) - - describe('identify', () => { - it('should be able to identify', async () => { - libp2p.peerId = peerIdFromString('12D3KooWJKCJW8Y26pRFNv78TCMGLNTfyN8oKaFswMRYXTzSbSsa') - libp2p.getMultiaddrs.returns([ - multiaddr('/ip4/0.0.0.0/tcp/1234/p2p/12D3KooWJKCJW8Y26pRFNv78TCMGLNTfyN8oKaFswMRYXTzSbSsa') - ]) - - const identify = await client.identify() - - expect(identify).to.exist() - expect(identify.peerId).to.exist() - expect(identify.addrs).to.exist() - expect(isPeerId(identify.peerId)) - }) - - it('should error if receive an error message', async () => { - libp2p.peerId = peerIdFromString('12D3KooWJKCJW8Y26pRFNv78TCMGLNTfyN8oKaFswMRYXTzSbSsa') - libp2p.getMultiaddrs.throws(new Error('Urk!')) - - await expect(client.identify()).to.eventually.be.rejectedWith(/Urk!/) - }) - }) - - describe('listPeers', () => { - it('should be able to listPeers', async () => { - const remotePeer = peerIdFromString('12D3KooWJKCJW8Y26pRFNv78TCMGLNTfyN8oKaFswMRYXTzSbSsa') - - libp2p.getConnections.returns([ - mockConnection(mockMultiaddrConnection(mockDuplex(), remotePeer)) - ]) - - const peers = await client.listPeers() - - expect(peers).to.have.lengthOf(1) - expect(peers[0].equals(remotePeer)).to.be.true() - }) - - it('should error if receive an error message', async () => { - libp2p.getConnections.throws(new Error('Urk!')) - - await expect(client.listPeers()).to.eventually.be.rejectedWith(/Urk!/) - }) - }) - - describe('connect', () => { - it('should be able to connect', async () => { - const remotePeer = peerIdFromString('12D3KooWJKCJW8Y26pRFNv78TCMGLNTfyN8oKaFswMRYXTzSbSsa') - const ma = multiaddr('/ip4/1.2.3.4/tcp/1234') - - await client.connect(remotePeer, [ma]) - - expect(libp2p.dial.calledWith(remotePeer)).to.be.true() - }) - - it('should error if receive an error message', async () => { - const remotePeer = peerIdFromString('12D3KooWJKCJW8Y26pRFNv78TCMGLNTfyN8oKaFswMRYXTzSbSsa') - const ma = multiaddr('/ip4/1.2.3.4/tcp/1234') - - libp2p.dial.rejects(new Error('Urk!')) - - await expect(client.connect(remotePeer, [ma])).to.eventually.be.rejectedWith(/Urk!/) - }) - }) -}) diff --git a/packages/libp2p-daemon-client/test/pubsub.spec.ts b/packages/libp2p-daemon-client/test/pubsub.spec.ts deleted file mode 100644 index 39adbd7d80..0000000000 --- a/packages/libp2p-daemon-client/test/pubsub.spec.ts +++ /dev/null @@ -1,123 +0,0 @@ -/* eslint-env mocha */ - -import { createServer, type Libp2pServer } from '@libp2p/daemon-server' -import { peerIdFromString } from '@libp2p/peer-id' -import { multiaddr } from '@multiformats/multiaddr' -import { expect } from 'aegir/chai' -import sinon from 'sinon' -import { type StubbedInstance, stubInterface } from 'sinon-ts' -import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' -import { createClient, type DaemonClient } from '../src/index.js' -import type { GossipSub } from '@chainsafe/libp2p-gossipsub' -import type { Libp2p } from '@libp2p/interface' -import type { KadDHT } from '@libp2p/kad-dht' - -const defaultMultiaddr = multiaddr('/ip4/0.0.0.0/tcp/12345') - -describe('daemon pubsub client', function () { - this.timeout(30e3) - - let libp2p: StubbedInstance> - let server: Libp2pServer - let client: DaemonClient - let pubsub: StubbedInstance - - beforeEach(async function () { - pubsub = stubInterface() - libp2p = stubInterface>() - libp2p.services.pubsub = pubsub - - server = createServer(defaultMultiaddr, libp2p) - - await server.start() - - client = createClient(server.getMultiaddr()) - }) - - afterEach(async () => { - if (server != null) { - await server.stop() - } - - sinon.restore() - }) - - describe('getTopics', () => { - it('should get empty list of topics when no subscriptions exist', async () => { - pubsub.getTopics.returns([]) - - const topics = await client.pubsub.getTopics() - - expect(topics).to.have.lengthOf(0) - }) - - it('should get a list with a topic when subscribed', async () => { - const topic = 'test-topic' - pubsub.getTopics.returns([topic]) - - const topics = await client.pubsub.getTopics() - - expect(topics).to.have.lengthOf(1) - expect(topics[0]).to.equal(topic) - }) - - it('should error if receive an error message', async () => { - pubsub.getTopics.throws(new Error('Urk!')) - - await expect(client.pubsub.getTopics()).to.eventually.be.rejectedWith(/Urk!/) - }) - }) - - describe('publish', () => { - it('should publish an event', async () => { - const topic = 'test-topic' - const data = uint8ArrayFromString('hello world') - - await client.pubsub.publish(topic, data) - - expect(pubsub.publish.called).to.be.true() - - const call = pubsub.publish.getCall(0) - - expect(call).to.have.nested.property('args[0]', topic) - expect(call).to.have.deep.nested.property('args[1]', data) - }) - - it('should error if receive an error message', async () => { - const topic = 'test-topic' - const data = uint8ArrayFromString('hello world') - pubsub.publish.throws(new Error('Urk!')) - - await expect(client.pubsub.publish(topic, data)).to.eventually.be.rejectedWith(/Urk!/) - }) - }) - - describe('getSubscribers', () => { - it('should get empty list of topics when no subscriptions exist', async () => { - pubsub.getSubscribers.returns([]) - - const topic = 'test-topic' - const topics = await client.pubsub.getSubscribers(topic) - - expect(topics).to.have.lengthOf(0) - }) - - it('should get a list with a peer when subscribed', async () => { - const topic = 'test-topic' - const peer = peerIdFromString('12D3KooWKnQbfH5t1XxJW5FBoMGNjmC9LTSbDdRJxtYj2bJV5XfP') - pubsub.getSubscribers.withArgs(topic).returns([peer]) - - const peers = await client.pubsub.getSubscribers(topic) - - expect(peers).to.have.lengthOf(1) - expect(peers[0].toString()).to.equal(peer.toString()) - }) - - it('should error if receive an error message', async () => { - const topic = 'test-topic' - pubsub.getSubscribers.throws(new Error('Urk!')) - - await expect(client.pubsub.getSubscribers(topic)).to.eventually.be.rejectedWith(/Urk!/) - }) - }) -}) diff --git a/packages/libp2p-daemon-client/test/stream.spec.ts b/packages/libp2p-daemon-client/test/stream.spec.ts deleted file mode 100644 index 76e1cf59e6..0000000000 --- a/packages/libp2p-daemon-client/test/stream.spec.ts +++ /dev/null @@ -1,91 +0,0 @@ -/* eslint-env mocha */ - -import { createServer, type Libp2pServer } from '@libp2p/daemon-server' -import { mockRegistrar, connectionPair } from '@libp2p/interface-compliance-tests/mocks' -import { peerIdFromString } from '@libp2p/peer-id' -import { multiaddr } from '@multiformats/multiaddr' -import { expect } from 'aegir/chai' -import all from 'it-all' -import { pipe } from 'it-pipe' -import sinon from 'sinon' -import { type StubbedInstance, stubInterface } from 'sinon-ts' -import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' -import { toString as uint8ArrayToString } from 'uint8arrays/to-string' -import { createClient, type DaemonClient } from '../src/index.js' -import type { GossipSub } from '@chainsafe/libp2p-gossipsub' -import type { Libp2p } from '@libp2p/interface' -import type { PeerStore } from '@libp2p/interface/peer-store' -import type { KadDHT } from '@libp2p/kad-dht' - -const defaultMultiaddr = multiaddr('/ip4/0.0.0.0/tcp/0') - -describe('daemon stream client', function () { - this.timeout(50e3) - - let libp2p: StubbedInstance> - let server: Libp2pServer - let client: DaemonClient - - beforeEach(async function () { - libp2p = stubInterface>() - libp2p.peerStore = stubInterface() - - server = createServer(defaultMultiaddr, libp2p) - - await server.start() - - client = createClient(server.getMultiaddr()) - }) - - afterEach(async () => { - if (server != null) { - await server.stop() - } - - sinon.restore() - }) - - it('should be able to open a stream, write to it and a stream handler, should handle the message', async () => { - const protocol = '/echo/1.0.0' - - const peerA = peerIdFromString('12D3KooWJKCJW8Y26pRFNv78TCMGLNTfyN8oKaFswMRYXTzSbSsa') - const registrarA = mockRegistrar() - await registrarA.handle(protocol, (data) => { - void pipe( - data.stream, - data.stream - ) - }) - - const peerB = peerIdFromString('12D3KooWJKCJW8Y26pRFNv78TCMGLNTfyN8oKaFswMRYXTzSbSsb') - const registrarB = mockRegistrar() - await registrarB.handle(protocol, (data) => { - void pipe( - data.stream, - data.stream - ) - }) - - const [peerAtoPeerB] = connectionPair({ - peerId: peerA, - registrar: registrarA - }, { - peerId: peerB, - registrar: registrarB - } - ) - - libp2p.dial.withArgs(peerB).resolves(peerAtoPeerB) - - const stream = await client.openStream(peerB, protocol) - - const data = await pipe( - [uint8ArrayFromString('hello world')], - stream, - async (source) => all(source) - ) - - expect(data).to.have.lengthOf(1) - expect(uint8ArrayToString(data[0].subarray())).to.equal('hello world') - }) -}) diff --git a/packages/libp2p-daemon-client/tsconfig.json b/packages/libp2p-daemon-client/tsconfig.json deleted file mode 100644 index f4c92c7e77..0000000000 --- a/packages/libp2p-daemon-client/tsconfig.json +++ /dev/null @@ -1,39 +0,0 @@ -{ - "extends": "aegir/src/config/tsconfig.aegir.json", - "compilerOptions": { - "outDir": "dist" - }, - "include": [ - "src", - "test" - ], - "references": [ - { - "path": "../interface" - }, - { - "path": "../interface-compliance-tests" - }, - { - "path": "../kad-dht" - }, - { - "path": "../libp2p-daemon-protocol" - }, - { - "path": "../libp2p-daemon-server" - }, - { - "path": "../logger" - }, - { - "path": "../peer-id" - }, - { - "path": "../pubsub-gossipsub" - }, - { - "path": "../transport-tcp" - } - ] -} diff --git a/packages/libp2p-daemon-client/typedoc.json b/packages/libp2p-daemon-client/typedoc.json deleted file mode 100644 index f599dc728d..0000000000 --- a/packages/libp2p-daemon-client/typedoc.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "entryPoints": [ - "./src/index.ts" - ] -} diff --git a/packages/libp2p-daemon-protocol/CHANGELOG.md b/packages/libp2p-daemon-protocol/CHANGELOG.md deleted file mode 100644 index 0814425181..0000000000 --- a/packages/libp2p-daemon-protocol/CHANGELOG.md +++ /dev/null @@ -1,159 +0,0 @@ -## [@libp2p/daemon-protocol-v4.0.1](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-protocol-v4.0.0...@libp2p/daemon-protocol-v4.0.1) (2023-04-24) - - -### Dependencies - -* bump @libp2p/interface-peer-store from 1.2.9 to 2.0.0 ([#201](https://github.com/libp2p/js-libp2p-daemon/issues/201)) ([9b146a8](https://github.com/libp2p/js-libp2p-daemon/commit/9b146a8c38c30a13401be6da5259cd9da6bdc25c)) - -## [@libp2p/daemon-protocol-v4.0.0](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-protocol-v3.0.6...@libp2p/daemon-protocol-v4.0.0) (2023-04-19) - - -### ⚠ BREAKING CHANGES - -* the type of the source/sink properties have changed - -### Dependencies - -* update it-stream-types to 2.x.x ([#196](https://github.com/libp2p/js-libp2p-daemon/issues/196)) ([a09f6d5](https://github.com/libp2p/js-libp2p-daemon/commit/a09f6d58942033b08b579735aaa1537b3a324776)) - -## [@libp2p/daemon-protocol-v3.0.6](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-protocol-v3.0.5...@libp2p/daemon-protocol-v3.0.6) (2023-02-22) - - -### Dependencies - -* bump aegir from 37.12.1 to 38.1.6 ([#183](https://github.com/libp2p/js-libp2p-daemon/issues/183)) ([6725a0a](https://github.com/libp2p/js-libp2p-daemon/commit/6725a0aeba9acb56a7530dece6c65a0f3eadfec5)) - -## [@libp2p/daemon-protocol-v3.0.5](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-protocol-v3.0.4...@libp2p/daemon-protocol-v3.0.5) (2023-02-22) - - -### Trivial Changes - -* remove lerna ([#171](https://github.com/libp2p/js-libp2p-daemon/issues/171)) ([367f912](https://github.com/libp2p/js-libp2p-daemon/commit/367f9122f2fe1c31c8de7a136cda18d024ff08d7)) - - -### Dependencies - -* **dev:** bump protons from 6.1.3 to 7.0.2 ([#179](https://github.com/libp2p/js-libp2p-daemon/issues/179)) ([07d5872](https://github.com/libp2p/js-libp2p-daemon/commit/07d5872e04f95e2e8957f083dae3721aa8dc307e)) - -## [@libp2p/daemon-protocol-v3.0.4](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-protocol-v3.0.3...@libp2p/daemon-protocol-v3.0.4) (2022-10-14) - - -### Bug Fixes - -* handle empty responses ([#145](https://github.com/libp2p/js-libp2p-daemon/issues/145)) ([0dfb823](https://github.com/libp2p/js-libp2p-daemon/commit/0dfb8236a0ab57a55fa0ebb91ac7a776a9f709da)) -* restore proto2 compatibility ([#146](https://github.com/libp2p/js-libp2p-daemon/issues/146)) ([9fe8e04](https://github.com/libp2p/js-libp2p-daemon/commit/9fe8e042757ec107cc137a9452fd021a62620b3c)) - -## [@libp2p/daemon-protocol-v3.0.3](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-protocol-v3.0.2...@libp2p/daemon-protocol-v3.0.3) (2022-10-13) - - -### Dependencies - -* update uint8arrays, protons and multiformats ([#143](https://github.com/libp2p/js-libp2p-daemon/issues/143)) ([661139c](https://github.com/libp2p/js-libp2p-daemon/commit/661139c674c9994724e32227d7d9ae2c5da1cea2)) - -## [@libp2p/daemon-protocol-v3.0.2](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-protocol-v3.0.1...@libp2p/daemon-protocol-v3.0.2) (2022-10-07) - - -### Dependencies - -* bump @libp2p/interface-transport from 1.0.4 to 2.0.0 ([#132](https://github.com/libp2p/js-libp2p-daemon/issues/132)) ([1a7b2cc](https://github.com/libp2p/js-libp2p-daemon/commit/1a7b2cc653dfb51e92edb1f652452e3c793156c3)) - -## [@libp2p/daemon-protocol-v3.0.1](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-protocol-v3.0.0...@libp2p/daemon-protocol-v3.0.1) (2022-09-14) - - -### Bug Fixes - -* fix proto file and generated code ([#94](https://github.com/libp2p/js-libp2p-daemon/issues/94)) ([5c22052](https://github.com/libp2p/js-libp2p-daemon/commit/5c22052c8da0da4febf88582e9e27a93ac1f710b)), closes [#66](https://github.com/libp2p/js-libp2p-daemon/issues/66) - -## [@libp2p/daemon-protocol-v3.0.0](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-protocol-v2.0.2...@libp2p/daemon-protocol-v3.0.0) (2022-09-09) - - -### ⚠ BREAKING CHANGES - -* the stream type returned by `client.openStream` has changed - -### Bug Fixes - -* allow opening remote streams ([#126](https://github.com/libp2p/js-libp2p-daemon/issues/126)) ([361cc57](https://github.com/libp2p/js-libp2p-daemon/commit/361cc5750de505ab0381ae43609c67d5d4f659a7)) - -## [@libp2p/daemon-protocol-v2.0.2](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-protocol-v2.0.1...@libp2p/daemon-protocol-v2.0.2) (2022-08-10) - - -### Bug Fixes - -* update all deps ([#124](https://github.com/libp2p/js-libp2p-daemon/issues/124)) ([5e46e1e](https://github.com/libp2p/js-libp2p-daemon/commit/5e46e1e26c23428046a6007ab158420d3d830145)) - -## [@libp2p/daemon-protocol-v2.0.1](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-protocol-v2.0.0...@libp2p/daemon-protocol-v2.0.1) (2022-07-31) - - -### Trivial Changes - -* update project config ([#111](https://github.com/libp2p/js-libp2p-daemon/issues/111)) ([345e663](https://github.com/libp2p/js-libp2p-daemon/commit/345e663e34278e780fc2f3a6b595294f925c4521)) - - -### Dependencies - -* update uint8arraylist and protons deps ([#115](https://github.com/libp2p/js-libp2p-daemon/issues/115)) ([34a8334](https://github.com/libp2p/js-libp2p-daemon/commit/34a83340ba855a9c08319ae1cd735dfa8b71c248)) - -## [@libp2p/daemon-protocol-v2.0.0](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-protocol-v1.0.6...@libp2p/daemon-protocol-v2.0.0) (2022-06-15) - - -### ⚠ BREAKING CHANGES - -* uses new single-issue libp2p interface modules - -### Features - -* update to latest libp2p interfaces ([#102](https://github.com/libp2p/js-libp2p-daemon/issues/102)) ([f5e9121](https://github.com/libp2p/js-libp2p-daemon/commit/f5e91210654ab3c411e316c1c657356c037a0f6a)) - -## [@libp2p/daemon-protocol-v1.0.6](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-protocol-v1.0.5...@libp2p/daemon-protocol-v1.0.6) (2022-05-25) - - -### Trivial Changes - -* update docs ([#91](https://github.com/libp2p/js-libp2p-daemon/issues/91)) ([5b072ff](https://github.com/libp2p/js-libp2p-daemon/commit/5b072ff89f30fd6cf55a3387bf0961c8ad78a22f)), closes [#83](https://github.com/libp2p/js-libp2p-daemon/issues/83) - -## [@libp2p/daemon-protocol-v1.0.5](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-protocol-v1.0.4...@libp2p/daemon-protocol-v1.0.5) (2022-05-10) - - -### Bug Fixes - -* encode enums correctly ([#86](https://github.com/libp2p/js-libp2p-daemon/issues/86)) ([6ce4633](https://github.com/libp2p/js-libp2p-daemon/commit/6ce4633f3db41ab66f9b8b1abbe84955dde3e9be)) - -## [@libp2p/daemon-protocol-v1.0.4](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-protocol-v1.0.3...@libp2p/daemon-protocol-v1.0.4) (2022-04-20) - - -### Bug Fixes - -* update interfaces and deps ([#84](https://github.com/libp2p/js-libp2p-daemon/issues/84)) ([25173d5](https://github.com/libp2p/js-libp2p-daemon/commit/25173d5b2edf0e9dd9132707d349cdc862caecdb)) - -## [@libp2p/daemon-protocol-v1.0.3](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-protocol-v1.0.2...@libp2p/daemon-protocol-v1.0.3) (2022-04-07) - - -### Bug Fixes - -* update generated file ([#82](https://github.com/libp2p/js-libp2p-daemon/issues/82)) ([fc66301](https://github.com/libp2p/js-libp2p-daemon/commit/fc66301b6da3d24bc065f37337705753873c6e60)) - -## [@libp2p/daemon-protocol-v1.0.2](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-protocol-v1.0.1...@libp2p/daemon-protocol-v1.0.2) (2022-04-07) - - -### Bug Fixes - -* remove protobufjs and replace with protons ([#81](https://github.com/libp2p/js-libp2p-daemon/issues/81)) ([78dd02a](https://github.com/libp2p/js-libp2p-daemon/commit/78dd02a679e55f22c7e24c1ee2b6f92a4679a0b9)) - -## [@libp2p/daemon-protocol-v1.0.1](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-protocol-v1.0.0...@libp2p/daemon-protocol-v1.0.1) (2022-04-07) - - -### Trivial Changes - -* update aegir to latest version ([#80](https://github.com/libp2p/js-libp2p-daemon/issues/80)) ([3a98959](https://github.com/libp2p/js-libp2p-daemon/commit/3a98959617d9c19bba9fb064defee3d51acfcc29)) - -## @libp2p/daemon-protocol-v1.0.0 (2022-03-28) - - -### ⚠ BREAKING CHANGES - -* This module is now ESM only - -### Features - -* convert to typescript ([#78](https://github.com/libp2p/js-libp2p-daemon/issues/78)) ([f18b2a4](https://github.com/libp2p/js-libp2p-daemon/commit/f18b2a45871a2704db51b03e8583eefdcd13554c)) diff --git a/packages/libp2p-daemon-protocol/LICENSE b/packages/libp2p-daemon-protocol/LICENSE deleted file mode 100644 index 20ce483c86..0000000000 --- a/packages/libp2p-daemon-protocol/LICENSE +++ /dev/null @@ -1,4 +0,0 @@ -This project is dual licensed under MIT and Apache-2.0. - -MIT: https://www.opensource.org/licenses/mit -Apache-2.0: https://www.apache.org/licenses/license-2.0 diff --git a/packages/libp2p-daemon-protocol/LICENSE-APACHE b/packages/libp2p-daemon-protocol/LICENSE-APACHE deleted file mode 100644 index 14478a3b60..0000000000 --- a/packages/libp2p-daemon-protocol/LICENSE-APACHE +++ /dev/null @@ -1,5 +0,0 @@ -Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - -http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. diff --git a/packages/libp2p-daemon-protocol/LICENSE-MIT b/packages/libp2p-daemon-protocol/LICENSE-MIT deleted file mode 100644 index 72dc60d84b..0000000000 --- a/packages/libp2p-daemon-protocol/LICENSE-MIT +++ /dev/null @@ -1,19 +0,0 @@ -The MIT License (MIT) - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. diff --git a/packages/libp2p-daemon-protocol/README.md b/packages/libp2p-daemon-protocol/README.md deleted file mode 100644 index d50e712fef..0000000000 --- a/packages/libp2p-daemon-protocol/README.md +++ /dev/null @@ -1,31 +0,0 @@ -# @libp2p/daemon-protocol - -[![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) -[![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) -[![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p) -[![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p/main.yml?branch=master\&style=flat-square)](https://github.com/libp2p/js-libp2p/actions/workflows/main.yml?query=branch%3Amaster) - -> Communication protocol between libp2p daemons and clients - -## Table of contents - -- [Install](#install) -- [License](#license) -- [Contribution](#contribution) - -## Install - -```console -$ npm i @libp2p/daemon-protocol -``` - -## License - -Licensed under either of - -- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) -- MIT ([LICENSE-MIT](LICENSE-MIT) / ) - -## Contribution - -Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. diff --git a/packages/libp2p-daemon-protocol/package.json b/packages/libp2p-daemon-protocol/package.json deleted file mode 100644 index e011080ebd..0000000000 --- a/packages/libp2p-daemon-protocol/package.json +++ /dev/null @@ -1,81 +0,0 @@ -{ - "name": "@libp2p/daemon-protocol", - "version": "4.0.1", - "description": "Communication protocol between libp2p daemons and clients", - "author": "", - "license": "Apache-2.0 OR MIT", - "homepage": "https://github.com/libp2p/js-libp2p/tree/master/packages/libp2p-daemon-protocol#readme", - "repository": { - "type": "git", - "url": "git+https://github.com/libp2p/js-libp2p.git" - }, - "bugs": { - "url": "https://github.com/libp2p/js-libp2p/issues" - }, - "type": "module", - "types": "./dist/src/index.d.ts", - "typesVersions": { - "*": { - "*": [ - "*", - "dist/*", - "dist/src/*", - "dist/src/*/index" - ], - "src/*": [ - "*", - "dist/*", - "dist/src/*", - "dist/src/*/index" - ] - } - }, - "files": [ - "src", - "dist", - "!dist/test", - "!**/*.tsbuildinfo" - ], - "exports": { - ".": { - "types": "./src/index.d.ts", - "import": "./dist/src/index.js" - }, - "./stream-handler": { - "types": "./dist/src/stream-handler.d.ts", - "import": "./dist/src/stream-handler.js" - }, - "./upgrader": { - "types": "./dist/src/upgrader.d.ts", - "import": "./dist/src/upgrader.js" - } - }, - "eslintConfig": { - "extends": "ipfs", - "parserOptions": { - "sourceType": "module" - }, - "ignorePatterns": [ - "*.d.ts", - "src/index.js" - ] - }, - "scripts": { - "clean": "aegir clean", - "lint": "aegir lint", - "generate": "protons ./src/index.proto", - "build": "aegir build" - }, - "dependencies": { - "@libp2p/interface": "^0.1.0", - "@libp2p/logger": "^3.0.0", - "it-handshake": "^4.1.3", - "protons-runtime": "^5.0.0", - "uint8arraylist": "^2.4.3" - }, - "devDependencies": { - "aegir": "^40.0.1", - "protons": "^7.0.2" - }, - "private": true -} diff --git a/packages/libp2p-daemon-protocol/src/index.proto b/packages/libp2p-daemon-protocol/src/index.proto deleted file mode 100644 index 038a513cb3..0000000000 --- a/packages/libp2p-daemon-protocol/src/index.proto +++ /dev/null @@ -1,209 +0,0 @@ -syntax = "proto3"; - -message Request { - enum Type { - IDENTIFY = 0; - CONNECT = 1; - STREAM_OPEN = 2; - STREAM_HANDLER = 3; - DHT = 4; - LIST_PEERS = 5; - CONNMANAGER = 6; - DISCONNECT = 7; - PUBSUB = 8; - PEERSTORE = 9; - } - - // the proto2 version of this field is "required" which means it will have - // no default value. the default for proto3 is "singluar" which omits the - // value on the wire if it's the default so for proto3 we make it "optional" - // to ensure a value is always written on to the wire - optional Type type = 1; - - optional ConnectRequest connect = 2; - optional StreamOpenRequest streamOpen = 3; - optional StreamHandlerRequest streamHandler = 4; - optional DHTRequest dht = 5; - optional ConnManagerRequest connManager = 6; - optional DisconnectRequest disconnect = 7; - optional PSRequest pubsub = 8; - optional PeerstoreRequest peerStore = 9; -} - -message Response { - enum Type { - OK = 0; - ERROR = 1; - } - - // the proto2 version of this field is "required" which means it will have - // no default value. the default for proto3 is "singluar" which omits the - // value on the wire if it's the default so for proto3 we make it "optional" - // to ensure a value is always written on to the wire - optional Type type = 1; - - optional ErrorResponse error = 2; - optional StreamInfo streamInfo = 3; - optional IdentifyResponse identify = 4; - optional DHTResponse dht = 5; - repeated PeerInfo peers = 6; - optional PSResponse pubsub = 7; - optional PeerstoreResponse peerStore = 8; -} - -message IdentifyResponse { - bytes id = 1; - repeated bytes addrs = 2; -} - -message ConnectRequest { - bytes peer = 1; - repeated bytes addrs = 2; - optional int64 timeout = 3; -} - -message StreamOpenRequest { - bytes peer = 1; - repeated string proto = 2; - optional int64 timeout = 3; -} - -message StreamHandlerRequest { - bytes addr = 1; - repeated string proto = 2; -} - -message ErrorResponse { - string msg = 1; -} - -message StreamInfo { - bytes peer = 1; - bytes addr = 2; - string proto = 3; -} - -message DHTRequest { - enum Type { - FIND_PEER = 0; - FIND_PEERS_CONNECTED_TO_PEER = 1; - FIND_PROVIDERS = 2; - GET_CLOSEST_PEERS = 3; - GET_PUBLIC_KEY = 4; - GET_VALUE = 5; - SEARCH_VALUE = 6; - PUT_VALUE = 7; - PROVIDE = 8; - } - - // the proto2 version of this field is "required" which means it will have - // no default value. the default for proto3 is "singluar" which omits the - // value on the wire if it's the default so for proto3 we make it "optional" - // to ensure a value is always written on to the wire - optional Type type = 1; - - optional bytes peer = 2; - optional bytes cid = 3; - optional bytes key = 4; - optional bytes value = 5; - optional int32 count = 6; - optional int64 timeout = 7; -} - -message DHTResponse { - enum Type { - BEGIN = 0; - VALUE = 1; - END = 2; - } - - // the proto2 version of this field is "required" which means it will have - // no default value. the default for proto3 is "singluar" which omits the - // value on the wire if it's the default so for proto3 we make it "optional" - // to ensure a value is always written on to the wire - optional Type type = 1; - - optional PeerInfo peer = 2; - optional bytes value = 3; -} - -message PeerInfo { - bytes id = 1; - repeated bytes addrs = 2; -} - -message ConnManagerRequest { - enum Type { - TAG_PEER = 0; - UNTAG_PEER = 1; - TRIM = 2; - } - - // the proto2 version of this field is "required" which means it will have - // no default value. the default for proto3 is "singluar" which omits the - // value on the wire if it's the default so for proto3 we make it "optional" - // to ensure a value is always written on to the wire - optional Type type = 1; - - optional bytes peer = 2; - optional string tag = 3; - optional int64 weight = 4; -} - -message DisconnectRequest { - bytes peer = 1; -} - -message PSRequest { - enum Type { - GET_TOPICS = 0; - LIST_PEERS = 1; - PUBLISH = 2; - SUBSCRIBE = 3; - } - - // the proto2 version of this field is "required" which means it will have - // no default value. the default for proto3 is "singluar" which omits the - // value on the wire if it's the default so for proto3 we make it "optional" - // to ensure a value is always written on to the wire - optional Type type = 1; - - optional string topic = 2; - optional bytes data = 3; -} - -message PSMessage { - optional bytes from = 1; - optional bytes data = 2; - optional bytes seqno = 3; - repeated string topicIDs = 4; - optional bytes signature = 5; - optional bytes key = 6; -} - -message PSResponse { - repeated string topics = 1; - repeated bytes peerIDs = 2; -} - -message PeerstoreRequest { - enum Type { - UNSPECIFIED = 0; - GET_PROTOCOLS = 1; - GET_PEER_INFO = 2; - } - - // the proto2 version of this field is "required" which means it will have - // no default value. the default for proto3 is "singluar" which omits the - // value on the wire if it's the default so for proto3 we make it "optional" - // to ensure a value is always written on to the wire - optional Type type = 1; - - optional bytes id = 2; - repeated string protos = 3; -} - -message PeerstoreResponse { - optional PeerInfo peer = 1; - repeated string protos = 2; -} diff --git a/packages/libp2p-daemon-protocol/src/index.ts b/packages/libp2p-daemon-protocol/src/index.ts deleted file mode 100644 index b9b517682c..0000000000 --- a/packages/libp2p-daemon-protocol/src/index.ts +++ /dev/null @@ -1,1639 +0,0 @@ -/* eslint-disable import/export */ -/* eslint-disable complexity */ -/* eslint-disable @typescript-eslint/no-namespace */ -/* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */ -/* eslint-disable @typescript-eslint/no-empty-interface */ - -import { enumeration, encodeMessage, decodeMessage, message } from 'protons-runtime' -import type { Codec } from 'protons-runtime' -import type { Uint8ArrayList } from 'uint8arraylist' - -export interface Request { - type?: Request.Type - connect?: ConnectRequest - streamOpen?: StreamOpenRequest - streamHandler?: StreamHandlerRequest - dht?: DHTRequest - connManager?: ConnManagerRequest - disconnect?: DisconnectRequest - pubsub?: PSRequest - peerStore?: PeerstoreRequest -} - -export namespace Request { - export enum Type { - IDENTIFY = 'IDENTIFY', - CONNECT = 'CONNECT', - STREAM_OPEN = 'STREAM_OPEN', - STREAM_HANDLER = 'STREAM_HANDLER', - DHT = 'DHT', - LIST_PEERS = 'LIST_PEERS', - CONNMANAGER = 'CONNMANAGER', - DISCONNECT = 'DISCONNECT', - PUBSUB = 'PUBSUB', - PEERSTORE = 'PEERSTORE' - } - - enum __TypeValues { - IDENTIFY = 0, - CONNECT = 1, - STREAM_OPEN = 2, - STREAM_HANDLER = 3, - DHT = 4, - LIST_PEERS = 5, - CONNMANAGER = 6, - DISCONNECT = 7, - PUBSUB = 8, - PEERSTORE = 9 - } - - export namespace Type { - export const codec = (): Codec => { - return enumeration(__TypeValues) - } - } - - let _codec: Codec - - export const codec = (): Codec => { - if (_codec == null) { - _codec = message((obj, w, opts = {}) => { - if (opts.lengthDelimited !== false) { - w.fork() - } - - if (obj.type != null) { - w.uint32(8) - Request.Type.codec().encode(obj.type, w) - } - - if (obj.connect != null) { - w.uint32(18) - ConnectRequest.codec().encode(obj.connect, w) - } - - if (obj.streamOpen != null) { - w.uint32(26) - StreamOpenRequest.codec().encode(obj.streamOpen, w) - } - - if (obj.streamHandler != null) { - w.uint32(34) - StreamHandlerRequest.codec().encode(obj.streamHandler, w) - } - - if (obj.dht != null) { - w.uint32(42) - DHTRequest.codec().encode(obj.dht, w) - } - - if (obj.connManager != null) { - w.uint32(50) - ConnManagerRequest.codec().encode(obj.connManager, w) - } - - if (obj.disconnect != null) { - w.uint32(58) - DisconnectRequest.codec().encode(obj.disconnect, w) - } - - if (obj.pubsub != null) { - w.uint32(66) - PSRequest.codec().encode(obj.pubsub, w) - } - - if (obj.peerStore != null) { - w.uint32(74) - PeerstoreRequest.codec().encode(obj.peerStore, w) - } - - if (opts.lengthDelimited !== false) { - w.ldelim() - } - }, (reader, length) => { - const obj: any = {} - - const end = length == null ? reader.len : reader.pos + length - - while (reader.pos < end) { - const tag = reader.uint32() - - switch (tag >>> 3) { - case 1: - obj.type = Request.Type.codec().decode(reader) - break - case 2: - obj.connect = ConnectRequest.codec().decode(reader, reader.uint32()) - break - case 3: - obj.streamOpen = StreamOpenRequest.codec().decode(reader, reader.uint32()) - break - case 4: - obj.streamHandler = StreamHandlerRequest.codec().decode(reader, reader.uint32()) - break - case 5: - obj.dht = DHTRequest.codec().decode(reader, reader.uint32()) - break - case 6: - obj.connManager = ConnManagerRequest.codec().decode(reader, reader.uint32()) - break - case 7: - obj.disconnect = DisconnectRequest.codec().decode(reader, reader.uint32()) - break - case 8: - obj.pubsub = PSRequest.codec().decode(reader, reader.uint32()) - break - case 9: - obj.peerStore = PeerstoreRequest.codec().decode(reader, reader.uint32()) - break - default: - reader.skipType(tag & 7) - break - } - } - - return obj - }) - } - - return _codec - } - - export const encode = (obj: Partial): Uint8Array => { - return encodeMessage(obj, Request.codec()) - } - - export const decode = (buf: Uint8Array | Uint8ArrayList): Request => { - return decodeMessage(buf, Request.codec()) - } -} - -export interface Response { - type?: Response.Type - error?: ErrorResponse - streamInfo?: StreamInfo - identify?: IdentifyResponse - dht?: DHTResponse - peers: PeerInfo[] - pubsub?: PSResponse - peerStore?: PeerstoreResponse -} - -export namespace Response { - export enum Type { - OK = 'OK', - ERROR = 'ERROR' - } - - enum __TypeValues { - OK = 0, - ERROR = 1 - } - - export namespace Type { - export const codec = (): Codec => { - return enumeration(__TypeValues) - } - } - - let _codec: Codec - - export const codec = (): Codec => { - if (_codec == null) { - _codec = message((obj, w, opts = {}) => { - if (opts.lengthDelimited !== false) { - w.fork() - } - - if (obj.type != null) { - w.uint32(8) - Response.Type.codec().encode(obj.type, w) - } - - if (obj.error != null) { - w.uint32(18) - ErrorResponse.codec().encode(obj.error, w) - } - - if (obj.streamInfo != null) { - w.uint32(26) - StreamInfo.codec().encode(obj.streamInfo, w) - } - - if (obj.identify != null) { - w.uint32(34) - IdentifyResponse.codec().encode(obj.identify, w) - } - - if (obj.dht != null) { - w.uint32(42) - DHTResponse.codec().encode(obj.dht, w) - } - - if (obj.peers != null) { - for (const value of obj.peers) { - w.uint32(50) - PeerInfo.codec().encode(value, w) - } - } - - if (obj.pubsub != null) { - w.uint32(58) - PSResponse.codec().encode(obj.pubsub, w) - } - - if (obj.peerStore != null) { - w.uint32(66) - PeerstoreResponse.codec().encode(obj.peerStore, w) - } - - if (opts.lengthDelimited !== false) { - w.ldelim() - } - }, (reader, length) => { - const obj: any = { - peers: [] - } - - const end = length == null ? reader.len : reader.pos + length - - while (reader.pos < end) { - const tag = reader.uint32() - - switch (tag >>> 3) { - case 1: - obj.type = Response.Type.codec().decode(reader) - break - case 2: - obj.error = ErrorResponse.codec().decode(reader, reader.uint32()) - break - case 3: - obj.streamInfo = StreamInfo.codec().decode(reader, reader.uint32()) - break - case 4: - obj.identify = IdentifyResponse.codec().decode(reader, reader.uint32()) - break - case 5: - obj.dht = DHTResponse.codec().decode(reader, reader.uint32()) - break - case 6: - obj.peers.push(PeerInfo.codec().decode(reader, reader.uint32())) - break - case 7: - obj.pubsub = PSResponse.codec().decode(reader, reader.uint32()) - break - case 8: - obj.peerStore = PeerstoreResponse.codec().decode(reader, reader.uint32()) - break - default: - reader.skipType(tag & 7) - break - } - } - - return obj - }) - } - - return _codec - } - - export const encode = (obj: Partial): Uint8Array => { - return encodeMessage(obj, Response.codec()) - } - - export const decode = (buf: Uint8Array | Uint8ArrayList): Response => { - return decodeMessage(buf, Response.codec()) - } -} - -export interface IdentifyResponse { - id: Uint8Array - addrs: Uint8Array[] -} - -export namespace IdentifyResponse { - let _codec: Codec - - export const codec = (): Codec => { - if (_codec == null) { - _codec = message((obj, w, opts = {}) => { - if (opts.lengthDelimited !== false) { - w.fork() - } - - if ((obj.id != null && obj.id.byteLength > 0)) { - w.uint32(10) - w.bytes(obj.id) - } - - if (obj.addrs != null) { - for (const value of obj.addrs) { - w.uint32(18) - w.bytes(value) - } - } - - if (opts.lengthDelimited !== false) { - w.ldelim() - } - }, (reader, length) => { - const obj: any = { - id: new Uint8Array(0), - addrs: [] - } - - const end = length == null ? reader.len : reader.pos + length - - while (reader.pos < end) { - const tag = reader.uint32() - - switch (tag >>> 3) { - case 1: - obj.id = reader.bytes() - break - case 2: - obj.addrs.push(reader.bytes()) - break - default: - reader.skipType(tag & 7) - break - } - } - - return obj - }) - } - - return _codec - } - - export const encode = (obj: Partial): Uint8Array => { - return encodeMessage(obj, IdentifyResponse.codec()) - } - - export const decode = (buf: Uint8Array | Uint8ArrayList): IdentifyResponse => { - return decodeMessage(buf, IdentifyResponse.codec()) - } -} - -export interface ConnectRequest { - peer: Uint8Array - addrs: Uint8Array[] - timeout?: bigint -} - -export namespace ConnectRequest { - let _codec: Codec - - export const codec = (): Codec => { - if (_codec == null) { - _codec = message((obj, w, opts = {}) => { - if (opts.lengthDelimited !== false) { - w.fork() - } - - if ((obj.peer != null && obj.peer.byteLength > 0)) { - w.uint32(10) - w.bytes(obj.peer) - } - - if (obj.addrs != null) { - for (const value of obj.addrs) { - w.uint32(18) - w.bytes(value) - } - } - - if (obj.timeout != null) { - w.uint32(24) - w.int64(obj.timeout) - } - - if (opts.lengthDelimited !== false) { - w.ldelim() - } - }, (reader, length) => { - const obj: any = { - peer: new Uint8Array(0), - addrs: [] - } - - const end = length == null ? reader.len : reader.pos + length - - while (reader.pos < end) { - const tag = reader.uint32() - - switch (tag >>> 3) { - case 1: - obj.peer = reader.bytes() - break - case 2: - obj.addrs.push(reader.bytes()) - break - case 3: - obj.timeout = reader.int64() - break - default: - reader.skipType(tag & 7) - break - } - } - - return obj - }) - } - - return _codec - } - - export const encode = (obj: Partial): Uint8Array => { - return encodeMessage(obj, ConnectRequest.codec()) - } - - export const decode = (buf: Uint8Array | Uint8ArrayList): ConnectRequest => { - return decodeMessage(buf, ConnectRequest.codec()) - } -} - -export interface StreamOpenRequest { - peer: Uint8Array - proto: string[] - timeout?: bigint -} - -export namespace StreamOpenRequest { - let _codec: Codec - - export const codec = (): Codec => { - if (_codec == null) { - _codec = message((obj, w, opts = {}) => { - if (opts.lengthDelimited !== false) { - w.fork() - } - - if ((obj.peer != null && obj.peer.byteLength > 0)) { - w.uint32(10) - w.bytes(obj.peer) - } - - if (obj.proto != null) { - for (const value of obj.proto) { - w.uint32(18) - w.string(value) - } - } - - if (obj.timeout != null) { - w.uint32(24) - w.int64(obj.timeout) - } - - if (opts.lengthDelimited !== false) { - w.ldelim() - } - }, (reader, length) => { - const obj: any = { - peer: new Uint8Array(0), - proto: [] - } - - const end = length == null ? reader.len : reader.pos + length - - while (reader.pos < end) { - const tag = reader.uint32() - - switch (tag >>> 3) { - case 1: - obj.peer = reader.bytes() - break - case 2: - obj.proto.push(reader.string()) - break - case 3: - obj.timeout = reader.int64() - break - default: - reader.skipType(tag & 7) - break - } - } - - return obj - }) - } - - return _codec - } - - export const encode = (obj: Partial): Uint8Array => { - return encodeMessage(obj, StreamOpenRequest.codec()) - } - - export const decode = (buf: Uint8Array | Uint8ArrayList): StreamOpenRequest => { - return decodeMessage(buf, StreamOpenRequest.codec()) - } -} - -export interface StreamHandlerRequest { - addr: Uint8Array - proto: string[] -} - -export namespace StreamHandlerRequest { - let _codec: Codec - - export const codec = (): Codec => { - if (_codec == null) { - _codec = message((obj, w, opts = {}) => { - if (opts.lengthDelimited !== false) { - w.fork() - } - - if ((obj.addr != null && obj.addr.byteLength > 0)) { - w.uint32(10) - w.bytes(obj.addr) - } - - if (obj.proto != null) { - for (const value of obj.proto) { - w.uint32(18) - w.string(value) - } - } - - if (opts.lengthDelimited !== false) { - w.ldelim() - } - }, (reader, length) => { - const obj: any = { - addr: new Uint8Array(0), - proto: [] - } - - const end = length == null ? reader.len : reader.pos + length - - while (reader.pos < end) { - const tag = reader.uint32() - - switch (tag >>> 3) { - case 1: - obj.addr = reader.bytes() - break - case 2: - obj.proto.push(reader.string()) - break - default: - reader.skipType(tag & 7) - break - } - } - - return obj - }) - } - - return _codec - } - - export const encode = (obj: Partial): Uint8Array => { - return encodeMessage(obj, StreamHandlerRequest.codec()) - } - - export const decode = (buf: Uint8Array | Uint8ArrayList): StreamHandlerRequest => { - return decodeMessage(buf, StreamHandlerRequest.codec()) - } -} - -export interface ErrorResponse { - msg: string -} - -export namespace ErrorResponse { - let _codec: Codec - - export const codec = (): Codec => { - if (_codec == null) { - _codec = message((obj, w, opts = {}) => { - if (opts.lengthDelimited !== false) { - w.fork() - } - - if ((obj.msg != null && obj.msg !== '')) { - w.uint32(10) - w.string(obj.msg) - } - - if (opts.lengthDelimited !== false) { - w.ldelim() - } - }, (reader, length) => { - const obj: any = { - msg: '' - } - - const end = length == null ? reader.len : reader.pos + length - - while (reader.pos < end) { - const tag = reader.uint32() - - switch (tag >>> 3) { - case 1: - obj.msg = reader.string() - break - default: - reader.skipType(tag & 7) - break - } - } - - return obj - }) - } - - return _codec - } - - export const encode = (obj: Partial): Uint8Array => { - return encodeMessage(obj, ErrorResponse.codec()) - } - - export const decode = (buf: Uint8Array | Uint8ArrayList): ErrorResponse => { - return decodeMessage(buf, ErrorResponse.codec()) - } -} - -export interface StreamInfo { - peer: Uint8Array - addr: Uint8Array - proto: string -} - -export namespace StreamInfo { - let _codec: Codec - - export const codec = (): Codec => { - if (_codec == null) { - _codec = message((obj, w, opts = {}) => { - if (opts.lengthDelimited !== false) { - w.fork() - } - - if ((obj.peer != null && obj.peer.byteLength > 0)) { - w.uint32(10) - w.bytes(obj.peer) - } - - if ((obj.addr != null && obj.addr.byteLength > 0)) { - w.uint32(18) - w.bytes(obj.addr) - } - - if ((obj.proto != null && obj.proto !== '')) { - w.uint32(26) - w.string(obj.proto) - } - - if (opts.lengthDelimited !== false) { - w.ldelim() - } - }, (reader, length) => { - const obj: any = { - peer: new Uint8Array(0), - addr: new Uint8Array(0), - proto: '' - } - - const end = length == null ? reader.len : reader.pos + length - - while (reader.pos < end) { - const tag = reader.uint32() - - switch (tag >>> 3) { - case 1: - obj.peer = reader.bytes() - break - case 2: - obj.addr = reader.bytes() - break - case 3: - obj.proto = reader.string() - break - default: - reader.skipType(tag & 7) - break - } - } - - return obj - }) - } - - return _codec - } - - export const encode = (obj: Partial): Uint8Array => { - return encodeMessage(obj, StreamInfo.codec()) - } - - export const decode = (buf: Uint8Array | Uint8ArrayList): StreamInfo => { - return decodeMessage(buf, StreamInfo.codec()) - } -} - -export interface DHTRequest { - type?: DHTRequest.Type - peer?: Uint8Array - cid?: Uint8Array - key?: Uint8Array - value?: Uint8Array - count?: number - timeout?: bigint -} - -export namespace DHTRequest { - export enum Type { - FIND_PEER = 'FIND_PEER', - FIND_PEERS_CONNECTED_TO_PEER = 'FIND_PEERS_CONNECTED_TO_PEER', - FIND_PROVIDERS = 'FIND_PROVIDERS', - GET_CLOSEST_PEERS = 'GET_CLOSEST_PEERS', - GET_PUBLIC_KEY = 'GET_PUBLIC_KEY', - GET_VALUE = 'GET_VALUE', - SEARCH_VALUE = 'SEARCH_VALUE', - PUT_VALUE = 'PUT_VALUE', - PROVIDE = 'PROVIDE' - } - - enum __TypeValues { - FIND_PEER = 0, - FIND_PEERS_CONNECTED_TO_PEER = 1, - FIND_PROVIDERS = 2, - GET_CLOSEST_PEERS = 3, - GET_PUBLIC_KEY = 4, - GET_VALUE = 5, - SEARCH_VALUE = 6, - PUT_VALUE = 7, - PROVIDE = 8 - } - - export namespace Type { - export const codec = (): Codec => { - return enumeration(__TypeValues) - } - } - - let _codec: Codec - - export const codec = (): Codec => { - if (_codec == null) { - _codec = message((obj, w, opts = {}) => { - if (opts.lengthDelimited !== false) { - w.fork() - } - - if (obj.type != null) { - w.uint32(8) - DHTRequest.Type.codec().encode(obj.type, w) - } - - if (obj.peer != null) { - w.uint32(18) - w.bytes(obj.peer) - } - - if (obj.cid != null) { - w.uint32(26) - w.bytes(obj.cid) - } - - if (obj.key != null) { - w.uint32(34) - w.bytes(obj.key) - } - - if (obj.value != null) { - w.uint32(42) - w.bytes(obj.value) - } - - if (obj.count != null) { - w.uint32(48) - w.int32(obj.count) - } - - if (obj.timeout != null) { - w.uint32(56) - w.int64(obj.timeout) - } - - if (opts.lengthDelimited !== false) { - w.ldelim() - } - }, (reader, length) => { - const obj: any = {} - - const end = length == null ? reader.len : reader.pos + length - - while (reader.pos < end) { - const tag = reader.uint32() - - switch (tag >>> 3) { - case 1: - obj.type = DHTRequest.Type.codec().decode(reader) - break - case 2: - obj.peer = reader.bytes() - break - case 3: - obj.cid = reader.bytes() - break - case 4: - obj.key = reader.bytes() - break - case 5: - obj.value = reader.bytes() - break - case 6: - obj.count = reader.int32() - break - case 7: - obj.timeout = reader.int64() - break - default: - reader.skipType(tag & 7) - break - } - } - - return obj - }) - } - - return _codec - } - - export const encode = (obj: Partial): Uint8Array => { - return encodeMessage(obj, DHTRequest.codec()) - } - - export const decode = (buf: Uint8Array | Uint8ArrayList): DHTRequest => { - return decodeMessage(buf, DHTRequest.codec()) - } -} - -export interface DHTResponse { - type?: DHTResponse.Type - peer?: PeerInfo - value?: Uint8Array -} - -export namespace DHTResponse { - export enum Type { - BEGIN = 'BEGIN', - VALUE = 'VALUE', - END = 'END' - } - - enum __TypeValues { - BEGIN = 0, - VALUE = 1, - END = 2 - } - - export namespace Type { - export const codec = (): Codec => { - return enumeration(__TypeValues) - } - } - - let _codec: Codec - - export const codec = (): Codec => { - if (_codec == null) { - _codec = message((obj, w, opts = {}) => { - if (opts.lengthDelimited !== false) { - w.fork() - } - - if (obj.type != null) { - w.uint32(8) - DHTResponse.Type.codec().encode(obj.type, w) - } - - if (obj.peer != null) { - w.uint32(18) - PeerInfo.codec().encode(obj.peer, w) - } - - if (obj.value != null) { - w.uint32(26) - w.bytes(obj.value) - } - - if (opts.lengthDelimited !== false) { - w.ldelim() - } - }, (reader, length) => { - const obj: any = {} - - const end = length == null ? reader.len : reader.pos + length - - while (reader.pos < end) { - const tag = reader.uint32() - - switch (tag >>> 3) { - case 1: - obj.type = DHTResponse.Type.codec().decode(reader) - break - case 2: - obj.peer = PeerInfo.codec().decode(reader, reader.uint32()) - break - case 3: - obj.value = reader.bytes() - break - default: - reader.skipType(tag & 7) - break - } - } - - return obj - }) - } - - return _codec - } - - export const encode = (obj: Partial): Uint8Array => { - return encodeMessage(obj, DHTResponse.codec()) - } - - export const decode = (buf: Uint8Array | Uint8ArrayList): DHTResponse => { - return decodeMessage(buf, DHTResponse.codec()) - } -} - -export interface PeerInfo { - id: Uint8Array - addrs: Uint8Array[] -} - -export namespace PeerInfo { - let _codec: Codec - - export const codec = (): Codec => { - if (_codec == null) { - _codec = message((obj, w, opts = {}) => { - if (opts.lengthDelimited !== false) { - w.fork() - } - - if ((obj.id != null && obj.id.byteLength > 0)) { - w.uint32(10) - w.bytes(obj.id) - } - - if (obj.addrs != null) { - for (const value of obj.addrs) { - w.uint32(18) - w.bytes(value) - } - } - - if (opts.lengthDelimited !== false) { - w.ldelim() - } - }, (reader, length) => { - const obj: any = { - id: new Uint8Array(0), - addrs: [] - } - - const end = length == null ? reader.len : reader.pos + length - - while (reader.pos < end) { - const tag = reader.uint32() - - switch (tag >>> 3) { - case 1: - obj.id = reader.bytes() - break - case 2: - obj.addrs.push(reader.bytes()) - break - default: - reader.skipType(tag & 7) - break - } - } - - return obj - }) - } - - return _codec - } - - export const encode = (obj: Partial): Uint8Array => { - return encodeMessage(obj, PeerInfo.codec()) - } - - export const decode = (buf: Uint8Array | Uint8ArrayList): PeerInfo => { - return decodeMessage(buf, PeerInfo.codec()) - } -} - -export interface ConnManagerRequest { - type?: ConnManagerRequest.Type - peer?: Uint8Array - tag?: string - weight?: bigint -} - -export namespace ConnManagerRequest { - export enum Type { - TAG_PEER = 'TAG_PEER', - UNTAG_PEER = 'UNTAG_PEER', - TRIM = 'TRIM' - } - - enum __TypeValues { - TAG_PEER = 0, - UNTAG_PEER = 1, - TRIM = 2 - } - - export namespace Type { - export const codec = (): Codec => { - return enumeration(__TypeValues) - } - } - - let _codec: Codec - - export const codec = (): Codec => { - if (_codec == null) { - _codec = message((obj, w, opts = {}) => { - if (opts.lengthDelimited !== false) { - w.fork() - } - - if (obj.type != null) { - w.uint32(8) - ConnManagerRequest.Type.codec().encode(obj.type, w) - } - - if (obj.peer != null) { - w.uint32(18) - w.bytes(obj.peer) - } - - if (obj.tag != null) { - w.uint32(26) - w.string(obj.tag) - } - - if (obj.weight != null) { - w.uint32(32) - w.int64(obj.weight) - } - - if (opts.lengthDelimited !== false) { - w.ldelim() - } - }, (reader, length) => { - const obj: any = {} - - const end = length == null ? reader.len : reader.pos + length - - while (reader.pos < end) { - const tag = reader.uint32() - - switch (tag >>> 3) { - case 1: - obj.type = ConnManagerRequest.Type.codec().decode(reader) - break - case 2: - obj.peer = reader.bytes() - break - case 3: - obj.tag = reader.string() - break - case 4: - obj.weight = reader.int64() - break - default: - reader.skipType(tag & 7) - break - } - } - - return obj - }) - } - - return _codec - } - - export const encode = (obj: Partial): Uint8Array => { - return encodeMessage(obj, ConnManagerRequest.codec()) - } - - export const decode = (buf: Uint8Array | Uint8ArrayList): ConnManagerRequest => { - return decodeMessage(buf, ConnManagerRequest.codec()) - } -} - -export interface DisconnectRequest { - peer: Uint8Array -} - -export namespace DisconnectRequest { - let _codec: Codec - - export const codec = (): Codec => { - if (_codec == null) { - _codec = message((obj, w, opts = {}) => { - if (opts.lengthDelimited !== false) { - w.fork() - } - - if ((obj.peer != null && obj.peer.byteLength > 0)) { - w.uint32(10) - w.bytes(obj.peer) - } - - if (opts.lengthDelimited !== false) { - w.ldelim() - } - }, (reader, length) => { - const obj: any = { - peer: new Uint8Array(0) - } - - const end = length == null ? reader.len : reader.pos + length - - while (reader.pos < end) { - const tag = reader.uint32() - - switch (tag >>> 3) { - case 1: - obj.peer = reader.bytes() - break - default: - reader.skipType(tag & 7) - break - } - } - - return obj - }) - } - - return _codec - } - - export const encode = (obj: Partial): Uint8Array => { - return encodeMessage(obj, DisconnectRequest.codec()) - } - - export const decode = (buf: Uint8Array | Uint8ArrayList): DisconnectRequest => { - return decodeMessage(buf, DisconnectRequest.codec()) - } -} - -export interface PSRequest { - type?: PSRequest.Type - topic?: string - data?: Uint8Array -} - -export namespace PSRequest { - export enum Type { - GET_TOPICS = 'GET_TOPICS', - LIST_PEERS = 'LIST_PEERS', - PUBLISH = 'PUBLISH', - SUBSCRIBE = 'SUBSCRIBE' - } - - enum __TypeValues { - GET_TOPICS = 0, - LIST_PEERS = 1, - PUBLISH = 2, - SUBSCRIBE = 3 - } - - export namespace Type { - export const codec = (): Codec => { - return enumeration(__TypeValues) - } - } - - let _codec: Codec - - export const codec = (): Codec => { - if (_codec == null) { - _codec = message((obj, w, opts = {}) => { - if (opts.lengthDelimited !== false) { - w.fork() - } - - if (obj.type != null) { - w.uint32(8) - PSRequest.Type.codec().encode(obj.type, w) - } - - if (obj.topic != null) { - w.uint32(18) - w.string(obj.topic) - } - - if (obj.data != null) { - w.uint32(26) - w.bytes(obj.data) - } - - if (opts.lengthDelimited !== false) { - w.ldelim() - } - }, (reader, length) => { - const obj: any = {} - - const end = length == null ? reader.len : reader.pos + length - - while (reader.pos < end) { - const tag = reader.uint32() - - switch (tag >>> 3) { - case 1: - obj.type = PSRequest.Type.codec().decode(reader) - break - case 2: - obj.topic = reader.string() - break - case 3: - obj.data = reader.bytes() - break - default: - reader.skipType(tag & 7) - break - } - } - - return obj - }) - } - - return _codec - } - - export const encode = (obj: Partial): Uint8Array => { - return encodeMessage(obj, PSRequest.codec()) - } - - export const decode = (buf: Uint8Array | Uint8ArrayList): PSRequest => { - return decodeMessage(buf, PSRequest.codec()) - } -} - -export interface PSMessage { - from?: Uint8Array - data?: Uint8Array - seqno?: Uint8Array - topicIDs: string[] - signature?: Uint8Array - key?: Uint8Array -} - -export namespace PSMessage { - let _codec: Codec - - export const codec = (): Codec => { - if (_codec == null) { - _codec = message((obj, w, opts = {}) => { - if (opts.lengthDelimited !== false) { - w.fork() - } - - if (obj.from != null) { - w.uint32(10) - w.bytes(obj.from) - } - - if (obj.data != null) { - w.uint32(18) - w.bytes(obj.data) - } - - if (obj.seqno != null) { - w.uint32(26) - w.bytes(obj.seqno) - } - - if (obj.topicIDs != null) { - for (const value of obj.topicIDs) { - w.uint32(34) - w.string(value) - } - } - - if (obj.signature != null) { - w.uint32(42) - w.bytes(obj.signature) - } - - if (obj.key != null) { - w.uint32(50) - w.bytes(obj.key) - } - - if (opts.lengthDelimited !== false) { - w.ldelim() - } - }, (reader, length) => { - const obj: any = { - topicIDs: [] - } - - const end = length == null ? reader.len : reader.pos + length - - while (reader.pos < end) { - const tag = reader.uint32() - - switch (tag >>> 3) { - case 1: - obj.from = reader.bytes() - break - case 2: - obj.data = reader.bytes() - break - case 3: - obj.seqno = reader.bytes() - break - case 4: - obj.topicIDs.push(reader.string()) - break - case 5: - obj.signature = reader.bytes() - break - case 6: - obj.key = reader.bytes() - break - default: - reader.skipType(tag & 7) - break - } - } - - return obj - }) - } - - return _codec - } - - export const encode = (obj: Partial): Uint8Array => { - return encodeMessage(obj, PSMessage.codec()) - } - - export const decode = (buf: Uint8Array | Uint8ArrayList): PSMessage => { - return decodeMessage(buf, PSMessage.codec()) - } -} - -export interface PSResponse { - topics: string[] - peerIDs: Uint8Array[] -} - -export namespace PSResponse { - let _codec: Codec - - export const codec = (): Codec => { - if (_codec == null) { - _codec = message((obj, w, opts = {}) => { - if (opts.lengthDelimited !== false) { - w.fork() - } - - if (obj.topics != null) { - for (const value of obj.topics) { - w.uint32(10) - w.string(value) - } - } - - if (obj.peerIDs != null) { - for (const value of obj.peerIDs) { - w.uint32(18) - w.bytes(value) - } - } - - if (opts.lengthDelimited !== false) { - w.ldelim() - } - }, (reader, length) => { - const obj: any = { - topics: [], - peerIDs: [] - } - - const end = length == null ? reader.len : reader.pos + length - - while (reader.pos < end) { - const tag = reader.uint32() - - switch (tag >>> 3) { - case 1: - obj.topics.push(reader.string()) - break - case 2: - obj.peerIDs.push(reader.bytes()) - break - default: - reader.skipType(tag & 7) - break - } - } - - return obj - }) - } - - return _codec - } - - export const encode = (obj: Partial): Uint8Array => { - return encodeMessage(obj, PSResponse.codec()) - } - - export const decode = (buf: Uint8Array | Uint8ArrayList): PSResponse => { - return decodeMessage(buf, PSResponse.codec()) - } -} - -export interface PeerstoreRequest { - type?: PeerstoreRequest.Type - id?: Uint8Array - protos: string[] -} - -export namespace PeerstoreRequest { - export enum Type { - UNSPECIFIED = 'UNSPECIFIED', - GET_PROTOCOLS = 'GET_PROTOCOLS', - GET_PEER_INFO = 'GET_PEER_INFO' - } - - enum __TypeValues { - UNSPECIFIED = 0, - GET_PROTOCOLS = 1, - GET_PEER_INFO = 2 - } - - export namespace Type { - export const codec = (): Codec => { - return enumeration(__TypeValues) - } - } - - let _codec: Codec - - export const codec = (): Codec => { - if (_codec == null) { - _codec = message((obj, w, opts = {}) => { - if (opts.lengthDelimited !== false) { - w.fork() - } - - if (obj.type != null) { - w.uint32(8) - PeerstoreRequest.Type.codec().encode(obj.type, w) - } - - if (obj.id != null) { - w.uint32(18) - w.bytes(obj.id) - } - - if (obj.protos != null) { - for (const value of obj.protos) { - w.uint32(26) - w.string(value) - } - } - - if (opts.lengthDelimited !== false) { - w.ldelim() - } - }, (reader, length) => { - const obj: any = { - protos: [] - } - - const end = length == null ? reader.len : reader.pos + length - - while (reader.pos < end) { - const tag = reader.uint32() - - switch (tag >>> 3) { - case 1: - obj.type = PeerstoreRequest.Type.codec().decode(reader) - break - case 2: - obj.id = reader.bytes() - break - case 3: - obj.protos.push(reader.string()) - break - default: - reader.skipType(tag & 7) - break - } - } - - return obj - }) - } - - return _codec - } - - export const encode = (obj: Partial): Uint8Array => { - return encodeMessage(obj, PeerstoreRequest.codec()) - } - - export const decode = (buf: Uint8Array | Uint8ArrayList): PeerstoreRequest => { - return decodeMessage(buf, PeerstoreRequest.codec()) - } -} - -export interface PeerstoreResponse { - peer?: PeerInfo - protos: string[] -} - -export namespace PeerstoreResponse { - let _codec: Codec - - export const codec = (): Codec => { - if (_codec == null) { - _codec = message((obj, w, opts = {}) => { - if (opts.lengthDelimited !== false) { - w.fork() - } - - if (obj.peer != null) { - w.uint32(10) - PeerInfo.codec().encode(obj.peer, w) - } - - if (obj.protos != null) { - for (const value of obj.protos) { - w.uint32(18) - w.string(value) - } - } - - if (opts.lengthDelimited !== false) { - w.ldelim() - } - }, (reader, length) => { - const obj: any = { - protos: [] - } - - const end = length == null ? reader.len : reader.pos + length - - while (reader.pos < end) { - const tag = reader.uint32() - - switch (tag >>> 3) { - case 1: - obj.peer = PeerInfo.codec().decode(reader, reader.uint32()) - break - case 2: - obj.protos.push(reader.string()) - break - default: - reader.skipType(tag & 7) - break - } - } - - return obj - }) - } - - return _codec - } - - export const encode = (obj: Partial): Uint8Array => { - return encodeMessage(obj, PeerstoreResponse.codec()) - } - - export const decode = (buf: Uint8Array | Uint8ArrayList): PeerstoreResponse => { - return decodeMessage(buf, PeerstoreResponse.codec()) - } -} diff --git a/packages/libp2p-daemon-protocol/src/stream-handler.ts b/packages/libp2p-daemon-protocol/src/stream-handler.ts deleted file mode 100644 index 3a38a038db..0000000000 --- a/packages/libp2p-daemon-protocol/src/stream-handler.ts +++ /dev/null @@ -1,68 +0,0 @@ -import { logger } from '@libp2p/logger' -import { handshake } from 'it-handshake' -import * as lp from 'it-length-prefixed' -import type { Handshake } from 'it-handshake' -import type { Duplex, Source } from 'it-stream-types' -import type { Uint8ArrayList } from 'uint8arraylist' - -const log = logger('libp2p:daemon-protocol:stream-handler') - -export interface StreamHandlerOptions { - stream: Duplex, Source, Promise> - maxLength?: number -} - -export class StreamHandler { - private readonly stream: Duplex, Source, Promise> - private readonly shake: Handshake - public decoder: Source - - /** - * Create a stream handler for connection - */ - constructor (opts: StreamHandlerOptions) { - const { stream, maxLength } = opts - - this.stream = stream - this.shake = handshake(this.stream) - this.decoder = lp.decode.fromReader(this.shake.reader, { maxDataLength: maxLength ?? 4096 }) - } - - /** - * Read and decode message - */ - async read (): Promise { - // @ts-expect-error decoder is really a generator - const msg = await this.decoder.next() - if (msg.value != null) { - return msg.value.subarray() - } - - log('read received no value, closing stream') - // End the stream, we didn't get data - await this.close() - } - - write (msg: Uint8Array | Uint8ArrayList): void { - log('write message') - this.shake.write( - lp.encode.single(msg).subarray() - ) - } - - /** - * Return the handshake rest stream and invalidate handler - */ - rest (): Duplex, Source, Promise> { - this.shake.rest() - return this.shake.stream - } - - /** - * Close the stream - */ - async close (): Promise { - log('closing the stream') - await this.rest().sink([]) - } -} diff --git a/packages/libp2p-daemon-protocol/src/upgrader.ts b/packages/libp2p-daemon-protocol/src/upgrader.ts deleted file mode 100644 index 33de547328..0000000000 --- a/packages/libp2p-daemon-protocol/src/upgrader.ts +++ /dev/null @@ -1,8 +0,0 @@ -import type { Upgrader } from '@libp2p/interface/transport' - -export const passThroughUpgrader: Upgrader = { - // @ts-expect-error should return a connection - upgradeInbound: async maConn => maConn, - // @ts-expect-error should return a connection - upgradeOutbound: async maConn => maConn -} diff --git a/packages/libp2p-daemon-protocol/tsconfig.json b/packages/libp2p-daemon-protocol/tsconfig.json deleted file mode 100644 index 1a5e68bbdb..0000000000 --- a/packages/libp2p-daemon-protocol/tsconfig.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "extends": "aegir/src/config/tsconfig.aegir.json", - "compilerOptions": { - "outDir": "dist" - }, - "include": [ - "src" - ], - "exclude": [ - "src/index.js" - ], - "references": [ - { - "path": "../interface" - }, - { - "path": "../logger" - } - ] -} diff --git a/packages/libp2p-daemon-protocol/typedoc.json b/packages/libp2p-daemon-protocol/typedoc.json deleted file mode 100644 index 15cd5d50df..0000000000 --- a/packages/libp2p-daemon-protocol/typedoc.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "entryPoints": [ - "./src/index.ts", - "./src/stream-handler.ts", - "./src/upgrader.ts" - ] -} diff --git a/packages/libp2p-daemon-server/.aegir.js b/packages/libp2p-daemon-server/.aegir.js deleted file mode 100644 index 135a6a2211..0000000000 --- a/packages/libp2p-daemon-server/.aegir.js +++ /dev/null @@ -1,8 +0,0 @@ - -export default { - build: { - config: { - platform: 'node' - } - } -} diff --git a/packages/libp2p-daemon-server/CHANGELOG.md b/packages/libp2p-daemon-server/CHANGELOG.md deleted file mode 100644 index f7c98c0a03..0000000000 --- a/packages/libp2p-daemon-server/CHANGELOG.md +++ /dev/null @@ -1,249 +0,0 @@ -## [@libp2p/daemon-server-v5.0.2](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-server-v5.0.1...@libp2p/daemon-server-v5.0.2) (2023-04-27) - - -### Bug Fixes - -* use interface-libp2p to ensure the correct services are set ([#203](https://github.com/libp2p/js-libp2p-daemon/issues/203)) ([8602a70](https://github.com/libp2p/js-libp2p-daemon/commit/8602a704e45cfa768ad55974d025b2d4be6f42a9)) - -## [@libp2p/daemon-server-v5.0.1](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-server-v5.0.0...@libp2p/daemon-server-v5.0.1) (2023-04-24) - - -### Dependencies - -* bump @libp2p/interface-peer-store from 1.2.9 to 2.0.0 ([#201](https://github.com/libp2p/js-libp2p-daemon/issues/201)) ([9b146a8](https://github.com/libp2p/js-libp2p-daemon/commit/9b146a8c38c30a13401be6da5259cd9da6bdc25c)) - -## [@libp2p/daemon-server-v5.0.0](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-server-v4.1.4...@libp2p/daemon-server-v5.0.0) (2023-04-19) - - -### ⚠ BREAKING CHANGES - -* the type of the source/sink properties have changed - -### Dependencies - -* update it-stream-types to 2.x.x ([#196](https://github.com/libp2p/js-libp2p-daemon/issues/196)) ([a09f6d5](https://github.com/libp2p/js-libp2p-daemon/commit/a09f6d58942033b08b579735aaa1537b3a324776)) -* update sibling dependencies ([e0ec5ec](https://github.com/libp2p/js-libp2p-daemon/commit/e0ec5ecf5bfd7f801274d37d51c3dcce652de2ba)) - -## [@libp2p/daemon-server-v4.1.4](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-server-v4.1.3...@libp2p/daemon-server-v4.1.4) (2023-04-12) - - -### Dependencies - -* bump @libp2p/interface-connection from 3.1.1 to 4.0.0 ([#195](https://github.com/libp2p/js-libp2p-daemon/issues/195)) ([798ecc5](https://github.com/libp2p/js-libp2p-daemon/commit/798ecc594bc64c8e34aad13e1b9884011f0b1f29)) - -## [@libp2p/daemon-server-v4.1.3](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-server-v4.1.2...@libp2p/daemon-server-v4.1.3) (2023-04-03) - - -### Dependencies - -* update all it-* deps to the latest versions ([#193](https://github.com/libp2p/js-libp2p-daemon/issues/193)) ([cb0aa85](https://github.com/libp2p/js-libp2p-daemon/commit/cb0aa85bbbad651db088594622a9438a127d2a10)) - -## [@libp2p/daemon-server-v4.1.2](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-server-v4.1.1...@libp2p/daemon-server-v4.1.2) (2023-03-31) - - -### Dependencies - -* bump it-drain from 2.0.1 to 3.0.1 ([#190](https://github.com/libp2p/js-libp2p-daemon/issues/190)) ([306bdc4](https://github.com/libp2p/js-libp2p-daemon/commit/306bdc4fc139c3af429314d7b7d78d0a2238d6f4)) - -## [@libp2p/daemon-server-v4.1.1](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-server-v4.1.0...@libp2p/daemon-server-v4.1.1) (2023-03-17) - - -### Dependencies - -* bump @multiformats/multiaddr from 11.6.1 to 12.0.0 ([#189](https://github.com/libp2p/js-libp2p-daemon/issues/189)) ([aaf7e2e](https://github.com/libp2p/js-libp2p-daemon/commit/aaf7e2e37423cae78cd16d8e16e06db40fdcd1e3)) - -## [@libp2p/daemon-server-v4.1.0](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-server-v4.0.3...@libp2p/daemon-server-v4.1.0) (2023-02-23) - - -### Features - -* add get subscribers for pubsub topics ([#184](https://github.com/libp2p/js-libp2p-daemon/issues/184)) ([c8be43e](https://github.com/libp2p/js-libp2p-daemon/commit/c8be43e5acd6a74cfdd01857343af6f6d8210d5d)) - -## [@libp2p/daemon-server-v4.0.3](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-server-v4.0.2...@libp2p/daemon-server-v4.0.3) (2023-02-22) - - -### Dependencies - -* bump aegir from 37.12.1 to 38.1.6 ([#183](https://github.com/libp2p/js-libp2p-daemon/issues/183)) ([6725a0a](https://github.com/libp2p/js-libp2p-daemon/commit/6725a0aeba9acb56a7530dece6c65a0f3eadfec5)) - -## [@libp2p/daemon-server-v4.0.2](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-server-v4.0.1...@libp2p/daemon-server-v4.0.2) (2023-02-22) - - -### Trivial Changes - -* remove lerna ([#171](https://github.com/libp2p/js-libp2p-daemon/issues/171)) ([367f912](https://github.com/libp2p/js-libp2p-daemon/commit/367f9122f2fe1c31c8de7a136cda18d024ff08d7)) - - -### Dependencies - -* **dev:** bump sinon from 14.0.2 to 15.0.1 ([#166](https://github.com/libp2p/js-libp2p-daemon/issues/166)) ([1702efb](https://github.com/libp2p/js-libp2p-daemon/commit/1702efb4248bea4cb9ec19c694c1caae1c0ff16d)) - -## [@libp2p/daemon-server-v4.0.1](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-server-v4.0.0...@libp2p/daemon-server-v4.0.1) (2023-01-07) - - -### Dependencies - -* bump @libp2p/tcp from 5.0.2 to 6.0.8 ([#165](https://github.com/libp2p/js-libp2p-daemon/issues/165)) ([fb676ab](https://github.com/libp2p/js-libp2p-daemon/commit/fb676ab66348b3c704d2385b4da0d7173bc4a04d)) - -## [@libp2p/daemon-server-v4.0.0](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-server-v3.0.5...@libp2p/daemon-server-v4.0.0) (2023-01-07) - - -### ⚠ BREAKING CHANGES - -* Update multiformats and related dependencies (#170) - -### Dependencies - -* Update multiformats and related dependencies ([#170](https://github.com/libp2p/js-libp2p-daemon/issues/170)) ([06744a7](https://github.com/libp2p/js-libp2p-daemon/commit/06744a77006dc77dcfb7bd860e4dc6f36a535603)) - -## [@libp2p/daemon-server-v3.0.5](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-server-v3.0.4...@libp2p/daemon-server-v3.0.5) (2022-10-17) - - -### Dependencies - -* bump it-drain from 1.0.5 to 2.0.0 ([#147](https://github.com/libp2p/js-libp2p-daemon/issues/147)) ([56663f8](https://github.com/libp2p/js-libp2p-daemon/commit/56663f83255a0720b4bf4c7e3805ee4ced8dc86d)) - -## [@libp2p/daemon-server-v3.0.4](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-server-v3.0.3...@libp2p/daemon-server-v3.0.4) (2022-10-14) - - -### Dependencies - -* **dev:** bump sinon-ts from 0.0.2 to 1.0.0 ([#144](https://github.com/libp2p/js-libp2p-daemon/issues/144)) ([cfc8755](https://github.com/libp2p/js-libp2p-daemon/commit/cfc8755aa1280ac4fc2aae67cf47d7b0b93f605d)) - -## [@libp2p/daemon-server-v3.0.3](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-server-v3.0.2...@libp2p/daemon-server-v3.0.3) (2022-10-13) - - -### Dependencies - -* update uint8arrays, protons and multiformats ([#143](https://github.com/libp2p/js-libp2p-daemon/issues/143)) ([661139c](https://github.com/libp2p/js-libp2p-daemon/commit/661139c674c9994724e32227d7d9ae2c5da1cea2)) - -## [@libp2p/daemon-server-v3.0.2](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-server-v3.0.1...@libp2p/daemon-server-v3.0.2) (2022-10-07) - - -### Dependencies - -* bump @libp2p/interface-transport from 1.0.4 to 2.0.0 ([#132](https://github.com/libp2p/js-libp2p-daemon/issues/132)) ([1a7b2cc](https://github.com/libp2p/js-libp2p-daemon/commit/1a7b2cc653dfb51e92edb1f652452e3c793156c3)) -* bump @libp2p/tcp from 3.0.0 to 4.0.1 ([4e64dce](https://github.com/libp2p/js-libp2p-daemon/commit/4e64dce5e6d18dadaa54a20fff7b2da8bbca11ae)) - -## [@libp2p/daemon-server-v3.0.1](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-server-v3.0.0...@libp2p/daemon-server-v3.0.1) (2022-09-21) - - -### Dependencies - -* update @multiformats/multiaddr to 11.0.0 ([#128](https://github.com/libp2p/js-libp2p-daemon/issues/128)) ([885d901](https://github.com/libp2p/js-libp2p-daemon/commit/885d9013d82a62e6756b06350932df1242a13296)) - -## [@libp2p/daemon-server-v3.0.0](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-server-v2.0.4...@libp2p/daemon-server-v3.0.0) (2022-09-09) - - -### ⚠ BREAKING CHANGES - -* the stream type returned by `client.openStream` has changed - -### Bug Fixes - -* allow opening remote streams ([#126](https://github.com/libp2p/js-libp2p-daemon/issues/126)) ([361cc57](https://github.com/libp2p/js-libp2p-daemon/commit/361cc5750de505ab0381ae43609c67d5d4f659a7)) - - -### Dependencies - -* update sibling dependencies ([c3ebd58](https://github.com/libp2p/js-libp2p-daemon/commit/c3ebd588abc36ef45667e8e4e4c0e220303b7510)) - -## [@libp2p/daemon-server-v2.0.4](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-server-v2.0.3...@libp2p/daemon-server-v2.0.4) (2022-08-10) - - -### Bug Fixes - -* update all deps ([#124](https://github.com/libp2p/js-libp2p-daemon/issues/124)) ([5e46e1e](https://github.com/libp2p/js-libp2p-daemon/commit/5e46e1e26c23428046a6007ab158420d3d830145)) - - -### Documentation - -* readme update ([f569ffc](https://github.com/libp2p/js-libp2p-daemon/commit/f569ffc5c3956248e685d99904408fd3f4d868f4)) - -## [@libp2p/daemon-server-v2.0.3](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-server-v2.0.2...@libp2p/daemon-server-v2.0.3) (2022-07-31) - - -### Trivial Changes - -* update project config ([#111](https://github.com/libp2p/js-libp2p-daemon/issues/111)) ([345e663](https://github.com/libp2p/js-libp2p-daemon/commit/345e663e34278e780fc2f3a6b595294f925c4521)) - - -### Dependencies - -* update uint8arraylist and protons deps ([#115](https://github.com/libp2p/js-libp2p-daemon/issues/115)) ([34a8334](https://github.com/libp2p/js-libp2p-daemon/commit/34a83340ba855a9c08319ae1cd735dfa8b71c248)) - -## [@libp2p/daemon-server-v2.0.2](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-server-v2.0.1...@libp2p/daemon-server-v2.0.2) (2022-06-17) - - -### Trivial Changes - -* update deps ([#105](https://github.com/libp2p/js-libp2p-daemon/issues/105)) ([0bdab0e](https://github.com/libp2p/js-libp2p-daemon/commit/0bdab0ee254e32d6dca0e5fe239d4ef16db41b87)) - -## [@libp2p/daemon-server-v2.0.1](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-server-v2.0.0...@libp2p/daemon-server-v2.0.1) (2022-06-15) - - -### Trivial Changes - -* update deps ([#103](https://github.com/libp2p/js-libp2p-daemon/issues/103)) ([2bfaa37](https://github.com/libp2p/js-libp2p-daemon/commit/2bfaa37e2f056dcd5de5a3882b77f52553c595d4)) - -## [@libp2p/daemon-server-v2.0.0](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-server-v1.0.5...@libp2p/daemon-server-v2.0.0) (2022-06-15) - - -### ⚠ BREAKING CHANGES - -* uses new single-issue libp2p interface modules - -### Features - -* update to latest libp2p interfaces ([#102](https://github.com/libp2p/js-libp2p-daemon/issues/102)) ([f5e9121](https://github.com/libp2p/js-libp2p-daemon/commit/f5e91210654ab3c411e316c1c657356c037a0f6a)) - -## [@libp2p/daemon-server-v1.0.5](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-server-v1.0.4...@libp2p/daemon-server-v1.0.5) (2022-05-25) - - -### Trivial Changes - -* update docs ([#91](https://github.com/libp2p/js-libp2p-daemon/issues/91)) ([5b072ff](https://github.com/libp2p/js-libp2p-daemon/commit/5b072ff89f30fd6cf55a3387bf0961c8ad78a22f)), closes [#83](https://github.com/libp2p/js-libp2p-daemon/issues/83) - -## [@libp2p/daemon-server-v1.0.4](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-server-v1.0.3...@libp2p/daemon-server-v1.0.4) (2022-05-23) - - -### Bug Fixes - -* update deps ([#90](https://github.com/libp2p/js-libp2p-daemon/issues/90)) ([b50eba3](https://github.com/libp2p/js-libp2p-daemon/commit/b50eba3770e47969dbc30cbcf87c41672cd9c175)) - -## [@libp2p/daemon-server-v1.0.3](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-server-v1.0.2...@libp2p/daemon-server-v1.0.3) (2022-05-10) - - -### Bug Fixes - -* encode enums correctly ([#86](https://github.com/libp2p/js-libp2p-daemon/issues/86)) ([6ce4633](https://github.com/libp2p/js-libp2p-daemon/commit/6ce4633f3db41ab66f9b8b1abbe84955dde3e9be)) - -## [@libp2p/daemon-server-v1.0.2](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-server-v1.0.1...@libp2p/daemon-server-v1.0.2) (2022-04-20) - - -### Bug Fixes - -* update interfaces and deps ([#84](https://github.com/libp2p/js-libp2p-daemon/issues/84)) ([25173d5](https://github.com/libp2p/js-libp2p-daemon/commit/25173d5b2edf0e9dd9132707d349cdc862caecdb)) - -## [@libp2p/daemon-server-v1.0.1](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-server-v1.0.0...@libp2p/daemon-server-v1.0.1) (2022-04-07) - - -### Bug Fixes - -* remove protobufjs and replace with protons ([#81](https://github.com/libp2p/js-libp2p-daemon/issues/81)) ([78dd02a](https://github.com/libp2p/js-libp2p-daemon/commit/78dd02a679e55f22c7e24c1ee2b6f92a4679a0b9)) - - -### Trivial Changes - -* update aegir to latest version ([#80](https://github.com/libp2p/js-libp2p-daemon/issues/80)) ([3a98959](https://github.com/libp2p/js-libp2p-daemon/commit/3a98959617d9c19bba9fb064defee3d51acfcc29)) - -## @libp2p/daemon-server-v1.0.0 (2022-03-28) - - -### ⚠ BREAKING CHANGES - -* This module is now ESM only - -### Features - -* convert to typescript ([#78](https://github.com/libp2p/js-libp2p-daemon/issues/78)) ([f18b2a4](https://github.com/libp2p/js-libp2p-daemon/commit/f18b2a45871a2704db51b03e8583eefdcd13554c)) diff --git a/packages/libp2p-daemon-server/LICENSE b/packages/libp2p-daemon-server/LICENSE deleted file mode 100644 index 20ce483c86..0000000000 --- a/packages/libp2p-daemon-server/LICENSE +++ /dev/null @@ -1,4 +0,0 @@ -This project is dual licensed under MIT and Apache-2.0. - -MIT: https://www.opensource.org/licenses/mit -Apache-2.0: https://www.apache.org/licenses/license-2.0 diff --git a/packages/libp2p-daemon-server/LICENSE-APACHE b/packages/libp2p-daemon-server/LICENSE-APACHE deleted file mode 100644 index 14478a3b60..0000000000 --- a/packages/libp2p-daemon-server/LICENSE-APACHE +++ /dev/null @@ -1,5 +0,0 @@ -Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - -http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. diff --git a/packages/libp2p-daemon-server/LICENSE-MIT b/packages/libp2p-daemon-server/LICENSE-MIT deleted file mode 100644 index 72dc60d84b..0000000000 --- a/packages/libp2p-daemon-server/LICENSE-MIT +++ /dev/null @@ -1,19 +0,0 @@ -The MIT License (MIT) - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. diff --git a/packages/libp2p-daemon-server/README.md b/packages/libp2p-daemon-server/README.md deleted file mode 100644 index a04616c4d8..0000000000 --- a/packages/libp2p-daemon-server/README.md +++ /dev/null @@ -1,54 +0,0 @@ -# @libp2p/daemon-server - -[![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) -[![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) -[![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p) -[![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p/main.yml?branch=master\&style=flat-square)](https://github.com/libp2p/js-libp2p/actions/workflows/main.yml?query=branch%3Amaster) - -> API server for libp2p-daemon instances - -## Table of contents - -- [Install](#install) -- [Specs](#specs) -- [Usage](#usage) -- [License](#license) -- [Contribution](#contribution) - -## Install - -```console -$ npm i @libp2p/daemon-server -``` - -## Specs - -The specs for the daemon are currently housed in the go implementation. You can read them at [libp2p/go-libp2p-daemon](https://github.com/libp2p/go-libp2p-daemon/blob/master/specs/README.md) - -## Usage - -```js -import { createServer } from '@libp2p/daemon-server' -import { createLibp2p } from 'libp2p' -import { multiaddr } from '@multiformats/multiaddr' - -const libp2p = await createLibp2p({ - // ..config -}) - -const multiaddr = multiaddr('/ip4/0.0.0.0/tcp/0') - -const server = await createServer(multiaddr, libp2p) -await server.start() -``` - -## License - -Licensed under either of - -- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) -- MIT ([LICENSE-MIT](LICENSE-MIT) / ) - -## Contribution - -Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. diff --git a/packages/libp2p-daemon-server/package.json b/packages/libp2p-daemon-server/package.json deleted file mode 100644 index 8d98a3cb7d..0000000000 --- a/packages/libp2p-daemon-server/package.json +++ /dev/null @@ -1,71 +0,0 @@ -{ - "name": "@libp2p/daemon-server", - "version": "5.0.2", - "description": "API server for libp2p-daemon instances", - "license": "Apache-2.0 OR MIT", - "homepage": "https://github.com/libp2p/js-libp2p/tree/master/packages/libp2p-daemon-server#readme", - "repository": { - "type": "git", - "url": "git+https://github.com/libp2p/js-libp2p.git" - }, - "bugs": { - "url": "https://github.com/libp2p/js-libp2p/issues" - }, - "keywords": [ - "libp2p" - ], - "type": "module", - "types": "./dist/src/index.d.ts", - "files": [ - "src", - "dist", - "!dist/test", - "!**/*.tsbuildinfo" - ], - "exports": { - ".": { - "types": "./src/index.d.ts", - "import": "./dist/src/index.js" - } - }, - "eslintConfig": { - "extends": "ipfs", - "parserOptions": { - "sourceType": "module" - }, - "ignorePatterns": [ - "*.d.ts", - "src/profocol/index.js" - ] - }, - "scripts": { - "clean": "aegir clean", - "lint": "aegir lint", - "dep-check": "aegir dep-check", - "build": "aegir build", - "pretest": "npm run build", - "test": "aegir test -t node", - "test:node": "aegir test -t node" - }, - "dependencies": { - "@chainsafe/libp2p-gossipsub": "^9.0.0", - "@libp2p/daemon-protocol": "^4.0.0", - "@libp2p/interface": "^0.1.0", - "@libp2p/kad-dht": "^10.0.0", - "@libp2p/logger": "^3.0.0", - "@libp2p/peer-id": "^3.0.0", - "@libp2p/tcp": "^8.0.0", - "@multiformats/multiaddr": "^12.1.3", - "it-drain": "^3.0.2", - "it-length-prefixed": "^9.0.1", - "it-pipe": "^3.0.1", - "it-pushable": "^3.2.0", - "multiformats": "^12.0.1", - "uint8arrays": "^4.0.4" - }, - "devDependencies": { - "aegir": "^40.0.1", - "sinon-ts": "^1.0.0" - }, - "private": true -} diff --git a/packages/libp2p-daemon-server/src/dht.ts b/packages/libp2p-daemon-server/src/dht.ts deleted file mode 100644 index f256f5e9b6..0000000000 --- a/packages/libp2p-daemon-server/src/dht.ts +++ /dev/null @@ -1,153 +0,0 @@ -/* eslint max-depth: ["error", 6] */ - -import { - DHTResponse -} from '@libp2p/daemon-protocol' -import { logger } from '@libp2p/logger' -import drain from 'it-drain' -import { ErrorResponse, OkResponse } from './responses.js' -import type { PeerId } from '@libp2p/interface/peer-id' -import type { KadDHT } from '@libp2p/kad-dht' -import type { CID } from 'multiformats/cid' - -const log = logger('libp2p:daemon-server:dht') - -export interface DHTOperationsInit { - dht: KadDHT -} - -export class DHTOperations { - private readonly dht: KadDHT - - constructor (init: DHTOperationsInit) { - const { dht } = init - - this.dht = dht - } - - async * provide (cid: CID): AsyncGenerator { - try { - await drain(this.dht.provide(cid)) - yield OkResponse() - } catch (err: any) { - log.error(err) - yield ErrorResponse(err) - } - } - - async * getClosestPeers (key: Uint8Array): AsyncGenerator { - yield OkResponse({ - dht: { - type: DHTResponse.Type.BEGIN - } - }) - - for await (const event of this.dht.getClosestPeers(key)) { - if (event.name === 'PEER_RESPONSE') { - yield * event.closer.map(peer => DHTResponse.encode({ - type: DHTResponse.Type.VALUE, - value: peer.id.toBytes() - })) - } - } - - yield DHTResponse.encode({ - type: DHTResponse.Type.END - }) - } - - async * getPublicKey (peerId: PeerId): AsyncGenerator { - yield ErrorResponse(new Error('FIX ME: not implemented')) - } - - async * getValue (key: Uint8Array): AsyncGenerator { - try { - for await (const event of this.dht.get(key)) { - if (event.name === 'VALUE') { - yield OkResponse({ - dht: { - type: DHTResponse.Type.VALUE, - value: event.value - } - }) - } - } - } catch (err: any) { - log.error(err) - yield ErrorResponse(err) - } - } - - async * putValue (key: Uint8Array, value: Uint8Array): AsyncGenerator { - try { - await drain(this.dht.put(key, value)) - - yield OkResponse() - } catch (err: any) { - log.error(err) - yield ErrorResponse(err) - } - } - - async * findPeer (peerId: PeerId): AsyncGenerator { - try { - for await (const event of this.dht.findPeer(peerId)) { - if (event.name === 'FINAL_PEER') { - yield OkResponse({ - dht: { - type: DHTResponse.Type.VALUE, - peer: { - id: event.peer.id.toBytes(), - addrs: event.peer.multiaddrs.map(m => m.bytes) - } - } - }) - } - } - - throw new Error('Peer not found') - } catch (err: any) { - log.error(err) - yield ErrorResponse(err) - } - } - - async * findProviders (cid: CID, count: number): AsyncGenerator { - yield OkResponse({ - dht: { - type: DHTResponse.Type.BEGIN - } - }) - - try { - const maxNumProviders = count - let found = 0 - - for await (const event of this.dht.findProviders(cid)) { - if (event.name === 'PEER_RESPONSE') { - for (const provider of event.providers) { - found++ - - yield DHTResponse.encode({ - type: DHTResponse.Type.VALUE, - peer: { - id: provider.id.toBytes(), - addrs: (provider.multiaddrs ?? []).map(m => m.bytes) - } - }) - } - - if (maxNumProviders === found) { - break - } - } - } - } catch (err: any) { - yield ErrorResponse(err) - } - - yield DHTResponse.encode({ - type: DHTResponse.Type.END - }) - } -} diff --git a/packages/libp2p-daemon-server/src/index.ts b/packages/libp2p-daemon-server/src/index.ts deleted file mode 100644 index acc9d26067..0000000000 --- a/packages/libp2p-daemon-server/src/index.ts +++ /dev/null @@ -1,535 +0,0 @@ -/* eslint max-depth: ["error", 6] */ - -import { - Request, - DHTRequest, - PeerstoreRequest, - PSRequest, - StreamInfo -} from '@libp2p/daemon-protocol' -import { StreamHandler } from '@libp2p/daemon-protocol/stream-handler' -import { passThroughUpgrader } from '@libp2p/daemon-protocol/upgrader' -import { logger } from '@libp2p/logger' -import { peerIdFromBytes } from '@libp2p/peer-id' -import { tcp } from '@libp2p/tcp' -import { multiaddr, protocols } from '@multiformats/multiaddr' -import * as lp from 'it-length-prefixed' -import { pipe } from 'it-pipe' -import { CID } from 'multiformats/cid' -import { DHTOperations } from './dht.js' -import { PubSubOperations } from './pubsub.js' -import { ErrorResponse, OkResponse } from './responses.js' -import type { GossipSub } from '@chainsafe/libp2p-gossipsub' -import type { Libp2p } from '@libp2p/interface' -import type { Connection, MultiaddrConnection, Stream } from '@libp2p/interface/connection' -import type { Listener, Transport } from '@libp2p/interface/transport' -import type { KadDHT } from '@libp2p/kad-dht' -import type { Multiaddr } from '@multiformats/multiaddr' - -const LIMIT = 1 << 22 // 4MB -const log = logger('libp2p:daemon-server') - -export interface OpenStream { - streamInfo: StreamInfo - connection: Stream -} - -export interface DaemonInit { - multiaddr: Multiaddr - libp2pNode: Libp2p<{ dht: KadDHT, pubsub: GossipSub }> -} - -export interface Libp2pServer { - start: () => Promise - stop: () => Promise - getMultiaddr: () => Multiaddr -} - -export class Server implements Libp2pServer { - private readonly multiaddr: Multiaddr - private readonly libp2p: Libp2p<{ dht: KadDHT, pubsub: GossipSub }> - private readonly tcp: Transport - private readonly listener: Listener - private readonly dhtOperations?: DHTOperations - private readonly pubsubOperations?: PubSubOperations - - constructor (init: DaemonInit) { - const { multiaddr, libp2pNode } = init - - this.multiaddr = multiaddr - this.libp2p = libp2pNode - this.tcp = tcp()() - this.listener = this.tcp.createListener({ - handler: this.handleConnection.bind(this), - upgrader: passThroughUpgrader - }) - this._onExit = this._onExit.bind(this) - - if (libp2pNode.services.dht != null) { - this.dhtOperations = new DHTOperations({ dht: libp2pNode.services.dht }) - } - - if (libp2pNode.services.pubsub != null) { - this.pubsubOperations = new PubSubOperations({ pubsub: libp2pNode.services.pubsub }) - } - } - - /** - * Connects the daemons libp2p node to the peer provided - */ - async connect (request: Request): Promise { - if (request.connect == null || request.connect.addrs == null) { - throw new Error('Invalid request') - } - - const peer = request.connect.peer - const addrs = request.connect.addrs.map((a) => multiaddr(a)) - const peerId = peerIdFromBytes(peer) - - await this.libp2p.peerStore.merge(peerId, { - multiaddrs: addrs - }) - return this.libp2p.dial(peerId) - } - - /** - * Opens a stream on one of the given protocols to the given peer - */ - async openStream (request: Request): Promise { - if (request.streamOpen == null || request.streamOpen.proto == null) { - throw new Error('Invalid request') - } - - const { peer, proto } = request.streamOpen - const peerId = peerIdFromBytes(peer) - const connection = await this.libp2p.dial(peerId) - const stream = await connection.newStream(proto, { - runOnTransientConnection: true - }) - - return { - streamInfo: { - peer: peerId.toBytes(), - addr: connection.remoteAddr.bytes, - proto: stream.protocol ?? '' - }, - connection: stream - } - } - - /** - * Sends inbound requests for the given protocol - * to the unix socket path provided. If an existing handler - * is registered at the path, it will be overridden. - */ - async registerStreamHandler (request: Request): Promise { - if (request.streamHandler == null || request.streamHandler.proto == null) { - throw new Error('Invalid request') - } - - const protocols = request.streamHandler.proto - const addr = multiaddr(request.streamHandler.addr) - let conn: MultiaddrConnection - - await this.libp2p.handle(protocols, ({ connection, stream }) => { - Promise.resolve() - .then(async () => { - // Connect the client socket with the libp2p connection - // @ts-expect-error because we use a passthrough upgrader, - // this is actually a MultiaddrConnection and not a Connection - conn = await this.tcp.dial(addr, { - upgrader: passThroughUpgrader - }) - - const message = StreamInfo.encode({ - peer: connection.remotePeer.toBytes(), - addr: connection.remoteAddr.bytes, - proto: stream.protocol ?? '' - }) - const encodedMessage = lp.encode.single(message) - - // Tell the client about the new connection - // And then begin piping the client and peer connection - await pipe( - (async function * () { - yield encodedMessage - yield * stream.source - }()), - async function * (source) { - for await (const list of source) { - // convert Uint8ArrayList to Uint8Arrays for the socket - yield * list - } - }, - conn, - stream.sink - ) - }) - .catch(async err => { - log.error(err) - - if (conn != null) { - await conn.close(err) - } - }) - .finally(() => { - if (conn != null) { - conn.close() - .catch(err => { - log.error(err) - }) - } - }) - }, { - runOnTransientConnection: true - }) - } - - /** - * Listens for process exit to handle cleanup - */ - _listen (): void { - // listen for graceful termination - process.on('SIGTERM', this._onExit) - process.on('SIGINT', this._onExit) - process.on('SIGHUP', this._onExit) - } - - _onExit (): void { - void this.stop({ exit: true }).catch(err => { - log.error(err) - }) - } - - /** - * Starts the daemon - */ - async start (): Promise { - this._listen() - await this.libp2p.start() - await this.listener.listen(this.multiaddr) - } - - getMultiaddr (): Multiaddr { - const addrs = this.listener.getAddrs() - - if (addrs.length > 0) { - return addrs[0] - } - - throw new Error('Not started') - } - - /** - * Stops the daemon - */ - async stop (options = { exit: false }): Promise { - await this.libp2p.stop() - await this.listener.close() - if (options.exit) { - log('server closed, exiting') - } - process.removeListener('SIGTERM', this._onExit) - process.removeListener('SIGINT', this._onExit) - process.removeListener('SIGHUP', this._onExit) - } - - async * handlePeerStoreRequest (request: PeerstoreRequest): AsyncGenerator { - try { - switch (request.type) { - case PeerstoreRequest.Type.GET_PROTOCOLS: - if (request.id == null) { - throw new Error('Invalid request') - } - - const peerId = peerIdFromBytes(request.id) // eslint-disable-line no-case-declarations - const peer = await this.libp2p.peerStore.get(peerId) // eslint-disable-line no-case-declarations - const protos = peer.protocols // eslint-disable-line no-case-declarations - yield OkResponse({ peerStore: { protos } }) - return - case PeerstoreRequest.Type.GET_PEER_INFO: - throw new Error('ERR_NOT_IMPLEMENTED') - default: - throw new Error('ERR_INVALID_REQUEST_TYPE') - } - } catch (err: any) { - log.error(err) - yield ErrorResponse(err) - } - } - - /** - * Parses and responds to PSRequests - */ - async * handlePubsubRequest (request: PSRequest): AsyncGenerator { - try { - if (this.libp2p.services.pubsub == null || (this.pubsubOperations == null)) { - throw new Error('PubSub not configured') - } - - switch (request.type) { - case PSRequest.Type.GET_TOPICS: - yield * this.pubsubOperations.getTopics() - return - case PSRequest.Type.SUBSCRIBE: - if (request.topic == null) { - throw new Error('Invalid request') - } - - yield * this.pubsubOperations.subscribe(request.topic) - return - case PSRequest.Type.PUBLISH: - if (request.topic == null || request.data == null) { - throw new Error('Invalid request') - } - - yield * this.pubsubOperations.publish(request.topic, request.data) - return - case PSRequest.Type.LIST_PEERS: - if (request.topic == null) { - throw new Error('Invalid request') - } - - yield * this.pubsubOperations.listPeers(request.topic) - return - default: - throw new Error('ERR_INVALID_REQUEST_TYPE') - } - } catch (err: any) { - log.error(err) - yield ErrorResponse(err) - } - } - - /** - * Parses and responds to DHTRequests - */ - async * handleDHTRequest (request: DHTRequest): AsyncGenerator { - try { - if (this.libp2p.services.dht == null || (this.dhtOperations == null)) { - throw new Error('DHT not configured') - } - - switch (request.type) { - case DHTRequest.Type.FIND_PEER: - if (request.peer == null) { - throw new Error('Invalid request') - } - - yield * this.dhtOperations.findPeer(peerIdFromBytes(request.peer)) - return - case DHTRequest.Type.FIND_PROVIDERS: - if (request.cid == null) { - throw new Error('Invalid request') - } - - yield * this.dhtOperations.findProviders(CID.decode(request.cid), request.count ?? 20) - return - case DHTRequest.Type.PROVIDE: - if (request.cid == null) { - throw new Error('Invalid request') - } - - yield * this.dhtOperations.provide(CID.decode(request.cid)) - return - case DHTRequest.Type.GET_CLOSEST_PEERS: - if (request.key == null) { - throw new Error('Invalid request') - } - - yield * this.dhtOperations.getClosestPeers(request.key) - return - case DHTRequest.Type.GET_PUBLIC_KEY: - if (request.peer == null) { - throw new Error('Invalid request') - } - - yield * this.dhtOperations.getPublicKey(peerIdFromBytes(request.peer)) - return - case DHTRequest.Type.GET_VALUE: - if (request.key == null) { - throw new Error('Invalid request') - } - - yield * this.dhtOperations.getValue(request.key) - return - case DHTRequest.Type.PUT_VALUE: - if (request.key == null || request.value == null) { - throw new Error('Invalid request') - } - - yield * this.dhtOperations.putValue(request.key, request.value) - return - default: - throw new Error('ERR_INVALID_REQUEST_TYPE') - } - } catch (err: any) { - log.error(err) - yield ErrorResponse(err) - } - } - - /** - * Handles requests for the given connection - */ - handleConnection (connection: Connection): void { - const daemon = this // eslint-disable-line @typescript-eslint/no-this-alias - // @ts-expect-error connection may actually be a maconn? - const streamHandler = new StreamHandler({ stream: connection, maxLength: LIMIT }) - - void pipe( - streamHandler.decoder, - source => (async function * () { - let request: Request - - for await (const buf of source) { - try { - request = Request.decode(buf) - - switch (request.type) { - // Connect to another peer - case Request.Type.CONNECT: { - try { - await daemon.connect(request) - } catch (err: any) { - yield ErrorResponse(err) - break - } - yield OkResponse() - break - } - // Get the daemon peer id and addresses - case Request.Type.IDENTIFY: { - yield OkResponse({ - identify: { - id: daemon.libp2p.peerId.toBytes(), - addrs: daemon.libp2p.getMultiaddrs().map(ma => ma.decapsulateCode(protocols('p2p').code)).map(m => m.bytes) - } - }) - break - } - // Get a list of our current peers - case Request.Type.LIST_PEERS: { - const peers = [] - const seen = new Set() - - for (const connection of daemon.libp2p.getConnections()) { - const peerId = connection.remotePeer.toString() - - if (seen.has(peerId)) { - continue - } - - seen.add(peerId) - - peers.push({ - id: connection.remotePeer.toBytes(), - addrs: [connection.remoteAddr.bytes] - }) - } - - yield OkResponse({ peers }) - break - } - case Request.Type.STREAM_OPEN: { - let response - try { - response = await daemon.openStream(request) - } catch (err: any) { - yield ErrorResponse(err) - break - } - - // write the response - yield OkResponse({ - streamInfo: response.streamInfo - }) - - const stream = streamHandler.rest() - // then pipe the connection to the client - await pipe( - stream, - response.connection, - async function * (source) { - for await (const list of source) { - yield * list - } - }, - stream - ) - // Exit the iterator, no more requests can come through - return - } - case Request.Type.STREAM_HANDLER: { - try { - await daemon.registerStreamHandler(request) - } catch (err: any) { - yield ErrorResponse(err) - break - } - - // write the response - yield OkResponse() - break - } - case Request.Type.PEERSTORE: { - if (request.peerStore == null) { - yield ErrorResponse(new Error('ERR_INVALID_REQUEST')) - break - } - - yield * daemon.handlePeerStoreRequest(request.peerStore) - break - } - case Request.Type.PUBSUB: { - if (request.pubsub == null) { - yield ErrorResponse(new Error('ERR_INVALID_REQUEST')) - break - } - - yield * daemon.handlePubsubRequest(request.pubsub) - break - } - case Request.Type.DHT: { - if (request.dht == null) { - yield ErrorResponse(new Error('ERR_INVALID_REQUEST')) - break - } - - yield * daemon.handleDHTRequest(request.dht) - break - } - // Not yet supported or doesn't exist - default: - yield ErrorResponse(new Error('ERR_INVALID_REQUEST_TYPE')) - break - } - } catch (err: any) { - log.error(err) - yield ErrorResponse(err) - continue - } - } - })(), - async function (source) { - for await (const result of source) { - streamHandler.write(result) - } - } - ).catch(err => { - log(err) - }) - } -} - -/** - * Creates a daemon from the provided Daemon Options - */ -export const createServer = (multiaddr: Multiaddr, libp2pNode: Libp2p<{ dht: KadDHT, pubsub: GossipSub }>): Libp2pServer => { - const daemon = new Server({ - multiaddr, - libp2pNode - }) - - return daemon -} diff --git a/packages/libp2p-daemon-server/src/pubsub.ts b/packages/libp2p-daemon-server/src/pubsub.ts deleted file mode 100644 index c59d1424a8..0000000000 --- a/packages/libp2p-daemon-server/src/pubsub.ts +++ /dev/null @@ -1,101 +0,0 @@ -/* eslint max-depth: ["error", 6] */ - -import { - PSMessage -} from '@libp2p/daemon-protocol' -import { logger } from '@libp2p/logger' -import { pushable } from 'it-pushable' -import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' -import { ErrorResponse, OkResponse } from './responses.js' -import type { GossipSub } from '@chainsafe/libp2p-gossipsub' - -const log = logger('libp2p:daemon-server:pubsub') - -export interface PubSubOperationsInit { - pubsub: GossipSub -} - -export class PubSubOperations { - private readonly pubsub: GossipSub - - constructor (init: PubSubOperationsInit) { - const { pubsub } = init - - this.pubsub = pubsub - } - - async * getTopics (): AsyncGenerator { - try { - yield OkResponse({ - pubsub: { - topics: this.pubsub.getTopics(), - peerIDs: [] - } - }) - } catch (err: any) { - log.error(err) - yield ErrorResponse(err) - } - } - - async * subscribe (topic: string): AsyncGenerator { - try { - const onMessage = pushable() - this.pubsub.subscribe(topic) - - this.pubsub.addEventListener('message', (evt) => { - const msg = evt.detail - - if (msg.topic !== topic) { - return - } - - if (msg.type === 'signed') { - onMessage.push(PSMessage.encode({ - from: msg.from.toBytes(), - data: msg.data, - seqno: msg.sequenceNumber == null ? undefined : uint8ArrayFromString(msg.sequenceNumber.toString(16).padStart(16, '0'), 'base16'), - topicIDs: [msg.topic], - signature: msg.signature, - key: msg.key - }).subarray()) - } else { - onMessage.push(PSMessage.encode({ - data: msg.data, - topicIDs: [msg.topic] - }).subarray()) - } - }) - - yield OkResponse() - yield * onMessage - } catch (err: any) { - log.error(err) - yield ErrorResponse(err) - } - } - - async * publish (topic: string, data: Uint8Array): AsyncGenerator { - try { - await this.pubsub.publish(topic, data) - yield OkResponse() - } catch (err: any) { - log.error(err) - yield ErrorResponse(err) - } - } - - async * listPeers (topic: string): AsyncGenerator { - try { - yield OkResponse({ - pubsub: { - topics: [topic], - peerIDs: this.pubsub.getSubscribers(topic).map(peer => peer.toBytes()) - } - }) - } catch (err: any) { - log.error(err) - yield ErrorResponse(err) - } - } -} diff --git a/packages/libp2p-daemon-server/src/responses.ts b/packages/libp2p-daemon-server/src/responses.ts deleted file mode 100644 index 96b1b9fbb4..0000000000 --- a/packages/libp2p-daemon-server/src/responses.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { Response } from '@libp2p/daemon-protocol' - -/** - * Creates and encodes an OK response - */ -export function OkResponse (data?: Partial): Uint8Array { - return Response.encode({ - type: Response.Type.OK, - peers: [], - ...data - }).subarray() -} - -/** - * Creates and encodes an ErrorResponse - */ -export function ErrorResponse (err: Error): Uint8Array { - return Response.encode({ - type: Response.Type.ERROR, - error: { - msg: err.message - }, - peers: [] - }).subarray() -} diff --git a/packages/libp2p-daemon-server/test/index.spec.ts b/packages/libp2p-daemon-server/test/index.spec.ts deleted file mode 100644 index 14db18b477..0000000000 --- a/packages/libp2p-daemon-server/test/index.spec.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* eslint-env mocha */ -/* eslint max-nested-callbacks: ["error", 5] */ - -import { multiaddr } from '@multiformats/multiaddr' -import { expect } from 'aegir/chai' -import { stubInterface } from 'sinon-ts' -import { createServer } from '../src/index.js' -import type { GossipSub } from '@chainsafe/libp2p-gossipsub' -import type { Libp2p } from '@libp2p/interface' -import type { KadDHT } from '@libp2p/kad-dht' - -const ma = multiaddr('/ip4/0.0.0.0/tcp/0') - -describe('server', () => { - it('should start', async () => { - const libp2p = stubInterface>() - - const server = createServer(ma, libp2p) - - await server.start() - - expect(libp2p.start.called).to.be.true() - - await server.stop() - }) - - it('should stop', async () => { - const libp2p = stubInterface>() - - const server = createServer(ma, libp2p) - - await server.start() - await server.stop() - - expect(libp2p.stop.called).to.be.true() - }) - - it('should return multiaddrs', async () => { - const libp2p = stubInterface>() - - const server = createServer(ma, libp2p) - - expect(() => server.getMultiaddr()).to.throw(/Not started/) - - await server.start() - - expect(server.getMultiaddr()).to.be.ok() - - await server.stop() - - expect(() => server.getMultiaddr()).to.throw(/Not started/) - }) -}) diff --git a/packages/libp2p-daemon-server/tsconfig.json b/packages/libp2p-daemon-server/tsconfig.json deleted file mode 100644 index 2909418dce..0000000000 --- a/packages/libp2p-daemon-server/tsconfig.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "extends": "aegir/src/config/tsconfig.aegir.json", - "compilerOptions": { - "outDir": "dist" - }, - "include": [ - "src", - "test" - ], - "references": [ - { - "path": "../interface" - }, - { - "path": "../kad-dht" - }, - { - "path": "../libp2p-daemon-protocol" - }, - { - "path": "../logger" - }, - { - "path": "../peer-id" - }, - { - "path": "../pubsub-gossipsub" - }, - { - "path": "../transport-tcp" - } - ] -} diff --git a/packages/libp2p-daemon-server/typedoc.json b/packages/libp2p-daemon-server/typedoc.json deleted file mode 100644 index f599dc728d..0000000000 --- a/packages/libp2p-daemon-server/typedoc.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "entryPoints": [ - "./src/index.ts" - ] -} diff --git a/packages/libp2p-daemon/.aegir.js b/packages/libp2p-daemon/.aegir.js deleted file mode 100644 index 135a6a2211..0000000000 --- a/packages/libp2p-daemon/.aegir.js +++ /dev/null @@ -1,8 +0,0 @@ - -export default { - build: { - config: { - platform: 'node' - } - } -} diff --git a/packages/libp2p-daemon/CHANGELOG.md b/packages/libp2p-daemon/CHANGELOG.md deleted file mode 100644 index f47810eb9e..0000000000 --- a/packages/libp2p-daemon/CHANGELOG.md +++ /dev/null @@ -1,379 +0,0 @@ -## [@libp2p/daemon-v2.0.9](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-v2.0.8...@libp2p/daemon-v2.0.9) (2023-04-19) - - -### Dependencies - -* update sibling dependencies ([db50405](https://github.com/libp2p/js-libp2p-daemon/commit/db50405ddec3a68ad265c3d3233595187bc4895d)) - -## [@libp2p/daemon-v2.0.8](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-v2.0.7...@libp2p/daemon-v2.0.8) (2023-03-17) - - -### Dependencies - -* bump @multiformats/multiaddr from 11.6.1 to 12.0.0 ([#189](https://github.com/libp2p/js-libp2p-daemon/issues/189)) ([aaf7e2e](https://github.com/libp2p/js-libp2p-daemon/commit/aaf7e2e37423cae78cd16d8e16e06db40fdcd1e3)) - -## [@libp2p/daemon-v2.0.7](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-v2.0.6...@libp2p/daemon-v2.0.7) (2023-02-22) - - -### Dependencies - -* bump aegir from 37.12.1 to 38.1.6 ([#183](https://github.com/libp2p/js-libp2p-daemon/issues/183)) ([6725a0a](https://github.com/libp2p/js-libp2p-daemon/commit/6725a0aeba9acb56a7530dece6c65a0f3eadfec5)) - -## [@libp2p/daemon-v2.0.6](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-v2.0.5...@libp2p/daemon-v2.0.6) (2023-02-22) - - -### Trivial Changes - -* remove lerna ([#171](https://github.com/libp2p/js-libp2p-daemon/issues/171)) ([367f912](https://github.com/libp2p/js-libp2p-daemon/commit/367f9122f2fe1c31c8de7a136cda18d024ff08d7)) - - -### Dependencies - -* **dev:** bump sinon from 14.0.2 to 15.0.1 ([#166](https://github.com/libp2p/js-libp2p-daemon/issues/166)) ([1702efb](https://github.com/libp2p/js-libp2p-daemon/commit/1702efb4248bea4cb9ec19c694c1caae1c0ff16d)) - -## [@libp2p/daemon-v2.0.5](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-v2.0.4...@libp2p/daemon-v2.0.5) (2023-01-07) - - -### Dependencies - -* update sibling dependencies ([775bd83](https://github.com/libp2p/js-libp2p-daemon/commit/775bd83a63ae99c4b892f0169f76dbe39163e2d4)) - -## [@libp2p/daemon-v2.0.4](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-v2.0.3...@libp2p/daemon-v2.0.4) (2022-10-13) - - -### Dependencies - -* update uint8arrays, protons and multiformats ([#143](https://github.com/libp2p/js-libp2p-daemon/issues/143)) ([661139c](https://github.com/libp2p/js-libp2p-daemon/commit/661139c674c9994724e32227d7d9ae2c5da1cea2)) - -## [@libp2p/daemon-v2.0.3](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-v2.0.2...@libp2p/daemon-v2.0.3) (2022-09-21) - - -### Dependencies - -* update @multiformats/multiaddr to 11.0.0 ([#128](https://github.com/libp2p/js-libp2p-daemon/issues/128)) ([885d901](https://github.com/libp2p/js-libp2p-daemon/commit/885d9013d82a62e6756b06350932df1242a13296)) - -## [@libp2p/daemon-v2.0.2](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-v2.0.1...@libp2p/daemon-v2.0.2) (2022-09-09) - - -### Trivial Changes - -* update project config ([#111](https://github.com/libp2p/js-libp2p-daemon/issues/111)) ([345e663](https://github.com/libp2p/js-libp2p-daemon/commit/345e663e34278e780fc2f3a6b595294f925c4521)) - - -### Dependencies - -* update sibling dependencies ([56711c4](https://github.com/libp2p/js-libp2p-daemon/commit/56711c4f14b0cf2370b8612fe07d42ed2ac8363c)) - -## [@libp2p/daemon-v2.0.1](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-v2.0.0...@libp2p/daemon-v2.0.1) (2022-06-15) - - -### Trivial Changes - -* update deps ([#103](https://github.com/libp2p/js-libp2p-daemon/issues/103)) ([2bfaa37](https://github.com/libp2p/js-libp2p-daemon/commit/2bfaa37e2f056dcd5de5a3882b77f52553c595d4)) - -## [@libp2p/daemon-v2.0.0](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-v1.0.4...@libp2p/daemon-v2.0.0) (2022-06-15) - - -### ⚠ BREAKING CHANGES - -* uses new single-issue libp2p interface modules - -### Features - -* update to latest libp2p interfaces ([#102](https://github.com/libp2p/js-libp2p-daemon/issues/102)) ([f5e9121](https://github.com/libp2p/js-libp2p-daemon/commit/f5e91210654ab3c411e316c1c657356c037a0f6a)) - -## [@libp2p/daemon-v1.0.4](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-v1.0.3...@libp2p/daemon-v1.0.4) (2022-05-25) - - -### Trivial Changes - -* update docs ([#91](https://github.com/libp2p/js-libp2p-daemon/issues/91)) ([5b072ff](https://github.com/libp2p/js-libp2p-daemon/commit/5b072ff89f30fd6cf55a3387bf0961c8ad78a22f)), closes [#83](https://github.com/libp2p/js-libp2p-daemon/issues/83) - -## [@libp2p/daemon-v1.0.3](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-v1.0.2...@libp2p/daemon-v1.0.3) (2022-05-23) - - -### Bug Fixes - -* update deps ([#90](https://github.com/libp2p/js-libp2p-daemon/issues/90)) ([b50eba3](https://github.com/libp2p/js-libp2p-daemon/commit/b50eba3770e47969dbc30cbcf87c41672cd9c175)) - -## [@libp2p/daemon-v1.0.2](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-v1.0.1...@libp2p/daemon-v1.0.2) (2022-04-20) - - -### Bug Fixes - -* update interfaces and deps ([#84](https://github.com/libp2p/js-libp2p-daemon/issues/84)) ([25173d5](https://github.com/libp2p/js-libp2p-daemon/commit/25173d5b2edf0e9dd9132707d349cdc862caecdb)) - -## [@libp2p/daemon-v1.0.1](https://github.com/libp2p/js-libp2p-daemon/compare/@libp2p/daemon-v1.0.0...@libp2p/daemon-v1.0.1) (2022-04-07) - - -### Trivial Changes - -* update aegir to latest version ([#80](https://github.com/libp2p/js-libp2p-daemon/issues/80)) ([3a98959](https://github.com/libp2p/js-libp2p-daemon/commit/3a98959617d9c19bba9fb064defee3d51acfcc29)) - -## @libp2p/daemon-v1.0.0 (2022-03-28) - - -### ⚠ BREAKING CHANGES - -* This module is now ESM only - -### Features - -* convert to typescript ([#78](https://github.com/libp2p/js-libp2p-daemon/issues/78)) ([f18b2a4](https://github.com/libp2p/js-libp2p-daemon/commit/f18b2a45871a2704db51b03e8583eefdcd13554c)) - -## [0.10.2](https://github.com/libp2p/js-libp2p-daemon/compare/v0.10.1...v0.10.2) (2022-01-26) - - - -## [0.10.1](https://github.com/libp2p/js-libp2p-daemon/compare/v0.10.0...v0.10.1) (2022-01-17) - - - -# [0.10.0](https://github.com/libp2p/js-libp2p-daemon/compare/v0.9.1...v0.10.0) (2022-01-17) - - -### Features - -* async peerstore ([#62](https://github.com/libp2p/js-libp2p-daemon/issues/62)) ([22e3cb0](https://github.com/libp2p/js-libp2p-daemon/commit/22e3cb05f7815f1f45e65398e87514f8ad961b49)) - - -### BREAKING CHANGES - -* peerstore methods are now all async - - - -## [0.9.1](https://github.com/libp2p/js-libp2p-daemon/compare/v0.9.0...v0.9.1) (2021-12-29) - - -### Bug Fixes - -* default nat hole punching to false ([#53](https://github.com/libp2p/js-libp2p-daemon/issues/53)) ([4bef1a3](https://github.com/libp2p/js-libp2p-daemon/commit/4bef1a384261fe442668f47b3799029cfb1043d3)) - - - -# [0.9.0](https://github.com/libp2p/js-libp2p-daemon/compare/v0.8.1...v0.9.0) (2021-12-29) - - -### chore - -* update deps ([#50](https://github.com/libp2p/js-libp2p-daemon/issues/50)) ([4231932](https://github.com/libp2p/js-libp2p-daemon/commit/42319320725fe248ee61a021981a5a065193ac99)) - - -### BREAKING CHANGES - -* only node15+ is supported - - - -## [0.8.1](https://github.com/libp2p/js-libp2p-daemon/compare/v0.8.0...v0.8.1) (2021-11-18) - - - -# [0.8.0](https://github.com/libp2p/js-libp2p-daemon/compare/v0.7.0...v0.8.0) (2021-11-18) - - -### chore - -* update dht ([#49](https://github.com/libp2p/js-libp2p-daemon/issues/49)) ([b1f1aaa](https://github.com/libp2p/js-libp2p-daemon/commit/b1f1aaab3466ec7ac693dcb5a211cd119aaa4f95)) - - -### BREAKING CHANGES - -* The DHT is now enabled by default - - - -# [0.7.0](https://github.com/libp2p/js-libp2p-daemon/compare/v0.6.1...v0.7.0) (2021-07-30) - - - -## [0.6.1](https://github.com/libp2p/js-libp2p-daemon/compare/v0.6.0...v0.6.1) (2021-06-11) - - - -# [0.6.0](https://github.com/libp2p/js-libp2p-daemon/compare/v0.5.2...v0.6.0) (2021-05-03) - - -### chore - -* update libp2p 0.31 ([#46](https://github.com/libp2p/js-libp2p-daemon/issues/46)) ([6625eba](https://github.com/libp2p/js-libp2p-daemon/commit/6625ebaa6027cee7cd8d08de09035f0edc894c1a)) - - -### BREAKING CHANGES - -* secio removed and noise is now default crypto, multiaddr@9 and libp2p@31 - - - -## [0.5.2](https://github.com/libp2p/js-libp2p-daemon/compare/v0.2.3...v0.5.2) (2021-02-16) - - -### Bug Fixes - -* replace node buffers with uint8arrays ([#41](https://github.com/libp2p/js-libp2p-daemon/issues/41)) ([cd009d5](https://github.com/libp2p/js-libp2p-daemon/commit/cd009d5e1f83724f907dd7f84239679633e8d197)) - - -### Features - -* add support for specifying noise ([#32](https://github.com/libp2p/js-libp2p-daemon/issues/32)) ([e5582cd](https://github.com/libp2p/js-libp2p-daemon/commit/e5582cdd00b7601cfe8ecc2b0d61a66bad71ab8a)) -* specify libp2p dependency through env ([#30](https://github.com/libp2p/js-libp2p-daemon/issues/30)) ([07b0695](https://github.com/libp2p/js-libp2p-daemon/commit/07b0695157da539774de75f2316748164fdbd72d)) - - - - -## [0.5.1](https://github.com/libp2p/js-libp2p-daemon/compare/v0.5.0...v0.5.1) (2020-08-26) - - - - -# [0.5.0](https://github.com/libp2p/js-libp2p-daemon/compare/v0.4.0...v0.5.0) (2020-08-23) - - -### Bug Fixes - -* replace node buffers with uint8arrays ([#41](https://github.com/libp2p/js-libp2p-daemon/issues/41)) ([cd009d5](https://github.com/libp2p/js-libp2p-daemon/commit/cd009d5)) - - -### BREAKING CHANGES - -* - All deps of this module now use uint8arrays in place of node buffers - -* chore: bump deps - -Co-authored-by: Jacob Heun - - - - -# [0.4.0](https://github.com/libp2p/js-libp2p-daemon/compare/v0.3.1...v0.4.0) (2020-06-05) - - - - -## [0.3.1](https://github.com/libp2p/js-libp2p-daemon/compare/v0.3.0...v0.3.1) (2020-04-22) - - -### Features - -* add support for specifying noise ([#32](https://github.com/libp2p/js-libp2p-daemon/issues/32)) ([e5582cd](https://github.com/libp2p/js-libp2p-daemon/commit/e5582cd)) - - - - -# [0.3.0](https://github.com/libp2p/js-libp2p-daemon/compare/v0.2.3...v0.3.0) (2020-01-31) - - -### Features - -* specify libp2p dependency through env ([#30](https://github.com/libp2p/js-libp2p-daemon/issues/30)) ([07b0695](https://github.com/libp2p/js-libp2p-daemon/commit/07b0695)) - - - - -## [0.2.3](https://github.com/libp2p/js-libp2p-daemon/compare/v0.2.2...v0.2.3) (2019-08-26) - - -### Bug Fixes - -* **tests:** fix secp256k1 test ([#26](https://github.com/libp2p/js-libp2p-daemon/issues/26)) ([fc46dbb](https://github.com/libp2p/js-libp2p-daemon/commit/fc46dbb)) - - -### Features - -* integrate gossipsub by default ([#19](https://github.com/libp2p/js-libp2p-daemon/issues/19)) ([2959fc8](https://github.com/libp2p/js-libp2p-daemon/commit/2959fc8)) - - - - -## [0.2.2](https://github.com/libp2p/js-libp2p-daemon/compare/v0.2.1...v0.2.2) (2019-07-10) - - -### Bug Fixes - -* **bin:** exit with status 1 on unhandled rejection ([#23](https://github.com/libp2p/js-libp2p-daemon/issues/23)) ([596005d](https://github.com/libp2p/js-libp2p-daemon/commit/596005d)) -* **main:** deal with unhandled rejections ([#20](https://github.com/libp2p/js-libp2p-daemon/issues/20)) ([49e685a](https://github.com/libp2p/js-libp2p-daemon/commit/49e685a)) -* **package.json:** fix main property ([#22](https://github.com/libp2p/js-libp2p-daemon/issues/22)) ([1d505b8](https://github.com/libp2p/js-libp2p-daemon/commit/1d505b8)) -* resolve loading of private key from file ([#21](https://github.com/libp2p/js-libp2p-daemon/issues/21)) ([3e70ace](https://github.com/libp2p/js-libp2p-daemon/commit/3e70ace)) - - - - -## [0.2.1](https://github.com/libp2p/js-libp2p-daemon/compare/v0.2.0...v0.2.1) (2019-04-29) - - -### Bug Fixes - -* peer info ([#17](https://github.com/libp2p/js-libp2p-daemon/issues/17)) ([69cf26b](https://github.com/libp2p/js-libp2p-daemon/commit/69cf26b)) - - -### Features - -* add support initial peerstore support ([#14](https://github.com/libp2p/js-libp2p-daemon/issues/14)) ([36a520c](https://github.com/libp2p/js-libp2p-daemon/commit/36a520c)) - - - - -# [0.2.0](https://github.com/libp2p/js-libp2p-daemon/compare/v0.1.2...v0.2.0) (2019-03-20) - - -### Bug Fixes - -* decapsulate ipfs protocol on daemon startup ([#11](https://github.com/libp2p/js-libp2p-daemon/issues/11)) ([190df09](https://github.com/libp2p/js-libp2p-daemon/commit/190df09)) - - -### Features - -* add pubsub support ([#12](https://github.com/libp2p/js-libp2p-daemon/issues/12)) ([5d27b90](https://github.com/libp2p/js-libp2p-daemon/commit/5d27b90)) -* add support for unix multiaddr listen ([#10](https://github.com/libp2p/js-libp2p-daemon/issues/10)) ([9106d68](https://github.com/libp2p/js-libp2p-daemon/commit/9106d68)) - - -### BREAKING CHANGES - -* The --sock param/flag has been replaced by --listen, which now expects a multiaddr string. - -Example: `jsp2pd --sock=/tmp/p2p.sock` would now be `jsp2pd --listen=/unix/tmp/p2p.sock` - -* feat: add support for unix multiaddr listen -* feat: add support for hostAddrs flag -* feat: add support for websockets -* feat: add announceAddrs support -* test: split up tests into files -* feat: use multiaddr instead of path for everything -* feat: update stream handler to use multiaddr bytes -* chore: fix lint -* chore: update multiaddr dep -* test: fix test runners -* fix: add a default host address -* fix: catch decapsulate errors when no ipfs present -* chore: fix feedback - - - - -## [0.1.2](https://github.com/libp2p/js-libp2p-daemon/compare/v0.1.1...v0.1.2) (2019-02-14) - - -### Bug Fixes - -* remove ipfs from identify multiaddrs ([7cee6ea](https://github.com/libp2p/js-libp2p-daemon/commit/7cee6ea)) - - - - -## [0.1.1](https://github.com/libp2p/js-libp2p-daemon/compare/v0.1.0...v0.1.1) (2019-02-13) - - -### Bug Fixes - -* connect should use peer id in bytes ([021b006](https://github.com/libp2p/js-libp2p-daemon/commit/021b006)) - - - - -# 0.1.0 (2019-01-31) - - -### Features - -* initial implementation of the libp2p daemon spec ([#1](https://github.com/libp2p/js-libp2p-daemon/issues/1)) ([383a6bd](https://github.com/libp2p/js-libp2p-daemon/commit/383a6bd)) diff --git a/packages/libp2p-daemon/LICENSE b/packages/libp2p-daemon/LICENSE deleted file mode 100644 index 20ce483c86..0000000000 --- a/packages/libp2p-daemon/LICENSE +++ /dev/null @@ -1,4 +0,0 @@ -This project is dual licensed under MIT and Apache-2.0. - -MIT: https://www.opensource.org/licenses/mit -Apache-2.0: https://www.apache.org/licenses/license-2.0 diff --git a/packages/libp2p-daemon/LICENSE-APACHE b/packages/libp2p-daemon/LICENSE-APACHE deleted file mode 100644 index 14478a3b60..0000000000 --- a/packages/libp2p-daemon/LICENSE-APACHE +++ /dev/null @@ -1,5 +0,0 @@ -Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - -http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. diff --git a/packages/libp2p-daemon/LICENSE-MIT b/packages/libp2p-daemon/LICENSE-MIT deleted file mode 100644 index 72dc60d84b..0000000000 --- a/packages/libp2p-daemon/LICENSE-MIT +++ /dev/null @@ -1,19 +0,0 @@ -The MIT License (MIT) - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. diff --git a/packages/libp2p-daemon/README.md b/packages/libp2p-daemon/README.md deleted file mode 100644 index 08787b3e45..0000000000 --- a/packages/libp2p-daemon/README.md +++ /dev/null @@ -1,53 +0,0 @@ -# @libp2p/daemon - -[![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) -[![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) -[![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p) -[![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p/main.yml?branch=master\&style=flat-square)](https://github.com/libp2p/js-libp2p/actions/workflows/main.yml?query=branch%3Amaster) - -> libp2p-daemon JavaScript implementation - -## Table of contents - -- [Install](#install) -- [Specs](#specs) -- [Usage](#usage) -- [License](#license) -- [Contribution](#contribution) - -## Install - -```console -$ npm i @libp2p/daemon -``` - -## Specs - -The specs for the daemon are currently housed in the go implementation. You can read them at [libp2p/go-libp2p-daemon](https://github.com/libp2p/go-libp2p-daemon/blob/master/specs/README.md) - -## Usage - -```console -$ jsp2pd --help -``` - -For a full list of options, you can run help `jsp2pd --help`. -Running the defaults, `jsp2pd`, will start the daemon and bind it to a local unix socket path. -Daemon clients will be able to communicate with the daemon over that unix socket. - -As an alternative, you can use this daemon with a different version of libp2p as the one specified in `package.json`. You just need to define its path through an environment variable as follows: - -```console -$ LIBP2P_JS=/path/to/js-libp2p/src/index.js jsp2pd -``` - -## License - -Licensed under either of - -- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) -- MIT ([LICENSE-MIT](LICENSE-MIT) / ) - -## Contribution - -Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. diff --git a/packages/libp2p-daemon/package.json b/packages/libp2p-daemon/package.json deleted file mode 100644 index d572cc51b0..0000000000 --- a/packages/libp2p-daemon/package.json +++ /dev/null @@ -1,60 +0,0 @@ -{ - "name": "@libp2p/daemon", - "version": "2.0.9", - "description": "libp2p-daemon JavaScript implementation", - "license": "Apache-2.0 OR MIT", - "homepage": "https://github.com/libp2p/js-libp2p/tree/master/packages/libp2p-daemon#readme", - "repository": { - "type": "git", - "url": "git+https://github.com/libp2p/js-libp2p.git" - }, - "bugs": { - "url": "https://github.com/libp2p/js-libp2p/issues" - }, - "keywords": [ - "libp2p" - ], - "bin": { - "jsp2pd": "dist/src/index.js" - }, - "type": "module", - "types": "./dist/src/index.d.ts", - "files": [ - "src", - "dist", - "!dist/test", - "!**/*.tsbuildinfo" - ], - "exports": { - ".": { - "types": "./src/index.d.ts", - "import": "./dist/src/index.js" - } - }, - "eslintConfig": { - "extends": "ipfs", - "parserOptions": { - "sourceType": "module" - } - }, - "scripts": { - "clean": "aegir clean", - "lint": "aegir lint", - "dep-check": "aegir dep-check", - "build": "aegir build", - "test": "aegir test -t node", - "test:node": "aegir test -t node" - }, - "dependencies": { - "@libp2p/daemon-server": "^5.0.0", - "@multiformats/multiaddr": "^12.1.3", - "es-main": "^1.0.2", - "yargs": "^17.3.1", - "yargs-promise": "^1.1.0" - }, - "devDependencies": { - "aegir": "^40.0.1", - "sinon": "^15.1.2" - }, - "private": true -} diff --git a/packages/libp2p-daemon/src/index.ts b/packages/libp2p-daemon/src/index.ts deleted file mode 100755 index d49325d8ca..0000000000 --- a/packages/libp2p-daemon/src/index.ts +++ /dev/null @@ -1,138 +0,0 @@ -#! /usr/bin/env node -/* eslint no-console: ["error", { allow: ["log", "warn", "error"] }] */ - -import { multiaddr } from '@multiformats/multiaddr' -import esMain from 'es-main' -import yargs from 'yargs' -// @ts-expect-error no types -import YargsPromise from 'yargs-promise' -import type { Libp2pServer } from '@libp2p/daemon-server' -import type { Multiaddr } from '@multiformats/multiaddr' - -const args = process.argv.slice(2) -const parser = new YargsPromise(yargs) - -const log = console.log - -export default async function main (processArgs: string[]): Promise { - parser.yargs - .option('listen', { - desc: 'daemon control listen multiaddr', - type: 'string', - default: '/unix/tmp/p2pd.sock' - }) - .option('quiet', { - alias: 'q', - desc: 'be quiet', - type: 'boolean', - default: false - }) - .option('id', { - desc: 'peer identity; private key file', - type: 'string', - default: '' - }) - .option('hostAddrs', { - desc: 'Comma separated list of multiaddrs the host should listen on', - type: 'string', - default: '' - }) - .option('announceAddrs', { - desc: 'Comma separated list of multiaddrs the host should announce to the network', - type: 'string', - default: '' - }) - .option('bootstrap', { - alias: 'b', - desc: 'Connects to bootstrap peers and bootstraps the dht if enabled', - type: 'boolean', - default: false - }) - .option('bootstrapPeers', { - desc: 'Comma separated list of bootstrap peers; defaults to the IPFS DHT peers', - type: 'string', - default: '' - }) - .option('dht', { - desc: 'Enables the DHT in full node mode', - type: 'boolean', - default: false - }) - .option('dhtClient', { - desc: '(Not yet supported) Enables the DHT in client mode', - type: 'boolean', - default: false - }) - .option('nat', { - desc: 'Enables UPnP NAT hole punching', - type: 'boolean', - default: false - }) - .option('connMgr', { - desc: '(Not yet supported) Enables the Connection Manager', - type: 'boolean', - default: false - }) - .option('connMgrLo', { - desc: 'Number identifying the number of peers below which this node will not activate preemptive disconnections', - type: 'number' - }) - .option('connMgrHi', { - desc: 'Number identifying the maximum number of peers the current peer is willing to be connected to before is starts disconnecting', - type: 'number' - }) - .option('pubsub', { - desc: 'Enables pubsub', - type: 'boolean', - default: false - }) - .option('pubsubRouter', { - desc: 'Specifies the pubsub router implementation', - type: 'string', - default: 'gossipsub' - }) - .fail((msg: string, err: Error | undefined, yargs?: any) => { - if (err != null) { - throw err // preserve stack - } - - if (args.length > 0) { - // eslint-disable-next-line - log(msg) - } - - yargs.showHelp() - }) - - const { data, argv } = await parser.parse(processArgs) - - if (data != null) { - // Log help and exit - // eslint-disable-next-line - log(data) - process.exit(0) - } - - const daemon = await createLibp2pServer(multiaddr(argv.listen), argv) - await daemon.start() - - if (argv.quiet !== true) { - // eslint-disable-next-line - log('daemon has started') - } -} - -export async function createLibp2pServer (listenAddr: Multiaddr, argv: any): Promise { - // const libp2p = await createLibp2p(argv) - // const daemon = await createServer(multiaddr(argv.listen), libp2p) - - throw new Error('Not implemented yet') -} - -if (esMain(import.meta)) { - main(process.argv) - .catch((err) => { - console.error(err) - process.exit(1) - }) -} diff --git a/packages/libp2p-daemon/test/cli.spec.ts b/packages/libp2p-daemon/test/cli.spec.ts deleted file mode 100644 index 2712cb8ddd..0000000000 --- a/packages/libp2p-daemon/test/cli.spec.ts +++ /dev/null @@ -1,85 +0,0 @@ -/* eslint-env mocha */ - -import { expect } from 'aegir/chai' -import sinon from 'sinon' -import cli from '../src/index.js' - -describe.skip('cli', () => { - const daemon = { createDaemon: (options: any) => {} } - - afterEach(() => { - sinon.restore() - }) - - it('should create a daemon with default options', async () => { - sinon.stub(daemon, 'createDaemon').callsFake((options) => { - expect(options).to.include({ - b: false, - bootstrap: false, - 'bootstrap-peers': '', - bootstrapPeers: '', - hostAddrs: '', - announceAddrs: '', - 'conn-mgr': false, - connMgr: false, - dht: false, - 'dht-client': false, - dhtClient: false, - id: '', - q: false, - quiet: false, - listen: '/unix/tmp/p2pd.sock' - }) - return { - start: () => {}, - stop: () => {} - } - }) - - await cli([ - '/bin/node', - '/daemon/src/cli/bin.js' - ]) - }) - - it('should be able to specify options', async () => { - sinon.stub(daemon, 'createDaemon').callsFake((options) => { - expect(options).to.include({ - b: true, - bootstrap: true, - 'bootstrap-peers': '/p2p/Qm1,/p2p/Qm2', - bootstrapPeers: '/p2p/Qm1,/p2p/Qm2', - hostAddrs: '/ip4/0.0.0.0/tcp/0,/ip4/0.0.0.0/tcp/0/wss', - announceAddrs: '/ip4/0.0.0.0/tcp/8080', - 'conn-mgr': true, - connMgr: true, - dht: true, - 'dht-client': true, - dhtClient: true, - id: '/path/to/key', - q: true, - quiet: true, - listen: '/unix/tmp/d.sock' - }) - return { - start: () => {}, - stop: () => {} - } - }) - - await cli([ - '/bin/node', - '/daemon/src/cli/bin.js', - '--dht=true', - '--b=true', - '--bootstrapPeers=/p2p/Qm1,/p2p/Qm2', - '--hostAddrs=/ip4/0.0.0.0/tcp/0,/ip4/0.0.0.0/tcp/0/wss', - '--announceAddrs=/ip4/0.0.0.0/tcp/8080', - '--connMgr=true', - '--dhtClient=true', - '--quiet=true', - '--id=/path/to/key', - '--listen=/unix/tmp/d.sock' - ]) - }) -}) diff --git a/packages/libp2p-daemon/tsconfig.json b/packages/libp2p-daemon/tsconfig.json deleted file mode 100644 index 6b7a2ea443..0000000000 --- a/packages/libp2p-daemon/tsconfig.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "extends": "aegir/src/config/tsconfig.aegir.json", - "compilerOptions": { - "outDir": "dist" - }, - "include": [ - "src", - "test" - ], - "references": [ - { - "path": "../libp2p-daemon-server" - } - ] -} diff --git a/packages/libp2p-daemon/typedoc.json b/packages/libp2p-daemon/typedoc.json deleted file mode 100644 index f599dc728d..0000000000 --- a/packages/libp2p-daemon/typedoc.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "entryPoints": [ - "./src/index.ts" - ] -} diff --git a/packages/libp2p/package.json b/packages/libp2p/package.json index 3498a29e85..ff3cef62d2 100644 --- a/packages/libp2p/package.json +++ b/packages/libp2p/package.json @@ -164,11 +164,11 @@ "@chainsafe/libp2p-noise": "^12.0.0", "@chainsafe/libp2p-yamux": "^4.0.0", "@libp2p/bootstrap": "^9.0.0", - "@libp2p/daemon-client": "^6.0.0", - "@libp2p/daemon-server": "^5.0.0", + "@libp2p/daemon-client": "^7.0.0", + "@libp2p/daemon-server": "^6.0.0", "@libp2p/floodsub": "^7.0.0", "@libp2p/interface-compliance-tests": "^4.0.0", - "@libp2p/interop": "^8.0.0", + "@libp2p/interop": "^9.0.0", "@libp2p/kad-dht": "^10.0.0", "@libp2p/mdns": "^9.0.0", "@libp2p/mplex": "^9.0.0", diff --git a/packages/libp2p/tsconfig.json b/packages/libp2p/tsconfig.json index e3088b86ec..a8ee4c8a55 100644 --- a/packages/libp2p/tsconfig.json +++ b/packages/libp2p/tsconfig.json @@ -29,12 +29,6 @@ { "path": "../keychain" }, - { - "path": "../libp2p-daemon-client" - }, - { - "path": "../libp2p-daemon-server" - }, { "path": "../logger" },