Regbot persistent call-id and other fixes (#130)

* use gw sid as call id and fix bug on updateing regbots

we must not mutate gw directly, as it is cached in the gateways array
 and adding properties would cause the JSON.stringify comparison to detect a
 false change on every checkStatus cycle, triggering unnecessary re-registrations.

* fix tests

add influx and also the registered now changes to remove previous reg on update

* better test scenario

still checks that we have 1 registered as expires now at 600s so it doesn't expire before the 65sec delay
This commit is contained in:
Sam Machin
2026-02-19 13:14:04 +00:00
committed by GitHub
parent a21269cb19
commit f909c6e077
5 changed files with 21 additions and 6 deletions

View File

@@ -28,7 +28,8 @@ class Regbot {
'protocol',
'account_sip_realm',
'outbound_sip_proxy',
'trunk_type'
'trunk_type',
'sip_gateway_sid'
].forEach((prop) => this[prop] = opts[prop]);
this.sip_realm = opts.sip_realm || opts.ipv4;
@@ -129,6 +130,7 @@ class Regbot {
method: 'REGISTER',
proxy,
headers: {
'Call-ID': this.sip_gateway_sid,
'From': this.from,
'To': this.from,
'Contact': `<${scheme}:${contactAddress};transport=${transport}>;expires=${DEFAULT_EXPIRES}`,

View File

@@ -249,16 +249,17 @@ const updateCarrierRegbots = async(logger, srf) => {
let batch_count = 0;
for (const gw of getUniqueGateways(gateways, logger)) {
// find gateway account sip realm.
let accountSipRealm;
if (!gw.carrier.register_public_ip_in_contact && gw.carrier.account_sid) {
const account = await lookupAccountBySid(gw.carrier.account_sid);
if (account && account.sip_realm) {
gw.account_sip_realm = account.sip_realm;
accountSipRealm = account.sip_realm;
}
}
try {
const rb = new Regbot(logger, {
voip_carrier_sid: gw.carrier.voip_carrier_sid,
account_sip_realm: gw.account_sip_realm,
account_sip_realm: accountSipRealm,
ipv4: gw.ipv4,
port: gw.port,
protocol: gw.protocol,
@@ -270,7 +271,8 @@ const updateCarrierRegbots = async(logger, srf) => {
from_domain: gw.carrier.register_from_domain,
use_public_ip_in_contact: gw.carrier.register_public_ip_in_contact,
outbound_sip_proxy: gw.carrier.outbound_sip_proxy,
trunk_type: gw.carrier.trunk_type
trunk_type: gw.carrier.trunk_type,
sip_gateway_sid: gw.sip_gateway_sid
});
regbots.push(rb);
rb.start(srf);

View File

@@ -44,6 +44,16 @@ services:
sbc-sip-sidecar:
ipv4_address: 172.39.0.12
influxdb:
image: influxdb:1.8
ports:
- "8086:8086/tcp"
environment:
INFLUXDB_DB: "jambones_time_series"
networks:
sbc-sip-sidecar:
ipv4_address: 172.39.0.16
redis:
image: redis:5-alpine
ports:

View File

@@ -72,6 +72,7 @@ test('trunk register tests', (t) => {
})
.then(() => {
const obj = srf.locals.regbotStatus();
console.log(`regbotStatus: total=${obj.total}, registered=${obj.registered}, active=${obj.active}`);
return t.ok(obj.total === 2 && obj.registered === 1, 'successfully added gateway that tests failure result');
})
.then(() => {

View File

@@ -58,7 +58,7 @@
[last_To:];tag=[pid]SIPpTag01[call_number]
[last_Call-ID:]
[last_CSeq:]
Contact: <sip:[local_ip]:[local_port];transport=[transport]>;expires=60
Contact: <sip:[local_ip]:[local_port];transport=[transport]>;expires=600
Content-Type: application/sdp
Content-Length: 0
@@ -75,7 +75,7 @@
[last_To:];tag=[pid]SIPpTag01[call_number]
[last_Call-ID:]
[last_CSeq:]
Contact: <sip:[local_ip]:[local_port];transport=[transport]>;expires=60
Contact: <sip:[local_ip]:[local_port];transport=[transport]>;expires=600
Content-Type: application/sdp
Content-Length: 0