Browse Source

move util.Key into its own package under blocks

pull/2/head
Jeromy 10 years ago
parent
commit
9839d64fd8
  1. 2
      net/conn/conn.go
  2. 4
      net/conn/interface.go
  3. 4
      peer/queue/distance.go
  4. 5
      peer/queue/queue_test.go

2
net/conn/conn.go

@ -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

4
net/conn/interface.go

@ -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

4
peer/queue/distance.go

@ -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{},

5
peer/queue/queue_test.go

@ -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{}

Loading…
Cancel
Save