New directory structure
This commit is contained in:
parent
1e560671b9
commit
efe222a5c6
110
source/app.d
110
source/app.d
|
@ -1,7 +1,15 @@
|
|||
module app;
|
||||
module besterd;
|
||||
|
||||
|
||||
|
||||
import std.stdio;
|
||||
import server.server;
|
||||
import std.conv : to;
|
||||
import std.socket : SocketOSException, parseAddress, UnixAddress;
|
||||
import utils.debugging : debugPrint;
|
||||
import std.stdio : File, writeln;
|
||||
import std.json : parseJSON, JSONValue;
|
||||
import listeners.listener;
|
||||
import listeners.types;
|
||||
|
||||
unittest d
|
||||
{
|
||||
|
@ -20,3 +28,101 @@ void main()
|
|||
|
||||
writeln("fdhjf he do be vibing though");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
JSONValue getConfig(string configurationFilePath)
|
||||
{
|
||||
/* TODO: Open the file here */
|
||||
File configFile;
|
||||
configFile.open(configurationFilePath);
|
||||
|
||||
/* The file buffer */
|
||||
byte[] fileBuffer;
|
||||
|
||||
/* Allocate the buffer to be the size of the file */
|
||||
fileBuffer.length = configFile.size();
|
||||
|
||||
/* Read the content of the file */
|
||||
/* TODO: Error handling ErrnoException */
|
||||
fileBuffer = configFile.rawRead(fileBuffer);
|
||||
configFile.close();
|
||||
|
||||
JSONValue config;
|
||||
|
||||
/* TODO: JSON error checking */
|
||||
config = parseJSON(cast(string)fileBuffer);
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
BesterListener[] getListeners(BesterServer server, JSONValue networkBlock)
|
||||
{
|
||||
BesterListener[] listeners;
|
||||
|
||||
/* TODO: Error handling and get keys and clean up for formality */
|
||||
|
||||
/* Look for IPv4 TCP block */
|
||||
JSONValue inet4TCPBlock = networkBlock["tcp4"];
|
||||
debugPrint("<<< IPv4 TCP Block >>>\n" ~ inet4TCPBlock.toPrettyString());
|
||||
string inet4Address = inet4TCPBlock["address"].str();
|
||||
ushort inet4Port = to!(ushort)(inet4TCPBlock["port"].str());
|
||||
TCP4Listener tcp4Listener = new TCP4Listener(server, parseAddress(inet4Address, inet4Port));
|
||||
listeners ~= tcp4Listener;
|
||||
|
||||
/* Look for IPv6 TCP block */
|
||||
JSONValue inet6TCPBlock = networkBlock["tcp6"];
|
||||
debugPrint("<<< IPv6 TCP Block >>>\n" ~ inet6TCPBlock.toPrettyString());
|
||||
string inet6Address = inet6TCPBlock["address"].str();
|
||||
ushort inet6Port = to!(ushort)(inet6TCPBlock["port"].str());
|
||||
TCP6Listener tcp6Listener = new TCP6Listener(server, parseAddress(inet6Address, inet6Port));
|
||||
listeners ~= tcp6Listener;
|
||||
|
||||
/* Look for UNIX Domain block */
|
||||
JSONValue unixDomainBlock = networkBlock["unix"];
|
||||
debugPrint("<<< UNIX Domain Block >>>\n" ~ unixDomainBlock.toPrettyString());
|
||||
string unixAddress = unixDomainBlock["address"].str();
|
||||
// UNIXListener unixListener = new UNIXListener(server, new UnixAddress(unixAddress));
|
||||
// listeners ~= unixListener;
|
||||
|
||||
return listeners;
|
||||
}
|
||||
|
||||
void startServer(string configurationFilePath)
|
||||
{
|
||||
/* The server configuration */
|
||||
JSONValue serverConfiguration = getConfig(configurationFilePath);
|
||||
debugPrint("<<< Bester.d configuration >>>\n" ~ serverConfiguration.toPrettyString());
|
||||
|
||||
try
|
||||
{
|
||||
/* The server */
|
||||
BesterServer server = null;
|
||||
|
||||
/* TODO: Bounds anc type checking */
|
||||
|
||||
/* Get the network block */
|
||||
JSONValue networkBlock = serverConfiguration["network"];
|
||||
|
||||
/* Create the Bester server */
|
||||
server = new BesterServer(serverConfiguration);
|
||||
|
||||
/* TODO: Get keys */
|
||||
BesterListener[] listeners = getListeners(server, networkBlock);
|
||||
|
||||
for(ulong i = 0; i < listeners.length; i++)
|
||||
{
|
||||
/* Add listener */
|
||||
server.addListener(listeners[i]);
|
||||
}
|
||||
|
||||
/* Start running the server (starts the listeners) */
|
||||
server.run();
|
||||
}
|
||||
catch(SocketOSException exception)
|
||||
{
|
||||
debugPrint("Error binding: " ~ exception.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,104 +0,0 @@
|
|||
module server.server;
|
||||
|
||||
import server.types;
|
||||
import std.conv : to;
|
||||
import std.socket : SocketOSException, parseAddress, UnixAddress;
|
||||
import utils.debugging : debugPrint;
|
||||
import std.stdio : File, writeln;
|
||||
import std.json : parseJSON, JSONValue;
|
||||
import server.listeners;
|
||||
|
||||
JSONValue getConfig(string configurationFilePath)
|
||||
{
|
||||
/* TODO: Open the file here */
|
||||
File configFile;
|
||||
configFile.open(configurationFilePath);
|
||||
|
||||
/* The file buffer */
|
||||
byte[] fileBuffer;
|
||||
|
||||
/* Allocate the buffer to be the size of the file */
|
||||
fileBuffer.length = configFile.size();
|
||||
|
||||
/* Read the content of the file */
|
||||
/* TODO: Error handling ErrnoException */
|
||||
fileBuffer = configFile.rawRead(fileBuffer);
|
||||
configFile.close();
|
||||
|
||||
JSONValue config;
|
||||
|
||||
/* TODO: JSON error checking */
|
||||
config = parseJSON(cast(string)fileBuffer);
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
BesterListener[] getListeners(BesterServer server, JSONValue networkBlock)
|
||||
{
|
||||
BesterListener[] listeners;
|
||||
|
||||
/* TODO: Error handling and get keys and clean up for formality */
|
||||
|
||||
/* Look for IPv4 TCP block */
|
||||
JSONValue inet4TCPBlock = networkBlock["tcp4"];
|
||||
debugPrint("<<< IPv4 TCP Block >>>\n" ~ inet4TCPBlock.toPrettyString());
|
||||
string inet4Address = inet4TCPBlock["address"].str();
|
||||
ushort inet4Port = to!(ushort)(inet4TCPBlock["port"].str());
|
||||
TCP4Listener tcp4Listener = new TCP4Listener(server, parseAddress(inet4Address, inet4Port));
|
||||
listeners ~= tcp4Listener;
|
||||
|
||||
/* Look for IPv6 TCP block */
|
||||
JSONValue inet6TCPBlock = networkBlock["tcp6"];
|
||||
debugPrint("<<< IPv6 TCP Block >>>\n" ~ inet6TCPBlock.toPrettyString());
|
||||
string inet6Address = inet6TCPBlock["address"].str();
|
||||
ushort inet6Port = to!(ushort)(inet6TCPBlock["port"].str());
|
||||
TCP6Listener tcp6Listener = new TCP6Listener(server, parseAddress(inet6Address, inet6Port));
|
||||
listeners ~= tcp6Listener;
|
||||
|
||||
/* Look for UNIX Domain block */
|
||||
JSONValue unixDomainBlock = networkBlock["unix"];
|
||||
debugPrint("<<< UNIX Domain Block >>>\n" ~ unixDomainBlock.toPrettyString());
|
||||
string unixAddress = unixDomainBlock["address"].str();
|
||||
// UNIXListener unixListener = new UNIXListener(server, new UnixAddress(unixAddress));
|
||||
// listeners ~= unixListener;
|
||||
|
||||
return listeners;
|
||||
}
|
||||
|
||||
void startServer(string configurationFilePath)
|
||||
{
|
||||
/* The server configuration */
|
||||
JSONValue serverConfiguration = getConfig(configurationFilePath);
|
||||
debugPrint("<<< Bester.d configuration >>>\n" ~ serverConfiguration.toPrettyString());
|
||||
|
||||
try
|
||||
{
|
||||
/* The server */
|
||||
BesterServer server = null;
|
||||
|
||||
/* TODO: Bounds anc type checking */
|
||||
|
||||
/* Get the network block */
|
||||
JSONValue networkBlock = serverConfiguration["network"];
|
||||
|
||||
/* Create the Bester server */
|
||||
server = new BesterServer(serverConfiguration);
|
||||
|
||||
/* TODO: Get keys */
|
||||
BesterListener[] listeners = getListeners(server, networkBlock);
|
||||
|
||||
for(ulong i = 0; i < listeners.length; i++)
|
||||
{
|
||||
/* Add listener */
|
||||
server.addListener(listeners[i]);
|
||||
}
|
||||
|
||||
/* Start running the server (starts the listeners) */
|
||||
server.run();
|
||||
}
|
||||
catch(SocketOSException exception)
|
||||
{
|
||||
debugPrint("Error binding: " ~ exception.toString());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
module server.types.connection;
|
||||
module connection.connection;
|
||||
|
||||
import utils.debugging : debugPrint;
|
||||
import std.conv : to;
|
||||
|
@ -8,10 +8,11 @@ import std.stdio : writeln, File;
|
|||
import std.json : JSONValue, parseJSON, JSONException, JSONType, toJSON;
|
||||
import std.string : cmp;
|
||||
import server.handler;
|
||||
import server.types.listeners;
|
||||
import listeners.listener;
|
||||
import server.server;
|
||||
|
||||
|
||||
private class BesterConnection : Thread
|
||||
public class BesterConnection : Thread
|
||||
{
|
||||
|
||||
/* The socket to the client */
|
|
@ -1,4 +1,4 @@
|
|||
module server.types.listener;
|
||||
module listeners.listener;
|
||||
|
||||
import utils.debugging : debugPrint;
|
||||
import std.conv : to;
|
||||
|
@ -8,6 +8,8 @@ import std.stdio : writeln, File;
|
|||
import std.json : JSONValue, parseJSON, JSONException, JSONType, toJSON;
|
||||
import std.string : cmp;
|
||||
import server.handler;
|
||||
import server.server;
|
||||
import connection.connection;
|
||||
|
||||
|
||||
/* TODO: Implement me */
|
|
@ -1,6 +1,8 @@
|
|||
module server.types.listeners.listeners;
|
||||
module listeners.types;
|
||||
|
||||
import listeners.listener;
|
||||
import server.server;
|
||||
|
||||
import server.types;
|
||||
import std.socket : Socket, Address, AddressFamily, SocketType;
|
||||
|
||||
public class UNIXListener : BesterListener
|
|
@ -1,4 +1,4 @@
|
|||
module server.types.server;
|
||||
module server.server;
|
||||
|
||||
import utils.debugging : debugPrint;
|
||||
import std.conv : to;
|
||||
|
@ -8,7 +8,8 @@ import std.stdio : writeln, File;
|
|||
import std.json : JSONValue, parseJSON, JSONException, JSONType, toJSON;
|
||||
import std.string : cmp;
|
||||
import server.handler;
|
||||
import server.types.listeners;
|
||||
import listeners.listener;
|
||||
import connection.connection;
|
||||
|
||||
public class BesterServer
|
||||
{
|
||||
|
@ -18,7 +19,7 @@ public class BesterServer
|
|||
* Associative array of `payloadType (string)`:`MessageHandler`
|
||||
* TODO: Implement this
|
||||
*/
|
||||
private MessageHandler[] handlers;
|
||||
public MessageHandler[] handlers;
|
||||
|
||||
/* The server's socket */
|
||||
private Socket serverSocket;
|
Loading…
Reference in New Issue