peerstore: make it possible to use an empty peer ID (#2006)
This commit is contained in:
parent
5b5eea45d3
commit
e004bd3fc5
|
@ -46,7 +46,10 @@ type addrSegment struct {
|
|||
}
|
||||
|
||||
func (segments *addrSegments) get(p peer.ID) *addrSegment {
|
||||
return segments[byte(p[len(p)-1])]
|
||||
if len(p) == 0 { // it's not terribly useful to use an empty peer ID, but at least we should not panic
|
||||
return segments[0]
|
||||
}
|
||||
return segments[uint8(p[len(p)-1])]
|
||||
}
|
||||
|
||||
type clock interface {
|
||||
|
|
|
@ -135,6 +135,12 @@ func testAddAddress(ab pstore.AddrBook, clk *mockClock.Mock) func(*testing.T) {
|
|||
ab.UpdateAddrs(id, 4*time.Second, 0)
|
||||
AssertAddressesEqual(t, nil, ab.Addrs(id))
|
||||
})
|
||||
|
||||
t.Run("accessing an empty peer ID", func(t *testing.T) {
|
||||
addrs := GenerateAddrs(5)
|
||||
ab.AddAddrs("", addrs, time.Hour)
|
||||
AssertAddressesEqual(t, addrs, ab.Addrs(""))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue