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
955ebe34
Unverified
Commit
955ebe34
authored
Apr 22, 2017
by
Jakub Sztandera
Browse files
Fix obsaddr_test compare function
parent
356f5ab1
Changes
2
Hide whitespace changes
Inline
Side-by-side
p2p/protocol/identify/obsaddr.go
View file @
955ebe34
...
...
@@ -63,9 +63,7 @@ func (oas *ObservedAddrSet) Addrs() []ma.Multiaddr {
continue
}
if
a
.
Activated
{
addrs
=
append
(
addrs
,
a
.
Addr
)
}
else
if
a
.
TryActivate
(
oas
.
ttl
)
{
if
a
.
Activated
||
a
.
TryActivate
(
oas
.
ttl
)
{
addrs
=
append
(
addrs
,
a
.
Addr
)
}
}
...
...
p2p/protocol/identify/obsaddr_test.go
View file @
955ebe34
...
...
@@ -18,6 +18,10 @@ func TestObsAddrSet(t *testing.T) {
}
addrsMarch
:=
func
(
a
,
b
[]
ma
.
Multiaddr
)
bool
{
if
len
(
a
)
!=
len
(
b
)
{
return
false
}
for
_
,
aa
:=
range
a
{
found
:=
false
for
_
,
bb
:=
range
b
{
...
...
@@ -38,8 +42,12 @@ func TestObsAddrSet(t *testing.T) {
a3
:=
m
(
"/ip4/1.2.3.4/tcp/1233"
)
a4
:=
m
(
"/ip4/1.2.3.4/tcp/1234"
)
a5
:=
m
(
"/ip4/1.2.3.4/tcp/1235"
)
a6
:=
m
(
"/ip4/1.2.3.6/tcp/1236"
)
a7
:=
m
(
"/ip4/1.2.3.7/tcp/1237"
)
b1
:=
m
(
"/ip4/1.2.3.6/tcp/1236"
)
b2
:=
m
(
"/ip4/1.2.3.7/tcp/1237"
)
b3
:=
m
(
"/ip4/1.2.3.8/tcp/1237"
)
b4
:=
m
(
"/ip4/1.2.3.9/tcp/1237"
)
b5
:=
m
(
"/ip4/1.2.3.10/tcp/1237"
)
oas
:=
ObservedAddrSet
{}
...
...
@@ -72,7 +80,9 @@ func TestObsAddrSet(t *testing.T) {
t
.
Error
(
"addrs should _still_ be empty (same obs group)"
)
}
oas
.
Add
(
a1
,
a6
)
oas
.
Add
(
a1
,
b1
)
oas
.
Add
(
a1
,
b2
)
oas
.
Add
(
a1
,
b3
)
if
!
addrsMarch
(
oas
.
Addrs
(),
[]
ma
.
Multiaddr
{
a1
})
{
t
.
Error
(
"addrs should only have a1"
)
}
...
...
@@ -80,12 +90,14 @@ func TestObsAddrSet(t *testing.T) {
oas
.
Add
(
a2
,
a5
)
oas
.
Add
(
a1
,
a5
)
oas
.
Add
(
a1
,
a5
)
oas
.
Add
(
a2
,
a6
)
oas
.
Add
(
a1
,
a6
)
oas
.
Add
(
a1
,
a6
)
oas
.
Add
(
a2
,
a7
)
oas
.
Add
(
a1
,
a7
)
oas
.
Add
(
a1
,
a7
)
oas
.
Add
(
a2
,
b1
)
oas
.
Add
(
a1
,
b1
)
oas
.
Add
(
a1
,
b1
)
oas
.
Add
(
a2
,
b2
)
oas
.
Add
(
a1
,
b2
)
oas
.
Add
(
a1
,
b2
)
oas
.
Add
(
a2
,
b4
)
oas
.
Add
(
a2
,
b5
)
if
!
addrsMarch
(
oas
.
Addrs
(),
[]
ma
.
Multiaddr
{
a1
,
a2
})
{
t
.
Error
(
"addrs should only have a1, a2"
)
}
...
...
@@ -93,7 +105,7 @@ func TestObsAddrSet(t *testing.T) {
// change the timeout constant so we can time it out.
oas
.
SetTTL
(
time
.
Millisecond
*
200
)
<-
time
.
After
(
time
.
Millisecond
*
210
)
if
!
addrsMarch
(
oas
.
Addrs
(),
[]
ma
.
Multiaddr
{
nil
}
)
{
if
!
addrsMarch
(
oas
.
Addrs
(),
nil
)
{
t
.
Error
(
"addrs should have timed out"
)
}
}
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