use system_information.sip_domain_name in the Contact header, if available (#71)

This commit is contained in:
Dave Horton
2024-06-26 13:15:23 -04:00
committed by GitHub
parent a6d15bc7aa
commit 3c498b2624
4 changed files with 50 additions and 15 deletions

View File

@@ -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: {