mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 14:16:44 +00:00
swarm/network/kademlia: fix index out of range when deleting last idle peer from kaddb
This commit is contained in:
parent
74cc29789a
commit
329c9b1c5d
2 changed files with 4 additions and 40 deletions
|
|
@ -247,14 +247,14 @@ func (self *KadDb) delete(row int, indexes ...int) {
|
||||||
dbrow := self.Nodes[row]
|
dbrow := self.Nodes[row]
|
||||||
for _, next := range indexes {
|
for _, next := range indexes {
|
||||||
// need to adjust dbcursor
|
// need to adjust dbcursor
|
||||||
if next > 0 {
|
|
||||||
if next <= self.cursors[row] {
|
if next <= self.cursors[row] {
|
||||||
self.cursors[row]--
|
self.cursors[row]--
|
||||||
}
|
}
|
||||||
|
if next > 0 {
|
||||||
nodes = append(nodes, dbrow[prev:next]...)
|
nodes = append(nodes, dbrow[prev:next]...)
|
||||||
}
|
}
|
||||||
prev = next + 1
|
|
||||||
delete(self.index, dbrow[next].Addr)
|
delete(self.index, dbrow[next].Addr)
|
||||||
|
prev = next + 1
|
||||||
}
|
}
|
||||||
self.Nodes[row] = append(nodes, dbrow[prev:]...)
|
self.Nodes[row] = append(nodes, dbrow[prev:]...)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@
|
||||||
package storage
|
package storage
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -44,41 +43,6 @@ func NewMemStore(d *DbStore, capacity uint) (m *MemStore) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x Key) Size() uint {
|
|
||||||
return uint(len(x))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x Key) isEqual(y Key) bool {
|
|
||||||
return bytes.Compare(x, y) == 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h Key) bits(i, j uint) uint {
|
|
||||||
ii := i >> 3
|
|
||||||
jj := i & 7
|
|
||||||
if ii >= h.Size() {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
if jj+j <= 8 {
|
|
||||||
return uint((h[ii] >> jj) & ((1 << j) - 1))
|
|
||||||
}
|
|
||||||
|
|
||||||
res := uint(h[ii] >> jj)
|
|
||||||
jj = 8 - jj
|
|
||||||
j -= jj
|
|
||||||
for j != 0 {
|
|
||||||
ii++
|
|
||||||
if j < 8 {
|
|
||||||
res += uint(h[ii]&((1<<j)-1)) << jj
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
res += uint(h[ii]) << jj
|
|
||||||
jj += 8
|
|
||||||
j -= 8
|
|
||||||
}
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
|
|
||||||
type memTree struct {
|
type memTree struct {
|
||||||
subtree []*memTree
|
subtree []*memTree
|
||||||
parent *memTree
|
parent *memTree
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue