mirror of
https://github.com/deavminet/dnetd
synced 2024-09-21 17:53:39 +02:00
Configure at start up (server linking)
This commit is contained in:
parent
4e4605ff4c
commit
5f443cfa2c
10
source/app.d
10
source/app.d
@ -1,7 +1,7 @@
|
||||
import std.stdio;
|
||||
import std.socket : parseAddress;
|
||||
import dnetd.dserver : DServer;
|
||||
import dnetd.dconfig : DConfig;
|
||||
import dnetd.dconfig : DConfig, DLinkConfig;
|
||||
import std.json;
|
||||
import std.exception;
|
||||
import gogga;
|
||||
@ -72,6 +72,14 @@ void main(string[] args)
|
||||
{
|
||||
/* Start the server */
|
||||
DServer dserver = new DServer(config);
|
||||
|
||||
/* Now configure the the linking */
|
||||
DLinkConfig linkConfig = DLinkConfig.getConfig(dserver, json["links"]);
|
||||
|
||||
/* TODO: COnfigure here */
|
||||
|
||||
|
||||
/* TODO: Start meyer here (remove from inside DServer) */
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -9,6 +9,8 @@ import std.json;
|
||||
import std.conv;
|
||||
import std.socket : Address, parseAddress;
|
||||
import gogga;
|
||||
import dnetd.dlink : DLink;
|
||||
import dnetd.dserver : DServer;
|
||||
|
||||
public final class DConfig
|
||||
{
|
||||
@ -131,9 +133,13 @@ public final class DGeneralConfig
|
||||
|
||||
public final class DLinkConfig
|
||||
{
|
||||
public static DLinkConfig getConfig(JSONValue linksBlock)
|
||||
/* Server links */
|
||||
private DLink[] links;
|
||||
private Address[] addresses;
|
||||
|
||||
public static DLinkConfig getConfig(DServer dserver, JSONValue linksBlock)
|
||||
{
|
||||
DLinkConfig dlinkConfig;
|
||||
DLinkConfig dlinkConfig = new DLinkConfig();
|
||||
|
||||
/* Get the active servers */
|
||||
string[] activeServers;
|
||||
@ -145,6 +151,25 @@ public final class DLinkConfig
|
||||
activeServers ~= server;
|
||||
}
|
||||
|
||||
/* Parse each link and add it to the link-list */
|
||||
foreach(string server; activeServers)
|
||||
{
|
||||
/* Get the peer block */
|
||||
JSONValue peerBlock = linksBlock[server];
|
||||
|
||||
/* Get the name */
|
||||
string name = peerBlock["name"].str();
|
||||
|
||||
/* Get the address */
|
||||
string address = peerBlock["address"].str();
|
||||
|
||||
/* Get the port */
|
||||
ushort port = to!(ushort)(peerBlock["port"].str());
|
||||
|
||||
/* Add the address and port tuple to the list of addresses to bind to */
|
||||
dlinkConfig.links ~= new DLink(server, name, parseAddress(address, port));
|
||||
}
|
||||
|
||||
|
||||
return dlinkConfig;
|
||||
}
|
||||
|
@ -6,6 +6,8 @@ import std.stdio;
|
||||
import std.conv;
|
||||
import dnetd.dserver;
|
||||
import dnetd.dconfig;
|
||||
import std.socket : Address;
|
||||
import core.thread : Thread;
|
||||
|
||||
/**
|
||||
* DLink
|
||||
@ -14,7 +16,7 @@ import dnetd.dconfig;
|
||||
* with information about what this link
|
||||
* knows and can tell us
|
||||
*/
|
||||
public final class DLink
|
||||
public final class DLidnk
|
||||
{
|
||||
/* The directly attached peer */
|
||||
private DConnection directPeer;
|
||||
@ -34,6 +36,58 @@ public final class DLink
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a server link
|
||||
*
|
||||
* Either used for inbound or outbound
|
||||
*/
|
||||
public final class DLink : Thread
|
||||
{
|
||||
/* Associated server */
|
||||
private DServer server;
|
||||
|
||||
/* The connection */
|
||||
private DConnection connection;
|
||||
|
||||
/**
|
||||
* Links details
|
||||
*/
|
||||
private string name;
|
||||
private Address address;
|
||||
|
||||
/**
|
||||
* Constructs a DLink for an outbound peering
|
||||
*/
|
||||
this(DServer server, string name, Address address)
|
||||
{
|
||||
/* Create an outbound connection */
|
||||
/* TODO: Fuuuuuuuuuuuuuuuuuuuck handling of shit here bababooey and not in dconnection.d as we would have done below */
|
||||
|
||||
/* Initialize a new outbound connection */
|
||||
initializeOutboundConnection();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes a new outbound connection
|
||||
*/
|
||||
private void initializeOutboundConnection()
|
||||
{
|
||||
/* Open a connection to the server */
|
||||
// connection = new DConnection();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a DLink for an inbound peering
|
||||
*/
|
||||
this(DServer server, string name, Address address, DConnection connection)
|
||||
{
|
||||
/* Save name and address */
|
||||
this(server, name, address);
|
||||
|
||||
/* Save connection */
|
||||
}
|
||||
}
|
||||
|
||||
public final class DMeyer
|
||||
{
|
||||
/* Direct peers */
|
||||
@ -49,6 +103,10 @@ public final class DMeyer
|
||||
|
||||
/* Initialize the locks */
|
||||
initLocks();
|
||||
|
||||
/* Open a connection to the server */
|
||||
|
||||
/* TODO: Open connections to all servers we are yet to open a connection to (check the `links` array) */
|
||||
}
|
||||
|
||||
/* Initialize locks */
|
||||
@ -57,32 +115,32 @@ public final class DMeyer
|
||||
linksMutex = new Mutex();
|
||||
}
|
||||
|
||||
/* Attach a direct peer */
|
||||
public void attachDirectPeer(DConnection peer)
|
||||
{
|
||||
/* TODO: Add to `directPeers` */
|
||||
linksMutex.lock();
|
||||
// /* 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));
|
||||
// links ~= new DLink(peer);
|
||||
// writeln("Attached direct peer: "~to!(string)(peer));
|
||||
|
||||
linksMutex.unlock();
|
||||
}
|
||||
// linksMutex.unlock();
|
||||
// }
|
||||
|
||||
/* Get a list of all servers we know of */
|
||||
|
||||
|
||||
public DLink getLink(DConnection peer)
|
||||
{
|
||||
DLink link;
|
||||
// public DLink getLink(DConnection peer)
|
||||
// {
|
||||
// DLink link;
|
||||
|
||||
linksMutex.lock();
|
||||
// linksMutex.lock();
|
||||
|
||||
|
||||
|
||||
linksMutex.unlock();
|
||||
// linksMutex.unlock();
|
||||
|
||||
return link;
|
||||
}
|
||||
// return link;
|
||||
// }
|
||||
|
||||
}
|
||||
|
@ -11,12 +11,12 @@
|
||||
},
|
||||
],
|
||||
"network" : "aBasedIRCNetwork",
|
||||
"name" : "MyBrandSpankingNewIRCServer",
|
||||
"name" : "server1",
|
||||
"motd" : "Welcome to my generic dnet chat server!"
|
||||
},
|
||||
|
||||
"links" : {
|
||||
"server1" : {
|
||||
"server2" : {
|
||||
"name": "server2",
|
||||
"address" : "127.0.0.1",
|
||||
"port" : "6666"
|
||||
|
@ -11,7 +11,7 @@
|
||||
}
|
||||
],
|
||||
"network" : "aBasedIRCNetwork",
|
||||
"name" : "MyBrandSpankingNewIRCServer",
|
||||
"name" : "server2",
|
||||
"motd" : "Welcome to my generic dnet chat server!"
|
||||
},
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user