From 3c0d8905779f4df627efb678b51d5f61f39ae233 Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Tue, 10 May 2022 01:08:20 -0400 Subject: [PATCH] Add Node config setting for RPC registration timeout --- node/README.md | 3 +++ node/example-config.json | 3 ++- node/src/client.js | 4 ++-- node/src/clientmanager.js | 3 ++- node/src/main.js | 2 +- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/node/README.md b/node/README.md index 422101e..260aaa4 100644 --- a/node/README.md +++ b/node/README.md @@ -2,3 +2,6 @@ If `type` is `unix`, `path` is the path where to create the socket, and `force` is whether to overwrite the socket file if it already exists. If `type` is `tcp`, `port` and `host` are the host/port where to listen. + +### Register timeout +`register_timeout` is the amount of time (in milliseconds) that a connecting peer must send a "register" command after initiating a connection. diff --git a/node/example-config.json b/node/example-config.json index 444565e..90a1de0 100644 --- a/node/example-config.json +++ b/node/example-config.json @@ -3,5 +3,6 @@ "type": "unix", "path": "/var/run/matrix-appservice-kakaotalk/rpc.sock", "force": false - } + }, + "register_timeout": 3000 } diff --git a/node/src/client.js b/node/src/client.js index defd0ab..b5889d9 100644 --- a/node/src/client.js +++ b/node/src/client.js @@ -455,10 +455,10 @@ export default class PeerClient { setTimeout(() => { if (!this.peerID && !this.stopped) { - this.log("Didn't receive register request within 3 seconds, terminating") + this.log(`Didn't receive register request within ${this.manager.registerTimeout/1000} seconds, terminating`) this.stop("Register request timeout") } - }, 3000) + }, this.manager.registerTimeout) } async stop(error = null) { diff --git a/node/src/clientmanager.js b/node/src/clientmanager.js index b89dcc0..fb02a46 100644 --- a/node/src/clientmanager.js +++ b/node/src/clientmanager.js @@ -22,8 +22,9 @@ import { promisify } from "./util.js" export default class ClientManager { - constructor(listenConfig) { + constructor(listenConfig, registerTimeout) { this.listenConfig = listenConfig + this.registerTimeout = registerTimeout this.server = net.createServer(this.acceptConnection) this.connections = [] this.clients = new Map() diff --git a/node/src/main.js b/node/src/main.js index d258d9f..daa9f68 100644 --- a/node/src/main.js +++ b/node/src/main.js @@ -32,7 +32,7 @@ const configPath = args["--config"] || "config.json" console.log("[Main] Reading config from", configPath) const config = JSON.parse(fs.readFileSync(configPath).toString()) -const manager = new ClientManager(config.listen) +const manager = new ClientManager(config.listen, config.register_timeout) function stop() { manager.stop().then(() => {