Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
go-libp2p
Commits
ec8044c7
Commit
ec8044c7
authored
Jun 15, 2016
by
Jeromy Johnson
Committed by
GitHub
Jun 15, 2016
Browse files
Merge pull request #69 from ipfs/fix/nat-cache-sync
fix minor race condition in nat detection code
parents
5100dcec
eca66a88
Changes
1
Hide whitespace changes
Inline
Side-by-side
p2p/nat/nat.go
View file @
ec8044c7
...
...
@@ -164,6 +164,7 @@ type mapping struct {
cached
ma
.
Multiaddr
cacheTime
time
.
Time
cacheLk
sync
.
Mutex
}
func
(
m
*
mapping
)
NAT
()
*
NAT
{
...
...
@@ -203,8 +204,12 @@ func (m *mapping) InternalAddr() ma.Multiaddr {
}
func
(
m
*
mapping
)
ExternalAddr
()
(
ma
.
Multiaddr
,
error
)
{
if
time
.
Now
()
.
Sub
(
m
.
cacheTime
)
<
CacheTime
{
return
m
.
cached
,
nil
m
.
cacheLk
.
Lock
()
ctime
:=
m
.
cacheTime
cval
:=
m
.
cached
m
.
cacheLk
.
Unlock
()
if
time
.
Now
()
.
Sub
(
ctime
)
<
CacheTime
{
return
cval
,
nil
}
if
m
.
ExternalPort
()
==
0
{
// dont even try right now.
...
...
@@ -234,8 +239,10 @@ func (m *mapping) ExternalAddr() (ma.Multiaddr, error) {
maddr2
:=
ipmaddr
.
Encapsulate
(
tcp
)
m
.
cacheLk
.
Lock
()
m
.
cached
=
maddr2
m
.
cacheTime
=
time
.
Now
()
m
.
cacheLk
.
Unlock
()
return
maddr2
,
nil
}
...
...
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