mirror of
https://github.com/jambonz/sbc-sip-sidecar.git
synced 2025-12-19 04:27:46 +00:00
use system_information.sip_domain_name in the Contact header, if available (#71)
This commit is contained in:
6
app.js
6
app.js
@@ -55,7 +55,8 @@ const {
|
||||
lookupClientByAccountAndUsername,
|
||||
lookupSipGatewaysByFilters,
|
||||
updateSipGatewayBySid,
|
||||
lookupCarrierBySid
|
||||
lookupCarrierBySid,
|
||||
lookupSystemInformation
|
||||
} = require('@jambonz/db-helpers')({
|
||||
host: JAMBONES_MYSQL_HOST,
|
||||
user: JAMBONES_MYSQL_USER,
|
||||
@@ -102,7 +103,8 @@ srf.locals = {
|
||||
lookupClientByAccountAndUsername,
|
||||
lookupSipGatewaysByFilters,
|
||||
updateSipGatewayBySid,
|
||||
lookupCarrierBySid
|
||||
lookupCarrierBySid,
|
||||
lookupSystemInformation
|
||||
},
|
||||
realtimeDbHelpers: {
|
||||
client,
|
||||
|
||||
@@ -56,9 +56,23 @@ class Regbot {
|
||||
this.status = 'none';
|
||||
}
|
||||
|
||||
start(srf) {
|
||||
this.logger.info(`starting regbot ${this.fromUser}@${this.sip_realm}`);
|
||||
async start(srf) {
|
||||
const { lookupSystemInformation } = srf.locals.dbHelpers;
|
||||
assert(!this.timer);
|
||||
|
||||
this.logger.info(`starting regbot for ${this.fromUser}@${this.sip_realm}`);
|
||||
try {
|
||||
const info = await lookupSystemInformation();
|
||||
if (info) {
|
||||
this.ourSipDomain = info.sip_domain_name;
|
||||
this.logger.info(`lookup of sip domain from system_information: ${this.ourSipDomain}`);
|
||||
}
|
||||
else {
|
||||
this.logger.info('no system_information found, we will use the realm or public ip as the domain');
|
||||
}
|
||||
} catch (err) {
|
||||
this.logger.info({ err }, 'Error looking up system information');
|
||||
}
|
||||
this.register(srf);
|
||||
}
|
||||
|
||||
@@ -83,13 +97,32 @@ class Regbot {
|
||||
async register(srf) {
|
||||
const { updateVoipCarriersRegisterStatus } = srf.locals.dbHelpers;
|
||||
try {
|
||||
const transport = this.protocol.includes('/') ? this.protocol.substring(0, this.protocol.indexOf('/')) :
|
||||
this.protocol;
|
||||
// transport
|
||||
const transport = (this.protocol.includes('/') ? this.protocol.substring(0, this.protocol.indexOf('/')) :
|
||||
this.protocol).toLowerCase();
|
||||
|
||||
// scheme
|
||||
let scheme = 'sip';
|
||||
if (transport === 'tls' && this.use_sips_scheme) scheme = 'sips';
|
||||
const publicAddress = srf.locals.sbcPublicIpAddress[transport] || srf.locals.sbcPublicIpAddress.udp;
|
||||
const contactAddress = this.use_public_ip_in_contact ?
|
||||
`${this.fromUser}@${publicAddress}` : this.aor;
|
||||
|
||||
let publicAddress = srf.locals.sbcPublicIpAddress.udp;
|
||||
if (transport !== 'udp') {
|
||||
if (srf.locals.sbcPublicIpAddress[transport]) {
|
||||
publicAddress = srf.locals.sbcPublicIpAddress[transport];
|
||||
}
|
||||
else if (transport === 'tls') {
|
||||
publicAddress = srf.locals.sbcPublicIpAddress.udp;
|
||||
}
|
||||
}
|
||||
|
||||
let contactAddress = this.aor;
|
||||
if (this.use_public_ip_in_contact) {
|
||||
contactAddress = `${this.fromUser}@${publicAddress}`;
|
||||
}
|
||||
else if (this.ourSipDomain) {
|
||||
contactAddress = `${this.fromUser}@${this.ourSipDomain}`;
|
||||
}
|
||||
|
||||
this.logger.debug(`sending REGISTER for ${this.aor}`);
|
||||
const isIPv4 = /[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}/.test(this.ipv4);
|
||||
const proxy = `sip:${this.ipv4}${isIPv4 ? `:${this.port}` : ''};transport=${transport}`;
|
||||
@@ -98,7 +131,7 @@ class Regbot {
|
||||
proxy,
|
||||
headers: {
|
||||
'From': this.from,
|
||||
'Contact': `<${scheme}:${contactAddress}>;expires=${DEFAULT_EXPIRES}`,
|
||||
'Contact': `<${scheme}:${contactAddress}>;transport=${transport};expires=${DEFAULT_EXPIRES}`,
|
||||
'Expires': DEFAULT_EXPIRES
|
||||
},
|
||||
auth: {
|
||||
|
||||
8
package-lock.json
generated
8
package-lock.json
generated
@@ -9,7 +9,7 @@
|
||||
"version": "0.9.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@jambonz/db-helpers": "^0.9.3",
|
||||
"@jambonz/db-helpers": "^0.9.4",
|
||||
"@jambonz/digest-utils": "^0.0.5",
|
||||
"@jambonz/mw-registrar": "^0.2.7",
|
||||
"@jambonz/realtimedb-helpers": "^0.8.8",
|
||||
@@ -763,9 +763,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@jambonz/db-helpers": {
|
||||
"version": "0.9.3",
|
||||
"resolved": "https://registry.npmjs.org/@jambonz/db-helpers/-/db-helpers-0.9.3.tgz",
|
||||
"integrity": "sha512-3XFs7NC7J7Q/eb1CwG1YJHa6N4elh8IP/4hMMDgoM9U5Loplx61XI4nZ58FIrY3C/F6gEF4UdjqKvbusEVw7cQ==",
|
||||
"version": "0.9.4",
|
||||
"resolved": "https://registry.npmjs.org/@jambonz/db-helpers/-/db-helpers-0.9.4.tgz",
|
||||
"integrity": "sha512-/YEj3lLH4ypWG9fe5xNOzipcgiwnBAk5Y0aoeW1c2THGyBqmo0FMkCoh3lebiU2OgkeIwrsoamNMa7ildQkXVg==",
|
||||
"dependencies": {
|
||||
"cidr-matcher": "^2.1.1",
|
||||
"debug": "^4.3.4",
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
},
|
||||
"homepage": "https://github.com/jambonz/sbc-sip-sidecar#readme",
|
||||
"dependencies": {
|
||||
"@jambonz/db-helpers": "^0.9.3",
|
||||
"@jambonz/db-helpers": "^0.9.4",
|
||||
"@jambonz/mw-registrar": "^0.2.7",
|
||||
"@jambonz/realtimedb-helpers": "^0.8.8",
|
||||
"@jambonz/stats-collector": "^0.1.10",
|
||||
|
||||
Reference in New Issue
Block a user