Skip to content

Commit d40afd4

Browse files
committed
routing.go: getClosest() fixes
1 parent 114e584 commit d40afd4

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

lib/routing.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func (l *RTHostList) Sort() {
105105

106106
func (l *RTHostList) PopFront() (h *RTHost) {
107107
h = l.v.At(0).(*RTHost)
108-
l.v.Cut(0, 0)
108+
l.v.Cut(0, 1)
109109
return
110110
}
111111

@@ -406,13 +406,11 @@ func (rt *BRoutingTable) getClosest(t string, n uint) *RTHostList {
406406
rt.logger.Logf("match bucket: rn %d\n", rn)
407407

408408
// init for for loop
409-
cangoup := bucketno < rt.maxbucket
410-
cangodown := bucketno > 0
409+
cangoup := (bucketno + 1) <= rt.maxbucket
410+
cangodown := (bucketno - 1) >= 0
411411
delta := 1
412412

413413
for (rn < n) && (cangoup || cangodown) {
414-
cangoup = (bucketno + delta) < rt.maxbucket
415-
cangodown = (bucketno - delta) > 0
416414
//rt.logger.Logf("bucketno %d rt.maxbucket %d\n", bucketno, rt.maxbucket)
417415
//rt.logger.Logf("bucketno - delta: %d. > 0: %v", bucketno-delta, (bucketno-delta) > 0)
418416
//rt.logger.Logf("round delta %d cangoup %v cangodown %v\n", delta, cangoup, cangodown)
@@ -432,6 +430,8 @@ func (rt *BRoutingTable) getClosest(t string, n uint) *RTHostList {
432430
}
433431

434432
delta++
433+
cangoup = (bucketno + delta) < rt.maxbucket
434+
cangodown = (bucketno - delta) > 0
435435
}
436436

437437
//rt.logger.Logf("sorting %v...\n", hl)

0 commit comments

Comments
 (0)