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-unixfs
Commits
51eeec1a
Commit
51eeec1a
authored
Sep 17, 2014
by
Juan Batiz-Benet
Committed by
Brian Tiger Chow
Sep 22, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sync safety to pq
parent
a21c1b6b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
3 deletions
+12
-3
peer/queue/distance.go
peer/queue/distance.go
+12
-3
No files found.
peer/queue/distance.go
View file @
51eeec1a
...
...
@@ -3,6 +3,7 @@ package queue
import
(
"container/heap"
"math/big"
"sync"
peer
"github.com/jbenet/go-ipfs/peer"
ks
"github.com/jbenet/go-ipfs/routing/keyspace"
...
...
@@ -25,17 +26,19 @@ type distancePQ struct {
// peers is a heap of peerDistance items
peers
[]
*
peerDistance
sync
.
RWMutex
}
func
(
pq
distancePQ
)
Len
()
int
{
func
(
pq
*
distancePQ
)
Len
()
int
{
return
len
(
pq
.
peers
)
}
func
(
pq
distancePQ
)
Less
(
i
,
j
int
)
bool
{
func
(
pq
*
distancePQ
)
Less
(
i
,
j
int
)
bool
{
return
-
1
==
pq
.
peers
[
i
]
.
distance
.
Cmp
(
pq
.
peers
[
j
]
.
distance
)
}
func
(
pq
distancePQ
)
Swap
(
i
,
j
int
)
{
func
(
pq
*
distancePQ
)
Swap
(
i
,
j
int
)
{
p
:=
pq
.
peers
p
[
i
],
p
[
j
]
=
p
[
j
],
p
[
i
]
}
...
...
@@ -54,6 +57,9 @@ func (pq *distancePQ) Pop() interface{} {
}
func
(
pq
*
distancePQ
)
Enqueue
(
p
*
peer
.
Peer
)
{
pq
.
Lock
()
defer
pq
.
Unlock
()
distance
:=
ks
.
XORKeySpace
.
Key
(
p
.
ID
)
.
Distance
(
pq
.
from
)
heap
.
Push
(
pq
,
&
peerDistance
{
...
...
@@ -63,6 +69,9 @@ func (pq *distancePQ) Enqueue(p *peer.Peer) {
}
func
(
pq
*
distancePQ
)
Dequeue
()
*
peer
.
Peer
{
pq
.
Lock
()
defer
pq
.
Unlock
()
if
len
(
pq
.
peers
)
<
1
{
panic
(
"called Dequeue on an empty PeerQueue"
)
// will panic internally anyway, but we can help debug here
...
...
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