Skip to content

Commit 460d315

Browse files
committed
Store hash before decoding, do not parse broken file twice
1 parent c3652d3 commit 460d315

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

cmd/stayrtr/stayrtr.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -517,13 +517,13 @@ func (s *state) updateFile(file string) (bool, error) {
517517
}
518518

519519
log.Infof("new cache file: Updating sha256 hash %x -> %x", s.lasthashCache, hsum)
520+
s.lasthashCache = hsum
520521

521522
rpkilistjson, err := decodeJSON(data)
522523
if err != nil {
523524
return false, err
524525
}
525526

526-
s.lasthashCache = hsum
527527
s.lastchange = time.Now().UTC()
528528
s.lastdata = rpkilistjson
529529

@@ -550,14 +550,15 @@ func (s *state) updateSlurm(file string) (bool, error) {
550550
return false, IdenticalFile{File: file}
551551
}
552552
}
553+
log.Infof("new slurm file: Updating sha256 hash %x -> %x", s.lasthashCache, hsum)
554+
s.lasthashSlurm = hsum
553555

554556
buf := bytes.NewBuffer(data)
555557

556558
slurm, err := prefixfile.DecodeJSONSlurm(buf)
557559
if err != nil {
558560
return false, err
559561
}
560-
s.lasthashSlurm = hsum
561562
s.slurm = slurm
562563
return true, nil
563564
}
@@ -664,12 +665,12 @@ func (s *state) exporter(wr http.ResponseWriter, r *http.Request) {
664665
}
665666

666667
type state struct {
667-
lastdata *prefixfile.RPKIList
668-
lasthashCache []byte
669-
lasthashSlurm []byte
670-
lastchange time.Time
671-
lastts time.Time
672-
sendNotifs bool
668+
lastdata *prefixfile.RPKIList
669+
lasthashCache []byte
670+
lasthashSlurm []byte
671+
lastchange time.Time
672+
lastts time.Time
673+
sendNotifs bool
673674

674675
fetchConfig *utils.FetchConfig
675676

0 commit comments

Comments
 (0)