aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLibravatar buttercat1791 <mjjurkoic@gmail.com>2024-05-31 08:36:07 -0500
committerLibravatar buttercat1791 <mjjurkoic@gmail.com>2024-05-31 08:36:07 -0500
commit308840a3a3d80616e5a61bebbcdebb6d8ad99c66 (patch)
treece12f499bd19d81278f22cfe05d440bdc2b134a5 /src
parentc070fcbdebc237eae47f37fe7f2f50004b9010af (diff)
Use namespaces in definition files
Diffstat (limited to 'src')
-rw-r--r--src/client/websocketpp_client.cpp17
-rw-r--r--src/data/event.cpp13
-rw-r--r--src/data/filters.cpp5
-rw-r--r--src/service/nostr_service_base.cpp57
-rw-r--r--src/signer/noscrypt_signer.cpp21
5 files changed, 59 insertions, 54 deletions
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<mutex> lock(this->_propertyMutex);
return this->_connectionHandles.find(uri) != this->_connectionHandles.end();
};
-tuple<string, bool> nostr::client::WebsocketppClient::send(string message, string uri)
+tuple<string, bool> WebsocketppClient::send(string message, string uri)
{
error_code error;
@@ -67,7 +68,7 @@ tuple<string, bool> nostr::client::WebsocketppClient::send(string message, strin
return make_tuple(uri, true);
};
-tuple<string, bool> nostr::client::WebsocketppClient::send(
+tuple<string, bool> WebsocketppClient::send(
string message,
string uri,
function<void(const string&)> messageHandler)
@@ -77,7 +78,7 @@ tuple<string, bool> nostr::client::WebsocketppClient::send(
return successes;
};
-void nostr::client::WebsocketppClient::receive(
+void WebsocketppClient::receive(
string uri,
function<void(const string&)> messageHandler)
{
@@ -93,7 +94,7 @@ void nostr::client::WebsocketppClient::receive(
});
};
-void nostr::client::WebsocketppClient::closeConnection(string uri)
+void WebsocketppClient::closeConnection(string uri)
{
lock_guard<mutex> 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<plog::IAppender> appender,
shared_ptr<client::IWebSocketClient> client)
: NostrServiceBase(appender, client, {}) { };
-nostr::service::NostrServiceBase::NostrServiceBase(
+NostrServiceBase::NostrServiceBase(
shared_ptr<plog::IAppender> appender,
shared_ptr<client::IWebSocketClient> client,
vector<string> relays)
@@ -25,26 +26,26 @@ nostr::service::NostrServiceBase::NostrServiceBase(
client->start();
};
-nostr::service::NostrServiceBase::~NostrServiceBase()
+NostrServiceBase::~NostrServiceBase()
{
this->_client->stop();
};
-vector<string> nostr::service::NostrServiceBase::defaultRelays() const
+vector<string> NostrServiceBase::defaultRelays() const
{ return this->_defaultRelays; };
-vector<string> nostr::service::NostrServiceBase::activeRelays() const
+vector<string> NostrServiceBase::activeRelays() const
{ return this->_activeRelays; };
-unordered_map<string, vector<string>> nostr::service::NostrServiceBase::subscriptions() const
+unordered_map<string, vector<string>> NostrServiceBase::subscriptions() const
{ return this->_subscriptions; };
-vector<string> nostr::service::NostrServiceBase::openRelayConnections()
+vector<string> NostrServiceBase::openRelayConnections()
{
return this->openRelayConnections(this->_defaultRelays);
};
-vector<string> nostr::service::NostrServiceBase::openRelayConnections(vector<string> relays)
+vector<string> NostrServiceBase::openRelayConnections(vector<string> relays)
{
PLOG_INFO << "Attempting to connect to Nostr relays.";
vector<string> unconnectedRelays = this->_getUnconnectedRelays(relays);
@@ -71,7 +72,7 @@ vector<string> nostr::service::NostrServiceBase::openRelayConnections(vector<str
return this->_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<string> relays)
+void NostrServiceBase::closeRelayConnections(vector<string> relays)
{
PLOG_INFO << "Disconnecting from Nostr relays.";
vector<string> connectedRelays = this->_getConnectedRelays(relays);
@@ -107,7 +108,7 @@ void nostr::service::NostrServiceBase::closeRelayConnections(vector<string> rela
};
// TODO: Make this method return a promise.
-tuple<vector<string>, vector<string>> nostr::service::NostrServiceBase::publishEvent(
+tuple<vector<string>, vector<string>> NostrServiceBase::publishEvent(
shared_ptr<nostr::data::Event> event)
{
vector<string> successfulRelays;
@@ -188,7 +189,7 @@ tuple<vector<string>, vector<string>> 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<shared_ptr<nostr::data::Event>> nostr::service::NostrServiceBase::queryRelays(
+vector<shared_ptr<nostr::data::Event>> NostrServiceBase::queryRelays(
shared_ptr<nostr::data::Filters> filters)
{
if (filters->limit > 64 || filters->limit < 1)
@@ -283,7 +284,7 @@ vector<shared_ptr<nostr::data::Event>> nostr::service::NostrServiceBase::queryRe
return events;
};
-string nostr::service::NostrServiceBase::queryRelays(
+string NostrServiceBase::queryRelays(
shared_ptr<nostr::data::Filters> filters,
function<void(const string&, shared_ptr<nostr::data::Event>)> eventHandler,
function<void(const string&)> eoseHandler,
@@ -335,7 +336,7 @@ string nostr::service::NostrServiceBase::queryRelays(
return subscriptionId;
};
-tuple<vector<string>, vector<string>> nostr::service::NostrServiceBase::closeSubscription(string subscriptionId)
+tuple<vector<string>, vector<string>> NostrServiceBase::closeSubscription(string subscriptionId)
{
vector<string> successfulRelays;
vector<string> failedRelays;
@@ -395,7 +396,7 @@ tuple<vector<string>, vector<string>> 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<string> nostr::service::NostrServiceBase::closeSubscriptions()
+vector<string> NostrServiceBase::closeSubscriptions()
{
unique_lock<mutex> lock(this->_propertyMutex);
vector<string> subscriptionIds;
@@ -458,7 +459,7 @@ vector<string> nostr::service::NostrServiceBase::closeSubscriptions()
return remainingSubscriptions;
};
-vector<string> nostr::service::NostrServiceBase::_getConnectedRelays(vector<string> relays)
+vector<string> NostrServiceBase::_getConnectedRelays(vector<string> relays)
{
PLOG_VERBOSE << "Identifying connected relays.";
vector<string> connectedRelays;
@@ -486,7 +487,7 @@ vector<string> nostr::service::NostrServiceBase::_getConnectedRelays(vector<stri
return connectedRelays;
};
-vector<string> nostr::service::NostrServiceBase::_getUnconnectedRelays(vector<string> relays)
+vector<string> NostrServiceBase::_getUnconnectedRelays(vector<string> relays)
{
PLOG_VERBOSE << "Identifying unconnected relays.";
vector<string> unconnectedRelays;
@@ -517,7 +518,7 @@ vector<string> nostr::service::NostrServiceBase::_getUnconnectedRelays(vector<st
return unconnectedRelays;
};
-bool nostr::service::NostrServiceBase::_isConnected(string relay)
+bool NostrServiceBase::_isConnected(string relay)
{
auto it = find(this->_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<std::mt19937_64> 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<mutex> 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<mutex> 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<void(const string&, shared_ptr<nostr::data::Event>)> eventHandler,
function<void(const string&)> eoseHandler,
@@ -645,7 +646,7 @@ void nostr::service::NostrServiceBase::_onSubscriptionMessage(
}
};
-void nostr::service::NostrServiceBase::_onAcceptance(
+void NostrServiceBase::_onAcceptance(
string message,
function<void(const bool)> 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<plog::IAppender> appender,
shared_ptr<nostr::service::INostrServiceBase> 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<string> relays,
string name,
string url,
@@ -74,7 +75,7 @@ string nostr::signer::NoscryptSigner::initiateConnection(
return ss.str();
};
-void nostr::signer::NoscryptSigner::sign(shared_ptr<data::Event> event)
+void NoscryptSigner::sign(shared_ptr<data::Event> event)
{
// Sign the event here.
};
@@ -83,7 +84,7 @@ void nostr::signer::NoscryptSigner::sign(shared_ptr<data::Event> event)
* @brief Initializes the noscrypt library context into the class's `context` property.
* @returns `true` if successful, `false` otherwise.
*/
-shared_ptr<NCContext> nostr::signer::NoscryptSigner::_initNoscryptContext()
+shared_ptr<NCContext> NoscryptSigner::_initNoscryptContext()
{
shared_ptr<NCContext> context;
auto contextStructSize = NCGetContextStructSize();
@@ -112,7 +113,7 @@ shared_ptr<NCContext> nostr::signer::NoscryptSigner::_initNoscryptContext()
* @remarks This keypair is intended for temporary use, and should not be saved or used outside
* of this class.
*/
-tuple<string, string> nostr::signer::NoscryptSigner::_createLocalKeypair()
+tuple<string, string> NoscryptSigner::_createLocalKeypair()
{
string privateKey;
string publicKey;
@@ -177,7 +178,7 @@ tuple<string, string> 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: