Skip to content

Commit

Permalink
Adjusted for example, seperated static functions
Browse files Browse the repository at this point in the history
  • Loading branch information
nbdy committed Apr 29, 2023
1 parent 7bdbe3d commit 098f655
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
4 changes: 2 additions & 2 deletions include/onionpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ std::vector<char *> onionpp::TorConfiguration::toArguments() {
std::string onionpp::TorConfiguration::getProxyAddress() const {
return "socks5h://127.0.0.1:" + std::to_string(m_u16SocksPort);
}
const char *onionpp::Tor::getVersion() {
const char *onionpp::STor::getVersion() {
return tor_api_get_provider_version();
}
bool onionpp::Tor::_start() {
Expand All @@ -111,7 +111,7 @@ bool onionpp::Tor::start(std::vector<char *> i_Arguments) {
tor_main_configuration_free(cfg);
return rVal;
}
std::string onionpp::Tor::hashPassword(const std::string &i_sValue) {
std::string onionpp::STor::hashPassword(const std::string &i_sValue) {
char output[256];
memset(output, 0, sizeof(output));
char key[29];
Expand Down
11 changes: 6 additions & 5 deletions include/onionpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,22 @@ class TorConfiguration {
std::string getProxyAddress() const;
};

struct STor {
static const char* getVersion();
static std::string hashPassword(const std::string &i_sValue);
};

class ITor {
public:
ITor() = default;
~ITor() = default;

virtual const char *getVersion() = 0;
virtual void start(bool i_Wait) = 0;
virtual std::string hashPassword(const std::string &i_sValue) = 0;
virtual bool isBootstrapped() = 0;
virtual void waitUntilBootstrapped() = 0;
};

class Tor : public ITor {
class Tor : public ITor, public STor {
pthread_t m_Thread {};
TorConfiguration m_Configuration;

Expand All @@ -74,9 +77,7 @@ class Tor : public ITor {
explicit Tor(const TorConfiguration &i_Configuration) : m_Configuration(i_Configuration) {}
~Tor();

const char *getVersion() override;
void start(bool i_Wait) override;
std::string hashPassword(const std::string &i_sValue) override;
bool isBootstrapped() override;
void waitUntilBootstrapped() override;

Expand Down
10 changes: 4 additions & 6 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,17 @@ int main() {
sigaction(SIGINT, &signalHandler, nullptr);
#endif

auto tor = onionpp::Tor();

std::cout << "Version: " << tor.getVersion() << std::endl;
auto hashedPassword = tor.hashPassword("my_password");
std::cout << "Version: " << onionpp::Tor::getVersion() << std::endl;
auto hashedPassword = onionpp::Tor::hashPassword("my_password");
std::cout << hashedPassword << std::endl;

auto cfg = onionpp::TorConfiguration();
onionpp::TorConfiguration cfg {};
cfg.setControlPortEnabled(true);
cfg.setHashedPasswordAuthenticationEnabled(true);
cfg.setHashedControlPassword(hashedPassword);
std::cout << "Created tor configuration" << std::endl;

tor.start(cfg);
onionpp::Tor tor(cfg);
std::cout << "Tor is running now and can be controlled via the control port." << std::endl;

while(bRun) {
Expand Down

0 comments on commit 098f655

Please sign in to comment.