Validate check if the Identity data is valid
()
| 385 | |
| 386 | // Validate check if the Identity data is valid |
| 387 | func (i *Identity) Validate() error { |
| 388 | lastTimes := make(map[string]lamport.Time) |
| 389 | |
| 390 | if len(i.versions) == 0 { |
| 391 | return fmt.Errorf("no version") |
| 392 | } |
| 393 | |
| 394 | for _, v := range i.versions { |
| 395 | if err := v.Validate(); err != nil { |
| 396 | return err |
| 397 | } |
| 398 | |
| 399 | // check for always increasing lamport time |
| 400 | // check that a new version didn't drop a clock |
| 401 | for name, previous := range lastTimes { |
| 402 | if now, ok := v.times[name]; ok { |
| 403 | if now < previous { |
| 404 | return fmt.Errorf("non-chronological lamport clock %s (%d --> %d)", name, previous, now) |
| 405 | } |
| 406 | } else { |
| 407 | return fmt.Errorf("version has less lamport clocks than before (missing %s)", name) |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | for name, now := range v.times { |
| 412 | lastTimes[name] = now |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | return nil |
| 417 | } |
| 418 | |
| 419 | func (i *Identity) lastVersion() *version { |
| 420 | if len(i.versions) <= 0 { |