Commit 155220bb authored by Aarsh Shah's avatar Aarsh Shah

changes as per review

parent d5e5a484
......@@ -68,9 +68,9 @@ func (rt *RoutingTable) GetAllBuckets() []*Bucket {
}
// GenRandPeerID generates a random peerID in bucket=bucketID
func (rt *RoutingTable) GenRandPeerID(bucketID int) (peer.ID, error) {
func (rt *RoutingTable) GenRandPeerID(bucketID int) peer.ID {
if bucketID < 0 {
panic(errors.New(fmt.Sprintf("bucketID %d is not non-negative", bucketID)))
panic(fmt.Sprintf("bucketID %d is not non-negative", bucketID))
}
rt.tabLock.RLock()
bucketLen := len(rt.Buckets)
......@@ -109,7 +109,7 @@ func (rt *RoutingTable) GenRandPeerID(bucketID int) (peer.ID, error) {
key := keyPrefixMap[targetPrefix]
id := [34]byte{mh.SHA2_256, 32}
binary.BigEndian.PutUint32(id[2:], key)
return peer.ID(id[:]), nil
return peer.ID(id[:])
}
// Returns the bucket for a given ID
......
......@@ -75,10 +75,7 @@ func TestGenRandPeerID(t *testing.T) {
// test generate rand peer ID
for bucketID := 0; bucketID < nBuckets; bucketID++ {
peerID, err := rt.GenRandPeerID(bucketID)
if err != nil || len(peerID) == 0 {
t.Fatalf("error %+v & peerID %s for bucket %d", err, peerID, bucketID)
}
peerID := rt.GenRandPeerID(bucketID)
// for bucketID upto maxPrefixLen of 16, CPL should be Exactly bucketID
if bucketID < 16 {
......
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