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-p2p-swarm
Commits
a37c480a
Commit
a37c480a
authored
Jun 04, 2019
by
Jakub Sztandera
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: cache full InterfaceListenAddresses
License: MIT Signed-off-by:
Jakub Sztandera
<
kubuxu@protonmail.ch
>
parent
9f9dd240
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
13 deletions
+13
-13
swarm.go
swarm.go
+2
-2
swarm_addr.go
swarm_addr.go
+11
-11
No files found.
swarm.go
View file @
a37c480a
...
...
@@ -60,7 +60,7 @@ type Swarm struct {
listeners
struct
{
sync
.
RWMutex
ifaceAddres
ses
[]
ma
.
Multiaddr
iface
Listen
Addres
[]
ma
.
Multiaddr
cacheEOL
time
.
Time
m
map
[
transport
.
Listener
]
struct
{}
...
...
swarm_addr.go
View file @
a37c480a
...
...
@@ -29,15 +29,14 @@ const ifaceAddrsCacheDuration = 1 * time.Minute
// use the known local interfaces.
func
(
s
*
Swarm
)
InterfaceListenAddresses
()
([]
ma
.
Multiaddr
,
error
)
{
s
.
listeners
.
RLock
()
// RLock start
listenAddrs
:=
s
.
listenAddressesNoLock
()
ifaceAddrs
:=
s
.
listeners
.
ifaceAddres
ses
iface
Listen
Addr
e
s
:=
s
.
listeners
.
iface
Listen
Addres
isEOL
:=
time
.
Now
()
.
After
(
s
.
listeners
.
cacheEOL
)
s
.
listeners
.
RUnlock
()
// RLock end
if
l
istenAddrs
!=
nil
&&
!
isEOL
{
if
ifaceL
istenAddr
e
s
!=
nil
&&
!
isEOL
{
// Cache is valid
return
addrutil
.
ResolveUnspecifiedAddresses
(
l
istenAddrs
,
ifaceAddrs
)
return
ifaceL
istenAddr
e
s
,
nil
}
// Cache is not valid
...
...
@@ -45,24 +44,25 @@ func (s *Swarm) InterfaceListenAddresses() ([]ma.Multiaddr, error) {
s
.
listeners
.
Lock
()
// Lock start
listenAddrs
=
s
.
listenAddressesNoLock
()
ifaceAddrs
=
s
.
listeners
.
ifaceAddresses
ifaceListenAddres
=
s
.
listeners
.
ifaceListenAddres
isEOL
=
time
.
Now
()
.
After
(
s
.
listeners
.
cacheEOL
)
if
l
istenAddrs
==
nil
||
isEOL
{
if
ifaceL
istenAddr
e
s
==
nil
||
isEOL
{
// Cache is still invalid
var
err
error
ifaceAddrs
,
err
=
addrutil
.
InterfaceAddresses
()
ifaceListenAddres
,
err
=
addrutil
.
ResolveUnspecifiedAddresses
(
s
.
listenAddressesNoLock
(),
nil
)
if
err
!=
nil
{
s
.
listeners
.
Unlock
()
// Lock early exit
return
nil
,
err
}
s
.
listeners
.
ifaceAddres
ses
=
ifaceAddrs
s
.
listeners
.
iface
Listen
Addres
=
iface
Listen
Addr
e
s
s
.
listeners
.
cacheEOL
=
time
.
Now
()
.
Add
(
ifaceAddrsCacheDuration
)
}
s
.
listeners
.
Unlock
()
// Lock end
return
addrutil
.
ResolveUnspecifiedAddresses
(
l
istenAddrs
,
ifaceAddrs
)
return
ifaceL
istenAddr
e
s
,
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