From 8fa965823a622a0cae8ea6107f10b868604b953a Mon Sep 17 00:00:00 2001 From: Suraxius Date: Sat, 5 Dec 2020 22:29:49 +0100 Subject: [PATCH] Restructuring project --- README.md | 3 + src/api/CMakeLists.txt | 9 +-- src/api/Server.cpp | 10 ++++ src/api/include/API.hpp | 4 +- src/api/include/Server.hpp | 18 ++++++ src/api/src/API.cpp | 0 src/cluster/CMakeLists.txt | 8 +-- src/cluster/Cluster.cpp | 8 +++ src/cluster/include/Cluster.hpp | 6 +- src/cluster/src/Cluster.cpp | 0 src/core/CMakeLists.txt | 5 +- src/core/ConfigManager.cpp | 5 ++ src/core/EventBus.cpp | 9 +++ src/core/Record.cpp | 11 ++++ "src/core/\\" | 18 ++++++ src/core/include/ConfigManager.hpp | 6 ++ src/core/include/EventBus.hpp | 5 ++ src/core/include/Key.hpp | 5 ++ src/core/include/Ledger.hpp | 6 ++ src/core/include/Logging.hpp | 11 ++++ src/core/include/PublicKey.hpp | 0 src/core/include/Record.hpp | 71 +++++++++++++++++++++++ src/core/include/Resource.hpp | 22 ++++++- src/core/include/Serialize.hpp | 15 +++-- src/core/include/Zone.hpp | 7 +++ src/core/main.cpp | 15 ++++- src/resolver/CMakeLists.txt | 2 +- src/resolver/{Resolver.cpp => Server.cpp} | 9 ++- src/resolver/include/Resolver.hpp | 12 +--- src/resolver/include/Server.hpp | 20 +++++++ src/storage/CMakeLists.txt | 9 +-- src/storage/Storage.cpp | 6 ++ src/storage/include/Storage.hpp | 4 ++ src/storage/src/Storage.cpp | 0 34 files changed, 292 insertions(+), 47 deletions(-) create mode 100644 src/api/Server.cpp create mode 100644 src/api/include/Server.hpp delete mode 100644 src/api/src/API.cpp create mode 100644 src/cluster/Cluster.cpp delete mode 100644 src/cluster/src/Cluster.cpp create mode 100644 src/core/Record.cpp create mode 100644 "src/core/\\" create mode 100644 src/core/include/Key.hpp create mode 100644 src/core/include/Logging.hpp delete mode 100644 src/core/include/PublicKey.hpp create mode 100644 src/core/include/Record.hpp create mode 100644 src/core/include/Zone.hpp rename src/resolver/{Resolver.cpp => Server.cpp} (58%) create mode 100644 src/resolver/include/Server.hpp create mode 100644 src/storage/Storage.cpp delete mode 100644 src/storage/src/Storage.cpp diff --git a/README.md b/README.md index 480c637..a2047fb 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,9 @@ A Distributed approach to Authoritative DNS #### Properties/Variables - smallCammelCase +### Namespaces +- LargeCamelCase + ### Files #### Source Files diff --git a/src/api/CMakeLists.txt b/src/api/CMakeLists.txt index c52183c..4a205b0 100644 --- a/src/api/CMakeLists.txt +++ b/src/api/CMakeLists.txt @@ -1,8 +1,5 @@ -add_library(API OBJECT) +add_library(API OBJECT Server.cpp) -target_sources(API PRIVATE src) - -target_include_directories(API - PUBLIC include - PRIVATE src) +target_include_directories(API PUBLIC include) +target_link_libraries(API PRIVATE Core) diff --git a/src/api/Server.cpp b/src/api/Server.cpp new file mode 100644 index 0000000..b4ca9c7 --- /dev/null +++ b/src/api/Server.cpp @@ -0,0 +1,10 @@ +#include "Server.hpp" + +namespace DistriNS { +namespace API { + +Server::Server(EventBus& eventBus) : eventBus(eventBus) { + //Constructor +} + +}} diff --git a/src/api/include/API.hpp b/src/api/include/API.hpp index 533f42a..9b615f7 100644 --- a/src/api/include/API.hpp +++ b/src/api/include/API.hpp @@ -1,6 +1,4 @@ #ifndef API_HPP #define API_HPP - -class API; - +#include "Server.hpp" #endif diff --git a/src/api/include/Server.hpp b/src/api/include/Server.hpp new file mode 100644 index 0000000..dc808c8 --- /dev/null +++ b/src/api/include/Server.hpp @@ -0,0 +1,18 @@ +#ifndef SERVER_HPP +#define SERVER_HPP +#include "EventBus.hpp" + +namespace DistriNS { +namespace API { + +using Core::EventBus; + +class Server { + const EventBus& eventBus; + + public: + Server(EventBus& eventBus); +}; + +}} +#endif diff --git a/src/api/src/API.cpp b/src/api/src/API.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/src/cluster/CMakeLists.txt b/src/cluster/CMakeLists.txt index d391807..a4972ac 100644 --- a/src/cluster/CMakeLists.txt +++ b/src/cluster/CMakeLists.txt @@ -1,7 +1,5 @@ -add_library(Cluster OBJECT) +add_library(Cluster OBJECT Cluster.cpp) -target_sources(Cluster PRIVATE src) +target_include_directories(Cluster PUBLIC include) -target_include_directories(Cluster - PUBLIC include - PRIVATE src) +target_link_libraries(Cluster PRIVATE Core) diff --git a/src/cluster/Cluster.cpp b/src/cluster/Cluster.cpp new file mode 100644 index 0000000..8a4745f --- /dev/null +++ b/src/cluster/Cluster.cpp @@ -0,0 +1,8 @@ +#include "Cluster.hpp" + +namespace DistriNS { +namespace Cluster { + +Cluster::Cluster() {}; + //Code +}} diff --git a/src/cluster/include/Cluster.hpp b/src/cluster/include/Cluster.hpp index 88cb666..aafb8aa 100644 --- a/src/cluster/include/Cluster.hpp +++ b/src/cluster/include/Cluster.hpp @@ -1,6 +1,8 @@ #ifndef CLUSTER_HPP #define CLUSTER_HPP -#include "Cluster.hpp" + +namespace DistriNS { +namespace Cluster { class Cluster { @@ -8,4 +10,6 @@ class Cluster Cluster(); }; +}} + #endif diff --git a/src/cluster/src/Cluster.cpp b/src/cluster/src/Cluster.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index e2f38ee..3ac4c78 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -1,11 +1,8 @@ -add_library(Core OBJECT EventBus.cpp ConfigManager.cpp) +add_library(Core OBJECT EventBus.cpp ConfigManager.cpp Record.cpp) target_include_directories(Core PUBLIC include) -#add_library(EventBus OBJECT EventBus.cpp EventBus.hpp) -#target_link_libraries(Core INTERFACE EventBus) - # Build Executable: add_executable(Distrins main.cpp) diff --git a/src/core/ConfigManager.cpp b/src/core/ConfigManager.cpp index f1e6f10..55c5a4e 100644 --- a/src/core/ConfigManager.cpp +++ b/src/core/ConfigManager.cpp @@ -1,6 +1,11 @@ #include "ConfigManager.hpp" +namespace DistriNS { +namespace Core { + + ConfigManager::ConfigManager(int numParameters, char **parameters) { //Process } +}} diff --git a/src/core/EventBus.cpp b/src/core/EventBus.cpp index 07a930a..8a2843c 100644 --- a/src/core/EventBus.cpp +++ b/src/core/EventBus.cpp @@ -2,8 +2,17 @@ #include #include +namespace DistriNS { +namespace Core { + EventBus::EventBus() {}; void EventBus::test() { std::cout << "Testing from within EventBus!" << std::endl; } + +void EventBus::run() { + std::cout << "Run event queue.... oops done! Exiting..." << std::endl; +} + +}} diff --git a/src/core/Record.cpp b/src/core/Record.cpp new file mode 100644 index 0000000..f8a6c6e --- /dev/null +++ b/src/core/Record.cpp @@ -0,0 +1,11 @@ +#include "Record.hpp" + +namespace DistriNS { +namespace Core { + + +string Record::serialize() { + return "Nothing implemented"; +} + +}} diff --git "a/src/core/\\" "b/src/core/\\" new file mode 100644 index 0000000..8a2843c --- /dev/null +++ "b/src/core/\\" @@ -0,0 +1,18 @@ +#include "EventBus.hpp" +#include +#include + +namespace DistriNS { +namespace Core { + +EventBus::EventBus() {}; + +void EventBus::test() { + std::cout << "Testing from within EventBus!" << std::endl; +} + +void EventBus::run() { + std::cout << "Run event queue.... oops done! Exiting..." << std::endl; +} + +}} diff --git a/src/core/include/ConfigManager.hpp b/src/core/include/ConfigManager.hpp index ce1cd0a..d56329b 100644 --- a/src/core/include/ConfigManager.hpp +++ b/src/core/include/ConfigManager.hpp @@ -1,10 +1,16 @@ #ifndef CONFIG_MANAGER_HPP #define CONFIG_MANAGER_HPP +namespace DistriNS { +namespace Core { + + class ConfigManager { public: ConfigManager(int numParameters, char **parameters); }; +}} + #endif diff --git a/src/core/include/EventBus.hpp b/src/core/include/EventBus.hpp index c68eaa4..44d3ebf 100644 --- a/src/core/include/EventBus.hpp +++ b/src/core/include/EventBus.hpp @@ -1,10 +1,15 @@ #ifndef EVENT_BUS_HPP #define EVENT_BUS_HPP +namespace DistriNS { +namespace Core { + class EventBus { public: EventBus(); void test(); + void run(); // Run the event queue worker }; +}} #endif diff --git a/src/core/include/Key.hpp b/src/core/include/Key.hpp new file mode 100644 index 0000000..9133b23 --- /dev/null +++ b/src/core/include/Key.hpp @@ -0,0 +1,5 @@ +namespace DistriNS { +namespace Core { + + +}} diff --git a/src/core/include/Ledger.hpp b/src/core/include/Ledger.hpp index 678e4a7..75c2578 100644 --- a/src/core/include/Ledger.hpp +++ b/src/core/include/Ledger.hpp @@ -1 +1,7 @@ +namespace DistriNS { +namespace Core { + + class Ledger; + +}} diff --git a/src/core/include/Logging.hpp b/src/core/include/Logging.hpp new file mode 100644 index 0000000..313082a --- /dev/null +++ b/src/core/include/Logging.hpp @@ -0,0 +1,11 @@ +#ifndef LOGGING_HPP +#define LOGGING_HPP + +namespace DistriNS { +namespace Core { + +class Logging; + +}} + +#endif diff --git a/src/core/include/PublicKey.hpp b/src/core/include/PublicKey.hpp deleted file mode 100644 index e69de29..0000000 diff --git a/src/core/include/Record.hpp b/src/core/include/Record.hpp new file mode 100644 index 0000000..7acf7dc --- /dev/null +++ b/src/core/include/Record.hpp @@ -0,0 +1,71 @@ +#ifndef RECORD_HPP +#define RECORD_HPP +#include +#include +#include "Resource.hpp" + +namespace DistriNS { +namespace Core { + + +using std::string; + +// Provides an abstract class for dns records that may be stored in the database +class Record : public Resource +{ + public: + //const uint16_t id; + string serialize(); +}; +/* +class ARecord : public Record { const uint16_t id = 1; }; +class AAAARecord : public Record { const uint16_t id = 28; }; +class AFSDBRecord : public Record { const uint16_t id = 18; }; +class APLRecord : public Record { const uint16_t id = 42; }; +class CAARecord : public Record { const uint16_t id = 257; }; +class CDNSKEYRecord : public Record { const uint16_t id = 60; }; +class CDSRecord : public Record { const uint16_t id = 59; }; +class CERTRecord : public Record { const uint16_t id = 37; }; +class CNAMERecord : public Record { const uint16_t id = 5; }; +class CSYNCRecord : public Record { const uint16_t id = 62; }; +class DHCIDRecord : public Record { const uint16_t id = 49; }; +class DLVRecord : public Record { const uint16_t id = 32769; }; +class DNAMERecord : public Record { const uint16_t id = 39; }; +class DNSKEYRecord : public Record { const uint16_t id = 48; }; +class DSRecord : public Record { const uint16_t id = 43; }; +class EUI48Record : public Record { const uint16_t id = 108; }; +class EUI64Record : public Record { const uint16_t id = 109; }; +class HINFORecord : public Record { const uint16_t id = 13; }; +class HIPRecord : public Record { const uint16_t id = 55; }; +class IPSECKEYRecord : public Record { const uint16_t id = 45; }; +class KEYRecord : public Record { const uint16_t id = 25; }; +class KXRecord : public Record { const uint16_t id = 36; }; +class LOCRecord : public Record { const uint16_t id = 29; }; +class MXRecord : public Record { const uint16_t id = 15; }; +class NAPTRRecord : public Record { const uint16_t id = 35; }; +class NSRecord : public Record { const uint16_t id = 2; }; +class NSECRecord : public Record { const uint16_t id = 47; }; +class NSEC3Record : public Record { const uint16_t id = 50; }; +class NSEC3PARAMRecord : public Record { const uint16_t id = 51; }; +class OPENPGPKEYRecord : public Record { const uint16_t id = 61; }; +class PTRRecord : public Record { const uint16_t id = 12; }; +class RRSIGRecord : public Record { const uint16_t id = 46; }; +class RPRecord : public Record { const uint16_t id = 17; }; +class SIGRecord : public Record { const uint16_t id = 24; }; +class SMIMEARecord : public Record { const uint16_t id = 53; }; +class SOARecord : public Record { const uint16_t id = 6; }; +class SRVRecord : public Record { const uint16_t id = 33; }; +class SSHFPRecord : public Record { const uint16_t id = 44; }; +class TARecord : public Record { const uint16_t id = 32768; }; +class TKEYRecord : public Record { const uint16_t id = 249; }; +class TLSARecord : public Record { const uint16_t id = 52; }; +class TSIGRecord : public Record { const uint16_t id = 250; }; +class TXTRecord : public Record { const uint16_t id = 16; }; +class URIRecord : public Record { const uint16_t id = 256; }; +class ZONEMDRecord : public Record { const uint16_t id = 63; }; +class SVCBRecord : public Record { const uint16_t id = 64; }; +class HTTPSRecord : public Record { const uint16_t id = 65; }; +*/ + +}} +#endif diff --git a/src/core/include/Resource.hpp b/src/core/include/Resource.hpp index 94332e7..6f386ca 100644 --- a/src/core/include/Resource.hpp +++ b/src/core/include/Resource.hpp @@ -1,2 +1,20 @@ -# Provides an abstract class for resources that may be stored in the database -class Resource; +#ifndef RESOURCE_HPP +#define RESOURCE_HPP + +#include +#include "Serialize.hpp" +namespace DistriNS { +namespace Core { + +using std::string; + +// Provides an abstract class for resources that may be stored in the ledger +class Resource : public Serialize +{ + public: + virtual string serialize() const = 0; +}; + +}} + +#endif diff --git a/src/core/include/Serialize.hpp b/src/core/include/Serialize.hpp index 423f25a..18d511c 100644 --- a/src/core/include/Serialize.hpp +++ b/src/core/include/Serialize.hpp @@ -1,10 +1,17 @@ -#ifndef #SERIALIZE_HPP -#define #SERIALIZE_HPP +#ifndef SERIALIZE_HPP +#define SERIALIZE_HPP #include + +namespace DistriNS { +namespace Core { + + using std::string; class Serialize { public: - virtual string Serialize() const = 0; -} + virtual string serialize() const = 0; +}; + +}} #endif diff --git a/src/core/include/Zone.hpp b/src/core/include/Zone.hpp new file mode 100644 index 0000000..5bff9df --- /dev/null +++ b/src/core/include/Zone.hpp @@ -0,0 +1,7 @@ +namespace DistriNS { +namespace Core { + + +class Zone : public Serialize, public Resource; + +}} diff --git a/src/core/main.cpp b/src/core/main.cpp index ef37826..1bb2cce 100644 --- a/src/core/main.cpp +++ b/src/core/main.cpp @@ -2,16 +2,25 @@ #include "Resolver.hpp" #include "EventBus.hpp" #include "ConfigManager.hpp" +#include "Record.hpp" //Testing int main(int args, char **argv) { using std::cout; using std::endl; + + using namespace DistriNS; + //using namespace Core; - ConfigManager cfg(args, argv); - auto eventBus = EventBus(); - Resolver resolver(eventBus); + Core::ConfigManager cfg(args, argv); + auto eventBus = Core::EventBus(); + Resolver::Server resolver(eventBus); + + //Record testrec = ARecord(); cout << "Booting complete." << endl; + //Run eventBus on main thread. + eventBus.run(); return 0; } + diff --git a/src/resolver/CMakeLists.txt b/src/resolver/CMakeLists.txt index 856c20d..bfb817b 100644 --- a/src/resolver/CMakeLists.txt +++ b/src/resolver/CMakeLists.txt @@ -1,5 +1,5 @@ -add_library(Resolver OBJECT Resolver.cpp) +add_library(Resolver OBJECT Server.cpp) target_include_directories(Resolver PUBLIC include) diff --git a/src/resolver/Resolver.cpp b/src/resolver/Server.cpp similarity index 58% rename from src/resolver/Resolver.cpp rename to src/resolver/Server.cpp index 78cf6cb..be4e23a 100644 --- a/src/resolver/Resolver.cpp +++ b/src/resolver/Server.cpp @@ -3,8 +3,13 @@ #include #include -Resolver::Resolver(EventBus &eventBus) : eventBus(eventBus) { +namespace DistriNS { +namespace Resolver { + +Server::Server(EventBus& eventBus) : eventBus(eventBus) { // Code //test: eventBus.test(); -}; +} + +}} diff --git a/src/resolver/include/Resolver.hpp b/src/resolver/include/Resolver.hpp index c2e25b5..f202d4b 100644 --- a/src/resolver/include/Resolver.hpp +++ b/src/resolver/include/Resolver.hpp @@ -1,13 +1,5 @@ #ifndef RESOLVER_HPP #define RESOLVER_HPP -#include "EventBus.hpp" - -class Resolver -{ - const EventBus &eventBus; - - public: - Resolver(EventBus &eventBus); -}; - +#include "Server.hpp" +//Include further classes here #endif diff --git a/src/resolver/include/Server.hpp b/src/resolver/include/Server.hpp new file mode 100644 index 0000000..7e93a9b --- /dev/null +++ b/src/resolver/include/Server.hpp @@ -0,0 +1,20 @@ +#ifndef SERVER_HPP +#define SERVER_HPP +#include "EventBus.hpp" + +namespace DistriNS { +namespace Resolver { + +using Core::EventBus; + +class Server +{ + const EventBus& eventBus; + + public: + Server(EventBus& eventBus); +}; + +}} + +#endif diff --git a/src/storage/CMakeLists.txt b/src/storage/CMakeLists.txt index 26c4559..27d1261 100644 --- a/src/storage/CMakeLists.txt +++ b/src/storage/CMakeLists.txt @@ -1,8 +1,5 @@ -add_library(Storage OBJECT) +add_library(Storage OBJECT Storage.cpp) -target_sources(Storage PRIVATE src) - -target_include_directories(Storage - PUBLIC include - PRIVATE src) +target_include_directories(Storage PUBLIC include) +target_link_libraries(Storage PRIVATE Core) diff --git a/src/storage/Storage.cpp b/src/storage/Storage.cpp new file mode 100644 index 0000000..2f73997 --- /dev/null +++ b/src/storage/Storage.cpp @@ -0,0 +1,6 @@ +#include "Storage.hpp" + +namespace DistriNS { +namespace Storage { + +}} diff --git a/src/storage/include/Storage.hpp b/src/storage/include/Storage.hpp index 446d063..5f1e2ca 100644 --- a/src/storage/include/Storage.hpp +++ b/src/storage/include/Storage.hpp @@ -2,5 +2,9 @@ #define STORAGE_HPP +namespace DistriNS { +namespace Storage { + +}} #endif diff --git a/src/storage/src/Storage.cpp b/src/storage/src/Storage.cpp deleted file mode 100644 index e69de29..0000000