Skip to content

Commit 7655e52

Browse files
authored
fix: connection monitor compatible with other ping implementations (#2671)
Update the number of bytes sent by the connection manager so that it is compatible with other `ping` implementations https://github.com/libp2p/go-libp2p/blob/master/p2p/protocol/ping/ping.go#L23 https://github.com/libp2p/rust-libp2p/blob/master/protocols/ping/src/protocol.rs#L48 https://github.com/libp2p/js-libp2p/blob/main/packages/protocol-ping/src/constants.ts#L2
1 parent 50b8971 commit 7655e52

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

packages/libp2p/src/connection-monitor.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { randomBytes } from '@libp2p/crypto'
12
import { serviceCapabilities } from '@libp2p/interface'
23
import { AdaptiveTimeout } from '@libp2p/utils/adaptive-timeout'
34
import { byteStream } from 'it-byte-stream'
@@ -9,6 +10,7 @@ const DEFAULT_PING_INTERVAL_MS = 10000
910
const PROTOCOL_VERSION = '1.0.0'
1011
const PROTOCOL_NAME = 'ping'
1112
const PROTOCOL_PREFIX = 'ipfs'
13+
const PING_LENGTH = 32
1214

1315
export interface ConnectionMonitorInit {
1416
/**
@@ -103,10 +105,10 @@ export class ConnectionMonitor implements Startable {
103105
start = Date.now()
104106

105107
await Promise.all([
106-
bs.write(new Uint8Array(1), {
108+
bs.write(randomBytes(PING_LENGTH), {
107109
signal
108110
}),
109-
bs.read(1, {
111+
bs.read(PING_LENGTH, {
110112
signal
111113
})
112114
])

0 commit comments

Comments
 (0)