Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
p2p
go-nat
Commits
3fa58ced
Commit
3fa58ced
authored
Sep 13, 2018
by
Can ZHANG
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Try to map external port the same as internal port
parent
66a3ad4c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
0 deletions
+13
-0
natpmp.go
natpmp.go
+7
-0
upnp.go
upnp.go
+6
-0
No files found.
natpmp.go
View file @
3fa58ced
...
@@ -93,6 +93,13 @@ func (n *natpmpNAT) AddPortMapping(protocol string, internalPort int, descriptio
...
@@ -93,6 +93,13 @@ func (n *natpmpNAT) AddPortMapping(protocol string, internalPort int, descriptio
}
}
}
}
// try to map external port the same as internal port
_
,
err
=
n
.
c
.
AddPortMapping
(
protocol
,
internalPort
,
internalPort
,
timeoutInSeconds
)
if
err
==
nil
{
n
.
ports
[
internalPort
]
=
internalPort
return
internalPort
,
nil
}
for
i
:=
0
;
i
<
3
;
i
++
{
for
i
:=
0
;
i
<
3
;
i
++
{
externalPort
:=
randomPort
()
externalPort
:=
randomPort
()
_
,
err
=
n
.
c
.
AddPortMapping
(
protocol
,
internalPort
,
externalPort
,
timeoutInSeconds
)
_
,
err
=
n
.
c
.
AddPortMapping
(
protocol
,
internalPort
,
externalPort
,
timeoutInSeconds
)
...
...
upnp.go
View file @
3fa58ced
...
@@ -176,6 +176,12 @@ func (u *upnp_NAT) AddPortMapping(protocol string, internalPort int, description
...
@@ -176,6 +176,12 @@ func (u *upnp_NAT) AddPortMapping(protocol string, internalPort int, description
}
}
}
}
// try to map external port the same as internal port
err
=
u
.
c
.
AddPortMapping
(
""
,
uint16
(
internalPort
),
mapProtocol
(
protocol
),
uint16
(
internalPort
),
ip
.
String
(),
true
,
description
,
timeoutInSeconds
)
if
err
==
nil
{
return
internalPort
,
nil
}
for
i
:=
0
;
i
<
3
;
i
++
{
for
i
:=
0
;
i
<
3
;
i
++
{
externalPort
:=
randomPort
()
externalPort
:=
randomPort
()
err
=
u
.
c
.
AddPortMapping
(
""
,
uint16
(
externalPort
),
mapProtocol
(
protocol
),
uint16
(
internalPort
),
ip
.
String
(),
true
,
description
,
timeoutInSeconds
)
err
=
u
.
c
.
AddPortMapping
(
""
,
uint16
(
externalPort
),
mapProtocol
(
protocol
),
uint16
(
internalPort
),
ip
.
String
(),
true
,
description
,
timeoutInSeconds
)
...
...
tavit ohanian
@tavit
mentioned in commit
523cb01f
·
Jul 10, 2021
mentioned in commit
523cb01f
mentioned in commit 523cb01fafd52a886eff7de2af8c2846322e761f
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment