Skip to content

Commit

Permalink
[stayrtr] add hash check on slurm data
Browse files Browse the repository at this point in the history
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 #114.
  • Loading branch information
netixx committed Feb 29, 2024
1 parent b773a90 commit 834eb64
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions cmd/stayrtr/stayrtr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 834eb64

Please sign in to comment.