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-kad-dht
Commits
b33ccf39
Unverified
Commit
b33ccf39
authored
Apr 09, 2020
by
Steven Allen
Committed by
GitHub
Apr 09, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #581 from libp2p/fix/dedup-addresses
fix: dedup addresses
parents
bfa23ff8
8634c92c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
5 deletions
+20
-5
dual/dual.go
dual/dual.go
+16
-1
dual/dual_test.go
dual/dual_test.go
+4
-4
No files found.
dual/dual.go
View file @
b33ccf39
...
...
@@ -15,6 +15,8 @@ import (
dht
"github.com/libp2p/go-libp2p-kad-dht"
helper
"github.com/libp2p/go-libp2p-routing-helpers"
ma
"github.com/multiformats/go-multiaddr"
"github.com/hashicorp/go-multierror"
)
...
...
@@ -151,9 +153,22 @@ func (dht *DHT) FindPeer(ctx context.Context, pid peer.ID) (peer.AddrInfo, error
wg
.
Wait
()
// combine addresses
deduped
:=
make
(
map
[
string
]
ma
.
Multiaddr
,
len
(
wanInfo
.
Addrs
)
+
len
(
lanInfo
.
Addrs
))
for
_
,
addr
:=
range
wanInfo
.
Addrs
{
deduped
[
string
(
addr
.
Bytes
())]
=
addr
}
for
_
,
addr
:=
range
lanInfo
.
Addrs
{
deduped
[
string
(
addr
.
Bytes
())]
=
addr
}
addrs
:=
make
([]
ma
.
Multiaddr
,
0
,
len
(
deduped
))
for
_
,
addr
:=
range
deduped
{
addrs
=
append
(
addrs
,
addr
)
}
return
peer
.
AddrInfo
{
ID
:
pid
,
Addrs
:
a
ppend
(
wanInfo
.
Addrs
,
lanInfo
.
Addrs
...
)
,
Addrs
:
a
ddrs
,
},
multierror
.
Append
(
wanErr
,
lanErr
)
.
ErrorOrNil
()
}
...
...
dual/dual_test.go
View file @
b33ccf39
...
...
@@ -356,14 +356,14 @@ func TestFindPeer(t *testing.T) {
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
len
(
p
.
Addrs
)
=
=
0
{
t
.
Fatal
(
"expeced find peer to find address
es."
)
if
len
(
p
.
Addrs
)
!
=
1
{
t
.
Fatal
f
(
"expeced find peer to find
1
address
, found %d"
,
len
(
p
.
Addrs
)
)
}
p
,
err
=
d
.
FindPeer
(
ctx
,
wan
.
PeerID
())
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
len
(
p
.
Addrs
)
=
=
0
{
t
.
Fatal
(
"expeced find peer to find addresses
."
)
if
len
(
p
.
Addrs
)
!
=
1
{
t
.
Fatal
f
(
"expeced find peer to find addresses
, found %d"
,
len
(
p
.
Addrs
)
)
}
}
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