Skip to content

Commit

Permalink
Store hash before decoding, do not parse broken file twice
Browse files Browse the repository at this point in the history
  • Loading branch information
ties committed Feb 29, 2024
1 parent c3652d3 commit 460d315
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions cmd/stayrtr/stayrtr.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,13 +517,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

Expand All @@ -550,14 +550,15 @@ 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)

slurm, err := prefixfile.DecodeJSONSlurm(buf)
if err != nil {
return false, err
}
s.lasthashSlurm = hsum
s.slurm = slurm
return true, nil
}
Expand Down Expand Up @@ -664,12 +665,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

Expand Down

0 comments on commit 460d315

Please sign in to comment.