This commit is contained in:
Tristan B. Kildaire 2020-10-05 15:59:08 +02:00
parent 1071d11345
commit cc4de82818
6 changed files with 135 additions and 0 deletions

View File

@ -5,5 +5,13 @@
"network" : "aBasedIRCNetwork",
"name" : "MyBrandSpankingNewIRCServer",
"motd" : "Welcome to my generic dnet chat server!"
},
"links" : {
"server1" : {
"name" : "server1",
"address" : "",
"port" : ""
}
}
}

26
meyer.md Normal file
View File

@ -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

View File

@ -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;

View File

@ -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;

78
source/dnetd/dlink.d Normal file
View File

@ -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;
}
}

View File

@ -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();
}