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
9839d64f
Commit
9839d64f
authored
Jun 01, 2015
by
Jeromy
Browse files
move util.Key into its own package under blocks
parent
78a6ca3f
Changes
4
Hide whitespace changes
Inline
Side-by-side
net/conn/conn.go
View file @
9839d64f
...
...
@@ -157,7 +157,7 @@ func ID(c Conn) string {
lh
:=
u
.
Hash
([]
byte
(
l
))
rh
:=
u
.
Hash
([]
byte
(
r
))
ch
:=
u
.
XOR
(
lh
,
rh
)
return
u
.
Key
(
ch
)
.
Pretty
()
return
peer
.
ID
(
ch
)
.
Pretty
()
}
// String returns the user-friendly String representation of a conn
...
...
net/conn/interface.go
View file @
9839d64f
...
...
@@ -5,9 +5,9 @@ import (
"net"
"time"
key
"github.com/ipfs/go-ipfs/blocks/key"
ic
"github.com/ipfs/go-ipfs/p2p/crypto"
peer
"github.com/ipfs/go-ipfs/p2p/peer"
u
"github.com/ipfs/go-ipfs/util"
msgio
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-msgio"
ma
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
...
...
@@ -15,7 +15,7 @@ import (
)
// Map maps Keys (Peer.IDs) to Connections.
type
Map
map
[
u
.
Key
]
Conn
type
Map
map
[
key
.
Key
]
Conn
type
PeerConn
interface
{
io
.
Closer
...
...
peer/queue/distance.go
View file @
9839d64f
...
...
@@ -5,9 +5,9 @@ import (
"math/big"
"sync"
key
"github.com/ipfs/go-ipfs/blocks/key"
peer
"github.com/ipfs/go-ipfs/p2p/peer"
ks
"github.com/ipfs/go-ipfs/routing/keyspace"
u
"github.com/ipfs/go-ipfs/util"
)
// peerMetric tracks a peer and its distance to something else.
...
...
@@ -93,7 +93,7 @@ func (pq *distancePQ) Dequeue() peer.ID {
// NewXORDistancePQ returns a PeerQueue which maintains its peers sorted
// in terms of their distances to each other in an XORKeySpace (i.e. using
// XOR as a metric of distance).
func
NewXORDistancePQ
(
fromKey
u
.
Key
)
PeerQueue
{
func
NewXORDistancePQ
(
fromKey
key
.
Key
)
PeerQueue
{
return
&
distancePQ
{
from
:
ks
.
XORKeySpace
.
Key
([]
byte
(
fromKey
)),
heap
:
peerMetricHeap
{},
...
...
peer/queue/queue_test.go
View file @
9839d64f
...
...
@@ -6,6 +6,7 @@ import (
"testing"
"time"
key
"github.com/ipfs/go-ipfs/blocks/key"
peer
"github.com/ipfs/go-ipfs/p2p/peer"
u
"github.com/ipfs/go-ipfs/util"
...
...
@@ -27,7 +28,7 @@ func TestQueue(t *testing.T) {
// [78 135 26 216 178 181 224 181 234 117 2 248 152 115 255 103 244 34 4 152 193 88 9 225 8 127 216 158 226 8 236 246]
// [125 135 124 6 226 160 101 94 192 57 39 12 18 79 121 140 190 154 147 55 44 83 101 151 63 255 94 179 51 203 241 51]
pq
:=
NewXORDistancePQ
(
u
.
Key
(
"11140beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a31"
))
pq
:=
NewXORDistancePQ
(
key
.
Key
(
"11140beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a31"
))
pq
.
Enqueue
(
p3
)
pq
.
Enqueue
(
p1
)
pq
.
Enqueue
(
p2
)
...
...
@@ -81,7 +82,7 @@ func TestSyncQueue(t *testing.T) {
}
ctx
:=
context
.
Background
()
pq
:=
NewXORDistancePQ
(
u
.
Key
(
"11140beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a31"
))
pq
:=
NewXORDistancePQ
(
key
.
Key
(
"11140beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a31"
))
cq
:=
NewChanQueue
(
ctx
,
pq
)
wg
:=
sync
.
WaitGroup
{}
...
...
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