1
0
mirror of https://github.com/bgp/stayrtr.git synced 2024-05-06 15:54:54 +00:00

Store hash before decoding, do not parse broken file twice

This commit is contained in:
Ties de Kock
2024-02-29 20:27:38 +01:00
parent b93d7a8477
commit 4c1c8fab66

View File

@ -520,13 +520,13 @@ func (s *state) updateFile(file string) (bool, error) {
}
log.Infof("new cache file: Updating sha256 hash %x -> %x", s.lasthashCache, hsum)
s.lasthashCache = hsum
rpkilistjson, err := decodeJSON(data)
if err != nil {
return false, err
}
s.lasthashCache = hsum
s.lastchange = time.Now().UTC()
s.lastdata = rpkilistjson
@ -553,6 +553,8 @@ func (s *state) updateSlurm(file string) (bool, error) {
return false, IdenticalFile{File: file}
}
}
log.Infof("new slurm file: Updating sha256 hash %x -> %x", s.lasthashCache, hsum)
s.lasthashSlurm = hsum
buf := bytes.NewBuffer(data)
@ -560,7 +562,6 @@ func (s *state) updateSlurm(file string) (bool, error) {
if err != nil {
return false, err
}
s.lasthashSlurm = hsum
s.slurm = slurm
return true, nil
}
@ -667,12 +668,12 @@ func (s *state) exporter(wr http.ResponseWriter, r *http.Request) {
}
type state struct {
lastdata *prefixfile.RPKIList
lasthashCache []byte
lasthashSlurm []byte
lastchange time.Time
lastts time.Time
sendNotifs bool
lastdata *prefixfile.RPKIList
lasthashCache []byte
lasthashSlurm []byte
lastchange time.Time
lastts time.Time
sendNotifs bool
fetchConfig *utils.FetchConfig