Skip to content

Commit

Permalink
fix review comment
Browse files Browse the repository at this point in the history
  • Loading branch information
xquanluu committed Nov 13, 2023
1 parent 4fec150 commit c4ec38b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ const debug = require('debug')('jambonz:sbc-outbound');
const CIDRMatcher = require('cidr-matcher');
const dns = require('dns');

const cidrMatcher = process.env.PRIVATE_VOIP_NETWORK_CIDR ?
new CIDRMatcher(process.env.PRIVATE_VOIP_NETWORK_CIDR.split(',')) : null;

function makeRtpEngineOpts(req, srcIsUsingSrtp, dstIsUsingSrtp, padCrypto, teams) {
const from = req.getParsedHeader('from');
const rtpCopy = JSON.parse(JSON.stringify(rtpCharacteristics));
Expand Down Expand Up @@ -184,7 +187,7 @@ const nudgeCallCounts = async(logger, sids, nudgeOperator, writers) => {
};

const isPrivateVoipNetwork = async(uri) => {
if (process.env.PRIVATE_VOIP_NETWORK_CIDR) {
if (cidrMatcher) {
try {
const arr = /sips?:.*@(.*):.*$/.exec(uri);
if (arr) {
Expand All @@ -195,9 +198,8 @@ const isPrivateVoipNetwork = async(uri) => {
} else {
addresses = await dns.resolve4(input);
}
const matcher = new CIDRMatcher(process.env.PRIVATE_VOIP_NETWORK_CIDR.split(','));
for (const ip of addresses) {
if (matcher.contains(ip)) {
if (cidrMatcher.contains(ip)) {
return true;
}
}
Expand Down

0 comments on commit c4ec38b

Please sign in to comment.