Skip to content

Commit

Permalink
initial delay regbot (#80)
Browse files Browse the repository at this point in the history
* initial delay regbot

* fix review comment

* fix review comment
  • Loading branch information
xquanluu authored Mar 10, 2025
1 parent 0f63223 commit e865286
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ 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;
const JAMBONES_REGBOT_INITIAL_DELAY_MS = process.env.JAMBONES_REGBOT_INITIAL_DELAY_MS || 250;

module.exports = {
JAMBONES_MYSQL_HOST,
Expand All @@ -55,5 +56,6 @@ module.exports = {
JAMBONES_CLUSTER_ID,
JAMBONES_REGBOT_CONTACT_USE_IP,
JAMBONES_REGBOT_MIN_EXPIRES_INTERVAL,
JAMBONES_REGBOT_DEFAULT_EXPIRES_INTERVAL
JAMBONES_REGBOT_DEFAULT_EXPIRES_INTERVAL,
JAMBONES_REGBOT_INITIAL_DELAY_MS
};
4 changes: 4 additions & 0 deletions lib/sip-trunk-register.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const debug = require('debug')('jambonz:sbc-registrar');
const {
JAMBONES_CLUSTER_ID,
JAMBONES_REGBOT_INITIAL_DELAY_MS,
} = require('./config');
const short = require('short-uuid');
const Regbot = require('./regbot');
const { sleepFor } = require('./utils');

const MAX_INITIAL_DELAY = 15;
const REGBOT_STATUS_CHECK_INTERVAL = 60;
Expand Down Expand Up @@ -185,6 +187,8 @@ const updateCarrierRegbots = async(logger, srf) => {
use_public_ip_in_contact: gw.carrier.register_public_ip_in_contact
});
regbots.push(rb);
// stagger the start of the regbots
await sleepFor(JAMBONES_REGBOT_INITIAL_DELAY_MS);
rb.start(srf);
} catch (err) {
const { updateVoipCarriersRegisterStatus } = srf.locals.dbHelpers;
Expand Down
5 changes: 4 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,14 @@ function isValidDomainOrIP(input) {
return false; // Invalid input
}

const sleepFor = async(ms) => new Promise((resolve) => setTimeout(resolve, ms));

module.exports = {
isUacBehindNat,
getSipProtocol,
addSipGatewayToBlacklist,
NAT_EXPIRES: 30,
isValidIPv4,
isValidDomainOrIP
isValidDomainOrIP,
sleepFor
};

0 comments on commit e865286

Please sign in to comment.