Skip to content

Commit 2b9d5bd

Browse files
committed
use challengeId
1 parent beb2cee commit 2b9d5bd

5 files changed

Lines changed: 13 additions & 8 deletions

File tree

src/stages.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void stage2CommentCleanup(PendingRequest* req) {
6868
void stage3Start(PendingRequest* preq) {
6969
auto& argon = ArgonState::get();
7070

71-
auto task = argon::web::startStage3(preq->account, preq->challengeSolution);
71+
auto task = argon::web::startStage3(preq->account, preq->challengeId, preq->challengeSolution);
7272

7373
argon.pushStage3Request(preq, std::move(task));
7474
}

src/state.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Task<void> sleepFor(auto duration) {
2323
struct Stage1ResponseData {
2424
std::string method;
2525
int id;
26+
uint32_t challengeId;
2627
int challenge;
2728
std::string ident;
2829
};
@@ -206,12 +207,13 @@ void ArgonState::processStage1Response(PendingRequest* req, web::WebResponse* re
206207

207208
auto data = std::move(datares).unwrap();
208209

209-
// store server ident
210+
// store some values
210211
req->serverIdent = std::move(data.ident);
212+
req->challengeId = data.challengeId;
213+
req->stage2ChosenMethod = data.method;
211214

212215
// start stage 2
213216
this->progress(req, req->retrying ? AuthProgress::RetryingSolve : AuthProgress::SolvingChallenge);
214-
req->stage2ChosenMethod = data.method;
215217
argon::stage2Start(req, data.id, data.challenge);
216218
}
217219

@@ -353,7 +355,7 @@ void ArgonState::waitAndRetryStage3(PendingRequest* req, int ms) {
353355
// Note to self: don't pass stuff in lambda captures here, it gets corrupted unlike args
354356
auto task = [](Duration duration, PendingRequest* req) -> web::WebTask {
355357
co_await sleepFor(duration);
356-
co_return co_await argon::web::pollStage3(req->account, req->challengeSolution);
358+
co_return co_await argon::web::pollStage3(req->account, req->challengeId, req->challengeSolution);
357359
}(duration, req);
358360

359361
req->stage3Listener.setFilter(std::move(task));

src/state.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ struct PendingRequest {
2020
std::string serverIdent;
2121
std::string challengeSolution;
2222
std::string stage2ChosenMethod;
23+
uint32_t challengeId = 0;
2324
int userCommentId;
2425
bool retrying = false;
2526
web::WebListener stage1Listener;

src/web.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,12 @@ WebTask stage2CommentCleanup(const AccountData& account, int id, std::string_vie
188188
return {}; // TODO
189189
}
190190

191-
WebTask startStage3(const AccountData& account, std::string_view solution) {
191+
WebTask startStage3(const AccountData& account, uint32_t challengeId, std::string_view solution) {
192192
auto& argon = ArgonState::get();
193193
std::string_view serverUrl = argon.getServerUrl();
194194

195195
auto payload = matjson::makeObject({
196+
{"challengeId", challengeId},
196197
{"accountId", account.accountId},
197198
{"solution", solution}
198199
});
@@ -206,11 +207,12 @@ WebTask startStage3(const AccountData& account, std::string_view solution) {
206207
return std::move(req);
207208
}
208209

209-
WebTask pollStage3(const AccountData& account, std::string_view solution) {
210+
WebTask pollStage3(const AccountData& account, uint32_t challengeId, std::string_view solution) {
210211
auto& argon = ArgonState::get();
211212
std::string_view serverUrl = argon.getServerUrl();
212213

213214
auto payload = matjson::makeObject({
215+
{"challengeId", challengeId},
214216
{"accountId", account.accountId},
215217
{"solution", solution}
216218
});

src/web.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ namespace argon::web {
2222
WebTask stage2MessageCleanup(const AccountData& account, int id, std::string_view serverUrl);
2323
WebTask stage2CommentCleanup(const AccountData& account, int id, std::string_view serverUrl);
2424

25-
WebTask startStage3(const AccountData& account, std::string_view solution);
26-
WebTask pollStage3(const AccountData& account, std::string_view solution);
25+
WebTask startStage3(const AccountData& account, uint32_t challengeId, std::string_view solution);
26+
WebTask pollStage3(const AccountData& account, uint32_t challengeId, std::string_view solution);
2727
}

0 commit comments

Comments
 (0)