Commit 9839d64f authored by Jeromy's avatar Jeromy
Browse files

move util.Key into its own package under blocks

parent 78a6ca3f
...@@ -157,7 +157,7 @@ func ID(c Conn) string { ...@@ -157,7 +157,7 @@ func ID(c Conn) string {
lh := u.Hash([]byte(l)) lh := u.Hash([]byte(l))
rh := u.Hash([]byte(r)) rh := u.Hash([]byte(r))
ch := u.XOR(lh, rh) 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 // String returns the user-friendly String representation of a conn
......
...@@ -5,9 +5,9 @@ import ( ...@@ -5,9 +5,9 @@ import (
"net" "net"
"time" "time"
key "github.com/ipfs/go-ipfs/blocks/key"
ic "github.com/ipfs/go-ipfs/p2p/crypto" ic "github.com/ipfs/go-ipfs/p2p/crypto"
peer "github.com/ipfs/go-ipfs/p2p/peer" 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" 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" ma "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
...@@ -15,7 +15,7 @@ import ( ...@@ -15,7 +15,7 @@ import (
) )
// Map maps Keys (Peer.IDs) to Connections. // Map maps Keys (Peer.IDs) to Connections.
type Map map[u.Key]Conn type Map map[key.Key]Conn
type PeerConn interface { type PeerConn interface {
io.Closer io.Closer
......
...@@ -5,9 +5,9 @@ import ( ...@@ -5,9 +5,9 @@ import (
"math/big" "math/big"
"sync" "sync"
key "github.com/ipfs/go-ipfs/blocks/key"
peer "github.com/ipfs/go-ipfs/p2p/peer" peer "github.com/ipfs/go-ipfs/p2p/peer"
ks "github.com/ipfs/go-ipfs/routing/keyspace" 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. // peerMetric tracks a peer and its distance to something else.
...@@ -93,7 +93,7 @@ func (pq *distancePQ) Dequeue() peer.ID { ...@@ -93,7 +93,7 @@ func (pq *distancePQ) Dequeue() peer.ID {
// NewXORDistancePQ returns a PeerQueue which maintains its peers sorted // NewXORDistancePQ returns a PeerQueue which maintains its peers sorted
// in terms of their distances to each other in an XORKeySpace (i.e. using // in terms of their distances to each other in an XORKeySpace (i.e. using
// XOR as a metric of distance). // XOR as a metric of distance).
func NewXORDistancePQ(fromKey u.Key) PeerQueue { func NewXORDistancePQ(fromKey key.Key) PeerQueue {
return &distancePQ{ return &distancePQ{
from: ks.XORKeySpace.Key([]byte(fromKey)), from: ks.XORKeySpace.Key([]byte(fromKey)),
heap: peerMetricHeap{}, heap: peerMetricHeap{},
......
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
"testing" "testing"
"time" "time"
key "github.com/ipfs/go-ipfs/blocks/key"
peer "github.com/ipfs/go-ipfs/p2p/peer" peer "github.com/ipfs/go-ipfs/p2p/peer"
u "github.com/ipfs/go-ipfs/util" u "github.com/ipfs/go-ipfs/util"
...@@ -27,7 +28,7 @@ func TestQueue(t *testing.T) { ...@@ -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] // [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] // [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(p3)
pq.Enqueue(p1) pq.Enqueue(p1)
pq.Enqueue(p2) pq.Enqueue(p2)
...@@ -81,7 +82,7 @@ func TestSyncQueue(t *testing.T) { ...@@ -81,7 +82,7 @@ func TestSyncQueue(t *testing.T) {
} }
ctx := context.Background() ctx := context.Background()
pq := NewXORDistancePQ(u.Key("11140beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a31")) pq := NewXORDistancePQ(key.Key("11140beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a31"))
cq := NewChanQueue(ctx, pq) cq := NewChanQueue(ctx, pq)
wg := sync.WaitGroup{} wg := sync.WaitGroup{}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment