mirror of
https://github.com/jambonz/sbc-sip-sidecar.git
synced 2025-12-19 04:27:46 +00:00
disable reg on error
This commit is contained in:
6
app.js
6
app.js
@@ -56,7 +56,8 @@ const {
|
||||
lookupSipGatewaysByFilters,
|
||||
updateSipGatewayBySid,
|
||||
lookupCarrierBySid,
|
||||
lookupSystemInformation
|
||||
lookupSystemInformation,
|
||||
updateCarrierBySid,
|
||||
} = require('@jambonz/db-helpers')({
|
||||
host: JAMBONES_MYSQL_HOST,
|
||||
user: JAMBONES_MYSQL_USER,
|
||||
@@ -104,7 +105,8 @@ srf.locals = {
|
||||
lookupSipGatewaysByFilters,
|
||||
updateSipGatewayBySid,
|
||||
lookupCarrierBySid,
|
||||
lookupSystemInformation
|
||||
lookupSystemInformation,
|
||||
updateCarrierBySid
|
||||
},
|
||||
realtimeDbHelpers: {
|
||||
client,
|
||||
|
||||
@@ -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,24 @@ 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) {
|
||||
writeAlerts({
|
||||
account_sid: carrier.account_sid,
|
||||
service_provider_sid: carrier.service_provider_sid,
|
||||
message: `Disabling Outbound Registration for carrier ${carrier.name}(${carrier.voip_carrier_sid})`
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user