-
Notifications
You must be signed in to change notification settings - Fork 14
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
[DO NOT review/merge it - just proposal] Separated config reading code from the rest logic #157
base: development/v.0.0.2
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
#pragma once | ||
|
||
#include "supernode/server/config.h" | ||
|
||
namespace graft::supernode { | ||
|
||
struct Config : public server::Config | ||
{ | ||
std::string data_dir; // base directory where supernode stake wallet and other supernodes wallets are located | ||
std::string stake_wallet_name; | ||
size_t stake_wallet_refresh_interval_ms; | ||
|
||
std::string watchonly_wallets_path; // path to watch-only wallets (supernodes) | ||
bool testnet; // testnet flag | ||
|
||
|
||
Config(void); | ||
}; | ||
|
||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
#pragma once | ||
|
||
namespace graft::supernode { | ||
|
||
class Config; | ||
|
||
class ConfigLoader | ||
{ | ||
public: | ||
ConfigLoader(void); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you need (void)? Is C somewhere assumed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. void is not related to C or C++. What the problem? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is most definitely related to C and is only even allowed in C++ because it needs to be compatible with C code. (But since this is a constructor it is especially pointless since C compatibility isn't even possible in the first place). See the C++ Core Guideline's strong recommendation against this. |
||
~ConfigLoader(void); | ||
|
||
ConfigLoader(const ConfigLoader&) = delete; | ||
ConfigLoader& operator = (const ConfigLoader&) = delete; | ||
|
||
bool load(int argc, const char** argv, Config& cfg); | ||
}; | ||
|
||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#pragma once | ||
|
||
#include "supernode/server/server.h" | ||
#include "supernode/config.h" | ||
|
||
namespace graft::supernode { | ||
|
||
using server::Server; | ||
|
||
class Node : public Server | ||
{ | ||
public: | ||
Node(void); | ||
~Node(void); | ||
|
||
bool run(const Config& cfg); | ||
|
||
protected: | ||
virtual void initMisc(server::Config& cfg) override; | ||
//virtual bool initConfigOption(int argc, const char** argv, ConfigOpts& configOpts) override; | ||
virtual void initRouters() override; | ||
|
||
private: | ||
void prepareDataDirAndSupernodes(); | ||
void startSupernodePeriodicTasks(); | ||
void setHttpRouters(ConnectionManager& httpcm); | ||
void setCoapRouters(ConnectionManager& coapcm); | ||
|
||
private: | ||
Config m_cfg; | ||
}; | ||
|
||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
|
||
#pragma once | ||
|
||
#include <functional> | ||
#include <map> | ||
#include <string> | ||
|
||
namespace graft { | ||
enum class Status: int; | ||
class Context; | ||
class InHttp; | ||
class OutHttp; | ||
} | ||
|
||
namespace graft::supernode::route { | ||
|
||
using Vars = std::multimap<std::string, std::string>; | ||
using graft::Context; | ||
using graft::Status; | ||
|
||
template<typename In, typename Out> | ||
using HandlerT = std::function<Status (const Vars&, const In&, Context&, Out&) >; | ||
|
||
using Input = graft::InHttp; | ||
using Output = graft::OutHttp; | ||
|
||
using Handler = HandlerT<Input, Output>; | ||
|
||
} | ||
|
||
|
||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
|
||
#pragma once | ||
|
||
#include "supernode/route/data.h" | ||
|
||
#include <string> | ||
|
||
namespace graft::supernode::route { | ||
|
||
struct Handler3 | ||
{ | ||
public: | ||
Handler pre_action; | ||
Handler worker_action; | ||
Handler post_action; | ||
std::string name; | ||
|
||
Handler3() = default; | ||
~Handler3() = default; | ||
|
||
Handler3(const Handler3&) = default; | ||
Handler3(Handler3&&) = default; | ||
|
||
Handler3& operator = (const Handler3&) = default; | ||
Handler3& operator = (Handler3&&) = default; | ||
|
||
Handler3(const Handler& pre_action, const Handler& action, const Handler& post_action, const std::string& name = std::string()); | ||
Handler3(Handler&& pre_action, Handler&& action, Handler&& post_action, std::string&& name = std::string()); | ||
Handler3(const Handler& worker_action); | ||
Handler3(Handler&& worker_action); | ||
}; | ||
|
||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
#pragma once | ||
|
||
#include "supernode/route/data.h" | ||
#include "supernode/route/handler3.h" | ||
#include "inout.h" | ||
|
||
namespace graft::supernode::route { | ||
|
||
struct JobParams | ||
{ | ||
Input input; | ||
Vars vars; | ||
Handler3 h3; | ||
}; | ||
|
||
} | ||
|
||
|
||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
|
||
#pragma once | ||
|
||
#include "supernode/route/handler3.h" | ||
|
||
#include <forward_list> | ||
#include <string> | ||
|
||
namespace graft::supernode::route { | ||
|
||
struct Route | ||
{ | ||
std::string endpoint; | ||
int method; | ||
Handler3 h3; | ||
|
||
Route(const std::string& end_poirnt, int method, const Handler3& h3); | ||
}; | ||
|
||
std::string method_to_str(int method); | ||
|
||
class RouteSet | ||
{ | ||
public: | ||
explicit RouteSet(const std::string& prefix = std::string()); | ||
RouteSet(RouteSet&&); | ||
~RouteSet(); | ||
|
||
void add(const std::string& endpoint, int method, const Handler3& ph3); | ||
void add(const std::string& endpoint, int method, const Handler3&& ph3); | ||
|
||
std::string dbg_dump(const std::string& prefix = std::string()) const; | ||
|
||
std::forward_list<Route> routes(void); | ||
const std::forward_list<Route> routes(void) const; | ||
|
||
private: | ||
std::forward_list<Route> m_routes; | ||
std::string m_endpointPrefix; | ||
}; | ||
|
||
} |
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 not "bool testnet = false;" or ""bool testnet = {}" instead of "Config(void);" ?
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.
Because I'd prefer use One way of initialization instead of two different ways.
And we can't always initialize all things inplace.