mirror of
https://github.com/jambonz/sbc-sip-sidecar.git
synced 2026-01-24 22:27:52 +00:00
Feature/registration interval config (#50)
* Add envvar support for default expiration interval * Move envvars to config file, finish work, and add description of envvars to Readme * Set expires value to MIN_EXPIRES when the retrieved value is lower than it or not parseable
This commit is contained in:
@@ -26,6 +26,8 @@ Configuration is provided via environment variables:
|
||||
|EXPIRES_INTERVAL| servers expire |no|
|
||||
|JWT_SECRET| secret for signing JWT token |yes|
|
||||
|ENCRYPTION_SECRET| secret for credential encryption(JWT_SECRET is deprecated) |yes|
|
||||
|JAMBONES_REGBOT_DEFAULT_EXPIRES_INTERVAL| default expire value for outbound registration in seconds (default 3600) |no|
|
||||
|JAMBONES_REGBOT_MIN_EXPIRES_INTERVAL| minimum expire value for outbound registration in seconds (default 30) |no|
|
||||
|
||||
## Registrar database
|
||||
|
||||
|
||||
@@ -28,6 +28,8 @@ const EXPIRES_INTERVAL = process.env.EXPIRES_INTERVAL;
|
||||
const CHECK_EXPIRES_INTERVAL = process.env.CHECK_EXPIRES_INTERVAL;
|
||||
const JAMBONES_CLUSTER_ID = process.env.JAMBONES_CLUSTER_ID ;
|
||||
const JAMBONES_REGBOT_CONTACT_USE_IP = process.env.JAMBONES_REGBOT_CONTACT_USE_IP;
|
||||
const JAMBONES_REGBOT_MIN_EXPIRES_INTERVAL = process.env.JAMBONES_REGBOT_MIN_EXPIRES_INTERVAL;
|
||||
const JAMBONES_REGBOT_DEFAULT_EXPIRES_INTERVAL = process.env.JAMBONES_REGBOT_DEFAULT_EXPIRES_INTERVAL;
|
||||
|
||||
module.exports = {
|
||||
JAMBONES_MYSQL_HOST,
|
||||
@@ -51,5 +53,7 @@ module.exports = {
|
||||
EXPIRES_INTERVAL,
|
||||
CHECK_EXPIRES_INTERVAL,
|
||||
JAMBONES_CLUSTER_ID,
|
||||
JAMBONES_REGBOT_CONTACT_USE_IP
|
||||
JAMBONES_REGBOT_CONTACT_USE_IP,
|
||||
JAMBONES_REGBOT_MIN_EXPIRES_INTERVAL,
|
||||
JAMBONES_REGBOT_DEFAULT_EXPIRES_INTERVAL
|
||||
};
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
const debug = require('debug')('jambonz:sbc-registrar');
|
||||
const {
|
||||
JAMBONES_CLUSTER_ID,
|
||||
JAMBONES_REGBOT_CONTACT_USE_IP
|
||||
JAMBONES_REGBOT_CONTACT_USE_IP,
|
||||
JAMBONES_REGBOT_DEFAULT_EXPIRES_INTERVAL,
|
||||
JAMBONES_REGBOT_MIN_EXPIRES_INTERVAL
|
||||
} = require('./config');
|
||||
const assert = require('assert');
|
||||
const short = require('short-uuid');
|
||||
const DEFAULT_EXPIRES = 3600;
|
||||
const DEFAULT_EXPIRES = (parseInt(JAMBONES_REGBOT_DEFAULT_EXPIRES_INTERVAL) || 3600);
|
||||
const MIN_EXPIRES = (parseInt(JAMBONES_REGBOT_MIN_EXPIRES_INTERVAL) || 30);
|
||||
const MAX_INITIAL_DELAY = 15;
|
||||
const REGBOT_STATUS_CHECK_INTERVAL = 60;
|
||||
const regbotKey = `${(JAMBONES_CLUSTER_ID || 'default')}:regbot-token`;
|
||||
@@ -114,7 +117,10 @@ class Regbot {
|
||||
else if (res.has('Expires')) {
|
||||
expires = parseInt(res.get('Expires'));
|
||||
}
|
||||
if (isNaN(expires) || expires < 30) expires = DEFAULT_EXPIRES;
|
||||
if (isNaN(expires) || expires < MIN_EXPIRES) {
|
||||
this.logger.info(`${this.aor}: got expires value of ${expires} registering to ${this.ipv4}:${this.port}, setting it to ${MIN_EXPIRES}`);
|
||||
expires = MIN_EXPIRES;
|
||||
}
|
||||
debug(`setting timer for next register to ${expires} seconds`);
|
||||
this.timer = setTimeout(this.register.bind(this, srf), (expires - 5) * 1000);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user