Add Node config setting for RPC registration timeout

This commit is contained in:
Andrew Ferrazzutti 2022-05-10 01:08:20 -04:00
parent 54c772d3ac
commit 3c0d890577
5 changed files with 10 additions and 5 deletions

View File

@ -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.

View File

@ -3,5 +3,6 @@
"type": "unix",
"path": "/var/run/matrix-appservice-kakaotalk/rpc.sock",
"force": false
}
},
"register_timeout": 3000
}

View File

@ -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) {

View File

@ -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()

View File

@ -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(() => {