-
Notifications
You must be signed in to change notification settings - Fork 1
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
Flag Handler Service #36
base: develop
Are you sure you want to change the base?
Conversation
c2902c4
to
e148114
Compare
@MayankMittal1 Fix lint issues after you are done. |
configs/types.go
Outdated
@@ -52,6 +52,12 @@ type MongoCfg struct { | |||
URL string `toml:"url"` | |||
} | |||
|
|||
type FlagCfg struct { | |||
FlagLength uint `toml:"flaglength"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe length could be fixed.
types/mongo.go
Outdated
|
||
type Challenge struct { | ||
ID int `json:"id" bson:"id" binding:"required"` | ||
TeamID int `json:"teamid" bson:"teamid" binding:"required"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need a TeamID inside challenge struct? To me it seems it is the last team who solved the challenge.
If that is the case please change this variable to something else.
type Flag struct { | ||
Value string `json:"value" bson:"value" binding:"required"` | ||
ChallengeID int `json:"challengeid" bson:"challengeid" binding:"required"` | ||
TeamID int `json:"teamid" bson:"teamid" binding:"required"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
types/mongo.go
Outdated
} | ||
|
||
type Submission struct { | ||
Submitter int `json:"submitter" bson:"submitter" binding:"required"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is submitter here ?
- Team which submits the flag ?
submission := &types.Submission{} | ||
submission.ChallengeID = flag.ChallengeID | ||
submission.Flag = flag.Value | ||
submission.Submitter = team.Index //time of submission could also be stored |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. We might need to store the submission time. And create a watcher service to prevent bruteforcing. Please make a note of this on the channel also.
if res, err := mongo.FetchChallenge(flag.ChallengeID); err != nil { | ||
log.Println(err) | ||
return false, 0 | ||
} else { | ||
team.Score += res.Points | ||
points = res.Points | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logic looks wrong. You are increasing points if you can't find the challenge.
} | ||
|
||
func flagUpdater(challenge bson.M) { | ||
flagValue := String(int(configs.FlagConfig.FlagLength)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
flagValue := String(int(configs.FlagConfig.FlagLength)) | |
flagLength := String(int(configs.FlagConfig.FlagLength)) |
Use uint. Dont cast it first to int then to string. If you already want it as a string change the type in FlagCfg
struct.
challengeBytes, _ := bson.Marshal(challenge) | ||
bson.Unmarshal(challengeBytes, challengeStruct) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check for errors.
flag.TeamID = challengeStruct.TeamID | ||
flag.ChallengeID = challengeStruct.ID | ||
flag.CreatedAt = time.Now() | ||
if _, err := mongo.InsertOne(context.Background(), mongo.FlagsCollection, flag); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure if this will be an issue. Use upsert here. Will do a discussion on this.
bad2738
to
447a2b9
Compare
447a2b9
to
fb3200c
Compare
author mayankmittal-iitr <[email protected]> 1638563217 +0530 committer Mayank Mittal <[email protected]> 1642515212 +0530 Add flag submission service
fb3200c
to
e149cf5
Compare
#32 Flag Submission Service