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

refactor!: extract ping service into separate module #2218

Merged
merged 7 commits into from
Nov 8, 2023
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
1 change: 1 addition & 0 deletions .release-please.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"packages/peer-store": {},
"packages/protocol-autonat": {},
"packages/protocol-perf": {},
"packages/protocol-ping": {},
"packages/pubsub": {},
"packages/pubsub-floodsub": {},
"packages/stream-multiplexer-mplex": {},
Expand Down
6 changes: 3 additions & 3 deletions doc/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -987,14 +987,14 @@ Changing the protocol name prefix can isolate default public network (IPFS) for
```js
import { createLibp2p } from 'libp2p'
import { identifyService } from 'libp2p/identify'
import { pingService } from 'libp2p/ping'
import { ping } from 'libp2p/@ping'

const node = await createLibp2p({
services: {
identify: identifyService({
protocolPrefix: 'ipfs' // default
}),
ping: pingService({
ping: ping({
protocolPrefix: 'ipfs' // default
})
}
Expand All @@ -1003,7 +1003,7 @@ const node = await createLibp2p({
protocols: [
"/ipfs/id/1.0.0", // identify service protocol (if we have multiplexers)
"/ipfs/id/push/1.0.0", // identify service push protocol (if we have multiplexers)
"/ipfs/ping/1.0.0", // built-in ping protocol
"/ipfs/ping/1.0.0", // ping protocol
]
*/
```
Expand Down
31 changes: 31 additions & 0 deletions doc/migrations/v0.46-v1.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ A migration guide for refactoring your application code from libp2p `v0.46` to `
## Table of Contents <!-- omit in toc -->

- [AutoNAT](#autonat)
- [Ping](#ping)
- [KeyChain](#keychain)
- [UPnPNat](#upnpnat)
- [Pnet](#pnet)
Expand Down Expand Up @@ -41,6 +42,36 @@ const node = await createLibp2p({
})
```

## Ping

The Ping service is now published in its own package.

**Before**

```ts
import { createLibp2p } from 'libp2p'
import { pingService } from 'libp2p/ping'

const node = await createLibp2p({
services: {
ping: pingService()
}
})
```

**After**

```ts
import { createLibp2p } from 'libp2p'
import { ping } from '@libp2p/ping'

const node = await createLibp2p({
services: {
ping: ping()
}
})
```

## KeyChain

The KeyChain object is no longer included on Libp2p and must be instantiated explicitly if desired.
Expand Down
6 changes: 3 additions & 3 deletions interop/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

> Multidimensional interop tests

# Install
# Install <!-- omit in toc -->

```console
$ npm i @libp2p/multidim-interop
Expand Down Expand Up @@ -57,7 +57,7 @@ $ docker build . -f ./interop/BrowserDockerfile -t js-libp2p-browsers
$ git clone https://github.com/libp2p/test-plans.git
```
2. (Optional) If you are running an M1 Mac you may need to override the build platform.
- Edit `/multidim-interop/dockerBuildWrapper.sh`
- Edit `/transport-interop/dockerBuildWrapper.sh`
- Add `--platform linux/arm64/v8` to the `docker buildx build` command
```
docker buildx build \
Expand All @@ -67,7 +67,7 @@ $ docker build . -f ./interop/BrowserDockerfile -t js-libp2p-browsers
```
3. (Optional) Enable some sort of debug output
- nim-libp2p
- edit `/multidim-interop/impl/nim/$VERSION/Dockerfile`
- edit `/transport-interop/impl/nim/$VERSION/Dockerfile`
- Change `-d:chronicles_log_level=WARN` to `-d:chronicles_log_level=DEBUG`
- rust-libp2p
- When starting the docker container add `-e RUST_LOG=debug`
Expand Down
1 change: 1 addition & 0 deletions interop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"@chainsafe/libp2p-noise": "^13.0.0",
"@chainsafe/libp2p-yamux": "^5.0.0",
"@libp2p/mplex": "^9.0.12",
"@libp2p/ping": "^0.0.0",
"@libp2p/tcp": "^8.0.13",
"@libp2p/webrtc": "^3.2.10",
"@libp2p/websockets": "^7.0.13",
Expand Down
4 changes: 2 additions & 2 deletions interop/test/ping.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { } from 'aegir/chai'
import { noise } from '@chainsafe/libp2p-noise'
import { yamux } from '@chainsafe/libp2p-yamux'
import { mplex } from '@libp2p/mplex'
import { ping, type PingService } from '@libp2p/ping'
import { tcp } from '@libp2p/tcp'
import { webRTC, webRTCDirect } from '@libp2p/webrtc'
import { webSockets } from '@libp2p/websockets'
Expand All @@ -14,7 +15,6 @@ import { type Multiaddr, multiaddr } from '@multiformats/multiaddr'
import { createLibp2p, type Libp2p, type Libp2pOptions } from 'libp2p'
import { circuitRelayTransport } from 'libp2p/circuit-relay'
import { type IdentifyService, identifyService } from 'libp2p/identify'
import { pingService, type PingService } from 'libp2p/ping'

async function redisProxy (commands: any[]): Promise<any> {
const res = await fetch(`http://localhost:${process.env.proxyPort ?? ''}/`, { body: JSON.stringify(commands), method: 'POST' })
Expand Down Expand Up @@ -49,7 +49,7 @@ describe('ping test', function () {
denyDialMultiaddr: async () => false
},
services: {
ping: pingService(),
ping: ping(),
identify: identifyService()
}
}
Expand Down
3 changes: 3 additions & 0 deletions interop/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
{
"path": "../packages/libp2p"
},
{
"path": "../packages/protocol-ping"
},
{
"path": "../packages/stream-multiplexer-mplex"
},
Expand Down
2 changes: 0 additions & 2 deletions packages/libp2p/.aegir.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export default {
const { plaintext } = await import('./dist/src/insecure/index.js')
const { circuitRelayServer, circuitRelayTransport } = await import('./dist/src/circuit-relay/index.js')
const { identifyService } = await import('./dist/src/identify/index.js')
const { pingService } = await import('./dist/src/ping/index.js')
const { fetchService } = await import('./dist/src/fetch/index.js')

const peerId = await createEd25519PeerId()
Expand Down Expand Up @@ -47,7 +46,6 @@ export default {
],
services: {
identify: identifyService(),
ping: pingService(),
fetch: fetchService(),
relay: circuitRelayServer({
reservations: {
Expand Down
4 changes: 0 additions & 4 deletions packages/libp2p/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@
"./insecure": {
"types": "./dist/src/insecure/index.d.ts",
"import": "./dist/src/insecure/index.js"
},
"./ping": {
"types": "./dist/src/ping/index.d.ts",
"import": "./dist/src/ping/index.js"
}
},
"eslintConfig": {
Expand Down
73 changes: 0 additions & 73 deletions packages/libp2p/test/configuration/protocol-prefix.node.ts

This file was deleted.

136 changes: 0 additions & 136 deletions packages/libp2p/test/ping/index.spec.ts

This file was deleted.

Loading
Loading