func checkEOL(e *pb.IpnsEntry) (time.Time, bool) { if e.GetValidityType() == pb.IpnsEntry_EOL { eol, err := u.ParseRFC3339(string(e.GetValidity())) if err != nil { return time.Time{}, false } return eol, true } return time.Time{}, false }
func selectRecord(recs []*pb.IpnsEntry, vals [][]byte) (int, error) { var best_seq uint64 best_i := -1 for i, r := range recs { if r == nil || r.GetSequence() < best_seq { continue } if best_i == -1 || r.GetSequence() > best_seq { best_seq = r.GetSequence() best_i = i } else if r.GetSequence() == best_seq { rt, err := u.ParseRFC3339(string(r.GetValidity())) if err != nil { continue } bestt, err := u.ParseRFC3339(string(recs[best_i].GetValidity())) if err != nil { continue } if rt.After(bestt) { best_i = i } else if rt == bestt { if bytes.Compare(vals[i], vals[best_i]) > 0 { best_i = i } } } } if best_i == -1 { return 0, errors.New("no usable records in given set") } return best_i, nil }
// ValidateIpnsRecord implements ValidatorFunc and verifies that the // given 'val' is an IpnsEntry and that that entry is valid. func ValidateIpnsRecord(k string, val []byte) error { entry := new(pb.IpnsEntry) err := proto.Unmarshal(val, entry) if err != nil { return err } switch entry.GetValidityType() { case pb.IpnsEntry_EOL: t, err := u.ParseRFC3339(string(entry.GetValidity())) if err != nil { log.Debug("failed parsing time for ipns record EOL") return err } if time.Now().After(t) { return ErrExpiredRecord } default: return ErrUnrecognizedValidity } return nil }