mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-27 16:07:42 +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)
|
||||
}
|
||||
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
|
||||
|
@ -10,6 +10,8 @@ import (
|
||||
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) {
|
||||
var recs []*pb.IpnsEntry
|
||||
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) {
|
||||
var best_seq uint64
|
||||
best_i := -1
|
||||
var bestSeq uint64
|
||||
besti := -1
|
||||
|
||||
for i, r := range recs {
|
||||
if r == nil || r.GetSequence() < best_seq {
|
||||
if r == nil || r.GetSequence() < bestSeq {
|
||||
continue
|
||||
}
|
||||
|
||||
if best_i == -1 || r.GetSequence() > best_seq {
|
||||
best_seq = r.GetSequence()
|
||||
best_i = i
|
||||
} else if r.GetSequence() == best_seq {
|
||||
if besti == -1 || r.GetSequence() > bestSeq {
|
||||
bestSeq = r.GetSequence()
|
||||
besti = i
|
||||
} else if r.GetSequence() == bestSeq {
|
||||
rt, err := u.ParseRFC3339(string(r.GetValidity()))
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
bestt, err := u.ParseRFC3339(string(recs[best_i].GetValidity()))
|
||||
bestt, err := u.ParseRFC3339(string(recs[besti].GetValidity()))
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if rt.After(bestt) {
|
||||
best_i = i
|
||||
besti = i
|
||||
} else if rt == bestt {
|
||||
if bytes.Compare(vals[i], vals[best_i]) > 0 {
|
||||
best_i = i
|
||||
if bytes.Compare(vals[i], vals[besti]) > 0 {
|
||||
besti = i
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if best_i == -1 {
|
||||
if besti == -1 {
|
||||
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
|
||||
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 {
|
||||
// ValidateIpnsRecord implements ValidatorFunc and verifies that the
|
||||
// given 'val' is an IpnsEntry and that that entry is valid.
|
||||
|
Reference in New Issue
Block a user