Skip to content

Port server to C++#36

Draft
UsualSpec wants to merge 13 commits intomainfrom
ChatGPT/portServerCpp
Draft

Port server to C++#36
UsualSpec wants to merge 13 commits intomainfrom
ChatGPT/portServerCpp

Conversation

@UsualSpec
Copy link
Collaborator

Attention! This was written by ChatGPT: https://chatgpt.com/share/672b9656-e62c-8009-834f-ee360f67e96f This is to be reviewed and probably largely refactored. Still serves as good start

Comment on lines 1 to 10
#include <grpcpp/grpcpp.h>
#include <jsoncpp/json/json.h>
#include <fstream>
#include <iostream>
#include <memory>
#include <pqxx/pqxx>
#include <thread>
#include "CLI.h"
#include "CMeasurementApiServicer.h"
#include "PgConnectorFactory.h"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably all should be in server.h


int main(int argc, char* argv[]) {
// Parse arguments
cxxopts::Options options("MeasurementServer", "Server for managing measurements via gRPC.");
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-> verify cxxopts validity. New dependency

("interactive", "Start server in interactive mode", cxxopts::value<bool>()->default_value("false"));

auto result = options.parse(argc, argv);
std::string secretsFilePath = result["secrets"].as<std::string>();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add checks!

configFile >> config;

// Start the server
serve(secrets, config, interactive);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: Validate that it is ok to just parse the interactive flag, not whole "args" as in python.

pbdef::api::msmtSettings CMeasurementApiServicer::getMsmtSttngsAndStart(const pbdef::api::clientRequest& request) {
pbdef::api::msmtSettings settings;
pqxx::work txn(*pgConn_);
pqxx::result r = txn.exec_params("SELECT setting_key, setting_value FROM measurement_settings WHERE client_uid = $1", request.uid());
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No! there is no measurement_settings table!

}

pbdef::api::nothing CMeasurementApiServicer::putStatusMsg(const pbdef::api::statusMessage& request) {
ClientManager cm;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No.


bool CMeasurementApiServicer::isValidMgmtClient(const pbdef::api::mgmtClientRequest& request) {
auto clientIt = allowedMgmtClients_.find(request.client_id());
return clientIt != allowedMgmtClients_.end() && clientIt->second == request.client_secret();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely not.

}
txn.commit();
logClientWasSeenNow(request.uid());
return clients;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rewrite this in gRPC style


pbdef::api::srvResponse CMeasurementApiServicer::issueRequestToClient(const pbdef::api::mgmtRequest& request) {
ClientManager cm;
cm.issueRequestToClient(request.client_uid(), request);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant