mirror of
https://github.com/fluencelabs/go-libp2p-kad-dht
synced 2025-04-24 22:32:13 +00:00
providers: improve time parsing error checking
This commit is contained in:
parent
069736916d
commit
2a3899be0d
@ -148,14 +148,12 @@ func loadProvSet(dstore ds.Datastore, k cid.Cid) (*providerSet, error) {
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func readTimeValue(i interface{}) (time.Time, error) {
|
||||
data, ok := i.([]byte)
|
||||
if !ok {
|
||||
return time.Time{}, fmt.Errorf("data was not a []byte")
|
||||
func readTimeValue(data []byte) (time.Time, error) {
|
||||
nsec, n := binary.Varint(data)
|
||||
if n <= 0 {
|
||||
return time.Time{}, fmt.Errorf("failed to parse time")
|
||||
}
|
||||
|
||||
nsec, _ := binary.Varint(data)
|
||||
|
||||
return time.Unix(0, nsec), nil
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user