Skip to content

Commit e1f192b

Browse files
authored
refactor!: extract ping service into separate module (#2218)
BREAKING CHANGE: imports from `libp2p/ping` must be updated to `@libp2p/ping`
1 parent e99f66b commit e1f192b

24 files changed

+436
-423
lines changed

.release-please.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"packages/peer-store": {},
2323
"packages/protocol-autonat": {},
2424
"packages/protocol-perf": {},
25+
"packages/protocol-ping": {},
2526
"packages/pubsub": {},
2627
"packages/pubsub-floodsub": {},
2728
"packages/stream-multiplexer-mplex": {},

doc/CONFIGURATION.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -987,14 +987,14 @@ Changing the protocol name prefix can isolate default public network (IPFS) for
987987
```js
988988
import { createLibp2p } from 'libp2p'
989989
import { identifyService } from 'libp2p/identify'
990-
import { pingService } from 'libp2p/ping'
990+
import { ping } from 'libp2p/@ping'
991991

992992
const node = await createLibp2p({
993993
services: {
994994
identify: identifyService({
995995
protocolPrefix: 'ipfs' // default
996996
}),
997-
ping: pingService({
997+
ping: ping({
998998
protocolPrefix: 'ipfs' // default
999999
})
10001000
}
@@ -1003,7 +1003,7 @@ const node = await createLibp2p({
10031003
protocols: [
10041004
"/ipfs/id/1.0.0", // identify service protocol (if we have multiplexers)
10051005
"/ipfs/id/push/1.0.0", // identify service push protocol (if we have multiplexers)
1006-
"/ipfs/ping/1.0.0", // built-in ping protocol
1006+
"/ipfs/ping/1.0.0", // ping protocol
10071007
]
10081008
*/
10091009
```

doc/migrations/v0.46-v1.0.0.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ A migration guide for refactoring your application code from libp2p `v0.46` to `
66
## Table of Contents <!-- omit in toc -->
77

88
- [AutoNAT](#autonat)
9+
- [Ping](#ping)
910
- [KeyChain](#keychain)
1011
- [UPnPNat](#upnpnat)
1112
- [Pnet](#pnet)
@@ -41,6 +42,36 @@ const node = await createLibp2p({
4142
})
4243
```
4344

45+
## Ping
46+
47+
The Ping service is now published in its own package.
48+
49+
**Before**
50+
51+
```ts
52+
import { createLibp2p } from 'libp2p'
53+
import { pingService } from 'libp2p/ping'
54+
55+
const node = await createLibp2p({
56+
services: {
57+
ping: pingService()
58+
}
59+
})
60+
```
61+
62+
**After**
63+
64+
```ts
65+
import { createLibp2p } from 'libp2p'
66+
import { ping } from '@libp2p/ping'
67+
68+
const node = await createLibp2p({
69+
services: {
70+
ping: ping()
71+
}
72+
})
73+
```
74+
4475
## KeyChain
4576

4677
The KeyChain object is no longer included on Libp2p and must be instantiated explicitly if desired.

interop/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
> Multidimensional interop tests
99
10-
# Install
10+
# Install <!-- omit in toc -->
1111

1212
```console
1313
$ npm i @libp2p/multidim-interop
@@ -57,7 +57,7 @@ $ docker build . -f ./interop/BrowserDockerfile -t js-libp2p-browsers
5757
$ git clone https://github.com/libp2p/test-plans.git
5858
```
5959
2. (Optional) If you are running an M1 Mac you may need to override the build platform.
60-
- Edit `/multidim-interop/dockerBuildWrapper.sh`
60+
- Edit `/transport-interop/dockerBuildWrapper.sh`
6161
- Add `--platform linux/arm64/v8` to the `docker buildx build` command
6262
```
6363
docker buildx build \
@@ -67,7 +67,7 @@ $ docker build . -f ./interop/BrowserDockerfile -t js-libp2p-browsers
6767
```
6868
3. (Optional) Enable some sort of debug output
6969
- nim-libp2p
70-
- edit `/multidim-interop/impl/nim/$VERSION/Dockerfile`
70+
- edit `/transport-interop/impl/nim/$VERSION/Dockerfile`
7171
- Change `-d:chronicles_log_level=WARN` to `-d:chronicles_log_level=DEBUG`
7272
- rust-libp2p
7373
- When starting the docker container add `-e RUST_LOG=debug`

interop/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"@chainsafe/libp2p-noise": "^13.0.0",
5555
"@chainsafe/libp2p-yamux": "^5.0.0",
5656
"@libp2p/mplex": "^9.0.12",
57+
"@libp2p/ping": "^0.0.0",
5758
"@libp2p/tcp": "^8.0.13",
5859
"@libp2p/webrtc": "^3.2.10",
5960
"@libp2p/websockets": "^7.0.13",

interop/test/ping.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { } from 'aegir/chai'
55
import { noise } from '@chainsafe/libp2p-noise'
66
import { yamux } from '@chainsafe/libp2p-yamux'
77
import { mplex } from '@libp2p/mplex'
8+
import { ping, type PingService } from '@libp2p/ping'
89
import { tcp } from '@libp2p/tcp'
910
import { webRTC, webRTCDirect } from '@libp2p/webrtc'
1011
import { webSockets } from '@libp2p/websockets'
@@ -14,7 +15,6 @@ import { type Multiaddr, multiaddr } from '@multiformats/multiaddr'
1415
import { createLibp2p, type Libp2p, type Libp2pOptions } from 'libp2p'
1516
import { circuitRelayTransport } from 'libp2p/circuit-relay'
1617
import { type IdentifyService, identifyService } from 'libp2p/identify'
17-
import { pingService, type PingService } from 'libp2p/ping'
1818

1919
async function redisProxy (commands: any[]): Promise<any> {
2020
const res = await fetch(`http://localhost:${process.env.proxyPort ?? ''}/`, { body: JSON.stringify(commands), method: 'POST' })
@@ -49,7 +49,7 @@ describe('ping test', function () {
4949
denyDialMultiaddr: async () => false
5050
},
5151
services: {
52-
ping: pingService(),
52+
ping: ping(),
5353
identify: identifyService()
5454
}
5555
}

interop/tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
{
1212
"path": "../packages/libp2p"
1313
},
14+
{
15+
"path": "../packages/protocol-ping"
16+
},
1417
{
1518
"path": "../packages/stream-multiplexer-mplex"
1619
},

packages/libp2p/.aegir.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ export default {
1818
const { plaintext } = await import('./dist/src/insecure/index.js')
1919
const { circuitRelayServer, circuitRelayTransport } = await import('./dist/src/circuit-relay/index.js')
2020
const { identifyService } = await import('./dist/src/identify/index.js')
21-
const { pingService } = await import('./dist/src/ping/index.js')
2221
const { fetchService } = await import('./dist/src/fetch/index.js')
2322

2423
const peerId = await createEd25519PeerId()
@@ -47,7 +46,6 @@ export default {
4746
],
4847
services: {
4948
identify: identifyService(),
50-
ping: pingService(),
5149
fetch: fetchService(),
5250
relay: circuitRelayServer({
5351
reservations: {

packages/libp2p/package.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,6 @@
6767
"./insecure": {
6868
"types": "./dist/src/insecure/index.d.ts",
6969
"import": "./dist/src/insecure/index.js"
70-
},
71-
"./ping": {
72-
"types": "./dist/src/ping/index.d.ts",
73-
"import": "./dist/src/ping/index.js"
7470
}
7571
},
7672
"eslintConfig": {

packages/libp2p/test/configuration/protocol-prefix.node.ts

Lines changed: 0 additions & 73 deletions
This file was deleted.

0 commit comments

Comments
 (0)