From 308840a3a3d80616e5a61bebbcdebb6d8ad99c66 Mon Sep 17 00:00:00 2001 From: buttercat1791 Date: Fri, 31 May 2024 08:36:07 -0500 Subject: Use namespaces in definition files --- src/client/websocketpp_client.cpp | 17 ++++++------ src/data/event.cpp | 13 +++++---- src/data/filters.cpp | 5 ++-- src/service/nostr_service_base.cpp | 57 +++++++++++++++++++------------------- src/signer/noscrypt_signer.cpp | 21 +++++++------- 5 files changed, 59 insertions(+), 54 deletions(-) (limited to 'src') diff --git a/src/client/websocketpp_client.cpp b/src/client/websocketpp_client.cpp index e4f6af6..b8458e6 100644 --- a/src/client/websocketpp_client.cpp +++ b/src/client/websocketpp_client.cpp @@ -2,21 +2,22 @@ #include "client/websocketpp_client.hpp" +using namespace nostr::client; using namespace std; -void nostr::client::WebsocketppClient::start() +void WebsocketppClient::start() { this->_client.init_asio(); this->_client.start_perpetual(); }; -void nostr::client::WebsocketppClient::stop() +void WebsocketppClient::stop() { this->_client.stop_perpetual(); this->_client.stop(); }; -void nostr::client::WebsocketppClient::openConnection(string uri) +void WebsocketppClient::openConnection(string uri) { error_code error; websocketpp_client::connection_ptr connection = this->_client.get_connection(uri, error); @@ -41,13 +42,13 @@ void nostr::client::WebsocketppClient::openConnection(string uri) this->_client.connect(connection); }; -bool nostr::client::WebsocketppClient::isConnected(string uri) +bool WebsocketppClient::isConnected(string uri) { lock_guard lock(this->_propertyMutex); return this->_connectionHandles.find(uri) != this->_connectionHandles.end(); }; -tuple nostr::client::WebsocketppClient::send(string message, string uri) +tuple WebsocketppClient::send(string message, string uri) { error_code error; @@ -67,7 +68,7 @@ tuple nostr::client::WebsocketppClient::send(string message, strin return make_tuple(uri, true); }; -tuple nostr::client::WebsocketppClient::send( +tuple WebsocketppClient::send( string message, string uri, function messageHandler) @@ -77,7 +78,7 @@ tuple nostr::client::WebsocketppClient::send( return successes; }; -void nostr::client::WebsocketppClient::receive( +void WebsocketppClient::receive( string uri, function messageHandler) { @@ -93,7 +94,7 @@ void nostr::client::WebsocketppClient::receive( }); }; -void nostr::client::WebsocketppClient::closeConnection(string uri) +void WebsocketppClient::closeConnection(string uri) { lock_guard lock(this->_propertyMutex); diff --git a/src/data/event.cpp b/src/data/event.cpp index bd37ee7..e275f31 100644 --- a/src/data/event.cpp +++ b/src/data/event.cpp @@ -4,9 +4,10 @@ #include "data/data.hpp" using namespace nlohmann; +using namespace nostr::data; using namespace std; -string nostr::data::Event::serialize() +string Event::serialize() { try { @@ -30,7 +31,7 @@ string nostr::data::Event::serialize() return j.dump(); }; -nostr::data::Event nostr::data::Event::fromString(string jstr) +Event Event::fromString(string jstr) { json j = json::parse(jstr); Event event; @@ -47,7 +48,7 @@ nostr::data::Event nostr::data::Event::fromString(string jstr) return event; }; -nostr::data::Event nostr::data::Event::fromJson(json j) +Event Event::fromJson(json j) { Event event; @@ -68,7 +69,7 @@ nostr::data::Event nostr::data::Event::fromJson(json j) return event; }; -void nostr::data::Event::validate() +void Event::validate() { bool hasPubkey = this->pubkey.length() > 0; if (!hasPubkey) @@ -89,7 +90,7 @@ void nostr::data::Event::validate() } }; -string nostr::data::Event::generateId(string serializedData) const +string Event::generateId(string serializedData) const { unsigned char hash[SHA256_DIGEST_LENGTH]; EVP_Digest(serializedData.c_str(), serializedData.length(), hash, NULL, EVP_sha256(), NULL); @@ -103,7 +104,7 @@ string nostr::data::Event::generateId(string serializedData) const return ss.str(); }; -bool nostr::data::Event::operator==(const Event& other) const +bool Event::operator==(const Event& other) const { if (this->id.empty()) { diff --git a/src/data/filters.cpp b/src/data/filters.cpp index e345c95..11c099b 100644 --- a/src/data/filters.cpp +++ b/src/data/filters.cpp @@ -3,9 +3,10 @@ #include "data/data.hpp" using namespace nlohmann; +using namespace nostr::data; using namespace std; -string nostr::data::Filters::serialize(string& subscriptionId) +string Filters::serialize(string& subscriptionId) { try { @@ -38,7 +39,7 @@ string nostr::data::Filters::serialize(string& subscriptionId) return jarr.dump(); }; -void nostr::data::Filters::validate() +void Filters::validate() { bool hasLimit = this->limit > 0; if (!hasLimit) diff --git a/src/service/nostr_service_base.cpp b/src/service/nostr_service_base.cpp index ec847b3..7f3d92c 100644 --- a/src/service/nostr_service_base.cpp +++ b/src/service/nostr_service_base.cpp @@ -8,14 +8,15 @@ #include "service/nostr_service_base.hpp" using namespace nlohmann; +using namespace nostr::service; using namespace std; -nostr::service::NostrServiceBase::NostrServiceBase( +NostrServiceBase::NostrServiceBase( shared_ptr appender, shared_ptr client) : NostrServiceBase(appender, client, {}) { }; -nostr::service::NostrServiceBase::NostrServiceBase( +NostrServiceBase::NostrServiceBase( shared_ptr appender, shared_ptr client, vector relays) @@ -25,26 +26,26 @@ nostr::service::NostrServiceBase::NostrServiceBase( client->start(); }; -nostr::service::NostrServiceBase::~NostrServiceBase() +NostrServiceBase::~NostrServiceBase() { this->_client->stop(); }; -vector nostr::service::NostrServiceBase::defaultRelays() const +vector NostrServiceBase::defaultRelays() const { return this->_defaultRelays; }; -vector nostr::service::NostrServiceBase::activeRelays() const +vector NostrServiceBase::activeRelays() const { return this->_activeRelays; }; -unordered_map> nostr::service::NostrServiceBase::subscriptions() const +unordered_map> NostrServiceBase::subscriptions() const { return this->_subscriptions; }; -vector nostr::service::NostrServiceBase::openRelayConnections() +vector NostrServiceBase::openRelayConnections() { return this->openRelayConnections(this->_defaultRelays); }; -vector nostr::service::NostrServiceBase::openRelayConnections(vector relays) +vector NostrServiceBase::openRelayConnections(vector relays) { PLOG_INFO << "Attempting to connect to Nostr relays."; vector unconnectedRelays = this->_getUnconnectedRelays(relays); @@ -71,7 +72,7 @@ vector nostr::service::NostrServiceBase::openRelayConnections(vector_activeRelays; }; -void nostr::service::NostrServiceBase::closeRelayConnections() +void NostrServiceBase::closeRelayConnections() { if (this->_activeRelays.size() == 0) { @@ -82,7 +83,7 @@ void nostr::service::NostrServiceBase::closeRelayConnections() this->closeRelayConnections(this->_activeRelays); }; -void nostr::service::NostrServiceBase::closeRelayConnections(vector relays) +void NostrServiceBase::closeRelayConnections(vector relays) { PLOG_INFO << "Disconnecting from Nostr relays."; vector connectedRelays = this->_getConnectedRelays(relays); @@ -107,7 +108,7 @@ void nostr::service::NostrServiceBase::closeRelayConnections(vector rela }; // TODO: Make this method return a promise. -tuple, vector> nostr::service::NostrServiceBase::publishEvent( +tuple, vector> NostrServiceBase::publishEvent( shared_ptr event) { vector successfulRelays; @@ -188,7 +189,7 @@ tuple, vector> nostr::service::NostrServiceBase::publishE // TODO: Make this method return a promise. // TODO: Add a timeout to this method to prevent hanging while waiting for the relay. -vector> nostr::service::NostrServiceBase::queryRelays( +vector> NostrServiceBase::queryRelays( shared_ptr filters) { if (filters->limit > 64 || filters->limit < 1) @@ -283,7 +284,7 @@ vector> nostr::service::NostrServiceBase::queryRe return events; }; -string nostr::service::NostrServiceBase::queryRelays( +string NostrServiceBase::queryRelays( shared_ptr filters, function)> eventHandler, function eoseHandler, @@ -335,7 +336,7 @@ string nostr::service::NostrServiceBase::queryRelays( return subscriptionId; }; -tuple, vector> nostr::service::NostrServiceBase::closeSubscription(string subscriptionId) +tuple, vector> NostrServiceBase::closeSubscription(string subscriptionId) { vector successfulRelays; vector failedRelays; @@ -395,7 +396,7 @@ tuple, vector> nostr::service::NostrServiceBase::closeSub return make_tuple(successfulRelays, failedRelays); }; -bool nostr::service::NostrServiceBase::closeSubscription(string subscriptionId, string relay) +bool NostrServiceBase::closeSubscription(string subscriptionId, string relay) { if (!this->_hasSubscription(subscriptionId, relay)) { @@ -435,7 +436,7 @@ bool nostr::service::NostrServiceBase::closeSubscription(string subscriptionId, return success; }; -vector nostr::service::NostrServiceBase::closeSubscriptions() +vector NostrServiceBase::closeSubscriptions() { unique_lock lock(this->_propertyMutex); vector subscriptionIds; @@ -458,7 +459,7 @@ vector nostr::service::NostrServiceBase::closeSubscriptions() return remainingSubscriptions; }; -vector nostr::service::NostrServiceBase::_getConnectedRelays(vector relays) +vector NostrServiceBase::_getConnectedRelays(vector relays) { PLOG_VERBOSE << "Identifying connected relays."; vector connectedRelays; @@ -486,7 +487,7 @@ vector nostr::service::NostrServiceBase::_getConnectedRelays(vector nostr::service::NostrServiceBase::_getUnconnectedRelays(vector relays) +vector NostrServiceBase::_getUnconnectedRelays(vector relays) { PLOG_VERBOSE << "Identifying unconnected relays."; vector unconnectedRelays; @@ -517,7 +518,7 @@ vector nostr::service::NostrServiceBase::_getUnconnectedRelays(vector_activeRelays.begin(), this->_activeRelays.end(), relay); if (it != this->_activeRelays.end()) // If the relay is in this->_activeRelays @@ -527,7 +528,7 @@ bool nostr::service::NostrServiceBase::_isConnected(string relay) return false; }; -void nostr::service::NostrServiceBase::_eraseActiveRelay(string relay) +void NostrServiceBase::_eraseActiveRelay(string relay) { auto it = find(this->_activeRelays.begin(), this->_activeRelays.end(), relay); if (it != this->_activeRelays.end()) // If the relay is in this->_activeRelays @@ -536,7 +537,7 @@ void nostr::service::NostrServiceBase::_eraseActiveRelay(string relay) } }; -void nostr::service::NostrServiceBase::_connect(string relay) +void NostrServiceBase::_connect(string relay) { PLOG_VERBOSE << "Connecting to relay " << relay; this->_client->openConnection(relay); @@ -555,7 +556,7 @@ void nostr::service::NostrServiceBase::_connect(string relay) } }; -void nostr::service::NostrServiceBase::_disconnect(string relay) +void NostrServiceBase::_disconnect(string relay) { this->_client->closeConnection(relay); @@ -563,20 +564,20 @@ void nostr::service::NostrServiceBase::_disconnect(string relay) this->_eraseActiveRelay(relay); }; -string nostr::service::NostrServiceBase::_generateSubscriptionId() +string NostrServiceBase::_generateSubscriptionId() { UUIDv4::UUIDGenerator uuidGenerator; UUIDv4::UUID uuid = uuidGenerator.getUUID(); return uuid.str(); }; -string nostr::service::NostrServiceBase::_generateCloseRequest(string subscriptionId) +string NostrServiceBase::_generateCloseRequest(string subscriptionId) { json jarr = json::array({ "CLOSE", subscriptionId }); return jarr.dump(); }; -bool nostr::service::NostrServiceBase::_hasSubscription(string subscriptionId) +bool NostrServiceBase::_hasSubscription(string subscriptionId) { lock_guard lock(this->_propertyMutex); auto it = this->_subscriptions.find(subscriptionId); @@ -584,7 +585,7 @@ bool nostr::service::NostrServiceBase::_hasSubscription(string subscriptionId) return it != this->_subscriptions.end(); }; -bool nostr::service::NostrServiceBase::_hasSubscription(string subscriptionId, string relay) +bool NostrServiceBase::_hasSubscription(string subscriptionId, string relay) { lock_guard lock(this->_propertyMutex); auto subscriptionIt = this->_subscriptions.find(subscriptionId); @@ -600,7 +601,7 @@ bool nostr::service::NostrServiceBase::_hasSubscription(string subscriptionId, s return relayIt != relays.end(); }; -void nostr::service::NostrServiceBase::_onSubscriptionMessage( +void NostrServiceBase::_onSubscriptionMessage( string message, function)> eventHandler, function eoseHandler, @@ -645,7 +646,7 @@ void nostr::service::NostrServiceBase::_onSubscriptionMessage( } }; -void nostr::service::NostrServiceBase::_onAcceptance( +void NostrServiceBase::_onAcceptance( string message, function acceptanceHandler) { diff --git a/src/signer/noscrypt_signer.cpp b/src/signer/noscrypt_signer.cpp index 6bc9af0..2b00cca 100644 --- a/src/signer/noscrypt_signer.cpp +++ b/src/signer/noscrypt_signer.cpp @@ -5,9 +5,10 @@ #include "signer/noscrypt_signer.hpp" +using namespace nostr::signer; using namespace std; -nostr::signer::NoscryptSigner::NoscryptSigner( +NoscryptSigner::NoscryptSigner( shared_ptr appender, shared_ptr nostrService) { @@ -24,17 +25,17 @@ nostr::signer::NoscryptSigner::NoscryptSigner( this->_localPublicKey = publicKey; }; -nostr::signer::NoscryptSigner::~NoscryptSigner() +NoscryptSigner::~NoscryptSigner() { NCDestroyContext(this->_noscryptContext.get()); }; -void nostr::signer::NoscryptSigner::receiveConnection(string connectionToken) +void NoscryptSigner::receiveConnection(string connectionToken) { // Receive the connection token here. }; -string nostr::signer::NoscryptSigner::initiateConnection( +string NoscryptSigner::initiateConnection( vector relays, string name, string url, @@ -74,7 +75,7 @@ string nostr::signer::NoscryptSigner::initiateConnection( return ss.str(); }; -void nostr::signer::NoscryptSigner::sign(shared_ptr event) +void NoscryptSigner::sign(shared_ptr event) { // Sign the event here. }; @@ -83,7 +84,7 @@ void nostr::signer::NoscryptSigner::sign(shared_ptr event) * @brief Initializes the noscrypt library context into the class's `context` property. * @returns `true` if successful, `false` otherwise. */ -shared_ptr nostr::signer::NoscryptSigner::_initNoscryptContext() +shared_ptr NoscryptSigner::_initNoscryptContext() { shared_ptr context; auto contextStructSize = NCGetContextStructSize(); @@ -112,7 +113,7 @@ shared_ptr nostr::signer::NoscryptSigner::_initNoscryptContext() * @remarks This keypair is intended for temporary use, and should not be saved or used outside * of this class. */ -tuple nostr::signer::NoscryptSigner::_createLocalKeypair() +tuple NoscryptSigner::_createLocalKeypair() { string privateKey; string publicKey; @@ -177,7 +178,7 @@ tuple nostr::signer::NoscryptSigner::_createLocalKeypair() #pragma region Logging -void nostr::signer::NoscryptSigner::_logNoscryptInitResult(NCResult initResult) +void NoscryptSigner::_logNoscryptInitResult(NCResult initResult) { switch (initResult) { case NC_SUCCESS: @@ -206,7 +207,7 @@ void nostr::signer::NoscryptSigner::_logNoscryptInitResult(NCResult initResult) } }; -void nostr::signer::NoscryptSigner::_logNoscryptSecretValidationResult(NCResult secretValidationResult) +void NoscryptSigner::_logNoscryptSecretValidationResult(NCResult secretValidationResult) { if (secretValidationResult == NC_SUCCESS) { @@ -218,7 +219,7 @@ void nostr::signer::NoscryptSigner::_logNoscryptSecretValidationResult(NCResult } }; -void nostr::signer::NoscryptSigner::_logNoscryptPubkeyGenerationResult(NCResult pubkeyGenerationResult) +void NoscryptSigner::_logNoscryptPubkeyGenerationResult(NCResult pubkeyGenerationResult) { switch (pubkeyGenerationResult) { case NC_SUCCESS: -- cgit