From f909c6e077bdb17b2085f37094cde6cc123d7c32 Mon Sep 17 00:00:00 2001 From: Sam Machin Date: Thu, 19 Feb 2026 13:14:04 +0000 Subject: [PATCH] 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 --- lib/regbot.js | 4 +++- lib/sip-trunk-register.js | 8 +++++--- test/docker-compose-testbed.yaml | 10 ++++++++++ test/regbot-tests.js | 1 + test/scenarios/uas-auth-register.xml | 4 ++-- 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/lib/regbot.js b/lib/regbot.js index 48cefb5..e85e893 100644 --- a/lib/regbot.js +++ b/lib/regbot.js @@ -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}`, diff --git a/lib/sip-trunk-register.js b/lib/sip-trunk-register.js index 8358b6d..c5ce347 100644 --- a/lib/sip-trunk-register.js +++ b/lib/sip-trunk-register.js @@ -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); diff --git a/test/docker-compose-testbed.yaml b/test/docker-compose-testbed.yaml index da19d7e..69a1731 100644 --- a/test/docker-compose-testbed.yaml +++ b/test/docker-compose-testbed.yaml @@ -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: diff --git a/test/regbot-tests.js b/test/regbot-tests.js index 30fe603..9f74d47 100644 --- a/test/regbot-tests.js +++ b/test/regbot-tests.js @@ -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(() => { diff --git a/test/scenarios/uas-auth-register.xml b/test/scenarios/uas-auth-register.xml index 25b65aa..40d223d 100644 --- a/test/scenarios/uas-auth-register.xml +++ b/test/scenarios/uas-auth-register.xml @@ -58,7 +58,7 @@ [last_To:];tag=[pid]SIPpTag01[call_number] [last_Call-ID:] [last_CSeq:] - Contact: ;expires=60 + Contact: ;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: ;expires=60 + Contact: ;expires=600 Content-Type: application/sdp Content-Length: 0