backend: save the checksum of each try, to be able to detect duplicates after
This commit is contained in:
parent
44d335bc9f
commit
333bb408e1
@ -11,6 +11,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"golang.org/x/crypto/blake2b"
|
||||||
|
|
||||||
"srs.epita.fr/fic-server/libfic"
|
"srs.epita.fr/fic-server/libfic"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -54,6 +56,13 @@ func treatSubmission(pathname string, team fic.Team, exercice_id string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Save checksum to treat duplicates
|
||||||
|
cksum := blake2b.Sum512(cnt_raw)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(id, "[ERR] JSON parsing error:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Parse it
|
// Parse it
|
||||||
var responses ResponsesUpload
|
var responses ResponsesUpload
|
||||||
err = json.Unmarshal(cnt_raw, &responses)
|
err = json.Unmarshal(cnt_raw, &responses)
|
||||||
@ -70,7 +79,7 @@ func treatSubmission(pathname string, team fic.Team, exercice_id string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check given answers
|
// Check given answers
|
||||||
solved, err := exercice.CheckResponse(responses.Keys, responses.MCQs, team)
|
solved, err := exercice.CheckResponse(cksum[:], responses.Keys, responses.MCQs, team)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(id, "[ERR] Unable to CheckResponse:", err)
|
log.Println(id, "[ERR] Unable to CheckResponse:", err)
|
||||||
genTeamMyFile(team)
|
genTeamMyFile(team)
|
||||||
|
@ -244,6 +244,7 @@ CREATE TABLE IF NOT EXISTS exercice_tries(
|
|||||||
id_exercice INTEGER NOT NULL,
|
id_exercice INTEGER NOT NULL,
|
||||||
id_team INTEGER NOT NULL,
|
id_team INTEGER NOT NULL,
|
||||||
time TIMESTAMP NOT NULL,
|
time TIMESTAMP NOT NULL,
|
||||||
|
cksum BINARY(64) NOT NULL,
|
||||||
nbdiff INTEGER NOT NULL DEFAULT 0,
|
nbdiff INTEGER NOT NULL DEFAULT 0,
|
||||||
FOREIGN KEY(id_exercice) REFERENCES exercices(id_exercice),
|
FOREIGN KEY(id_exercice) REFERENCES exercices(id_exercice),
|
||||||
FOREIGN KEY(id_team) REFERENCES teams(id_team)
|
FOREIGN KEY(id_team) REFERENCES teams(id_team)
|
||||||
|
@ -205,8 +205,8 @@ func (e Exercice) GetLevel() (int, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewTry registers a solving attempt for the given Team.
|
// NewTry registers a solving attempt for the given Team.
|
||||||
func (e Exercice) NewTry(t Team) error {
|
func (e Exercice) NewTry(t Team, cksum []byte) error {
|
||||||
if _, err := DBExec("INSERT INTO exercice_tries (id_exercice, id_team, time) VALUES (?, ?, ?)", e.Id, t.Id, time.Now()); err != nil {
|
if _, err := DBExec("INSERT INTO exercice_tries (id_exercice, id_team, time, cksum) VALUES (?, ?, ?, ?)", e.Id, t.Id, time.Now(), cksum); err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
return nil
|
return nil
|
||||||
@ -264,8 +264,8 @@ func (e Exercice) TriedCount() int64 {
|
|||||||
|
|
||||||
// CheckResponse, given both flags and MCQ responses, figures out if thoses are correct (or if they are previously solved).
|
// CheckResponse, given both flags and MCQ responses, figures out if thoses are correct (or if they are previously solved).
|
||||||
// In the meanwhile, CheckResponse registers good answers given (but it does not mark the challenge as solved at the end).
|
// In the meanwhile, CheckResponse registers good answers given (but it does not mark the challenge as solved at the end).
|
||||||
func (e Exercice) CheckResponse(respflags map[string]string, respmcq map[int64]bool, t Team) (bool, error) {
|
func (e Exercice) CheckResponse(cksum []byte, respflags map[string]string, respmcq map[int64]bool, t Team) (bool, error) {
|
||||||
if err := e.NewTry(t); err != nil {
|
if err := e.NewTry(t, cksum); err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
} else if flags, err := e.GetFlags(); err != nil {
|
} else if flags, err := e.GetFlags(); err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
|
Loading…
Reference in New Issue
Block a user