Skip to content

Commit 56df3a6

Browse files
authored
Fix/regtrunks (#118)
* restore only use port if proxy is IPv4 address broke in this commit 543f52d * use sip gateway host for DNS lookup of ephemeral gw and only if not an IP address
1 parent 1f7980d commit 56df3a6

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

lib/regbot.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const {
66
REGISTER_RESPONSE_REMOVE,
77
JAMBONES_REGBOT_USER_AGENT
88
} = require('./config');
9-
const {isValidDomainOrIP} = require('./utils');
9+
const {isValidDomainOrIP, isValidIPv4} = require('./utils');
1010
const DEFAULT_EXPIRES = (parseInt(JAMBONES_REGBOT_DEFAULT_EXPIRES_INTERVAL) || 3600);
1111
const MIN_EXPIRES = (parseInt(JAMBONES_REGBOT_MIN_EXPIRES_INTERVAL) || 30);
1212
const assert = require('assert');
@@ -119,7 +119,8 @@ class Regbot {
119119
proxy = `sip:${this.outbound_sip_proxy};transport=${transport}`;
120120
this.logger.debug(`sending via proxy ${proxy}`);
121121
} else {
122-
proxy = `sip:${this.ipv4}:${this.port};transport=${transport}`;
122+
const isIPv4 = isValidIPv4(this.ipv4);
123+
proxy = `sip:${this.ipv4}${isIPv4 ? `:${this.port}` : ''};transport=${transport}`;
123124
this.logger.debug(`sending to registrar ${proxy}`);
124125
}
125126
const req = await srf.request(`${scheme}:${this.sip_realm}`, {
@@ -203,14 +204,14 @@ class Regbot {
203204
}));
204205

205206
// for reg trunks, create ephemeral set of IP addresses for inbound gateways
206-
if (this.trunk_type === 'reg') {
207+
if (this.trunk_type === 'reg' && !isValidIPv4(this.ipv4)) {
207208
this.addresses = [];
208209
if (this.port) {
209-
const addrs = await dnsResolverA(this.logger, this.sip_realm);
210+
const addrs = await dnsResolverA(this.logger, this.ipv4);
210211
this.addresses.push(...addrs);
211212
}
212213
else {
213-
const addrs = await dnsResolverSrv(this.logger, this.sip_realm, this.transport);
214+
const addrs = await dnsResolverSrv(this.logger, this.ipv4, this.transport);
214215
this.addresses.push(...addrs);
215216
}
216217

0 commit comments

Comments
 (0)