From 4c1c8fab66388b0002405fd146661b75a1450fd4 Mon Sep 17 00:00:00 2001 From: Ties de Kock Date: Thu, 29 Feb 2024 20:27:38 +0100 Subject: [PATCH] Store hash before decoding, do not parse broken file twice --- cmd/stayrtr/stayrtr.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/cmd/stayrtr/stayrtr.go b/cmd/stayrtr/stayrtr.go index 76bd52f..5d73c76 100644 --- a/cmd/stayrtr/stayrtr.go +++ b/cmd/stayrtr/stayrtr.go @@ -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