Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
duniter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nodes
typescript
duniter
Commits
6cfb3992
Commit
6cfb3992
authored
6 years ago
by
Cédric Moreau
Browse files
Options
Downloads
Patches
Plain Diff
[enh] UPnP: priorize Ethernet IP
parent
19719cc8
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/modules/upnp-provider.ts
+51
-1
51 additions, 1 deletion
app/modules/upnp-provider.ts
with
51 additions
and
1 deletion
app/modules/upnp-provider.ts
+
51
−
1
View file @
6cfb3992
...
...
@@ -11,6 +11,9 @@
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
import
*
as
os
from
"
os
"
import
{
Underscore
}
from
"
../lib/common-libs/underscore
"
const
upnp
=
require
(
'
nat-upnp
'
);
export
interface
UPnPBinding
{
...
...
@@ -33,7 +36,11 @@ export class UpnpProvider {
private
ttl
=
600
,
private
logger
?:
any
,
private
host
=
''
)
{}
)
{
if
(
!
host
)
{
this
.
host
=
this
.
getBestHostForUPnP
()
}
}
async
checkUPnPisAvailable
()
{
try
{
...
...
@@ -167,4 +174,47 @@ export class UpnpProvider {
})
})
}
/**
* Apparently on computers with both Wi-Fi and Ethernet, UPnP fails to open the port.
* Giving the priority to Ethernet seems to fix the problem.
* @param family
*/
private
getBestHostForUPnP
(
family
=
''
)
{
let
netInterfaces
=
os
.
networkInterfaces
()
let
keys
=
Underscore
.
keys
(
netInterfaces
)
let
res
=
[];
for
(
const
name
of
keys
)
{
let
addresses
=
netInterfaces
[
name
]
for
(
const
addr
of
addresses
)
{
if
(
!
family
||
addr
.
family
==
family
)
{
res
.
push
({
name
:
name
,
value
:
addr
.
address
})
}
}
}
const
interfacePriorityRegCatcher
=
[
/^tun
\d
+/
,
/^enp
\d
+s
\d
+/
,
/^enp
\d
+s
\d
+f
\d
+/
,
/^eth
\d
+/
,
/^Ethernet/
,
/^wlp
\d
+s
\d
+/
,
/^wlan
\d
+/
,
/^Wi-Fi/
,
/^lo/
,
/^Loopback/
,
/^None/
]
const
best
=
Underscore
.
sortBy
(
res
,
function
(
entry
:
any
)
{
for
(
let
i
=
0
;
i
<
interfacePriorityRegCatcher
.
length
;
i
++
)
{
// `i` is the priority (0 is the better, 1 is the second, ...)
if
(
entry
.
name
.
match
(
interfacePriorityRegCatcher
[
i
]))
return
i
}
return
interfacePriorityRegCatcher
.
length
})[
0
]
return
(
best
&&
best
.
value
)
||
""
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment