|
1 | 1 | /* Copyright (C) 2016 NooBaa */
|
2 |
| -/* eslint max-lines: ['error', 1550] */ |
| 2 | +/* eslint max-lines: ['error', 1650] */ |
3 | 3 | 'use strict';
|
4 | 4 |
|
5 | 5 | module.exports = Ice;
|
@@ -450,7 +450,7 @@ Ice.prototype._add_tcp_transient_passive_candidates = function() {
|
450 | 450 | conn.destroy();
|
451 | 451 | return;
|
452 | 452 | }
|
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); |
454 | 454 | self._init_tcp_connection(conn);
|
455 | 455 | });
|
456 | 456 |
|
@@ -764,9 +764,9 @@ Ice.prototype._init_tcp_connection = function(conn, session) {
|
764 | 764 | function init_tcp_connection(conn, session, ice, ice_lookup) {
|
765 | 765 | const info = {
|
766 | 766 | family: conn.remoteFamily,
|
767 |
| - address: conn.remoteAddress, |
| 767 | + address: get_connection_remote_address(conn), |
768 | 768 | 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), |
770 | 770 | tcp: conn,
|
771 | 771 | transport: 'tcp',
|
772 | 772 | session: session,
|
@@ -1308,12 +1308,19 @@ Ice.prototype.close = function() {
|
1308 | 1308 |
|
1309 | 1309 |
|
1310 | 1310 | 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 | + }; |
1311 | 1318 | // the key is used finding duplicates or locating the candidate
|
1312 | 1319 | // on successful connect check, so is crucial to identify exactly
|
1313 | 1320 | // the needed properties, not less, and no more.
|
1314 | 1321 | cand.key = make_candidate_key(cand.transport, cand.family, cand.address, cand.port);
|
1315 | 1322 | cand.priority =
|
1316 |
| - (ip_module.isPrivate(cand.address) ? 1000 : 0) + |
| 1323 | + (is_private_no_throw(cand.address) ? 1000 : 0) + |
1317 | 1324 | (cand.transport === 'tcp' ? 100 : 0) +
|
1318 | 1325 | // (cand.family === 'IPv4' ? 10 : 0) +
|
1319 | 1326 | (cand.tcp_type === CAND_TCP_TYPE_SO ? 0 : 1);
|
@@ -1537,3 +1544,10 @@ function allocate_port_in_range(port_range) {
|
1537 | 1544 | return port;
|
1538 | 1545 | });
|
1539 | 1546 | }
|
| 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