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 28, 2024
1 parent 7bec069 commit d2aa31a
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 @@ -499,21 +499,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 @@ -533,12 +533,21 @@ func (s *state) updateSlurm(file string) (bool, error) {
RefreshStatusCode.WithLabelValues(file, fmt.Sprintf("%d", code)).Inc()
}

hsum := newSHA256(data)
if s.lasthashCache != nil {
cres := bytes.Compare(s.lasthashCache, 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 @@ -646,7 +655,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 d2aa31a

Please sign in to comment.