From 8890cd3e79c7c44db5bcbfd2ee91b01eb0a373f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tristan=20=F0=9F=85=B1=2E=20Kildaire?= <21629986@sun.ac.za> Date: Wed, 23 Sep 2020 10:33:10 +0200 Subject: [PATCH] Updated dependancies --- dub.json | 3 ++ dub.selections.json | 7 ++++ source/dnetd/dconnection.d | 70 +++++++++++++++++++++++++++++++++++++- 3 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 dub.selections.json diff --git a/dub.json b/dub.json index 0928b28..7a4657e 100644 --- a/dub.json +++ b/dub.json @@ -3,6 +3,9 @@ "Tristan B. Kildaire" ], "copyright": "Copyright © 2020, Tristan B. Kildaire", + "dependencies": { + "tristanable": "~>0.0.27" + }, "description": "dnet server", "license": "AGPLv3", "name": "dnet" diff --git a/dub.selections.json b/dub.selections.json new file mode 100644 index 0000000..4a87284 --- /dev/null +++ b/dub.selections.json @@ -0,0 +1,7 @@ +{ + "fileVersion": 1, + "versions": { + "bformat": "1.0.8", + "tristanable": "0.0.27" + } +} diff --git a/source/dnetd/dconnection.d b/source/dnetd/dconnection.d index c6106ac..e75fb08 100644 --- a/source/dnetd/dconnection.d +++ b/source/dnetd/dconnection.d @@ -12,11 +12,20 @@ module dnetd.dconnection; import core.thread : Thread; import std.socket : Socket; +import bmessage; +import tristanable.encoding : DataMessage; + public class DConnection : Thread { - /* The client's socket */ + /** + * Connection information + */ private Socket socket; + private bool hasAuthed; + + /* Reserved tag for push notifications */ + private long notificationTag = 0; this(Socket socket) { @@ -26,18 +35,77 @@ public class DConnection : Thread /* Set the socket */ this.socket = socket; + /* Initialize the tagging facility */ + initTagger(); + /* Start the connection handler */ start(); } + /** + * Initializes tristanable + * TODO: Implemet me (also tristanable needs reserved tags first) + */ + private void initTagger() + { + + } + /** * Byte dequeue loop */ private void worker() { + /* Received bytes (for bformat) */ + byte[] receivedBytes; + + /* Received message */ + DataMessage receivedMessage; + while(true) + { + /** + * Block to receive a bformat message + * + * (Does decoding for bformat too) + */ + bool status = receiveMessage(socket, receivedBytes); + + /* TODO: Check status */ + + /* Decode the tristanable message (tagged message) */ + receivedMessage = DataMessage.decode(receivedBytes); + + /* TODO: Tristanable needs reserved-tag support (client-side concern) */ + } + } + + /** + * Process the received message + */ + private void process(DataMessage message) + { + /* Get the command byte */ + byte commandByte = message.data[0]; + + /* If `auth` command */ + if(commandByte == 0 && !hasAuthed) + { + + } + /* If `link` command */ + else if(commandByte == 1 && !hasAuthed) + { + + } + /* TODO: Handle this case */ + else { } } + + /** + * + */ }