mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-30 01:52:26 +08:00
Code cleanup
License: MIT Signed-off-by: Dirk McCormick <dirkmdev@gmail.com>
This commit is contained in:
@ -64,7 +64,7 @@ func TestValidation(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if resp != p {
|
if resp != p {
|
||||||
t.Fatal("Mismatch between published path %s and resolved path %s", p, resp)
|
t.Fatalf("Mismatch between published path %s and resolved path %s", p, resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create expired entry
|
// Create expired entry
|
||||||
|
@ -10,6 +10,8 @@ import (
|
|||||||
proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
|
proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Selects best record by checking which has the highest sequence number
|
||||||
|
// and latest EOL
|
||||||
func IpnsSelectorFunc(k string, vals [][]byte) (int, error) {
|
func IpnsSelectorFunc(k string, vals [][]byte) (int, error) {
|
||||||
var recs []*pb.IpnsEntry
|
var recs []*pb.IpnsEntry
|
||||||
for _, v := range vals {
|
for _, v := range vals {
|
||||||
@ -26,40 +28,40 @@ func IpnsSelectorFunc(k string, vals [][]byte) (int, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func selectRecord(recs []*pb.IpnsEntry, vals [][]byte) (int, error) {
|
func selectRecord(recs []*pb.IpnsEntry, vals [][]byte) (int, error) {
|
||||||
var best_seq uint64
|
var bestSeq uint64
|
||||||
best_i := -1
|
besti := -1
|
||||||
|
|
||||||
for i, r := range recs {
|
for i, r := range recs {
|
||||||
if r == nil || r.GetSequence() < best_seq {
|
if r == nil || r.GetSequence() < bestSeq {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if best_i == -1 || r.GetSequence() > best_seq {
|
if besti == -1 || r.GetSequence() > bestSeq {
|
||||||
best_seq = r.GetSequence()
|
bestSeq = r.GetSequence()
|
||||||
best_i = i
|
besti = i
|
||||||
} else if r.GetSequence() == best_seq {
|
} else if r.GetSequence() == bestSeq {
|
||||||
rt, err := u.ParseRFC3339(string(r.GetValidity()))
|
rt, err := u.ParseRFC3339(string(r.GetValidity()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
bestt, err := u.ParseRFC3339(string(recs[best_i].GetValidity()))
|
bestt, err := u.ParseRFC3339(string(recs[besti].GetValidity()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if rt.After(bestt) {
|
if rt.After(bestt) {
|
||||||
best_i = i
|
besti = i
|
||||||
} else if rt == bestt {
|
} else if rt == bestt {
|
||||||
if bytes.Compare(vals[i], vals[best_i]) > 0 {
|
if bytes.Compare(vals[i], vals[besti]) > 0 {
|
||||||
best_i = i
|
besti = i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if best_i == -1 {
|
if besti == -1 {
|
||||||
return 0, errors.New("no usable records in given set")
|
return 0, errors.New("no usable records in given set")
|
||||||
}
|
}
|
||||||
|
|
||||||
return best_i, nil
|
return besti, nil
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,9 @@ var ErrInvalidPath = errors.New("record path invalid")
|
|||||||
// signature verification
|
// signature verification
|
||||||
var ErrSignature = errors.New("record signature verification failed")
|
var ErrSignature = errors.New("record signature verification failed")
|
||||||
|
|
||||||
|
// Returns a ValidChecker for IPNS records
|
||||||
|
// The validator function will get a public key from the KeyBook
|
||||||
|
// to verify the record's signature
|
||||||
func NewIpnsRecordValidator(kbook pstore.KeyBook) *record.ValidChecker {
|
func NewIpnsRecordValidator(kbook pstore.KeyBook) *record.ValidChecker {
|
||||||
// ValidateIpnsRecord implements ValidatorFunc and verifies that the
|
// ValidateIpnsRecord implements ValidatorFunc and verifies that the
|
||||||
// given 'val' is an IpnsEntry and that that entry is valid.
|
// given 'val' is an IpnsEntry and that that entry is valid.
|
||||||
|
Reference in New Issue
Block a user