Skip to content

Commit

Permalink
Feature/registration interval config (#50)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
javibookline authored Jan 15, 2024
1 parent 612226c commit c1f2a5f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 5 additions & 1 deletion lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
};
12 changes: 9 additions & 3 deletions lib/sip-trunk-register.js
Original file line number Diff line number Diff line change
@@ -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`;
Expand Down Expand Up @@ -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}`);

Check failure on line 121 in lib/sip-trunk-register.js

View workflow job for this annotation

GitHub Actions / build

This line has a length of 148. Maximum allowed is 120
expires = MIN_EXPIRES;
}
debug(`setting timer for next register to ${expires} seconds`);
this.timer = setTimeout(this.register.bind(this, srf), (expires - 5) * 1000);
}
Expand Down

0 comments on commit c1f2a5f

Please sign in to comment.