-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
72b94b4
commit d20697b
Showing
68 changed files
with
1,222 additions
and
2,628 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,42 @@ | ||
host: 0.0.0.0 | ||
port: 2999 | ||
privateKey: private_key_used_to_hash_password | ||
debug: false | ||
enableCors: true | ||
rateLimit: 1000 | ||
host: 0.0.0.0 # host blizzard should run on | ||
privateKey: d057ab405abcee847b3c0ee6e8324cfbdb693803 # private key used to encrypt sessions | ||
port: 2999 # port blizzard should run on | ||
debug: true # whether to enable debug mode, deprecated, will be removed in the future | ||
enableCors: true # where to enable cors | ||
rateLimit: 100 # limit to x requests per second | ||
|
||
judges: | ||
north-pole: 0.0.0.0:172 | ||
ethereal: 192.168.31.202:2345 # http address of judge | ||
|
||
oauth: | ||
github: | ||
clientId: your_github_client_id | ||
clientSecret: your_github_client_secret | ||
clientId: ba4983ed38e2e43dfbeb | ||
clientSecret: 63b04c44475d709f939529b193551acd119a001c | ||
discord: | ||
clientId: your_discord_client_id | ||
clientSecret: your_discord_client_secret | ||
clientId: 1089944774880018493 | ||
clientSecret: rKLXDoSAiiZxBtAXhFa_vovmwMsBUYfU | ||
|
||
storage: | ||
problems: /path/to/problems | ||
posts: /path/to/posts | ||
submissions: /path/to/submissions | ||
readmes: /path/to/readmes | ||
|
||
redis: | ||
host: 192.168.31.240 | ||
port: 6379 | ||
db: 0 | ||
|
||
rabbitmq: | ||
username: guest | ||
password: guest | ||
host: localhost | ||
port: 5672 | ||
|
||
database: | ||
secure: false | ||
address: db_addr | ||
username: db_username | ||
password: db_pwd | ||
name: db_name | ||
secure: false # whether to use tls for connection to db | ||
host: localhost | ||
port: 5432 | ||
username: postgres | ||
password: postgres | ||
name: arctic |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
package cache | ||
|
||
import ( | ||
"blizzard/blizzard/db/models/contest" | ||
"blizzard/blizzard/utils" | ||
"context" | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"github.com/redis/rueidis" | ||
"strconv" | ||
"strings" | ||
"sync" | ||
) | ||
|
||
type ResultCache struct { | ||
rueidis.Client | ||
l sync.RWMutex | ||
tl sync.RWMutex | ||
} | ||
|
||
var Result *ResultCache | ||
|
||
const defaultResultKey = "blizzard::case_results[%d]" | ||
|
||
const defaultTagKey = "blizzard::pending_submission[%d]" | ||
|
||
const defaultTtl = 15 | ||
|
||
// 30 minutes | ||
const defaultInitialTtl = 30 * 60 | ||
|
||
func init() { | ||
Result = &ResultCache{Client: create(1, "results")} | ||
} | ||
|
||
func (c *ResultCache) GetTag(id uint32) (uint64, error) { | ||
c.tl.RLock() | ||
defer c.tl.RUnlock() | ||
return c.Do(context.Background(), c.B().Get().Key(c.createTagKey(id)).Build()).AsUint64() | ||
} | ||
|
||
func (c *ResultCache) SetTag(id uint32, tag uint64) error { | ||
c.tl.Lock() | ||
defer c.tl.Unlock() | ||
key := c.createTagKey(id) | ||
res := c.DoMulti( | ||
context.Background(), | ||
c.B().Set().Key(key).Value(strconv.FormatUint(tag, 10)).Build(), | ||
c.B().Expire().Key(key).Seconds(defaultInitialTtl).Build()) | ||
if e := res[0].Error(); e != nil { | ||
return e | ||
} | ||
return res[1].Error() | ||
} | ||
|
||
func (c *ResultCache) DeleteTag(id uint32) error { | ||
c.tl.Lock() | ||
defer c.tl.Unlock() | ||
return c.Do(context.Background(), c.B().Del().Key(c.createTagKey(id)).Build()).Error() | ||
} | ||
|
||
func (c *ResultCache) createKey(id uint32) string { | ||
return fmt.Sprintf(defaultResultKey, id) | ||
} | ||
|
||
func (c *ResultCache) createTagKey(id uint32) string { | ||
return fmt.Sprintf(defaultTagKey, id) | ||
} | ||
|
||
func (c *ResultCache) Create(id uint32, count uint16) error { | ||
if c.IsPending(id) { | ||
return errors.New("submission is being judged") | ||
} | ||
key := c.createKey(id) | ||
res := c.DoMulti( | ||
context.Background(), | ||
c.B().Del().Key(key).Build(), | ||
c.B().Rpush().Key(key).Element(utils.ArrayFill("", int(count))...).Build(), | ||
c.B().Expire().Key(key).Seconds(defaultInitialTtl).Build(), | ||
) | ||
if e := res[1].Error(); e != nil { | ||
return e | ||
} | ||
return res[2].Error() | ||
} | ||
|
||
func (c *ResultCache) IsPending(id uint32) bool { | ||
c.l.RLock() | ||
defer c.l.RUnlock() | ||
exists, e := c.Do(context.Background(), c.B().Exists().Key(c.createKey(id)).Build()).AsBool() | ||
return exists && e == nil | ||
} | ||
|
||
func (c *ResultCache) Store(id uint32, caseId uint16, r contest.CaseResult, ttl int) error { | ||
c.l.Lock() | ||
defer c.l.Unlock() | ||
buf, e := json.Marshal(r) | ||
if e != nil { | ||
return e | ||
} | ||
key := c.createKey(id) | ||
if ttl == 0 { | ||
ttl = defaultTtl | ||
} | ||
res := c.DoMulti( | ||
context.Background(), | ||
c.B().Lset().Key(key).Index(int64(caseId)).Element(string(buf)).Build(), | ||
c.B().Expire().Key(key).Seconds(int64(ttl)).Build(), | ||
) | ||
if e = res[0].Error(); e != nil { | ||
return e | ||
} | ||
return res[1].Error() | ||
} | ||
|
||
func (c *ResultCache) Get(id uint32) (string, error) { | ||
c.l.RLock() | ||
defer c.l.RUnlock() | ||
res := c.Do(context.Background(), c.B().Lrange().Key(c.createKey(id)).Start(0).Stop(-1).Build()) | ||
if e := res.Error(); e != nil { | ||
return "[]", e | ||
} | ||
arr, e := res.AsStrSlice() | ||
if e != nil { | ||
return "[]", e | ||
} | ||
return fmt.Sprintf("[%s]", strings.Join(arr, ",")), nil | ||
} | ||
|
||
func (c *ResultCache) Clean(id uint32) { | ||
c.l.Lock() | ||
defer c.l.Unlock() | ||
c.Do(context.Background(), c.B().Del().Key(c.createKey(id)).Build()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package cache | ||
|
||
func GetUsers() { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package core | ||
|
||
type Runtime struct { | ||
Name string | ||
Extension string | ||
} | ||
|
||
var LanguageMatrix = map[string]*Runtime{ | ||
"gnuc++11": { | ||
Name: "GNU C++ 11", | ||
Extension: "cpp", | ||
}, | ||
"gnuc++14": { | ||
Name: "GNU C++ 14", | ||
Extension: "cpp", | ||
}, | ||
"gnuc++17": { | ||
Name: "GNU C++ 17", | ||
Extension: "cpp", | ||
}, | ||
"gnuc++20": { | ||
Name: "GNU C++ 20", | ||
Extension: "cpp", | ||
}, | ||
"python3": { | ||
Name: "Python 3", | ||
Extension: "py", | ||
}, | ||
"go": { | ||
Name: "Go", | ||
Extension: "go", | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package cron | ||
|
||
import ( | ||
"blizzard/blizzard/cron/jobs" | ||
"github.com/go-co-op/gocron" | ||
"time" | ||
) | ||
|
||
func init() { | ||
s := gocron.NewScheduler(time.UTC) | ||
s.Every("10s").Do(jobs.UpdateJudgeStatus) | ||
s.StartAsync() | ||
} |
Oops, something went wrong.