Skip to content

Commit 54b044d

Browse files
fix: Turn off nagle's algorithm for peer connections (#1073)
* fix: Turn off nagle's algorythm for peer connections * Update src/discovery/local-discovery.js --------- Co-authored-by: Mauve Signweaver <[email protected]>
1 parent 82ecf13 commit 54b044d

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/discovery/local-discovery.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@ import { getErrorCode } from '../lib/error.js'
1515
/** @typedef {{ publicKey: Buffer, secretKey: Buffer }} Keypair */
1616
/** @typedef {OpenedNoiseStream<net.Socket>} OpenedNetNoiseStream */
1717

18+
/** @satisfies {import('node:net').ServerOpts | import('node:net').TcpNetConnectOpts} */
1819
const TCP_KEEP_ALIVE_OPTIONS = {
1920
keepAlive: true,
2021
keepAliveInitialDelay: 30_000,
22+
// Turn off Nagle's algorythm, to reduce latency
23+
// https://github.com/digidem/comapeo-core/issues/1070
24+
noDelay: true,
2125
}
2226
export const ERR_DUPLICATE = 'Duplicate connection'
2327

@@ -108,9 +112,9 @@ export class LocalDiscovery extends TypedEmitter {
108112
return
109113
}
110114
const socket = net.connect({
115+
...TCP_KEEP_ALIVE_OPTIONS,
111116
host: address,
112117
port,
113-
...TCP_KEEP_ALIVE_OPTIONS,
114118
})
115119
socket.on('error', this.#handleSocketError)
116120
socket.once('connect', () => {

0 commit comments

Comments
 (0)