Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: update to latest libp2p interfaces #102

Merged
merged 1 commit into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 25 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
# js-libp2p-daemon
# js-libp2p-daemon <!-- omit in toc -->

[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)
[![](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)
[![](https://img.shields.io/badge/freenode-%23libp2p-yellow.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23libp2p)
[![](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg)](https://discuss.libp2p.io)
[![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-interfaces.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-interfaces)
[![test & maybe release](https://github.com/libp2p/js-libp2p-daemon/actions/workflows/js-test-and-release.yml/badge.svg)](https://github.com/libp2p/js-libp2p-daemon/actions/workflows/js-test-and-release.yml)
[![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)
[![IRC](https://img.shields.io/badge/freenode-%23libp2p-yellow.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23libp2p)
[![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-daemon.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-daemon)
[![CI](https://img.shields.io/github/workflow/status/libp2p/js-libp2p-interfaces/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/libp2p/js-libp2p-daemon/actions/workflows/js-test-and-release.yml)

> Standalone libp2p executable

## Table of contents <!-- omit in toc -->

- [Structure](#structure)
- [Contribute](#contribute)
- [License](#license)
- [Contribution](#contribution)

## Structure

* [`/packages/libp2p-daemon`](./packages/libp2p-daemon) The CLI tool - starts an instance of the server
* [`/packages/libp2p-daemon-client`](./packages/libp2p-daemon-client) A client to talk to libp2p-daemon instances
* [`/packages/libp2p-daemon-protocol`](./packages/libp2p-daemon-protocol) The wire protocol used by the client/server
* [`/packages/libp2p-daemon-server`](./packages/libp2p-daemon-server) An RPC server controllable by the client
- [`/packages/libp2p-daemon`](./packages/libp2p-daemon) libp2p-daemon JavaScript implementation
- [`/packages/libp2p-daemon-client`](./packages/libp2p-daemon-client) libp2p-daemon client implementation
- [`/packages/libp2p-daemon-protocol`](./packages/libp2p-daemon-protocol) Communication protocol between libp2p daemons and clients
- [`/packages/libp2p-daemon-server`](./packages/libp2p-daemon-server) API server for libp2p-daemon instances

## Contribute

Expand All @@ -26,4 +32,11 @@ This repository falls under the IPFS [Code of Conduct](https://github.com/ipfs/c

## License

[Apache-2.0](LICENSE-APACHE) or [MIT](LICENSE-MIT) © Protocol Labs
Licensed under either of

- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/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.
65 changes: 38 additions & 27 deletions packages/libp2p-daemon-client/README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
# libp2p-daemon client JavaScript implementation <!-- omit in toc -->
# @libp2p/daemon-client <!-- omit in toc -->

[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](https://protocol.ai/)
[![](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)
[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23libp2p)
[![Discourse posts](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg)](https://discuss.libp2p.io)
[![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)
[![IRC](https://img.shields.io/badge/freenode-%23libp2p-yellow.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23libp2p)
[![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-daemon.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-daemon)
[![CI](https://img.shields.io/github/workflow/status/libp2p/js-libp2p-interfaces/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/libp2p/js-libp2p-daemon/actions/workflows/js-test-and-release.yml)

> A Javascript client to interact with a standalone deployment of a libp2p host, running in its own OS process. Essentially, this client allows to communicate with other peers, interact with the DHT, participate in pubsub, etc. no matter the language they are implemented with.
> libp2p-daemon client implementation

## Table of Contents <!-- omit in toc -->
## Table of contents <!-- omit in toc -->

- [Specs](#specs)
- [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)
- [Contribute](#contribute)
- [License](#license)
- [Contribution](#contribution)

## Specs
## Install

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)
```console
$ npm i @libp2p/daemon-client
```

## Install
## Specs

`npm install @libp2p/daemon-client`
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

Expand Down Expand Up @@ -58,25 +62,32 @@ 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)
- [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)

## Contribute

This module is actively under development. Please check out the issues and submit PRs!

## License

[Apache-2.0](LICENSE-APACHE) or [MIT](LICENSE-MIT) © Protocol Labs
Licensed under either of

- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/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.
17 changes: 12 additions & 5 deletions packages/libp2p-daemon-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
],
"exports": {
".": {
"types": "./src/index.d.ts",
"import": "./dist/src/index.js"
}
},
Expand Down Expand Up @@ -130,20 +131,26 @@
},
"dependencies": {
"@libp2p/daemon-protocol": "^1.0.0",
"@libp2p/interfaces": "^2.0.1",
"@libp2p/logger": "^1.1.4",
"@libp2p/interface-peer-id": "^1.0.2",
"@libp2p/interface-peer-info": "^1.0.1",
"@libp2p/logger": "^2.0.0",
"@libp2p/peer-id": "^1.1.10",
"@libp2p/tcp": "^1.0.8",
"@libp2p/tcp": "^2.0.0",
"@multiformats/multiaddr": "^10.1.8",
"err-code": "^3.0.1",
"it-stream-types": "^1.0.4",
"multiformats": "^9.6.4"
},
"devDependencies": {
"@libp2p/components": "^1.0.0",
"@libp2p/daemon-server": "^1.0.0",
"@libp2p/interface-compliance-tests": "^2.0.1",
"@libp2p/interface-compliance-tests": "^3.0.1",
"@libp2p/interface-dht": "^1.0.0",
"@libp2p/interface-mocks": "^1.0.1",
"@libp2p/interface-peer-store": "^1.0.0",
"@libp2p/interface-pubsub": "^1.0.1",
"@libp2p/peer-id-factory": "^1.0.9",
"aegir": "^37.0.5",
"aegir": "^37.2.0",
"it-all": "^1.0.6",
"it-pipe": "^2.0.3",
"sinon": "^14.0.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/libp2p-daemon-client/src/dht.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {
DHTResponse
} from '@libp2p/daemon-protocol'
import type { DaemonClient } from './index.js'
import { isPeerId, PeerId } from '@libp2p/interfaces/peer-id'
import type { PeerInfo } from '@libp2p/interfaces/peer-info'
import { isPeerId, PeerId } from '@libp2p/interface-peer-id'
import type { PeerInfo } from '@libp2p/interface-peer-info'
import { peerIdFromBytes } from '@libp2p/peer-id'

export class DHT {
Expand Down
4 changes: 2 additions & 2 deletions packages/libp2p-daemon-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { StreamHandler } from '@libp2p/daemon-protocol/stream-handler'
import { Multiaddr } from '@multiformats/multiaddr'
import { DHT } from './dht.js'
import { Pubsub } from './pubsub.js'
import { isPeerId, PeerId } from '@libp2p/interfaces/peer-id'
import { isPeerId, PeerId } from '@libp2p/interface-peer-id'
import { passThroughUpgrader } from '@libp2p/daemon-protocol/upgrader'
import { peerIdFromBytes } from '@libp2p/peer-id'
import type { Duplex } from 'it-stream-types'
import type { CID } from 'multiformats/cid'
import type { PeerInfo } from '@libp2p/interfaces/peer-info'
import type { PeerInfo } from '@libp2p/interface-peer-info'

class Client implements DaemonClient {
private readonly multiaddr: Multiaddr
Expand Down
2 changes: 1 addition & 1 deletion packages/libp2p-daemon-client/test/dht.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { createServer, Libp2p, Libp2pServer } from '@libp2p/daemon-server'
import { createClient, DaemonClient } from '../src/index.js'
import { Multiaddr } from '@multiformats/multiaddr'
import { StubbedInstance, stubInterface } from 'ts-sinon'
import { DualDHT, ValueEvent, FinalPeerEvent, PeerResponseEvent, MessageType, EventTypes } from '@libp2p/interfaces/dht'
import { DualDHT, ValueEvent, FinalPeerEvent, PeerResponseEvent, MessageType, EventTypes } from '@libp2p/interface-dht'
import { peerIdFromString } from '@libp2p/peer-id'
import { CID } from 'multiformats/cid'
import all from 'it-all'
Expand Down
6 changes: 3 additions & 3 deletions packages/libp2p-daemon-client/test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import { createServer, Libp2p, Libp2pServer } from '@libp2p/daemon-server'
import { createClient, DaemonClient } from '../src/index.js'
import { Multiaddr } from '@multiformats/multiaddr'
import { StubbedInstance, stubInterface } from 'ts-sinon'
import { isPeerId } from '@libp2p/interfaces/peer-id'
import { isPeerId } from '@libp2p/interface-peer-id'
import { peerIdFromString } from '@libp2p/peer-id'
import { mockConnection, mockDuplex, mockMultiaddrConnection } from '@libp2p/interface-compliance-tests/mocks'
import type { PeerStore, AddressBook } from '@libp2p/interfaces/peer-store'
import { mockConnection, mockDuplex, mockMultiaddrConnection } from '@libp2p/interface-mocks'
import type { PeerStore, AddressBook } from '@libp2p/interface-peer-store'

const defaultMultiaddr = new Multiaddr('/ip4/0.0.0.0/tcp/0')

Expand Down
2 changes: 1 addition & 1 deletion packages/libp2p-daemon-client/test/pubsub.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { createServer, Libp2p, Libp2pServer } from '@libp2p/daemon-server'
import { createClient, DaemonClient } from '../src/index.js'
import { Multiaddr } from '@multiformats/multiaddr'
import { StubbedInstance, stubInterface } from 'ts-sinon'
import type { PubSub } from '@libp2p/interfaces/pubsub'
import type { PubSub } from '@libp2p/interface-pubsub'

const defaultMultiaddr = new Multiaddr('/ip4/0.0.0.0/tcp/12345')

Expand Down
6 changes: 3 additions & 3 deletions packages/libp2p-daemon-client/test/stream.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import { createClient, DaemonClient } from '../src/index.js'
import { Multiaddr } from '@multiformats/multiaddr'
import { StubbedInstance, stubInterface } from 'ts-sinon'
import { peerIdFromString } from '@libp2p/peer-id'
import { mockRegistrar, connectionPair } from '@libp2p/interface-compliance-tests/mocks'
import type { PeerStore, AddressBook } from '@libp2p/interfaces/peer-store'
import { mockRegistrar, connectionPair } from '@libp2p/interface-mocks'
import type { PeerStore, AddressBook } from '@libp2p/interface-peer-store'
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
import all from 'it-all'
import { pipe } from 'it-pipe'
import { Components } from '@libp2p/interfaces/components'
import { Components } from '@libp2p/components'

const defaultMultiaddr = new Multiaddr('/ip4/0.0.0.0/tcp/0')

Expand Down
26 changes: 18 additions & 8 deletions packages/libp2p-daemon-protocol/README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
# js-libp2p-daemon-protocol <!-- omit in toc -->
# @libp2p/daemon-protocol <!-- omit in toc -->

<a href="http://libp2p.io/"><img src="https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square" /></a>
<a href="http://webchat.freenode.net/?channels=%23libp2p"><img src="https://img.shields.io/badge/freenode-%23libp2p-yellow.svg?style=flat-square" /></a>
<a href="https://discuss.libp2p.io"><img src="https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg" /></a>
[![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)
[![IRC](https://img.shields.io/badge/freenode-%23libp2p-yellow.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23libp2p)
[![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-daemon.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-daemon)
[![CI](https://img.shields.io/github/workflow/status/libp2p/js-libp2p-interfaces/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/libp2p/js-libp2p-daemon/actions/workflows/js-test-and-release.yml)

> Contains the protobuf definitions of the communication protocol for libp2p daemons
> Communication protocol between libp2p daemons and clients

## Table of contents <!-- omit in toc -->

- [Install](#install)
- [Contribute](#contribute)
- [License](#license)
- [Contribution](#contribution)

## Install

```
npm i @libp2p/daemon-protocol
```console
$ npm i @libp2p/daemon-protocol
```

## Contribute
Expand All @@ -24,4 +27,11 @@ This module is actively under development. Please check out the issues and submi

## License

[Apache-2.0](LICENSE-APACHE) or [MIT](LICENSE-MIT) © Protocol Labs
Licensed under either of

- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/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.
9 changes: 7 additions & 2 deletions packages/libp2p-daemon-protocol/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,21 @@
},
"files": [
"src",
"dist",
"dist/src",
"!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"
}
},
Expand Down Expand Up @@ -150,10 +153,12 @@
"release": "aegir release"
},
"dependencies": {
"@libp2p/interface-transport": "^1.0.0",
"it-handshake": "^4.0.0",
"protons-runtime": "^1.0.4"
},
"devDependencies": {
"aegir": "^37.0.14",
"aegir": "^37.2.0",
"protons": "^3.0.4"
}
}
2 changes: 1 addition & 1 deletion packages/libp2p-daemon-protocol/src/upgrader.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Upgrader } from '@libp2p/interfaces/transport'
import type { Upgrader } from '@libp2p/interface-transport'

export const passThroughUpgrader: Upgrader = {
// @ts-expect-error should return a connection
Expand Down
Loading