mirror of
https://github.com/jambonz/sbc-sip-sidecar.git
synced 2026-10-04 02:04:20 +00:00
use system_information.sip_domain_name in the Contact header, if available (#71)
This commit is contained in:
@@ -55,7 +55,8 @@ const {
|
|||||||
lookupClientByAccountAndUsername,
|
lookupClientByAccountAndUsername,
|
||||||
lookupSipGatewaysByFilters,
|
lookupSipGatewaysByFilters,
|
||||||
updateSipGatewayBySid,
|
updateSipGatewayBySid,
|
||||||
lookupCarrierBySid
|
lookupCarrierBySid,
|
||||||
|
lookupSystemInformation
|
||||||
} = require('@jambonz/db-helpers')({
|
} = require('@jambonz/db-helpers')({
|
||||||
host: JAMBONES_MYSQL_HOST,
|
host: JAMBONES_MYSQL_HOST,
|
||||||
user: JAMBONES_MYSQL_USER,
|
user: JAMBONES_MYSQL_USER,
|
||||||
@@ -102,7 +103,8 @@ srf.locals = {
|
|||||||
lookupClientByAccountAndUsername,
|
lookupClientByAccountAndUsername,
|
||||||
lookupSipGatewaysByFilters,
|
lookupSipGatewaysByFilters,
|
||||||
updateSipGatewayBySid,
|
updateSipGatewayBySid,
|
||||||
lookupCarrierBySid
|
lookupCarrierBySid,
|
||||||
|
lookupSystemInformation
|
||||||
},
|
},
|
||||||
realtimeDbHelpers: {
|
realtimeDbHelpers: {
|
||||||
client,
|
client,
|
||||||
|
|||||||
@@ -56,9 +56,23 @@ class Regbot {
|
|||||||
this.status = 'none';
|
this.status = 'none';
|
||||||
}
|
}
|
||||||
|
|
||||||
start(srf) {
|
async start(srf) {
|
||||||
this.logger.info(`starting regbot ${this.fromUser}@${this.sip_realm}`);
|
const { lookupSystemInformation } = srf.locals.dbHelpers;
|
||||||
assert(!this.timer);
|
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);
|
this.register(srf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,13 +97,32 @@ class Regbot {
|
|||||||
async register(srf) {
|
async register(srf) {
|
||||||
const { updateVoipCarriersRegisterStatus } = srf.locals.dbHelpers;
|
const { updateVoipCarriersRegisterStatus } = srf.locals.dbHelpers;
|
||||||
try {
|
try {
|
||||||
const transport = this.protocol.includes('/') ? this.protocol.substring(0, this.protocol.indexOf('/')) :
|
// transport
|
||||||
this.protocol;
|
const transport = (this.protocol.includes('/') ? this.protocol.substring(0, this.protocol.indexOf('/')) :
|
||||||
|
this.protocol).toLowerCase();
|
||||||
|
|
||||||
|
// scheme
|
||||||
let scheme = 'sip';
|
let scheme = 'sip';
|
||||||
if (transport === 'tls' && this.use_sips_scheme) scheme = 'sips';
|
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 ?
|
let publicAddress = srf.locals.sbcPublicIpAddress.udp;
|
||||||
`${this.fromUser}@${publicAddress}` : this.aor;
|
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}`);
|
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 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}`;
|
const proxy = `sip:${this.ipv4}${isIPv4 ? `:${this.port}` : ''};transport=${transport}`;
|
||||||
@@ -98,7 +131,7 @@ class Regbot {
|
|||||||
proxy,
|
proxy,
|
||||||
headers: {
|
headers: {
|
||||||
'From': this.from,
|
'From': this.from,
|
||||||
'Contact': `<${scheme}:${contactAddress}>;expires=${DEFAULT_EXPIRES}`,
|
'Contact': `<${scheme}:${contactAddress}>;transport=${transport};expires=${DEFAULT_EXPIRES}`,
|
||||||
'Expires': DEFAULT_EXPIRES
|
'Expires': DEFAULT_EXPIRES
|
||||||
},
|
},
|
||||||
auth: {
|
auth: {
|
||||||
|
|||||||
Generated
+4
-4
@@ -9,7 +9,7 @@
|
|||||||
"version": "0.9.0",
|
"version": "0.9.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@jambonz/db-helpers": "^0.9.3",
|
"@jambonz/db-helpers": "^0.9.4",
|
||||||
"@jambonz/digest-utils": "^0.0.5",
|
"@jambonz/digest-utils": "^0.0.5",
|
||||||
"@jambonz/mw-registrar": "^0.2.7",
|
"@jambonz/mw-registrar": "^0.2.7",
|
||||||
"@jambonz/realtimedb-helpers": "^0.8.8",
|
"@jambonz/realtimedb-helpers": "^0.8.8",
|
||||||
@@ -763,9 +763,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@jambonz/db-helpers": {
|
"node_modules/@jambonz/db-helpers": {
|
||||||
"version": "0.9.3",
|
"version": "0.9.4",
|
||||||
"resolved": "https://registry.npmjs.org/@jambonz/db-helpers/-/db-helpers-0.9.3.tgz",
|
"resolved": "https://registry.npmjs.org/@jambonz/db-helpers/-/db-helpers-0.9.4.tgz",
|
||||||
"integrity": "sha512-3XFs7NC7J7Q/eb1CwG1YJHa6N4elh8IP/4hMMDgoM9U5Loplx61XI4nZ58FIrY3C/F6gEF4UdjqKvbusEVw7cQ==",
|
"integrity": "sha512-/YEj3lLH4ypWG9fe5xNOzipcgiwnBAk5Y0aoeW1c2THGyBqmo0FMkCoh3lebiU2OgkeIwrsoamNMa7ildQkXVg==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"cidr-matcher": "^2.1.1",
|
"cidr-matcher": "^2.1.1",
|
||||||
"debug": "^4.3.4",
|
"debug": "^4.3.4",
|
||||||
|
|||||||
+1
-1
@@ -27,7 +27,7 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/jambonz/sbc-sip-sidecar#readme",
|
"homepage": "https://github.com/jambonz/sbc-sip-sidecar#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@jambonz/db-helpers": "^0.9.3",
|
"@jambonz/db-helpers": "^0.9.4",
|
||||||
"@jambonz/mw-registrar": "^0.2.7",
|
"@jambonz/mw-registrar": "^0.2.7",
|
||||||
"@jambonz/realtimedb-helpers": "^0.8.8",
|
"@jambonz/realtimedb-helpers": "^0.8.8",
|
||||||
"@jambonz/stats-collector": "^0.1.10",
|
"@jambonz/stats-collector": "^0.1.10",
|
||||||
|
|||||||
Reference in New Issue
Block a user