use outbound proxy for registrations where set (#103)

* use outbound proxy for registrations where set

* remove requirement that port can only be set on IP address not host

* switch logging back to debug and remove unused function

* Update regbot.js
This commit is contained in:
Sam Machin
2025-05-12 12:58:55 +01:00
committed by GitHub
parent 5f107d19bc
commit 543f52d3dd
2 changed files with 13 additions and 5 deletions

View File

@@ -5,7 +5,7 @@ const {
REGISTER_RESPONSE_REMOVE
} = require('./config');
const debug = require('debug')('jambonz:sbc-registrar');
const {isValidIPv4, isValidDomainOrIP} = require('./utils');
const {isValidDomainOrIP} = require('./utils');
const DEFAULT_EXPIRES = (parseInt(JAMBONES_REGBOT_DEFAULT_EXPIRES_INTERVAL) || 3600);
const MIN_EXPIRES = (parseInt(JAMBONES_REGBOT_MIN_EXPIRES_INTERVAL) || 30);
const assert = require('assert');
@@ -24,6 +24,7 @@ class Regbot {
this.port = opts.port;
this.use_public_ip_in_contact = opts.use_public_ip_in_contact || JAMBONES_REGBOT_CONTACT_USE_IP;
this.use_sips_scheme = opts.use_sips_scheme || false;
this.outbound_sip_proxy = opts.outbound_sip_proxy;
this.fromUser = opts.from_user || this.username;
const fromDomain = opts.from_domain || this.sip_realm;
@@ -91,10 +92,15 @@ class Regbot {
}
this.logger.debug(`sending REGISTER for ${this.aor}`);
const isIPv4 = isValidIPv4(this.ipv4);
const proxy = `sip:${this.ipv4}${isIPv4 ? `:${this.port}` : ''};transport=${transport}`;
this.logger.debug({isIPv4}, `sending via proxy ${proxy}`);
let proxy;
if (this.outbound_sip_proxy) {
proxy = `sip:${this.outbound_sip_proxy};transport=${transport}`;
this.logger.debug(`sending via proxy ${proxy}`);
} else {
proxy = `sip:${this.ipv4}:${this.port};transport=${transport}`;
this.logger.debug(`sending to registrar ${proxy}`);
}
const req = await srf.request(`${scheme}:${this.sip_realm}`, {
method: 'REGISTER',
proxy,

View File

@@ -29,7 +29,8 @@ function pickRelevantCarrierProperties(c) {
register_sip_realm: c.register_sip_realm,
register_from_user: c.register_from_user,
register_from_domain: c.register_from_domain,
register_public_ip_in_contact: c.register_public_ip_in_contact
register_public_ip_in_contact: c.register_public_ip_in_contact,
outbound_sip_proxy: c.outbound_sip_proxy
};
}
@@ -237,6 +238,7 @@ const updateCarrierRegbots = async(logger, srf) => {
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,
outbound_sip_proxy: gw.carrier.outbound_sip_proxy
});
regbots.push(rb);
rb.start(srf);