make infohash and peerID byte arrays (#169)

This commit is contained in:
mrd0ll4r
2016-05-16 23:48:23 -04:00
committed by Jimmy Zelinskie
parent a081e5195b
commit 7f16c55d81
16 changed files with 113 additions and 46 deletions
+4 -4
View File
@@ -78,20 +78,20 @@ var _ store.PeerStore = &peerStore{}
func (s *peerStore) shardIndex(infoHash chihaya.InfoHash) uint32 {
idx := fnv.New32()
idx.Write([]byte(infoHash))
idx.Write(infoHash[:])
return idx.Sum32() % uint32(len(s.shards))
}
func peerKey(p chihaya.Peer) string {
return string(p.IP) + string(p.ID)
return string(p.IP) + string(p.ID[:])
}
func seedersKey(infoHash chihaya.InfoHash) string {
return string(infoHash) + "-s"
return string(infoHash[:]) + "-s"
}
func leechersKey(infoHash chihaya.InfoHash) string {
return string(infoHash) + "-l"
return string(infoHash[:]) + "-l"
}
func (s *peerStore) PutSeeder(infoHash chihaya.InfoHash, p chihaya.Peer) error {
+5 -5
View File
@@ -25,7 +25,7 @@ func peerInSlice(peer chihaya.Peer, peers []chihaya.Peer) bool {
func TestPeerStoreAPI(t *testing.T) {
var (
hash = chihaya.InfoHash("11111111111111111111")
hash = chihaya.InfoHash([20]byte{})
peers = []struct {
seeder bool
@@ -62,7 +62,7 @@ func TestPeerStoreAPI(t *testing.T) {
for _, p := range peers {
// Construct chihaya.Peer from test data.
peer := chihaya.Peer{
ID: chihaya.PeerID(p.peerID),
ID: chihaya.PeerIDFromString(p.peerID),
IP: net.ParseIP(p.ip),
Port: p.port,
}
@@ -95,7 +95,7 @@ func TestPeerStoreAPI(t *testing.T) {
for _, p := range peers {
// Construct chihaya.Peer from test data.
peer := chihaya.Peer{
ID: chihaya.PeerID(p.peerID),
ID: chihaya.PeerIDFromString(p.peerID),
IP: net.ParseIP(p.ip),
Port: p.port,
}
@@ -121,7 +121,7 @@ func TestPeerStoreAPI(t *testing.T) {
for _, p := range peers {
// Construct chihaya.Peer from test data.
peer := chihaya.Peer{
ID: chihaya.PeerID(p.peerID),
ID: chihaya.PeerIDFromString(p.peerID),
IP: net.ParseIP(p.ip),
Port: p.port,
}
@@ -136,7 +136,7 @@ func TestPeerStoreAPI(t *testing.T) {
assert.Equal(t, 6, s.NumSeeders(hash))
assert.Equal(t, 4, s.NumLeechers(hash))
peer := chihaya.Peer{
ID: chihaya.PeerID(peers[0].peerID),
ID: chihaya.PeerIDFromString(peers[0].peerID),
IP: net.ParseIP(peers[0].ip),
Port: peers[0].port,
}