Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/registration interval config #50

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
};
9 changes: 6 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,7 @@ 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) expires = Math.max(MIN_EXPIRES, DEFAULT_EXPIRES);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the scenario where MIN_EXPIRES will possibly be greater than DEFAULT_EXPIRES?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we enable setting DEFAULT_EXPIRES via envvar, well, someone could pass a lower value

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's dumb, but I figured if a minimum is set, then we should comply with it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why would we allow a default expires value to be less than the minimum? I don't believe in coding to support a case like that, we should rather reject attempts to set meaningless values such as these

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at what level should those attempts be rejected? do we kill the process when loading the envvars? or do we just specify it in the docs and let the code run?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jambonz/helm-charts#36 includes these new envvars in the helm charts too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davehorton would you rather leave it as it was?

if (isNaN(expires) || expires < MIN_EXPIRES) expires = DEFAULT_EXPIRES;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say if expires < MIN_EXPIRES log a message and set it to MIN_EXPIRES

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davehorton is this more in line with what you had in mind?

89832c8

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

debug(`setting timer for next register to ${expires} seconds`);
this.timer = setTimeout(this.register.bind(this, srf), (expires - 5) * 1000);
}
Expand Down