Skip to content

Commit f924d96

Browse files
authored
Merge pull request #8535 from dannyzaken/danny-fixes
remove link-local suffix from remoteAddress in ice.js
2 parents 7bc42c2 + 5df7894 commit f924d96

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

src/rpc/ice.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* Copyright (C) 2016 NooBaa */
2-
/* eslint max-lines: ['error', 1550] */
2+
/* eslint max-lines: ['error', 1650] */
33
'use strict';
44

55
module.exports = Ice;
@@ -450,7 +450,7 @@ Ice.prototype._add_tcp_transient_passive_candidates = function() {
450450
conn.destroy();
451451
return;
452452
}
453-
dbg.log3('ICE TCP ACCEPTED CONNECTION', conn.remoteAddress + ':' + conn.remotePort);
453+
dbg.log3('ICE TCP ACCEPTED CONNECTION', get_connection_remote_address(conn) + ':' + conn.remotePort);
454454
self._init_tcp_connection(conn);
455455
});
456456

@@ -764,9 +764,9 @@ Ice.prototype._init_tcp_connection = function(conn, session) {
764764
function init_tcp_connection(conn, session, ice, ice_lookup) {
765765
const info = {
766766
family: conn.remoteFamily,
767-
address: conn.remoteAddress,
767+
address: get_connection_remote_address(conn),
768768
port: conn.remotePort,
769-
key: make_candidate_key('tcp', conn.remoteFamily, conn.remoteAddress, conn.remotePort),
769+
key: make_candidate_key('tcp', conn.remoteFamily, get_connection_remote_address(conn), conn.remotePort),
770770
tcp: conn,
771771
transport: 'tcp',
772772
session: session,
@@ -1308,12 +1308,19 @@ Ice.prototype.close = function() {
13081308

13091309

13101310
function IceCandidate(cand) {
1311+
const is_private_no_throw = address => {
1312+
try {
1313+
return ip_module.isPrivate(address);
1314+
} catch (err) {
1315+
return false;
1316+
}
1317+
};
13111318
// the key is used finding duplicates or locating the candidate
13121319
// on successful connect check, so is crucial to identify exactly
13131320
// the needed properties, not less, and no more.
13141321
cand.key = make_candidate_key(cand.transport, cand.family, cand.address, cand.port);
13151322
cand.priority =
1316-
(ip_module.isPrivate(cand.address) ? 1000 : 0) +
1323+
(is_private_no_throw(cand.address) ? 1000 : 0) +
13171324
(cand.transport === 'tcp' ? 100 : 0) +
13181325
// (cand.family === 'IPv4' ? 10 : 0) +
13191326
(cand.tcp_type === CAND_TCP_TYPE_SO ? 0 : 1);
@@ -1537,3 +1544,10 @@ function allocate_port_in_range(port_range) {
15371544
return port;
15381545
});
15391546
}
1547+
1548+
1549+
// get remote address from the connection and remove the link-local suffix (e.g.: %eth0)
1550+
function get_connection_remote_address(conn) {
1551+
const ip = conn.remoteAddress;
1552+
return ip.split('%')[0];
1553+
}

0 commit comments

Comments
 (0)