aboutsummaryrefslogtreecommitdiffhomepage
path: root/backend
diff options
context:
space:
mode:
Diffstat (limited to 'backend')
-rw-r--r--backend/game/hub.go3
-rw-r--r--backend/taskqueue/processor.go7
2 files changed, 8 insertions, 2 deletions
diff --git a/backend/game/hub.go b/backend/game/hub.go
index 8f27466..436acf5 100644
--- a/backend/game/hub.go
+++ b/backend/game/hub.go
@@ -41,9 +41,8 @@ func (hub *Hub) CalcCodeSize(code string, language string) int {
trimmed := re.ReplaceAllString(code, "")
if language == "php" {
return len(strings.TrimSuffix(strings.TrimPrefix(strings.TrimPrefix(trimmed, "<?php"), "<?"), "?>"))
- } else {
- return len(trimmed)
}
+ return len(trimmed)
}
func (hub *Hub) EnqueueTestTasks(ctx context.Context, submissionID, gameID, userID int, language, code string) error {
diff --git a/backend/taskqueue/processor.go b/backend/taskqueue/processor.go
index 8dadfdf..c4cf60b 100644
--- a/backend/taskqueue/processor.go
+++ b/backend/taskqueue/processor.go
@@ -3,6 +3,7 @@ package taskqueue
import (
"bytes"
"context"
+ "crypto/md5"
"encoding/json"
"fmt"
"net/http"
@@ -16,6 +17,7 @@ func newProcessor() processor {
type testrunRequestData struct {
Code string `json:"code"`
+ CodeHash string `json:"code_hash"`
Stdin string `json:"stdin"`
MaxDuration int `json:"max_duration_ms"`
}
@@ -32,6 +34,7 @@ func (p *processor) doProcessTaskRunTestcase(
) (*TaskResultRunTestcase, error) {
reqData := testrunRequestData{
Code: payload.Code,
+ CodeHash: calcCodeHash(payload.Code),
Stdin: payload.Stdin,
MaxDuration: 5000,
}
@@ -64,3 +67,7 @@ func (p *processor) doProcessTaskRunTestcase(
Stderr: resData.Stderr,
}, nil
}
+
+func calcCodeHash(code string) string {
+ return fmt.Sprintf("%x", md5.Sum([]byte(code)))
+}