From 905ad5018811c4e1f3cb955c4439800b3f9c210b Mon Sep 17 00:00:00 2001 From: "Tristan B. Kildaire" Date: Fri, 29 Jan 2021 21:21:59 +0200 Subject: [PATCH] Moved code for outbound server linking to DServer --- source/app.d | 7 ------- source/dnetd/dlink.d | 17 +++++------------ source/dnetd/dserver.d | 21 +++++++++++++++++++++ 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/source/app.d b/source/app.d index 357e77d..73f00ed 100644 --- a/source/app.d +++ b/source/app.d @@ -85,13 +85,6 @@ void main(string[] args) /* Start the server (TODO: This should start Meyer) */ dserver.startServer(); - - /* Start all DLink outbound handlers (TODO: Move to DServer) */ - foreach(DLink link; serverLinks) - { - link.start(); - } - } catch(JSONException e) { diff --git a/source/dnetd/dlink.d b/source/dnetd/dlink.d index 7b9387b..985a89a 100644 --- a/source/dnetd/dlink.d +++ b/source/dnetd/dlink.d @@ -175,6 +175,9 @@ public final class DMeyer /* Open a connection to the server */ /* TODO: Open connections to all servers we are yet to open a connection to (check the `links` array) */ + + + this.links = links; } /** @@ -191,18 +194,8 @@ public final class DMeyer linksMutex = new Mutex(); } - /** - * Adds a peer to the links list - */ - public void addLink(DLink newLink) + public DLink[] getOutboundLinks() { - /* Lock the list */ - linksMutex.lock(); - - /* Add the link */ - links ~= newLink; - - /* Unlock the list */ - linksMutex.unlock(); + return links; } } diff --git a/source/dnetd/dserver.d b/source/dnetd/dserver.d index 142b8a7..4920620 100644 --- a/source/dnetd/dserver.d +++ b/source/dnetd/dserver.d @@ -162,6 +162,27 @@ public class DServer : Thread { /* Start the listener starter */ start(); + + /* Start outbound server linking */ + startOutboundLinks(); + gprintln("poes"); + } + + /** + * This will look at the link manager (DMeyer) + * and loop through each DLink in it and + * establish an outbound connection and therefore + * connection handler for each of them + */ + private void startOutboundLinks() + { + DLink[] serverLinks = meyerSS.getOutboundLinks(); + + /* Start all DLink outbound handlers (TODO: Move to DServer) */ + foreach(DLink link; serverLinks) + { + link.start(); + } } public void addChannel(DConnection causer, DChannel channel)