discover local ip address based on authentication response from drachtio-server (#143)

This commit is contained in:
Dave Horton
2024-05-16 10:50:07 -04:00
committed by GitHub
parent a46ad934a8
commit 831005f7a1
3 changed files with 31 additions and 14 deletions

29
app.js
View File

@@ -145,11 +145,28 @@ if (process.env.DRACHTIO_HOST && !process.env.K8S) {
const matcher = new CIDRMatcher(cidrs);
srf.connect({host: process.env.DRACHTIO_HOST, port: process.env.DRACHTIO_PORT, secret: process.env.DRACHTIO_SECRET });
srf.on('connect', (err, hp) => {
srf.on('connect', (err, hp, version, localHostports) => {
if (err) return this.logger.error({err}, 'Error connecting to drachtio server');
logger.info(`connected to drachtio listening on ${hp}`);
let addedPrivateIp = false;
logger.info(`connected to drachtio ${version} listening on ${hp}, local hostports: ${localHostports}`);
const hostports = hp.split(',');
if (localHostports) {
const locals = localHostports.split(',');
for (const hp of locals) {
const arr = /^(.*)\/(.*):(\d+)$/.exec(hp);
if (arr && 'tcp' === arr[1] && matcher.contains(arr[2])) {
const hostport = `${arr[2]}:${arr[3]}`;
logger.info(`adding sbc private address to redis: ${hostport}`);
srf.locals.privateSipAddress = hostport;
srf.locals.addToRedis = () => addToSet(setName, hostport);
srf.locals.removeFromRedis = () => removeFromSet(setName, hostport);
srf.locals.addToRedis();
addedPrivateIp = true;
}
}
}
for (const hp of hostports) {
const arr = /^(.*)\/(.*):(\d+)$/.exec(hp);
if (arr && 'udp' === arr[1] && !matcher.contains(arr[2])) {
@@ -157,7 +174,7 @@ if (process.env.DRACHTIO_HOST && !process.env.K8S) {
srf.locals.sipAddress = arr[2];
if (!process.env.SBC_ACCOUNT_SID) addSbcAddress(arr[2]);
}
else if (arr && 'tcp' === arr[1] && matcher.contains(arr[2])) {
else if (!addedPrivateIp && arr && 'tcp' === arr[1] && matcher.contains(arr[2])) {
const hostport = `${arr[2]}:${arr[3]}`;
logger.info(`adding sbc private address to redis: ${hostport}`);
srf.locals.privateSipAddress = hostport;
@@ -173,13 +190,13 @@ else {
logger.info(`listening in outbound mode on port ${process.env.DRACHTIO_PORT}`);
});
srf.listen({port: process.env.DRACHTIO_PORT, secret: process.env.DRACHTIO_SECRET});
srf.on('connect', (err, hp) => {
srf.on('connect', (err, hp, version, localHostports) => {
if (err) return this.logger.error({err}, 'Error connecting to drachtio server');
logger.info(`connected to drachtio listening on ${hp}`);
logger.info(`connected to drachtio ${version} listening on ${hp}, local hostports: ${localHostports}`);
if (process.env.K8S_FEATURE_SERVER_TRANSPORT === 'tcp') {
const matcher = new CIDRMatcher(['192.168.0.0/24', '172.16.0.0/16', '10.0.0.0/8']);
const hostports = hp.split(',');
const hostports = localHostports ? localHostports.split(',') : hp.split(',');
for (const hp of hostports) {
const arr = /^(.*)\/(.*):(\d+)$/.exec(hp);
if (arr && matcher.contains(arr[2])) {

14
package-lock.json generated
View File

@@ -23,7 +23,7 @@
"cidr-matcher": "^2.1.1",
"debug": "^4.3.4",
"drachtio-fn-b2b-sugar": "0.1.0",
"drachtio-srf": "^4.5.35",
"drachtio-srf": "^4.5.38",
"express": "^4.19.2",
"pino": "^8.20.0",
"verify-aws-sns-signature": "^0.1.0",
@@ -2899,9 +2899,9 @@
}
},
"node_modules/drachtio-srf": {
"version": "4.5.35",
"resolved": "https://registry.npmjs.org/drachtio-srf/-/drachtio-srf-4.5.35.tgz",
"integrity": "sha512-4LOb6Rjie8OHpUdqjhU8Zpkc6rquA4LBLqjH419bAJFKG/XqMYeIqPo7PF3GLy5TGghrx487RTP0DmFbH5B01g==",
"version": "4.5.38",
"resolved": "https://registry.npmjs.org/drachtio-srf/-/drachtio-srf-4.5.38.tgz",
"integrity": "sha512-dEafgn1OPfkc30Gq3JwJBF4Q7O96fsuqMnE2OO1NqRG0DkwworMIPsusWDo0ePbi+NH74rMjLPmVyC/owA0HXg==",
"dependencies": {
"debug": "^3.2.7",
"delegates": "^0.1.0",
@@ -8974,9 +8974,9 @@
"requires": {}
},
"drachtio-srf": {
"version": "4.5.35",
"resolved": "https://registry.npmjs.org/drachtio-srf/-/drachtio-srf-4.5.35.tgz",
"integrity": "sha512-4LOb6Rjie8OHpUdqjhU8Zpkc6rquA4LBLqjH419bAJFKG/XqMYeIqPo7PF3GLy5TGghrx487RTP0DmFbH5B01g==",
"version": "4.5.38",
"resolved": "https://registry.npmjs.org/drachtio-srf/-/drachtio-srf-4.5.38.tgz",
"integrity": "sha512-dEafgn1OPfkc30Gq3JwJBF4Q7O96fsuqMnE2OO1NqRG0DkwworMIPsusWDo0ePbi+NH74rMjLPmVyC/owA0HXg==",
"requires": {
"debug": "^3.2.7",
"delegates": "^0.1.0",

View File

@@ -39,7 +39,7 @@
"cidr-matcher": "^2.1.1",
"debug": "^4.3.4",
"drachtio-fn-b2b-sugar": "0.1.0",
"drachtio-srf": "^4.5.35",
"drachtio-srf": "^4.5.38",
"express": "^4.19.2",
"pino": "^8.20.0",
"verify-aws-sns-signature": "^0.1.0",