Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store hash before decoding, do not parse broken file twice #118

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
ties marked this conversation as resolved.
Show resolved Hide resolved
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)
ties marked this conversation as resolved.
Show resolved Hide resolved
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
Loading