Skip to content

Commit

Permalink
Merge pull request #118 from ties/only-parse-broken-file-once
Browse files Browse the repository at this point in the history
Store hash before decoding, do not parse broken file twice
  • Loading branch information
ties authored Mar 1, 2024
2 parents b93d7a8 + 4c1c8fa commit 8adf6b5
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 @@ -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

Expand All @@ -553,14 +553,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 @@ -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

Expand Down

0 comments on commit 8adf6b5

Please sign in to comment.