Skip to content

Commit 9637cc4

Browse files
committed
refactor!: extract ping service into separate module
BREAKING CHANGE: imports from `libp2p/ping` must be updated to `@libp2p/ping`
1 parent e99f66b commit 9637cc4

File tree

21 files changed

+400
-418
lines changed

21 files changed

+400
-418
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/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
}

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.

packages/libp2p/test/ping/index.spec.ts

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

0 commit comments

Comments
 (0)