mirror of
https://github.com/jambonz/sbc-sip-sidecar.git
synced 2026-03-21 18:58:05 +00:00
add configurable backup for outbound reg failure (#128)
This commit is contained in:
@@ -42,6 +42,7 @@ const JAMBONES_REGBOT_BATCH_SIZE = process.env.JAMBONES_REGBOT_BATCH_SIZE || 10;
|
||||
const OPTIONS_RESPONSE_REMOVE = process.env.OPTIONS_RESPONSE_REMOVE?.split(',').map(Number) || [];
|
||||
const REGISTER_RESPONSE_REMOVE = process.env.REGISTER_RESPONSE_REMOVE?.split(',').map(Number) || [];
|
||||
const JAMBONES_REGBOT_USER_AGENT = process.env.JAMBONES_REGBOT_USER_AGENT ;
|
||||
const JAMBONES_REGBOT_FAILURE_RETRY_INTERVAL = process.env.JAMBONES_REGBOT_FAILURE_RETRY_INTERVAL;
|
||||
|
||||
module.exports = {
|
||||
JAMBONES_MYSQL_HOST,
|
||||
@@ -77,5 +78,6 @@ module.exports = {
|
||||
JAMBONES_REGBOT_BATCH_SIZE,
|
||||
OPTIONS_RESPONSE_REMOVE,
|
||||
REGISTER_RESPONSE_REMOVE,
|
||||
JAMBONES_REGBOT_USER_AGENT
|
||||
JAMBONES_REGBOT_USER_AGENT,
|
||||
JAMBONES_REGBOT_FAILURE_RETRY_INTERVAL
|
||||
};
|
||||
|
||||
@@ -4,11 +4,13 @@ const {
|
||||
JAMBONES_REGBOT_MIN_EXPIRES_INTERVAL,
|
||||
JAMBONES_REGBOT_CONTACT_USE_IP,
|
||||
REGISTER_RESPONSE_REMOVE,
|
||||
JAMBONES_REGBOT_USER_AGENT
|
||||
JAMBONES_REGBOT_USER_AGENT,
|
||||
JAMBONES_REGBOT_FAILURE_RETRY_INTERVAL
|
||||
} = require('./config');
|
||||
const {isValidDomainOrIP, isValidIPv4} = require('./utils');
|
||||
const DEFAULT_EXPIRES = (parseInt(JAMBONES_REGBOT_DEFAULT_EXPIRES_INTERVAL) || 3600);
|
||||
const MIN_EXPIRES = (parseInt(JAMBONES_REGBOT_MIN_EXPIRES_INTERVAL) || 30);
|
||||
const FAILURE_RETRY_INTERVAL = (parseInt(JAMBONES_REGBOT_FAILURE_RETRY_INTERVAL) || 300);
|
||||
const assert = require('assert');
|
||||
const version = require('../package.json').version;
|
||||
const useragent = JAMBONES_REGBOT_USER_AGENT || `Jambonz ${version}`;
|
||||
@@ -143,7 +145,7 @@ class Regbot {
|
||||
if (res.status !== 200) {
|
||||
this.status = 'fail';
|
||||
this.logger.info(`${this.aor}: got ${res.status} registering to ${this.ipv4}:${this.port}`);
|
||||
this.timer = setTimeout(this.register.bind(this, srf), 30 * 1000);
|
||||
this.timer = setTimeout(this.register.bind(this, srf), FAILURE_RETRY_INTERVAL * 1000);
|
||||
if (REGISTER_RESPONSE_REMOVE.includes(res.status)) {
|
||||
const { updateCarrierBySid, lookupCarrierBySid } = srf.locals.dbHelpers;
|
||||
await updateCarrierBySid(this.voip_carrier_sid, {requires_register: false});
|
||||
@@ -245,7 +247,7 @@ class Regbot {
|
||||
});
|
||||
} catch (err) {
|
||||
this.logger.error({ err }, `${this.aor}: Error registering to ${this.ipv4}:${this.port}`);
|
||||
this.timer = setTimeout(this.register.bind(this, srf), 60 * 1000);
|
||||
this.timer = setTimeout(this.register.bind(this, srf), FAILURE_RETRY_INTERVAL * 1000);
|
||||
updateVoipCarriersRegisterStatus(this.voip_carrier_sid, JSON.stringify({
|
||||
status: 'fail',
|
||||
reason: err
|
||||
|
||||
@@ -63,24 +63,30 @@ async function getLocalSIPDomain(logger, srf) {
|
||||
*/
|
||||
function getUniqueGateways(gateways, logger) {
|
||||
const uniqueGatewayKeys = new Set();
|
||||
const duplicateCounts = new Map();
|
||||
const uniqueGateways = [];
|
||||
|
||||
return gateways.filter((gw) => {
|
||||
for (const gw of gateways) {
|
||||
const key = `${gw.ipv4}:${gw.sip_realm}:${gw.carrier?.register_username}:${gw.carrier?.register_password}`;
|
||||
if (!gw.carrier?.register_password) {
|
||||
logger.info({gw}, `Gateway ${key} does not have a password, ignoring`);
|
||||
return false;
|
||||
continue;
|
||||
}
|
||||
|
||||
// If we've already seen this key, it's a duplicate
|
||||
if (uniqueGatewayKeys.has(key)) {
|
||||
logger.info({gw}, `Found duplicate gateway ${key}, ignoring`);
|
||||
return false;
|
||||
duplicateCounts.set(key, (duplicateCounts.get(key) || 1) + 1);
|
||||
} else {
|
||||
uniqueGatewayKeys.add(key);
|
||||
uniqueGateways.push(gw);
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise, add it to our Set and keep this gateway
|
||||
uniqueGatewayKeys.add(key);
|
||||
return true;
|
||||
});
|
||||
// Log summary for each duplicate gateway
|
||||
for (const [key, count] of duplicateCounts) {
|
||||
logger.info({key, count}, `Found ${count} duplicate gateways for ${key}, ignoring duplicates`);
|
||||
}
|
||||
|
||||
return uniqueGateways;
|
||||
}
|
||||
|
||||
module.exports = async(logger, srf) => {
|
||||
@@ -222,7 +228,7 @@ const updateCarrierRegbots = async(logger, srf) => {
|
||||
if (hasChanged) {
|
||||
|
||||
debug('updateCarrierRegbots: got new or changed carriers');
|
||||
logger.info({gws}, 'updateCarrierRegbots: got new or changed carriers');
|
||||
logger.info({count: gws.length}, 'updateCarrierRegbots: got new or changed carriers');
|
||||
|
||||
// Clear and repopulate arrays in chunks to avoid argument limit
|
||||
carriers.length = 0;
|
||||
|
||||
Reference in New Issue
Block a user