mirror of
https://github.com/jambonz/sbc-sip-sidecar.git
synced 2025-12-19 04:27:46 +00:00
move lookupSystemInformation up to parent function and add a timer (#93)
* move lookupSystemInformation up to parent function and add a timer * lint
This commit is contained in:
@@ -36,22 +36,9 @@ class Regbot {
|
||||
}
|
||||
|
||||
async start(srf) {
|
||||
const { lookupSystemInformation } = srf.locals.dbHelpers;
|
||||
assert(!this.timer);
|
||||
|
||||
this.logger.info(`starting regbot for ${this.fromUser}@${this.sip_realm}`);
|
||||
try {
|
||||
const info = await lookupSystemInformation();
|
||||
if (info) {
|
||||
this.ourSipDomain = info.sip_domain_name;
|
||||
this.logger.info(`lookup of sip domain from system_information: ${this.ourSipDomain}`);
|
||||
}
|
||||
else {
|
||||
this.logger.info('no system_information found, we will use the realm or public ip as the domain');
|
||||
}
|
||||
} catch (err) {
|
||||
this.logger.info({ err }, 'Error looking up system information');
|
||||
}
|
||||
this.register(srf);
|
||||
}
|
||||
|
||||
@@ -75,8 +62,7 @@ class Regbot {
|
||||
|
||||
async register(srf) {
|
||||
const { updateVoipCarriersRegisterStatus } = srf.locals.dbHelpers;
|
||||
const { writeAlerts } = srf.locals;
|
||||
|
||||
const { writeAlerts, localSIPDomain } = srf.locals;
|
||||
try {
|
||||
// transport
|
||||
const transport = (this.protocol.includes('/') ? this.protocol.substring(0, this.protocol.indexOf('/')) :
|
||||
@@ -100,8 +86,8 @@ class Regbot {
|
||||
if (this.use_public_ip_in_contact) {
|
||||
contactAddress = `${this.fromUser}@${publicAddress}`;
|
||||
}
|
||||
else if (this.ourSipDomain) {
|
||||
contactAddress = `${this.fromUser}@${this.ourSipDomain}`;
|
||||
else if (localSIPDomain) {
|
||||
contactAddress = `${this.fromUser}@${localSIPDomain}`;
|
||||
}
|
||||
|
||||
this.logger.debug(`sending REGISTER for ${this.aor}`);
|
||||
|
||||
@@ -32,6 +32,24 @@ function pickRelevantCarrierProperties(c) {
|
||||
};
|
||||
}
|
||||
|
||||
async function getLocalSIPDomain(logger, srf) {
|
||||
const { lookupSystemInformation } = srf.locals.dbHelpers;
|
||||
try {
|
||||
const systemInfo = await lookupSystemInformation();
|
||||
if (systemInfo) {
|
||||
logger.info(`lookup of sip domain from system_information: ${systemInfo.sip_domain_name}`);
|
||||
srf.locals.localSIPDomain = systemInfo.sip_domain_name;
|
||||
}
|
||||
else {
|
||||
logger.info('no system_information found, we will use the realm or public ip as the domain');
|
||||
return false;
|
||||
}
|
||||
} catch (err) {
|
||||
logger.info({ err }, 'Error looking up system information');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = async(logger, srf) => {
|
||||
if (initialized) return;
|
||||
initialized = true;
|
||||
@@ -42,6 +60,10 @@ module.exports = async(logger, srf) => {
|
||||
active: false
|
||||
};
|
||||
|
||||
/* Set the Local SIP domain on srf.locals */
|
||||
await getLocalSIPDomain(logger, srf); // Initial Setup
|
||||
setInterval(getLocalSIPDomain, 300000, logger, srf); //Refresh SIP Domain every 5 mins
|
||||
|
||||
/* sleep a random duration between 0 and MAX_INITIAL_DELAY seconds */
|
||||
const ms = Math.floor(Math.random() * MAX_INITIAL_DELAY) * 1000;
|
||||
logger.info(`waiting ${ms}ms before attempting to claim regbot responsibility with token ${myToken}`);
|
||||
@@ -184,7 +206,7 @@ const updateCarrierRegbots = async(logger, srf) => {
|
||||
sip_realm: gw.carrier.register_sip_realm,
|
||||
from_user: gw.carrier.register_from_user,
|
||||
from_domain: gw.carrier.register_from_domain,
|
||||
use_public_ip_in_contact: gw.carrier.register_public_ip_in_contact
|
||||
use_public_ip_in_contact: gw.carrier.register_public_ip_in_contact,
|
||||
});
|
||||
regbots.push(rb);
|
||||
// stagger the start of the regbots
|
||||
|
||||
Reference in New Issue
Block a user