From fa15d5cb08124ad215349430066c572296f7f130 Mon Sep 17 00:00:00 2001 From: "Tristan B. Kildaire" Date: Fri, 29 Jan 2021 16:44:31 +0200 Subject: [PATCH] Restructured configuration sub-system --- source/app.d | 9 +++--- source/dnetd/dconfig.d | 57 -------------------------------------- source/dnetd/dconnection.d | 2 +- source/dnetd/dlink.d | 2 +- source/dnetd/dserver.d | 27 +++++++++++------- 5 files changed, 24 insertions(+), 73 deletions(-) diff --git a/source/app.d b/source/app.d index 1c0a2cd..7b59774 100644 --- a/source/app.d +++ b/source/app.d @@ -1,7 +1,7 @@ import std.stdio; import std.socket : parseAddress; import dnetd.dserver : DServer; -import dnetd.dconfig : DConfig, DLinkConfig; +import dnetd.dconfig : DGeneralConfig, DLinkConfig; import std.json; import std.exception; import gogga; @@ -66,7 +66,7 @@ void main(string[] args) } /* Create a new configuration file and check configuration parameters */ - DConfig config = DConfig.getConfig(json); + DGeneralConfig config = DGeneralConfig.getConfig(json["general"]); /* If the configuration reading was successful (valid JSON) */ if(config) @@ -80,10 +80,11 @@ void main(string[] args) /* Get all server links */ DLink[] serverLinks = linkConfig.getLinks(); - /* Create a new Meyer */ + /* Create a new Meyer (link manager) and attach the links to it */ + DMeyer meyer = new DMeyer(dserver, serverLinks); - /* Attach the Meyer to the server */ + diff --git a/source/dnetd/dconfig.d b/source/dnetd/dconfig.d index 96caecc..9b8e586 100644 --- a/source/dnetd/dconfig.d +++ b/source/dnetd/dconfig.d @@ -12,63 +12,6 @@ import gogga; import dnetd.dlink : DLink; import dnetd.dserver : DServer; -public final class DConfig -{ - /* General configuration */ - private DGeneralConfig generalConfig; - - /* Link configuration */ - private DLinkConfig linksConfig; - - private this() - { - /* TODO: */ - } - - public DGeneralConfig getGeneral() - { - return generalConfig; - } - - public DLinkConfig getLinks() - { - return linksConfig; - } - - public static DConfig getConfig(JSONValue json) - { - /* The newly created configuration */ - DConfig config = new DConfig(); - - try - { - /* TODO: Parse */ - - /* Get the `general` block */ - JSONValue generalBlock = json["general"]; - config.generalConfig = DGeneralConfig.getConfig(generalBlock); - - /* Get the `links` block */ - JSONValue linksBlock = json["links"]; - config.linksConfig = DLinkConfig.getConfig(linksBlock); - } - catch(JSONException e) - { - /* Set config to null (signals an error) */ - config = null; - } - - return config; - } - - public JSONValue saveConfig() - { - JSONValue config; - - - return config; - } -} public final class DGeneralConfig { diff --git a/source/dnetd/dconnection.d b/source/dnetd/dconnection.d index adcf032..71a60fd 100644 --- a/source/dnetd/dconnection.d +++ b/source/dnetd/dconnection.d @@ -644,7 +644,7 @@ public class DConnection : Thread bool status = true; /* Get the message of the day */ - string motd = server.getConfig().getGeneral().getMotd(); + string motd = server.getGeneralConfig().getMotd(); /* Encode the reply */ reply ~= [status]; diff --git a/source/dnetd/dlink.d b/source/dnetd/dlink.d index 32d5c22..83f1c75 100644 --- a/source/dnetd/dlink.d +++ b/source/dnetd/dlink.d @@ -106,7 +106,7 @@ public final class DMeyer /* Associated server */ private DServer server; - this(DServer server, DLinkConfig linkConfig) + this(DServer server, DLink[] links) { this.server = server; diff --git a/source/dnetd/dserver.d b/source/dnetd/dserver.d index 9a5f5bf..142b8a7 100644 --- a/source/dnetd/dserver.d +++ b/source/dnetd/dserver.d @@ -26,7 +26,7 @@ import gogga; public class DServer : Thread { /* Server configuration */ - private DConfig config; + private DGeneralConfig generalConfig; /** * Connection queue @@ -51,16 +51,16 @@ public class DServer : Thread private DListener[] listeners; /* TODO: Implement new constructor */ - this(DConfig config) + this(DGeneralConfig generalConfig) { /* Set the function to be called on thread start */ super(&startListeners); - /* Set the server's config */ - this.config = config; + /* Set the server's general config */ + this.generalConfig = generalConfig; /* Construct the listeners */ - initListeners(config.getGeneral().getAddresses()); + initListeners(generalConfig.getAddresses()); /* Initialize the server */ init(); @@ -111,9 +111,9 @@ public class DServer : Thread } } - public DConfig getConfig() + public DGeneralConfig getGeneralConfig() { - return config; + return generalConfig; } private void init() @@ -148,11 +148,18 @@ public class DServer : Thread return meyerSS; } + public DMeyer getLinkManager() + { + return getMeyer(); + } + + public void attachLinkManager(DMeyer linkManager) + { + meyerSS = linkManager; + } + public void startServer() { - // /* Initialize the Meyer linking sub-system */ - // meyerSS = new DMeyer(this, config.getLinks()); - /* Start the listener starter */ start(); }