From 834eb645da63c5d15115227b213cb630783a265d Mon Sep 17 00:00:00 2001 From: netixx Date: Wed, 28 Feb 2024 09:26:24 +0100 Subject: [PATCH] [stayrtr] add hash check on slurm data Hash was already performed on cache/vrp data this performs it for slurm as well, preventing uneeded refreshes when neither file have changed. Partial fix for https://github.com/bgp/stayrtr/issues/114. --- cmd/stayrtr/stayrtr.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/cmd/stayrtr/stayrtr.go b/cmd/stayrtr/stayrtr.go index 7b0a6dc..5068868 100644 --- a/cmd/stayrtr/stayrtr.go +++ b/cmd/stayrtr/stayrtr.go @@ -507,21 +507,21 @@ func (s *state) updateFile(file string) (bool, error) { } hsum := newSHA256(data) - if s.lasthash != nil { - cres := bytes.Compare(s.lasthash, hsum) + if s.lasthashCache != nil { + cres := bytes.Compare(s.lasthashCache, hsum) if cres == 0 { return false, IdenticalFile{File: file} } } - log.Infof("new cache file: Updating sha256 hash %x -> %x", s.lasthash, hsum) + log.Infof("new cache file: Updating sha256 hash %x -> %x", s.lasthashCache, hsum) rpkilistjson, err := decodeJSON(data) if err != nil { return false, err } - s.lasthash = hsum + s.lasthashCache = hsum s.lastchange = time.Now().UTC() s.lastdata = rpkilistjson @@ -541,12 +541,21 @@ func (s *state) updateSlurm(file string) (bool, error) { RefreshStatusCode.WithLabelValues(file, fmt.Sprintf("%d", code)).Inc() } + hsum := newSHA256(data) + if s.lasthashSlurm != nil { + cres := bytes.Compare(s.lasthashSlurm, hsum) + if cres == 0 { + return false, IdenticalFile{File: file} + } + } + buf := bytes.NewBuffer(data) slurm, err := prefixfile.DecodeJSONSlurm(buf) if err != nil { return false, err } + s.lasthashSlurm = hsum s.slurm = slurm return true, nil } @@ -654,7 +663,8 @@ func (s *state) exporter(wr http.ResponseWriter, r *http.Request) { type state struct { lastdata *prefixfile.RPKIList - lasthash []byte + lasthashCache []byte + lasthashSlurm []byte lastchange time.Time lastts time.Time sendNotifs bool