mirror of
https://github.com/jambonz/sbc-sip-sidecar.git
synced 2025-12-19 04:27:46 +00:00
Disable Options and Registration on certain failures (#90)
* disable options ping on defined errors * correct sid * disable reg on error * fix path * fixes from testing * fixes from testing * lint * update dbhelpers dep * remove whitespace in CONFIG strings * lint * this seems like a better way of convering and matching status codes
This commit is contained in:
@@ -31,6 +31,8 @@ const JAMBONES_REGBOT_CONTACT_USE_IP = process.env.JAMBONES_REGBOT_CONTACT_USE_I
|
||||
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;
|
||||
const OPTIONS_RESPONSE_REMOVE = process.env.OPTIONS_RESPONSE_REMOVE?.split(',').map(Number) || [];
|
||||
const REGISTER_RESPONSE_REMOVE = process.env.REGISTER_RESPONSE_REMOVE?.split(',').map(Number) || [];
|
||||
|
||||
module.exports = {
|
||||
JAMBONES_MYSQL_HOST,
|
||||
@@ -57,5 +59,7 @@ module.exports = {
|
||||
JAMBONES_REGBOT_CONTACT_USE_IP,
|
||||
JAMBONES_REGBOT_MIN_EXPIRES_INTERVAL,
|
||||
JAMBONES_REGBOT_DEFAULT_EXPIRES_INTERVAL,
|
||||
JAMBONES_REGBOT_INITIAL_DELAY_MS
|
||||
JAMBONES_REGBOT_INITIAL_DELAY_MS,
|
||||
OPTIONS_RESPONSE_REMOVE,
|
||||
REGISTER_RESPONSE_REMOVE
|
||||
};
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
const {
|
||||
JAMBONES_REGBOT_DEFAULT_EXPIRES_INTERVAL,
|
||||
JAMBONES_REGBOT_MIN_EXPIRES_INTERVAL,
|
||||
JAMBONES_REGBOT_CONTACT_USE_IP
|
||||
JAMBONES_REGBOT_CONTACT_USE_IP,
|
||||
REGISTER_RESPONSE_REMOVE
|
||||
} = require('./config');
|
||||
const debug = require('debug')('jambonz:sbc-registrar');
|
||||
const {isValidIPv4, isValidDomainOrIP} = require('./utils');
|
||||
@@ -74,6 +75,8 @@ class Regbot {
|
||||
|
||||
async register(srf) {
|
||||
const { updateVoipCarriersRegisterStatus } = srf.locals.dbHelpers;
|
||||
const { writeAlerts } = srf.locals;
|
||||
|
||||
try {
|
||||
// transport
|
||||
const transport = (this.protocol.includes('/') ? this.protocol.substring(0, this.protocol.indexOf('/')) :
|
||||
@@ -120,11 +123,26 @@ class Regbot {
|
||||
password: this.password
|
||||
}
|
||||
});
|
||||
req.on('response', (res) => {
|
||||
req.on('response', async(res) => {
|
||||
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);
|
||||
if (REGISTER_RESPONSE_REMOVE.includes(res.status)) {
|
||||
const { updateCarrierBySid, lookupCarrierBySid } = srf.locals.dbHelpers;
|
||||
await updateCarrierBySid(this.voip_carrier_sid, {requires_register: false});
|
||||
this.stop(); //Remove the retry timer
|
||||
const carrier = await lookupCarrierBySid(this.voip_carrier_sid);
|
||||
if (carrier) {
|
||||
// eslint-disable-next-line max-len
|
||||
this.logger.info(`Disabling Outbound Registration for carrier ${carrier.name} (sid:${carrier.voip_carrier_sid})`);
|
||||
writeAlerts({
|
||||
account_sid: carrier.account_sid,
|
||||
service_provider_sid: carrier.service_provider_sid,
|
||||
message: `Disabling Outbound Registration for carrier ${carrier.name} (sid:${carrier.voip_carrier_sid})`
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
const { addSipGatewayToBlacklist, removeSipGatewayFromBlacklist, isSipGatewayBlacklisted } = require('./utils');
|
||||
const {OPTIONS_RESPONSE_REMOVE} = require('./config');
|
||||
|
||||
const send_options_gateways = [];
|
||||
const send_options_bots = [];
|
||||
@@ -50,6 +51,22 @@ class OptionsBot {
|
||||
});
|
||||
}
|
||||
}
|
||||
if (OPTIONS_RESPONSE_REMOVE.includes(res.status)) {
|
||||
const { updateSipGatewayBySid } = srf.locals.dbHelpers;
|
||||
await updateSipGatewayBySid(this.sip_gateway_sid, {send_options_ping: false});
|
||||
const carrier = await lookupCarrierBySid(this.voip_carrier_sid);
|
||||
if (carrier) {
|
||||
// eslint-disable-next-line max-len
|
||||
this.logger.info(`Disabling Options ping for ${this.ipv4} in carrier ${carrier.name} (sid:${carrier.voip_carrier_sid})`);
|
||||
writeAlerts({
|
||||
account_sid: carrier.account_sid,
|
||||
service_provider_sid: carrier.service_provider_sid,
|
||||
// eslint-disable-next-line max-len
|
||||
message: `Disabling Options ping for ${this.ipv4} in carrier ${carrier.name} (sid:${carrier.voip_carrier_sid})`
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
// If the gateway is blacklisted, remove it from the blacklist as we have successfully pinged it
|
||||
if (await isSipGatewayBlacklisted(realtimeDbHelpers.client, logger, this.sip_gateway_sid)) {
|
||||
|
||||
Reference in New Issue
Block a user