From cc4de828187a492a99acfd650d18cf30bb08cb7f Mon Sep 17 00:00:00 2001 From: "Tristan B. Kildaire" Date: Mon, 5 Oct 2020 15:59:08 +0200 Subject: [PATCH] Freeze --- config.json | 8 ++++ meyer.md | 26 +++++++++++++ source/app.d | 6 +++ source/dnetd/dconnection.d | 3 ++ source/dnetd/dlink.d | 78 ++++++++++++++++++++++++++++++++++++++ source/dnetd/dserver.d | 14 +++++++ 6 files changed, 135 insertions(+) create mode 100644 meyer.md create mode 100644 source/dnetd/dlink.d diff --git a/config.json b/config.json index 51969b7..5f64916 100644 --- a/config.json +++ b/config.json @@ -5,5 +5,13 @@ "network" : "aBasedIRCNetwork", "name" : "MyBrandSpankingNewIRCServer", "motd" : "Welcome to my generic dnet chat server!" + }, + + "links" : { + "server1" : { + "name" : "server1", + "address" : "", + "port" : "" + } } } \ No newline at end of file diff --git a/meyer.md b/meyer.md new file mode 100644 index 0000000..03b7f58 --- /dev/null +++ b/meyer.md @@ -0,0 +1,26 @@ +Meyer link protocol +=================== + +This document describes the Meyer linking protocol which is used to maintain server links in the dnet network and deliver data across the links. + +## Protocol + +Every server maintains a list of connections (server, clients and unspec), this is the `DConnection[]` array. What we are concerned with here is the subset of that array which has `ConnectionType.SERVER` (so all servers). + +We also maintain a list of all servers that we know of via links, this is called `sl` and normally written in the notation of `sl=[]`. Some of these elements will be servers in `DConnection[]` (direct) however not all will be (indirect). + +### Link request + +A link request is when Server B makes a request to Server A to link up (`Server B -> Server A`) then the following happens. + +Server A checks its `sl=[]` and checks if the announced server name by Server B is in it, if so it closes the request as they must be linked already directly or indirectly. + +However, if not then it will add `B` to its `sl=[]`, so now it is `sl=[B]`. Another thing to note is when Server B makes the request (regardless of if it will go through or not), it will + + +WHen a server wants to link with another it sends a lin request containing: + +1. it's server name +2. a list of the links it has (direct and indirect) + +The receiving server checks first of all if \ No newline at end of file diff --git a/source/app.d b/source/app.d index 122374e..7b1aecd 100644 --- a/source/app.d +++ b/source/app.d @@ -7,6 +7,12 @@ import std.exception; void main(string[] args) { + int i = -1; + long k = i; + writeln(cast(ulong)k); + + + /* Configuration file */ string configFilename; diff --git a/source/dnetd/dconnection.d b/source/dnetd/dconnection.d index f2108da..8d6185c 100644 --- a/source/dnetd/dconnection.d +++ b/source/dnetd/dconnection.d @@ -313,6 +313,9 @@ public class DConnection : Thread { /* TODO: Implement me later */ + /* Check if this connection is a DLink'd one */ + //server.getMeyer().get + /* Set the type of this connection to `server` */ connType = ConnectionType.SERVER; diff --git a/source/dnetd/dlink.d b/source/dnetd/dlink.d new file mode 100644 index 0000000..e3404bb --- /dev/null +++ b/source/dnetd/dlink.d @@ -0,0 +1,78 @@ +module dnetd.dlink; + +import dnetd.dconnection; +import core.sync.mutex : Mutex; +import std.stdio; +import std.conv; +import dnetd.dserver; + +/** +* DLink +* +* Couples a DConneciton (direct peer) +* with information about what this link +* knows and can tell us +*/ +public final class DLink +{ + /* The directly attached peer */ + private DConnection directPeer; + + /* Servers (by name) this server is aware of */ + private string[] knowledgeList; + + this(DConnection directPeer) + { + this.directPeer = directPeer; + } + + /* Call this to update list */ + public void updateKB() + { + /* TODO: Ask DConneciton here for the servers he knows */ + } +} + +public final class DMeyer +{ + /* List of links (direct peers + additional information) */ + private DLink[] links; + private Mutex linksMutex; + + private DServer server; + + this(DServer server) + { + this.server = server; + linksMutex = new Mutex(); + } + + /* Attach a direct peer */ + public void attachDirectPeer(DConnection peer) + { + /* TODO: Add to `directPeers` */ + linksMutex.lock(); + + links ~= new DLink(peer); + writeln("Attached direct peer: "~to!(string)(peer)); + + linksMutex.unlock(); + } + + /* Get a list of all servers we know of */ + + + public DLink getLink(DConnection peer) + { + DLink link; + + linksMutex.lock(); + + + + linksMutex.unlock(); + + return link; + } + +} diff --git a/source/dnetd/dserver.d b/source/dnetd/dserver.d index fe093fd..935da5a 100644 --- a/source/dnetd/dserver.d +++ b/source/dnetd/dserver.d @@ -19,6 +19,7 @@ import core.sync.mutex : Mutex; import std.stdio; import std.conv : to; import dnetd.dconfig; +import dnetd.dlink; public class DServer : Thread { @@ -43,6 +44,11 @@ public class DServer : Thread */ private DChannel[] channels; private Mutex channelLock; + + /** + * Meyer linking subsystem + */ + private DMeyer meyerSS; /* TODO: Implement new constructor */ this(DConfig config) @@ -111,8 +117,16 @@ public class DServer : Thread channelLock = new Mutex(); } + public DMeyer getMeyer() + { + return meyerSS; + } + private void startServer() { + /* Initialize the Meyer linking sub-system */ + meyerSS = new DMeyer(this); + /* Start the connection dequeue thread */ start(); }