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-bitswap
Commits
84f61d6a
Commit
84f61d6a
authored
Aug 22, 2019
by
Dirk McCormick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: move rand outside lock
parent
95de8551
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
1 deletion
+4
-1
session/sessionwants.go
session/sessionwants.go
+4
-1
No files found.
session/sessionwants.go
View file @
84f61d6a
package
session
import
(
"math"
"math/rand"
"sync"
"time"
...
...
@@ -133,13 +134,15 @@ func (sw *sessionWants) LiveWants() []cid.Cid {
// RandomLiveWant returns a randomly selected live want
func
(
sw
*
sessionWants
)
RandomLiveWant
()
cid
.
Cid
{
r
:=
rand
.
Float64
()
sw
.
RLock
()
defer
sw
.
RUnlock
()
if
len
(
sw
.
liveWants
)
==
0
{
return
cid
.
Cid
{}
}
i
:=
rand
.
Intn
(
len
(
sw
.
liveWants
))
i
:=
math
.
Floor
(
r
*
float64
(
len
(
sw
.
liveWants
))
)
// picking a random live want
for
k
:=
range
sw
.
liveWants
{
if
i
==
0
{
...
...
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