mirror of
https://github.com/jambonz/sbc-sip-sidecar.git
synced 2025-12-19 04:27:46 +00:00
add support for registration trunks which result in a set of ephemera… (#112)
* add support for registration trunks which result in a set of ephemeral sip gateways to be stored in redis * wip * refactor createEphemeralGateways into realtime dbhelpers * minor * update eslint
This commit is contained in:
@@ -1 +0,0 @@
|
|||||||
test/*
|
|
||||||
126
.eslintrc.json
126
.eslintrc.json
@@ -1,126 +0,0 @@
|
|||||||
{
|
|
||||||
"env": {
|
|
||||||
"node": true,
|
|
||||||
"es6": true
|
|
||||||
},
|
|
||||||
"parserOptions": {
|
|
||||||
"ecmaFeatures": {
|
|
||||||
"jsx": false,
|
|
||||||
"modules": false
|
|
||||||
},
|
|
||||||
"ecmaVersion": 2020
|
|
||||||
},
|
|
||||||
"plugins": ["promise"],
|
|
||||||
"rules": {
|
|
||||||
"promise/always-return": "error",
|
|
||||||
"promise/no-return-wrap": "error",
|
|
||||||
"promise/param-names": "error",
|
|
||||||
"promise/catch-or-return": "error",
|
|
||||||
"promise/no-native": "off",
|
|
||||||
"promise/no-nesting": "warn",
|
|
||||||
"promise/no-promise-in-callback": "warn",
|
|
||||||
"promise/no-callback-in-promise": "warn",
|
|
||||||
"promise/no-return-in-finally": "warn",
|
|
||||||
|
|
||||||
// Possible Errors
|
|
||||||
// http://eslint.org/docs/rules/#possible-errors
|
|
||||||
"comma-dangle": [2, "only-multiline"],
|
|
||||||
"no-control-regex": 2,
|
|
||||||
"no-debugger": 2,
|
|
||||||
"no-dupe-args": 2,
|
|
||||||
"no-dupe-keys": 2,
|
|
||||||
"no-duplicate-case": 2,
|
|
||||||
"no-empty-character-class": 2,
|
|
||||||
"no-ex-assign": 2,
|
|
||||||
"no-extra-boolean-cast" : 2,
|
|
||||||
"no-extra-parens": [2, "functions"],
|
|
||||||
"no-extra-semi": 2,
|
|
||||||
"no-func-assign": 2,
|
|
||||||
"no-invalid-regexp": 2,
|
|
||||||
"no-irregular-whitespace": 2,
|
|
||||||
"no-negated-in-lhs": 2,
|
|
||||||
"no-obj-calls": 2,
|
|
||||||
"no-proto": 2,
|
|
||||||
"no-unexpected-multiline": 2,
|
|
||||||
"no-unreachable": 2,
|
|
||||||
"use-isnan": 2,
|
|
||||||
"valid-typeof": 2,
|
|
||||||
|
|
||||||
// Best Practices
|
|
||||||
// http://eslint.org/docs/rules/#best-practices
|
|
||||||
"no-fallthrough": 2,
|
|
||||||
"no-octal": 2,
|
|
||||||
"no-redeclare": 2,
|
|
||||||
"no-self-assign": 2,
|
|
||||||
"no-unused-labels": 2,
|
|
||||||
|
|
||||||
// Strict Mode
|
|
||||||
// http://eslint.org/docs/rules/#strict-mode
|
|
||||||
"strict": [2, "never"],
|
|
||||||
|
|
||||||
// Variables
|
|
||||||
// http://eslint.org/docs/rules/#variables
|
|
||||||
"no-delete-var": 2,
|
|
||||||
"no-undef": 2,
|
|
||||||
"no-unused-vars": [2, {"args": "none"}],
|
|
||||||
|
|
||||||
// Node.js and CommonJS
|
|
||||||
// http://eslint.org/docs/rules/#nodejs-and-commonjs
|
|
||||||
"no-mixed-requires": 2,
|
|
||||||
"no-new-require": 2,
|
|
||||||
"no-path-concat": 2,
|
|
||||||
"no-restricted-modules": [2, "sys", "_linklist"],
|
|
||||||
|
|
||||||
// Stylistic Issues
|
|
||||||
// http://eslint.org/docs/rules/#stylistic-issues
|
|
||||||
"comma-spacing": 2,
|
|
||||||
"eol-last": 2,
|
|
||||||
"indent": [2, 2, {"SwitchCase": 1}],
|
|
||||||
"keyword-spacing": 2,
|
|
||||||
"max-len": [2, 120, 2],
|
|
||||||
"new-parens": 2,
|
|
||||||
"no-mixed-spaces-and-tabs": 2,
|
|
||||||
"no-multiple-empty-lines": [2, {"max": 2}],
|
|
||||||
"no-trailing-spaces": [2, {"skipBlankLines": false }],
|
|
||||||
"quotes": [2, "single", "avoid-escape"],
|
|
||||||
"semi": 2,
|
|
||||||
"space-before-blocks": [2, "always"],
|
|
||||||
"space-before-function-paren": [2, "never"],
|
|
||||||
"space-in-parens": [2, "never"],
|
|
||||||
"space-infix-ops": 2,
|
|
||||||
"space-unary-ops": 2,
|
|
||||||
|
|
||||||
// ECMAScript 6
|
|
||||||
// http://eslint.org/docs/rules/#ecmascript-6
|
|
||||||
"arrow-parens": [2, "always"],
|
|
||||||
"arrow-spacing": [2, {"before": true, "after": true}],
|
|
||||||
"constructor-super": 2,
|
|
||||||
"no-class-assign": 2,
|
|
||||||
"no-confusing-arrow": 2,
|
|
||||||
"no-const-assign": 2,
|
|
||||||
"no-dupe-class-members": 2,
|
|
||||||
"no-new-symbol": 2,
|
|
||||||
"no-this-before-super": 2,
|
|
||||||
"prefer-const": 2
|
|
||||||
},
|
|
||||||
"globals": {
|
|
||||||
"DTRACE_HTTP_CLIENT_REQUEST" : false,
|
|
||||||
"LTTNG_HTTP_CLIENT_REQUEST" : false,
|
|
||||||
"COUNTER_HTTP_CLIENT_REQUEST" : false,
|
|
||||||
"DTRACE_HTTP_CLIENT_RESPONSE" : false,
|
|
||||||
"LTTNG_HTTP_CLIENT_RESPONSE" : false,
|
|
||||||
"COUNTER_HTTP_CLIENT_RESPONSE" : false,
|
|
||||||
"DTRACE_HTTP_SERVER_REQUEST" : false,
|
|
||||||
"LTTNG_HTTP_SERVER_REQUEST" : false,
|
|
||||||
"COUNTER_HTTP_SERVER_REQUEST" : false,
|
|
||||||
"DTRACE_HTTP_SERVER_RESPONSE" : false,
|
|
||||||
"LTTNG_HTTP_SERVER_RESPONSE" : false,
|
|
||||||
"COUNTER_HTTP_SERVER_RESPONSE" : false,
|
|
||||||
"DTRACE_NET_STREAM_END" : false,
|
|
||||||
"LTTNG_NET_STREAM_END" : false,
|
|
||||||
"COUNTER_NET_SERVER_CONNECTION_CLOSE" : false,
|
|
||||||
"DTRACE_NET_SERVER_CONNECTION" : false,
|
|
||||||
"LTTNG_NET_SERVER_CONNECTION" : false,
|
|
||||||
"COUNTER_NET_SERVER_CONNECTION" : false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -2,6 +2,8 @@
|
|||||||
logs
|
logs
|
||||||
*.log
|
*.log
|
||||||
|
|
||||||
|
CLAUDE.md
|
||||||
|
|
||||||
# Runtime data
|
# Runtime data
|
||||||
pids
|
pids
|
||||||
*.pid
|
*.pid
|
||||||
|
|||||||
6
app.js
6
app.js
@@ -85,7 +85,8 @@ const {
|
|||||||
addToSet,
|
addToSet,
|
||||||
removeFromSet,
|
removeFromSet,
|
||||||
isMemberOfSet,
|
isMemberOfSet,
|
||||||
retrieveSet
|
retrieveSet,
|
||||||
|
createEphemeralGateway,
|
||||||
} = require('@jambonz/realtimedb-helpers')({}, logger);
|
} = require('@jambonz/realtimedb-helpers')({}, logger);
|
||||||
|
|
||||||
const interval = SBC_PUBLIC_ADDRESS_KEEP_ALIVE_IN_MILISECOND || 900000; // Default 15 minutes
|
const interval = SBC_PUBLIC_ADDRESS_KEEP_ALIVE_IN_MILISECOND || 900000; // Default 15 minutes
|
||||||
@@ -116,7 +117,8 @@ srf.locals = {
|
|||||||
addKey,
|
addKey,
|
||||||
addKeyNx,
|
addKeyNx,
|
||||||
retrieveKey,
|
retrieveKey,
|
||||||
retrieveSet
|
retrieveSet,
|
||||||
|
createEphemeralGateway,
|
||||||
},
|
},
|
||||||
writeAlerts,
|
writeAlerts,
|
||||||
AlertType
|
AlertType
|
||||||
|
|||||||
137
eslint.config.js
Normal file
137
eslint.config.js
Normal file
@@ -0,0 +1,137 @@
|
|||||||
|
const promisePlugin = require('eslint-plugin-promise');
|
||||||
|
|
||||||
|
module.exports = [
|
||||||
|
{
|
||||||
|
ignores: ['test/*']
|
||||||
|
},
|
||||||
|
{
|
||||||
|
files: ['**/*.js'],
|
||||||
|
languageOptions: {
|
||||||
|
ecmaVersion: 2020,
|
||||||
|
sourceType: 'commonjs',
|
||||||
|
globals: {
|
||||||
|
// Node.js globals
|
||||||
|
console: 'readonly',
|
||||||
|
process: 'readonly',
|
||||||
|
Buffer: 'readonly',
|
||||||
|
__dirname: 'readonly',
|
||||||
|
__filename: 'readonly',
|
||||||
|
module: 'readonly',
|
||||||
|
require: 'readonly',
|
||||||
|
exports: 'readonly',
|
||||||
|
setTimeout: 'readonly',
|
||||||
|
clearTimeout: 'readonly',
|
||||||
|
setInterval: 'readonly',
|
||||||
|
clearInterval: 'readonly',
|
||||||
|
setImmediate: 'readonly',
|
||||||
|
clearImmediate: 'readonly',
|
||||||
|
// DTrace/LTTNG globals
|
||||||
|
DTRACE_HTTP_CLIENT_REQUEST: false,
|
||||||
|
LTTNG_HTTP_CLIENT_REQUEST: false,
|
||||||
|
COUNTER_HTTP_CLIENT_REQUEST: false,
|
||||||
|
DTRACE_HTTP_CLIENT_RESPONSE: false,
|
||||||
|
LTTNG_HTTP_CLIENT_RESPONSE: false,
|
||||||
|
COUNTER_HTTP_CLIENT_RESPONSE: false,
|
||||||
|
DTRACE_HTTP_SERVER_REQUEST: false,
|
||||||
|
LTTNG_HTTP_SERVER_REQUEST: false,
|
||||||
|
COUNTER_HTTP_SERVER_REQUEST: false,
|
||||||
|
DTRACE_HTTP_SERVER_RESPONSE: false,
|
||||||
|
LTTNG_HTTP_SERVER_RESPONSE: false,
|
||||||
|
COUNTER_HTTP_SERVER_RESPONSE: false,
|
||||||
|
DTRACE_NET_STREAM_END: false,
|
||||||
|
LTTNG_NET_STREAM_END: false,
|
||||||
|
COUNTER_NET_SERVER_CONNECTION_CLOSE: false,
|
||||||
|
DTRACE_NET_SERVER_CONNECTION: false,
|
||||||
|
LTTNG_NET_SERVER_CONNECTION: false,
|
||||||
|
COUNTER_NET_SERVER_CONNECTION: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
plugins: {
|
||||||
|
promise: promisePlugin
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
// Promise plugin rules
|
||||||
|
'promise/always-return': 'error',
|
||||||
|
'promise/no-return-wrap': 'error',
|
||||||
|
'promise/param-names': 'error',
|
||||||
|
'promise/catch-or-return': 'error',
|
||||||
|
'promise/no-native': 'off',
|
||||||
|
'promise/no-nesting': 'warn',
|
||||||
|
'promise/no-promise-in-callback': 'warn',
|
||||||
|
'promise/no-callback-in-promise': 'warn',
|
||||||
|
'promise/no-return-in-finally': 'warn',
|
||||||
|
|
||||||
|
// Possible Errors
|
||||||
|
'comma-dangle': [2, 'only-multiline'],
|
||||||
|
'no-control-regex': 2,
|
||||||
|
'no-debugger': 2,
|
||||||
|
'no-dupe-args': 2,
|
||||||
|
'no-dupe-keys': 2,
|
||||||
|
'no-duplicate-case': 2,
|
||||||
|
'no-empty-character-class': 2,
|
||||||
|
'no-ex-assign': 2,
|
||||||
|
'no-extra-boolean-cast': 2,
|
||||||
|
'no-extra-parens': [2, 'functions'],
|
||||||
|
'no-extra-semi': 2,
|
||||||
|
'no-func-assign': 2,
|
||||||
|
'no-invalid-regexp': 2,
|
||||||
|
'no-irregular-whitespace': 2,
|
||||||
|
'no-obj-calls': 2,
|
||||||
|
'no-proto': 2,
|
||||||
|
'no-unexpected-multiline': 2,
|
||||||
|
'no-unreachable': 2,
|
||||||
|
'use-isnan': 2,
|
||||||
|
'valid-typeof': 2,
|
||||||
|
|
||||||
|
// Best Practices
|
||||||
|
'no-fallthrough': 2,
|
||||||
|
'no-octal': 2,
|
||||||
|
'no-redeclare': 2,
|
||||||
|
'no-self-assign': 2,
|
||||||
|
'no-unused-labels': 2,
|
||||||
|
|
||||||
|
// Strict Mode
|
||||||
|
'strict': [2, 'never'],
|
||||||
|
|
||||||
|
// Variables
|
||||||
|
'no-delete-var': 2,
|
||||||
|
'no-undef': 2,
|
||||||
|
'no-unused-vars': [2, {args: 'none'}],
|
||||||
|
|
||||||
|
// Node.js and CommonJS
|
||||||
|
'no-mixed-requires': 2,
|
||||||
|
'no-new-require': 2,
|
||||||
|
'no-path-concat': 2,
|
||||||
|
|
||||||
|
// Stylistic Issues
|
||||||
|
'comma-spacing': 2,
|
||||||
|
'eol-last': 2,
|
||||||
|
'indent': [2, 2, {SwitchCase: 1}],
|
||||||
|
'keyword-spacing': 2,
|
||||||
|
'max-len': [2, 120, 2],
|
||||||
|
'new-parens': 2,
|
||||||
|
'no-mixed-spaces-and-tabs': 2,
|
||||||
|
'no-multiple-empty-lines': [2, {max: 2}],
|
||||||
|
'no-trailing-spaces': [2, {skipBlankLines: false}],
|
||||||
|
'quotes': [2, 'single', 'avoid-escape'],
|
||||||
|
'semi': 2,
|
||||||
|
'space-before-blocks': [2, 'always'],
|
||||||
|
'space-before-function-paren': [2, 'never'],
|
||||||
|
'space-in-parens': [2, 'never'],
|
||||||
|
'space-infix-ops': 2,
|
||||||
|
'space-unary-ops': 2,
|
||||||
|
|
||||||
|
// ECMAScript 6
|
||||||
|
'arrow-parens': [2, 'always'],
|
||||||
|
'arrow-spacing': [2, {before: true, after: true}],
|
||||||
|
'constructor-super': 2,
|
||||||
|
'no-class-assign': 2,
|
||||||
|
'no-confusing-arrow': 2,
|
||||||
|
'no-const-assign': 2,
|
||||||
|
'no-dupe-class-members': 2,
|
||||||
|
'no-new-symbol': 2,
|
||||||
|
'no-this-before-super': 2,
|
||||||
|
'prefer-const': 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
];
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
const dns = require('dns').promises;
|
||||||
const {
|
const {
|
||||||
JAMBONES_REGBOT_DEFAULT_EXPIRES_INTERVAL,
|
JAMBONES_REGBOT_DEFAULT_EXPIRES_INTERVAL,
|
||||||
JAMBONES_REGBOT_MIN_EXPIRES_INTERVAL,
|
JAMBONES_REGBOT_MIN_EXPIRES_INTERVAL,
|
||||||
@@ -17,24 +18,20 @@ class Regbot {
|
|||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
|
|
||||||
[
|
[
|
||||||
|
'voip_carrier_sid',
|
||||||
'ipv4',
|
'ipv4',
|
||||||
'port',
|
'port',
|
||||||
'username',
|
'username',
|
||||||
'password',
|
'password',
|
||||||
'sip_realm',
|
|
||||||
'protocol',
|
'protocol',
|
||||||
'account_sip_realm'
|
'account_sip_realm',
|
||||||
|
'outbound_sip_proxy',
|
||||||
|
'trunk_type'
|
||||||
].forEach((prop) => this[prop] = opts[prop]);
|
].forEach((prop) => this[prop] = opts[prop]);
|
||||||
|
|
||||||
this.voip_carrier_sid = opts.voip_carrier_sid;
|
|
||||||
this.username = opts.username;
|
|
||||||
this.password = opts.password;
|
|
||||||
this.sip_realm = opts.sip_realm || opts.ipv4;
|
this.sip_realm = opts.sip_realm || opts.ipv4;
|
||||||
this.ipv4 = opts.ipv4;
|
|
||||||
this.port = opts.port;
|
|
||||||
this.use_public_ip_in_contact = opts.use_public_ip_in_contact || JAMBONES_REGBOT_CONTACT_USE_IP;
|
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.use_sips_scheme = opts.use_sips_scheme || false;
|
||||||
this.outbound_sip_proxy = opts.outbound_sip_proxy;
|
|
||||||
|
|
||||||
this.fromUser = opts.from_user || this.username;
|
this.fromUser = opts.from_user || this.username;
|
||||||
const fromDomain = opts.from_domain || this.sip_realm;
|
const fromDomain = opts.from_domain || this.sip_realm;
|
||||||
@@ -72,6 +69,7 @@ class Regbot {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async register(srf) {
|
async register(srf) {
|
||||||
|
const { createEphemeralGateway } = srf.locals.realtimeDbHelpers;
|
||||||
const { updateVoipCarriersRegisterStatus } = srf.locals.dbHelpers;
|
const { updateVoipCarriersRegisterStatus } = srf.locals.dbHelpers;
|
||||||
const { writeAlerts, localSIPDomain } = srf.locals;
|
const { writeAlerts, localSIPDomain } = srf.locals;
|
||||||
try {
|
try {
|
||||||
@@ -183,6 +181,8 @@ class Regbot {
|
|||||||
this.timer = setTimeout(this.register.bind(this, srf), (expires / 2) * 1000);
|
this.timer = setTimeout(this.register.bind(this, srf), (expires / 2) * 1000);
|
||||||
}
|
}
|
||||||
const timestamp = new Date().toISOString();
|
const timestamp = new Date().toISOString();
|
||||||
|
|
||||||
|
//update registration status for the carrier in the database
|
||||||
updateVoipCarriersRegisterStatus(this.voip_carrier_sid, JSON.stringify({
|
updateVoipCarriersRegisterStatus(this.voip_carrier_sid, JSON.stringify({
|
||||||
status: res.status === 200 ? 'ok' : 'fail',
|
status: res.status === 200 ? 'ok' : 'fail',
|
||||||
reason: `${res.status} ${res.reason}`,
|
reason: `${res.status} ${res.reason}`,
|
||||||
@@ -191,6 +191,31 @@ class Regbot {
|
|||||||
timestamp: timestamp,
|
timestamp: timestamp,
|
||||||
expires: expires
|
expires: expires
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
// for reg trunks, create ephemeral set of IP addresses for inbound gateways
|
||||||
|
if (this.trunk_type === 'reg') {
|
||||||
|
const addresses = [];
|
||||||
|
if (this.port) {
|
||||||
|
const addrs = await dnsResolverA(this.logger, this.sip_realm);
|
||||||
|
addresses.push(...addrs);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const addrs = await dnsResolverSrv(this.logger, this.sip_realm, this.transport);
|
||||||
|
addresses.push(...addrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (addresses.length) {
|
||||||
|
try {
|
||||||
|
await Promise.all(
|
||||||
|
addresses.map((ip) => createEphemeralGateway(ip, this.voip_carrier_sid, expires))
|
||||||
|
);
|
||||||
|
} catch (err) {
|
||||||
|
this.logger.error({addresses, err}, 'Error creating hash for reg-gateway');
|
||||||
|
}
|
||||||
|
this.logger.debug({addresses},
|
||||||
|
`Created ephemeral gateways for registration trunk ${this.voip_carrier_sid}, ${this.sip_realm}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.logger.error({ err }, `${this.aor}: Error registering to ${this.ipv4}:${this.port}`);
|
this.logger.error({ err }, `${this.aor}: Error registering to ${this.ipv4}:${this.port}`);
|
||||||
@@ -204,5 +229,44 @@ class Regbot {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const dnsResolverA = async(logger, hostname) => {
|
||||||
|
try {
|
||||||
|
const addresses = await dns.resolve4(hostname);
|
||||||
|
logger.debug({addresses}, `Regbot: resolved ${hostname} into ${addresses.length} IPs`);
|
||||||
|
return addresses;
|
||||||
|
} catch (err) {
|
||||||
|
logger.info({err}, `Error resolving ${hostname}`);
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
};
|
||||||
|
|
||||||
|
const dnsResolverSrv = async(logger, hostname, transport) => {
|
||||||
|
let name;
|
||||||
|
switch (transport) {
|
||||||
|
case 'tls':
|
||||||
|
name = `_sips._tcp.${hostname}`;
|
||||||
|
break;
|
||||||
|
case 'tcp':
|
||||||
|
name = `_sip._tcp.${hostname}`;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
name = `_sip._udp.${hostname}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const arr = await dns.resolveSrv(name);
|
||||||
|
logger.debug({arr}, `Regbot: resolved ${hostname}/${transport} into ${arr.length} results`);
|
||||||
|
const ips = await Promise.all(
|
||||||
|
arr.map((obj) => dnsResolverA(logger, obj.name))
|
||||||
|
);
|
||||||
|
return ips.flat();
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
logger.info({err}, `SRV Error resolving ${hostname}`);
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
module.exports = Regbot;
|
module.exports = Regbot;
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ const regbots = [];
|
|||||||
const carriers = [];
|
const carriers = [];
|
||||||
const gateways = [];
|
const gateways = [];
|
||||||
|
|
||||||
|
const getCountSuccessfulRegbots = () => regbots.filter((rb) => rb.status === 'registered').length;
|
||||||
|
|
||||||
function pickRelevantCarrierProperties(c) {
|
function pickRelevantCarrierProperties(c) {
|
||||||
return {
|
return {
|
||||||
@@ -32,6 +33,7 @@ function pickRelevantCarrierProperties(c) {
|
|||||||
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,
|
outbound_sip_proxy: c.outbound_sip_proxy,
|
||||||
account_sid: c.account_sid,
|
account_sid: c.account_sid,
|
||||||
|
trunk_type: c.trunk_type || 'static_ip'
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,6 +93,14 @@ module.exports = async(logger, srf) => {
|
|||||||
active: false
|
active: false
|
||||||
};
|
};
|
||||||
|
|
||||||
|
srf.locals.regbotStatus = () => {
|
||||||
|
return {
|
||||||
|
total: regbots.length,
|
||||||
|
registered: getCountSuccessfulRegbots(),
|
||||||
|
active: srf.locals.regbot.active
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
/* Set the Local SIP domain on srf.locals */
|
/* Set the Local SIP domain on srf.locals */
|
||||||
await getLocalSIPDomain(logger, srf); // Initial Setup
|
await getLocalSIPDomain(logger, srf); // Initial Setup
|
||||||
setInterval(getLocalSIPDomain, 300000, logger, srf); //Refresh SIP Domain every 5 mins
|
setInterval(getLocalSIPDomain, 300000, logger, srf); //Refresh SIP Domain every 5 mins
|
||||||
@@ -209,11 +219,10 @@ const updateCarrierRegbots = async(logger, srf) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (JSON.stringify(gws) !== JSON.stringify(gateways)) hasChanged = true;
|
if (JSON.stringify(gws) !== JSON.stringify(gateways)) hasChanged = true;
|
||||||
|
|
||||||
if (hasChanged) {
|
if (hasChanged) {
|
||||||
|
|
||||||
debug('updateCarrierRegbots: got new or changed carriers');
|
debug('updateCarrierRegbots: got new or changed carriers');
|
||||||
logger.info('updateCarrierRegbots: got new or changed carriers');
|
logger.info({gws}, 'updateCarrierRegbots: got new or changed carriers');
|
||||||
carriers.length = 0;
|
carriers.length = 0;
|
||||||
Array.prototype.push.apply(carriers, cs);
|
Array.prototype.push.apply(carriers, cs);
|
||||||
|
|
||||||
@@ -248,7 +257,8 @@ const updateCarrierRegbots = async(logger, srf) => {
|
|||||||
from_user: gw.carrier.register_from_user,
|
from_user: gw.carrier.register_from_user,
|
||||||
from_domain: gw.carrier.register_from_domain,
|
from_domain: gw.carrier.register_from_domain,
|
||||||
use_public_ip_in_contact: gw.carrier.register_public_ip_in_contact,
|
use_public_ip_in_contact: gw.carrier.register_public_ip_in_contact,
|
||||||
outbound_sip_proxy: gw.carrier.outbound_sip_proxy
|
outbound_sip_proxy: gw.carrier.outbound_sip_proxy,
|
||||||
|
trunk_type: gw.carrier.trunk_type
|
||||||
});
|
});
|
||||||
regbots.push(rb);
|
regbots.push(rb);
|
||||||
rb.start(srf);
|
rb.start(srf);
|
||||||
|
|||||||
1040
package-lock.json
generated
1040
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -31,20 +31,20 @@
|
|||||||
"@jambonz/db-helpers": "^0.9.18",
|
"@jambonz/db-helpers": "^0.9.18",
|
||||||
"@jambonz/digest-utils": "^0.0.6",
|
"@jambonz/digest-utils": "^0.0.6",
|
||||||
"@jambonz/mw-registrar": "^0.2.7",
|
"@jambonz/mw-registrar": "^0.2.7",
|
||||||
"@jambonz/realtimedb-helpers": "^0.8.13",
|
"@jambonz/realtimedb-helpers": "^0.8.18",
|
||||||
"@jambonz/stats-collector": "^0.1.10",
|
"@jambonz/stats-collector": "^0.1.10",
|
||||||
"@jambonz/time-series": "^0.2.8",
|
"@jambonz/time-series": "^0.2.8",
|
||||||
"debug": "^4.3.4",
|
"debug": "^4.3.4",
|
||||||
"drachtio-mw-registration-parser": "^0.1.2",
|
"drachtio-mw-registration-parser": "^0.1.2",
|
||||||
"drachtio-mw-response-time": "^1.0.2",
|
"drachtio-mw-response-time": "^1.0.2",
|
||||||
"drachtio-srf": "^5.0.5",
|
"drachtio-srf": "^5.0.5",
|
||||||
"pino": "^8.20.0",
|
"pino": "^10.1.0",
|
||||||
"short-uuid": "^4.2.2"
|
"short-uuid": "^4.2.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"clear-module": "^4.1.2",
|
"clear-module": "^4.1.2",
|
||||||
"eslint": "^7.32.0",
|
"eslint": "^9.17.0",
|
||||||
"eslint-plugin-promise": "^6.1.1",
|
"eslint-plugin-promise": "^7.2.1",
|
||||||
"nyc": "^15.1.0",
|
"nyc": "^15.1.0",
|
||||||
"tape": "^5.7.5"
|
"tape": "^5.7.5"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
/* SQLEditor (MySQL (2))*/
|
/* SQLEditor (MySQL (2))*/
|
||||||
|
|
||||||
SET FOREIGN_KEY_CHECKS=0;
|
SET FOREIGN_KEY_CHECKS=0;
|
||||||
|
|
||||||
DROP TABLE IF EXISTS account_static_ips;
|
DROP TABLE IF EXISTS account_static_ips;
|
||||||
@@ -351,6 +350,8 @@ speech_credential_sid CHAR(36) NOT NULL,
|
|||||||
model VARCHAR(512) NOT NULL,
|
model VARCHAR(512) NOT NULL,
|
||||||
reported_usage ENUM('REPORTED_USAGE_UNSPECIFIED','REALTIME','OFFLINE') DEFAULT 'REALTIME',
|
reported_usage ENUM('REPORTED_USAGE_UNSPECIFIED','REALTIME','OFFLINE') DEFAULT 'REALTIME',
|
||||||
name VARCHAR(64) NOT NULL,
|
name VARCHAR(64) NOT NULL,
|
||||||
|
voice_cloning_key MEDIUMTEXT,
|
||||||
|
use_voice_cloning_key BOOLEAN DEFAULT false,
|
||||||
PRIMARY KEY (google_custom_voice_sid)
|
PRIMARY KEY (google_custom_voice_sid)
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -358,7 +359,9 @@ CREATE TABLE system_information
|
|||||||
(
|
(
|
||||||
domain_name VARCHAR(255),
|
domain_name VARCHAR(255),
|
||||||
sip_domain_name VARCHAR(255),
|
sip_domain_name VARCHAR(255),
|
||||||
monitoring_domain_name VARCHAR(255)
|
monitoring_domain_name VARCHAR(255),
|
||||||
|
private_network_cidr VARCHAR(8192),
|
||||||
|
log_level ENUM('info', 'debug') NOT NULL DEFAULT 'info'
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE users
|
CREATE TABLE users
|
||||||
@@ -412,6 +415,9 @@ register_from_user VARCHAR(128),
|
|||||||
register_from_domain VARCHAR(255),
|
register_from_domain VARCHAR(255),
|
||||||
register_public_ip_in_contact BOOLEAN NOT NULL DEFAULT false,
|
register_public_ip_in_contact BOOLEAN NOT NULL DEFAULT false,
|
||||||
register_status VARCHAR(4096),
|
register_status VARCHAR(4096),
|
||||||
|
dtmf_type ENUM('rfc2833','tones','info') NOT NULL DEFAULT 'rfc2833',
|
||||||
|
outbound_sip_proxy VARCHAR(255),
|
||||||
|
trunk_type ENUM('static_ip','auth','reg') NOT NULL DEFAULT 'static_ip',
|
||||||
PRIMARY KEY (voip_carrier_sid)
|
PRIMARY KEY (voip_carrier_sid)
|
||||||
) COMMENT='A Carrier or customer PBX that can send or receive calls';
|
) COMMENT='A Carrier or customer PBX that can send or receive calls';
|
||||||
|
|
||||||
@@ -497,7 +503,7 @@ messaging_hook_sid CHAR(36) COMMENT 'webhook to call for inbound SMS/MMS ',
|
|||||||
app_json TEXT,
|
app_json TEXT,
|
||||||
speech_synthesis_vendor VARCHAR(64) NOT NULL DEFAULT 'google',
|
speech_synthesis_vendor VARCHAR(64) NOT NULL DEFAULT 'google',
|
||||||
speech_synthesis_language VARCHAR(12) NOT NULL DEFAULT 'en-US',
|
speech_synthesis_language VARCHAR(12) NOT NULL DEFAULT 'en-US',
|
||||||
speech_synthesis_voice VARCHAR(256),
|
speech_synthesis_voice VARCHAR(256) DEFAULT 'en-US-Standard-C',
|
||||||
speech_synthesis_label VARCHAR(64),
|
speech_synthesis_label VARCHAR(64),
|
||||||
speech_recognizer_vendor VARCHAR(64) NOT NULL DEFAULT 'google',
|
speech_recognizer_vendor VARCHAR(64) NOT NULL DEFAULT 'google',
|
||||||
speech_recognizer_language VARCHAR(64) NOT NULL DEFAULT 'en-US',
|
speech_recognizer_language VARCHAR(64) NOT NULL DEFAULT 'en-US',
|
||||||
@@ -510,6 +516,7 @@ fallback_speech_synthesis_label VARCHAR(64),
|
|||||||
fallback_speech_recognizer_vendor VARCHAR(64),
|
fallback_speech_recognizer_vendor VARCHAR(64),
|
||||||
fallback_speech_recognizer_language VARCHAR(64),
|
fallback_speech_recognizer_language VARCHAR(64),
|
||||||
fallback_speech_recognizer_label VARCHAR(64),
|
fallback_speech_recognizer_label VARCHAR(64),
|
||||||
|
env_vars TEXT,
|
||||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
record_all_calls BOOLEAN NOT NULL DEFAULT false,
|
record_all_calls BOOLEAN NOT NULL DEFAULT false,
|
||||||
PRIMARY KEY (application_sid)
|
PRIMARY KEY (application_sid)
|
||||||
@@ -552,6 +559,7 @@ siprec_hook_sid CHAR(36),
|
|||||||
record_all_calls BOOLEAN NOT NULL DEFAULT false,
|
record_all_calls BOOLEAN NOT NULL DEFAULT false,
|
||||||
record_format VARCHAR(16) NOT NULL DEFAULT 'mp3',
|
record_format VARCHAR(16) NOT NULL DEFAULT 'mp3',
|
||||||
bucket_credential VARCHAR(8192) COMMENT 'credential used to authenticate with storage service',
|
bucket_credential VARCHAR(8192) COMMENT 'credential used to authenticate with storage service',
|
||||||
|
enable_debug_log BOOLEAN NOT NULL DEFAULT false,
|
||||||
PRIMARY KEY (account_sid)
|
PRIMARY KEY (account_sid)
|
||||||
) COMMENT='An enterprise that uses the platform for comm services';
|
) COMMENT='An enterprise that uses the platform for comm services';
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
insert into voip_carriers (voip_carrier_sid, name, e164_leading_plus, requires_register, register_username, register_sip_realm, register_password, register_from_user, register_from_domain, register_public_ip_in_contact)
|
insert into voip_carriers (voip_carrier_sid, name, e164_leading_plus, requires_register, register_username, register_sip_realm, register_password, register_from_user, register_from_domain, register_public_ip_in_contact)
|
||||||
values ('287c1452-620d-4195-9f19-c9814ef90d78', 'westco', 1, 1, 'foo', 'sip.jambonz.org', 'bar', 'reguser', 'regdomain', 0);
|
values ('287c1452-620d-4195-9f19-c9814ef90d78', 'westco', 1, 1, 'foo', 'sip.jambonz.org', 'bar', 'reguser', 'regdomain', 0);
|
||||||
insert into sip_gateways (sip_gateway_sid, voip_carrier_sid, ipv4, inbound, outbound, send_options_ping)
|
insert into sip_gateways (sip_gateway_sid, voip_carrier_sid, ipv4, port, inbound, outbound, send_options_ping)
|
||||||
values ('124a5339-c62c-4075-9e19-f4de70a96597', '287c1452-620d-4195-9f19-c9814ef90d78', '172.39.0.14', true, true, true);
|
values ('124a5339-c62c-4075-9e19-f4de70a96597', '287c1452-620d-4195-9f19-c9814ef90d78', '172.39.0.14', 5060, true, true, true);
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
insert into sip_gateways (sip_gateway_sid, voip_carrier_sid, ipv4, inbound, outbound)
|
insert into sip_gateways (sip_gateway_sid, voip_carrier_sid, ipv4, port, inbound, outbound)
|
||||||
values ('987a5339-c62c-4075-9e19-f4de70a96597', '287c1452-620d-4195-9f19-c9814ef90d78', '172.39.0.15', false, true);
|
values ('987a5339-c62c-4075-9e19-f4de70a96597', '287c1452-620d-4195-9f19-c9814ef90d78', '172.39.0.15', 5060, false, true);
|
||||||
|
|||||||
6
test/db/populate-test-data4.sql
Normal file
6
test/db/populate-test-data4.sql
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
delete from sip_gateways;
|
||||||
|
delete from voip_carriers;
|
||||||
|
insert into voip_carriers (voip_carrier_sid, name, e164_leading_plus, requires_register, register_username, register_sip_realm, register_password, register_from_user, register_public_ip_in_contact, trunk_type)
|
||||||
|
values ('287c1452-620d-4195-9f19-c9814ef90d78', 'westco', 1, 1, 'daveh', 'beachdog.sip.jambonz.cloud', 'foobarbazzle', 'daveh', 0, 'reg');
|
||||||
|
insert into sip_gateways (sip_gateway_sid, voip_carrier_sid, ipv4, port, inbound, outbound, send_options_ping)
|
||||||
|
values ('124a5339-c62c-4075-9e19-f4de70a96597', '287c1452-620d-4195-9f19-c9814ef90d78', 'beachdog.sip.jambonz.cloud', 5060, false, true, false);
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
require('./docker_start');
|
require('./docker_start');
|
||||||
require('./create-test-db');
|
require('./create-test-db');
|
||||||
// require('./regbot-tests');
|
require('./regbot-tests');
|
||||||
require('./regbot-unit-test');
|
require('./regbot-unit-test');
|
||||||
require('./sip-register-tests');
|
require('./sip-register-tests');
|
||||||
require('./sip-options-tests');
|
require('./sip-options-tests');
|
||||||
|
|||||||
@@ -48,10 +48,11 @@ test('populating more test case data', (t) => {
|
|||||||
test('trunk register tests', (t) => {
|
test('trunk register tests', (t) => {
|
||||||
clearModule.all();
|
clearModule.all();
|
||||||
const { srf } = require('../app');
|
const { srf } = require('../app');
|
||||||
t.timeoutAfter(60000);
|
t.timeoutAfter(180000);
|
||||||
|
|
||||||
|
console.log('waiting 15 seconds for regbot to start up');
|
||||||
connect(srf)
|
connect(srf)
|
||||||
.then(wait.bind(null, 1500))
|
.then(wait.bind(null, 15000))
|
||||||
.then(() => {
|
.then(() => {
|
||||||
const obj = srf.locals.regbotStatus();
|
const obj = srf.locals.regbotStatus();
|
||||||
return t.ok(obj.total === 1 && obj.registered === 1, 'initial regbot running and successfully registered to trunk');
|
return t.ok(obj.total === 1 && obj.registered === 1, 'initial regbot running and successfully registered to trunk');
|
||||||
@@ -66,21 +67,27 @@ test('trunk register tests', (t) => {
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
return wait(35000);
|
console.log('waiting 65 seconds for regbot to come around to check for new gateways');
|
||||||
|
return wait(65000);
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
const obj = srf.locals.regbotStatus();
|
const obj = srf.locals.regbotStatus();
|
||||||
|
//console.log({obj}, 'regbot status after adding new gateway');
|
||||||
return t.ok(obj.total === 2 && obj.registered === 1, 'successfully added gateway that tests failure result');
|
return t.ok(obj.total === 2 && obj.registered === 1, 'successfully added gateway that tests failure result');
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
exec(`mysql -h 127.0.0.1 -u root --protocol=tcp -D jambones_test -e "delete from sip_gateways where sip_gateway_sid = '987a5339-c62c-4075-9e19-f4de70a96597'"`, (err, stdout, stderr) => {
|
exec(`mysql -h 127.0.0.1 -u root --protocol=tcp -D jambones_test < ${__dirname}/db/populate-test-data4.sql`, (err, stdout, stderr) => {
|
||||||
if (err) return reject(err);
|
if (err) return reject(err);
|
||||||
t.pass('added new gateway');
|
t.pass('added new reg trunk');
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
.then(() => {
|
||||||
|
console.log('waiting 65 seconds for regbot to come around to check for new reg trunk');
|
||||||
|
return wait(65000);
|
||||||
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
if (srf.locals.lb) srf.locals.lb.disconnect();
|
if (srf.locals.lb) srf.locals.lb.disconnect();
|
||||||
srf.disconnect();
|
srf.disconnect();
|
||||||
@@ -96,10 +103,11 @@ test('trunk register tests', (t) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
test('trunk register tests when its IP in redis cache', (t) => {
|
test('trunk register tests when its IP in redis cache', (t) => {
|
||||||
clearModule.all();
|
clearModule.all();
|
||||||
const { srf } = require('../app');
|
const { srf } = require('../app');
|
||||||
t.timeoutAfter(60000);
|
t.timeoutAfter(90000);
|
||||||
addToSet(setName, "172.39.0.10:5060");
|
addToSet(setName, "172.39.0.10:5060");
|
||||||
|
|
||||||
connect(srf)
|
connect(srf)
|
||||||
@@ -125,7 +133,6 @@ test('trunk register tests when its IP in redis cache', (t) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
test('trunk register with sbc public IP address', (t) => {
|
test('trunk register with sbc public IP address', (t) => {
|
||||||
clearModule.all();
|
clearModule.all();
|
||||||
const { srf } = require('../app');
|
const { srf } = require('../app');
|
||||||
@@ -196,3 +203,4 @@ test('trunk not register tests when its IP is not in redis cache', (t) => {
|
|||||||
t.error(err);
|
t.error(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
*/
|
||||||
Reference in New Issue
Block a user