Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
a77c431e
Commit
a77c431e
authored
Mar 30, 2015
by
Felix Lange
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
p2p/discover: fix off by one error causing buckets to contain duplicates
parent
de7af720
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
1 deletion
+43
-1
table.go
p2p/discover/table.go
+1
-1
table_test.go
p2p/discover/table_test.go
+42
-0
No files found.
p2p/discover/table.go
View file @
a77c431e
...
...
@@ -328,7 +328,7 @@ func (b *bucket) bump(n *Node) bool {
if
b
.
entries
[
i
]
.
ID
==
n
.
ID
{
n
.
bumpActive
()
// move it to the front
copy
(
b
.
entries
[
1
:
],
b
.
entries
[
:
i
+
1
])
copy
(
b
.
entries
[
1
:
],
b
.
entries
[
:
i
])
b
.
entries
[
0
]
=
n
return
true
}
...
...
p2p/discover/table_test.go
View file @
a77c431e
...
...
@@ -66,6 +66,48 @@ func TestTable_pingReplace(t *testing.T) {
doit
(
false
,
false
)
}
func
TestBucket_bumpNoDuplicates
(
t
*
testing
.
T
)
{
t
.
Parallel
()
cfg
:=
&
quick
.
Config
{
MaxCount
:
1000
,
Rand
:
quickrand
,
Values
:
func
(
args
[]
reflect
.
Value
,
rand
*
rand
.
Rand
)
{
// generate a random list of nodes. this will be the content of the bucket.
n
:=
rand
.
Intn
(
bucketSize
-
1
)
+
1
nodes
:=
make
([]
*
Node
,
n
)
for
i
:=
range
nodes
{
nodes
[
i
]
=
&
Node
{
ID
:
randomID
(
NodeID
{},
200
)}
}
args
[
0
]
=
reflect
.
ValueOf
(
nodes
)
// generate random bump positions.
bumps
:=
make
([]
int
,
rand
.
Intn
(
100
))
for
i
:=
range
bumps
{
bumps
[
i
]
=
rand
.
Intn
(
len
(
nodes
))
}
args
[
1
]
=
reflect
.
ValueOf
(
bumps
)
},
}
prop
:=
func
(
nodes
[]
*
Node
,
bumps
[]
int
)
(
ok
bool
)
{
b
:=
&
bucket
{
entries
:
make
([]
*
Node
,
len
(
nodes
))}
copy
(
b
.
entries
,
nodes
)
for
i
,
pos
:=
range
bumps
{
b
.
bump
(
b
.
entries
[
pos
])
if
hasDuplicates
(
b
.
entries
)
{
t
.
Logf
(
"bucket has duplicates after %d/%d bumps:"
,
i
+
1
,
len
(
bumps
))
for
_
,
n
:=
range
b
.
entries
{
t
.
Logf
(
" %p"
,
n
)
}
return
false
}
}
return
true
}
if
err
:=
quick
.
Check
(
prop
,
cfg
);
err
!=
nil
{
t
.
Error
(
err
)
}
}
func
fillBucket
(
tab
*
Table
,
ld
int
)
(
last
*
Node
)
{
b
:=
tab
.
buckets
[
ld
]
for
len
(
b
.
entries
)
<
bucketSize
{
...
...
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