-
Notifications
You must be signed in to change notification settings - Fork 12
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
Showing
12 changed files
with
171 additions
and
217 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
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,92 @@ | ||
/* | ||
* Copyright (c) 2024 Ember | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
#include "AccountClient.h" | ||
#include <vector> | ||
|
||
namespace ember { | ||
|
||
AccountClient::AccountClient(spark::v2::Server& spark, log::Logger& logger) | ||
: services::Accountv2Client(spark), | ||
logger_(logger) { | ||
connect("127.0.0.1", 8000); // temp | ||
} | ||
|
||
void AccountClient::on_link_up(const spark::v2::Link& link) { | ||
LOG_TRACE(logger_) << log_func << LOG_ASYNC; | ||
link_ = link; | ||
} | ||
|
||
void AccountClient::on_link_down(const spark::v2::Link& link) { | ||
LOG_TRACE(logger_) << log_func << LOG_ASYNC; | ||
} | ||
|
||
void AccountClient::locate_session(const std::uint32_t account_id, LocateCB cb) const { | ||
LOG_TRACE(logger_) << log_func << LOG_ASYNC; | ||
|
||
messaging::Accountv2::SessionLookupT msg { | ||
.account_id = account_id | ||
}; | ||
|
||
send<messaging::Accountv2::SessionResponse>(msg, link_, | ||
[this, cb = std::move(cb)](auto link, auto message) { | ||
handle_locate_response(message, cb); | ||
} | ||
); | ||
} | ||
|
||
void AccountClient::locate_account_id(const std::string& username, AccountCB cb) const { | ||
LOG_TRACE(logger_) << log_func << LOG_ASYNC; | ||
|
||
messaging::Accountv2::LookupIDT msg { | ||
.account_name = username | ||
}; | ||
|
||
send<messaging::Accountv2::AccountFetchResponse>(msg, link_, | ||
[this, cb = std::move(cb)](auto link, auto message) { | ||
handle_lookup_response(message, cb); | ||
} | ||
); | ||
} | ||
|
||
void AccountClient::handle_lookup_response( | ||
std::expected<const messaging::Accountv2::AccountFetchResponse*, spark::v2::Result> resp, | ||
const AccountCB& cb) const { | ||
LOG_TRACE(logger_) << log_func << LOG_ASYNC; | ||
|
||
if(!resp) { | ||
cb(messaging::Accountv2::Status::RPC_ERROR, {}); | ||
return; | ||
} | ||
|
||
const auto msg = *resp; | ||
cb(msg->status(), msg->account_id()); | ||
} | ||
|
||
void AccountClient::handle_locate_response( | ||
std::expected<const messaging::Accountv2::SessionResponse*, spark::v2::Result> resp, | ||
const LocateCB& cb) const { | ||
LOG_TRACE(logger_) << log_func << LOG_ASYNC; | ||
|
||
if(!resp) { | ||
cb(messaging::Accountv2::Status::RPC_ERROR, {}); | ||
return; | ||
} | ||
|
||
const auto msg = *resp; | ||
|
||
if(!msg->key()) { | ||
cb(msg->status(), {}); | ||
return; | ||
} | ||
|
||
auto key = Botan::BigInt::decode(msg->key()->data(), msg->key()->size()); | ||
cb(msg->status(), std::move(key)); | ||
} | ||
|
||
} // ember |
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,49 @@ | ||
/* | ||
* Copyright (c) 2024 Ember | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <Accountv2ClientStub.h> | ||
#include <logger/Logger.h> | ||
#include <spark/v2/Server.h> | ||
#include <botan/bigint.h> | ||
#include <functional> | ||
#include <cstdint> | ||
|
||
namespace ember { | ||
|
||
class AccountClient final : public services::Accountv2Client { | ||
public: | ||
using LocateCB = std::function<void(messaging::Accountv2::Status, Botan::BigInt)>; | ||
using AccountCB = std::function<void(messaging::Accountv2::Status, std::uint32_t)>; | ||
|
||
private: | ||
log::Logger& logger_; | ||
spark::v2::Link link_; | ||
|
||
void on_link_up(const spark::v2::Link& link) override; | ||
void on_link_down(const spark::v2::Link& link) override; | ||
|
||
void handle_locate_response( | ||
std::expected<const messaging::Accountv2::SessionResponse*, spark::v2::Result> resp, | ||
const LocateCB& cb | ||
) const; | ||
|
||
void handle_lookup_response( | ||
std::expected<const messaging::Accountv2::AccountFetchResponse*, spark::v2::Result> resp, | ||
const AccountCB& cb | ||
) const; | ||
|
||
public: | ||
AccountClient(spark::v2::Server& spark, log::Logger& logger); | ||
|
||
void locate_session(std::uint32_t account_id, LocateCB cb) const; | ||
void locate_account_id(const std::string& username, AccountCB cb) const; | ||
}; | ||
|
||
} // ember |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.