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
dms3
go-dms3
Commits
5ecc4e89
Commit
5ecc4e89
authored
9 years ago
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use ALL THE ADDRESSES!
parent
04f77316
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
9 deletions
+12
-9
p2p/discovery/mdns.go
p2p/discovery/mdns.go
+12
-9
No files found.
p2p/discovery/mdns.go
View file @
5ecc4e89
...
...
@@ -42,21 +42,22 @@ type mdnsService struct {
interval
time
.
Duration
}
func
getDialableListenAddr
(
ph
host
.
Host
)
(
*
net
.
TCPAddr
,
error
)
{
func
getDialableListenAddrs
(
ph
host
.
Host
)
([]
*
net
.
TCPAddr
,
error
)
{
var
out
[]
*
net
.
TCPAddr
for
_
,
addr
:=
range
ph
.
Addrs
()
{
if
manet
.
IsIPLoopback
(
addr
)
{
continue
}
na
,
err
:=
manet
.
ToNetAddr
(
addr
)
if
err
!=
nil
{
continue
}
tcp
,
ok
:=
na
.
(
*
net
.
TCPAddr
)
if
ok
{
return
tcp
,
nil
out
=
append
(
out
,
tcp
)
}
}
return
nil
,
errors
.
New
(
"failed to find good external addr from peerhost"
)
if
len
(
out
)
==
0
{
return
nil
,
errors
.
New
(
"failed to find good external addr from peerhost"
)
}
return
out
,
nil
}
func
NewMdnsService
(
peerhost
host
.
Host
,
interval
time
.
Duration
)
(
Service
,
error
)
{
...
...
@@ -67,12 +68,14 @@ func NewMdnsService(peerhost host.Host, interval time.Duration) (Service, error)
var
ipaddrs
[]
net
.
IP
port
:=
4001
addr
,
err
:=
getDialableListenAddr
(
peerhost
)
addr
s
,
err
:=
getDialableListenAddr
s
(
peerhost
)
if
err
!=
nil
{
log
.
Warning
(
err
)
}
else
{
ipaddrs
=
[]
net
.
IP
{
addr
.
IP
}
port
=
addr
.
Port
port
=
addrs
[
0
]
.
Port
for
_
,
a
:=
range
addrs
{
ipaddrs
=
append
(
ipaddrs
,
a
.
IP
)
}
}
myid
:=
peerhost
.
ID
()
.
Pretty
()
...
...
This diff is collapsed.
Click to expand it.
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