From 3b0136d72529cc573db140bfb4356825ea6f1d9f Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Wed, 15 Mar 2023 20:43:09 +0200 Subject: [PATCH 01/40] Constants - Added `RPL_LOCALUSERS` --- source/birchwood/protocol/constants.d | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/source/birchwood/protocol/constants.d b/source/birchwood/protocol/constants.d index e3ab7d6..3ef2f1a 100644 --- a/source/birchwood/protocol/constants.d +++ b/source/birchwood/protocol/constants.d @@ -144,5 +144,10 @@ module birchwood.protocol.constants; ERR_BADCHANMASK = 476, + /** + * ircv3 + */ + RPL_LOCALUSERS = 265, + BIRCHWOOD_UNKNOWN_RESP_CODE = 0 } \ No newline at end of file From 454dc86e663e8c19148e2c172feca0e367c51694 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Wed, 15 Mar 2023 20:47:37 +0200 Subject: [PATCH 02/40] Constants - Added `RPL_GLOBALUSERS` and `RPL_WHOISCERTFP` --- source/birchwood/protocol/constants.d | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/birchwood/protocol/constants.d b/source/birchwood/protocol/constants.d index 3ef2f1a..e6d7e26 100644 --- a/source/birchwood/protocol/constants.d +++ b/source/birchwood/protocol/constants.d @@ -148,6 +148,9 @@ module birchwood.protocol.constants; * ircv3 */ RPL_LOCALUSERS = 265, + RPL_GLOBALUSERS = 266, + RPL_WHOISCERTFP = 276, + BIRCHWOOD_UNKNOWN_RESP_CODE = 0 } \ No newline at end of file From 3393b6099371bbb4e71ba31de9b31a2854d048d2 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Wed, 15 Mar 2023 21:27:01 +0200 Subject: [PATCH 03/40] Client - Switch to BNET test server --- source/birchwood/client/client.d | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/birchwood/client/client.d b/source/birchwood/client/client.d index 5e9fb27..cd78303 100644 --- a/source/birchwood/client/client.d +++ b/source/birchwood/client/client.d @@ -904,11 +904,11 @@ public class Client : Thread unittest { /* FIXME: Get domaina name resolution support */ - ConnectionInfo connInfo = ConnectionInfo.newConnection("irc.freenode.net", 6667, "testBirchwood"); + // ConnectionInfo connInfo = ConnectionInfo.newConnection("irc.freenode.net", 6667, "testBirchwood"); //freenode: 149.28.246.185 //snootnet: 178.62.125.123 //bonobonet: fd08:8441:e254::5 - // ConnectionInfo connInfo = ConnectionInfo.newConnection("worcester.community.networks.deavmi.assigned.network", 6667, "testBirchwood"); + ConnectionInfo connInfo = ConnectionInfo.newConnection("worcester.community.networks.deavmi.assigned.network", 6667, "testBirchwood"); // // Set the fakelag to 1 second // connInfo.setFakeLag(1); From 5782b84c5d341cc37c2f85f2869dcc24af3e4402 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Thu, 16 Mar 2023 12:56:14 +0200 Subject: [PATCH 04/40] Constants - `005` is now `RPL_ISUPPORT` in ircv3 and not `RPL_BOUNCE` as in rf2812 --- source/birchwood/protocol/constants.d | 1 + 1 file changed, 1 insertion(+) diff --git a/source/birchwood/protocol/constants.d b/source/birchwood/protocol/constants.d index e6d7e26..136083a 100644 --- a/source/birchwood/protocol/constants.d +++ b/source/birchwood/protocol/constants.d @@ -150,6 +150,7 @@ module birchwood.protocol.constants; RPL_LOCALUSERS = 265, RPL_GLOBALUSERS = 266, RPL_WHOISCERTFP = 276, + RPL_ISUPPORT = 005, // THis overrides the old rfc2812 RPL_BOUNCE code (we can only support one of these) BIRCHWOOD_UNKNOWN_RESP_CODE = 0 From d21229b8997789aed0a9f8d9a83c6fe2f18b0361 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Thu, 16 Mar 2023 12:56:28 +0200 Subject: [PATCH 05/40] Constants - Typo fix --- source/birchwood/protocol/constants.d | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/birchwood/protocol/constants.d b/source/birchwood/protocol/constants.d index 136083a..c834e21 100644 --- a/source/birchwood/protocol/constants.d +++ b/source/birchwood/protocol/constants.d @@ -150,7 +150,7 @@ module birchwood.protocol.constants; RPL_LOCALUSERS = 265, RPL_GLOBALUSERS = 266, RPL_WHOISCERTFP = 276, - RPL_ISUPPORT = 005, // THis overrides the old rfc2812 RPL_BOUNCE code (we can only support one of these) + RPL_ISUPPORT = 005, // This overrides the old rfc2812 RPL_BOUNCE code (we can only support one of these) BIRCHWOOD_UNKNOWN_RESP_CODE = 0 From 9070bf457370178b2498b1a96bdd74c2175a5178 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Thu, 16 Mar 2023 12:59:52 +0200 Subject: [PATCH 06/40] Client - Switched to `ReplyType.RPL_USPPORT` --- source/birchwood/client/client.d | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/birchwood/client/client.d b/source/birchwood/client/client.d index 1c8291e..8a56150 100644 --- a/source/birchwood/client/client.d +++ b/source/birchwood/client/client.d @@ -137,7 +137,7 @@ public class Client : Thread import birchwood.protocol.constants : ReplyType; - if(commandReply.getReplyType() == ReplyType.RPL_BOUNCE) + if(commandReply.getReplyType() == ReplyType.RPL_ISUPPORT) { logger.log("Take a look:\n\n"~commandReply.getParams()); } From 9633e76c1c9335a23f95e5500ca6ae322aeefdf3 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Thu, 16 Mar 2023 13:05:32 +0200 Subject: [PATCH 07/40] Constants - Added `RPL_BOUNCE` support back with the new code `010` as per the IRCv3 spec --- source/birchwood/protocol/constants.d | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/birchwood/protocol/constants.d b/source/birchwood/protocol/constants.d index 24d1718..6c831b2 100644 --- a/source/birchwood/protocol/constants.d +++ b/source/birchwood/protocol/constants.d @@ -156,7 +156,7 @@ public enum ReplyType : ulong RPL_YOURHOST = 002, RPL_CREATED = 003, RPL_MYINFO = 004, - // RPL_BOUNCE = 005, // TODO: We care about the key-value pairs here in RPL_BOUNCE + RPL_BOUNCE = 010, // In ircv3 this changed from 005 to 010 ERR_NOCHANMODES = 477, /** From 9134a437d56f1a2cd204caa9b2a6a8c486930fb6 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Thu, 16 Mar 2023 13:07:29 +0200 Subject: [PATCH 08/40] Constants - Apparently that syntax does octal number representation, I don't want that --- source/birchwood/protocol/constants.d | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/source/birchwood/protocol/constants.d b/source/birchwood/protocol/constants.d index 6c831b2..0863eec 100644 --- a/source/birchwood/protocol/constants.d +++ b/source/birchwood/protocol/constants.d @@ -152,11 +152,11 @@ public enum ReplyType : ulong /** * rfc 2812 */ - RPL_WELCOME = 001, - RPL_YOURHOST = 002, - RPL_CREATED = 003, - RPL_MYINFO = 004, - RPL_BOUNCE = 010, // In ircv3 this changed from 005 to 010 + RPL_WELCOME = 1, + RPL_YOURHOST = 2, + RPL_CREATED = 3, + RPL_MYINFO = 4, + RPL_BOUNCE = 10, // In ircv3 this changed from 005 to 010 ERR_NOCHANMODES = 477, /** @@ -165,7 +165,7 @@ public enum ReplyType : ulong RPL_LOCALUSERS = 265, RPL_GLOBALUSERS = 266, RPL_WHOISCERTFP = 276, - RPL_ISUPPORT = 005, // This overrides the old rfc2812 RPL_BOUNCE code (we can only support one of these) + RPL_ISUPPORT = 5, // This overrides the old rfc2812 RPL_BOUNCE code (we can only support one of these) From b024a14c7a8839bb28b036a6c78f61497e0598e9 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Thu, 16 Mar 2023 13:20:46 +0200 Subject: [PATCH 09/40] Client - WIP --- source/birchwood/client/client.d | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/birchwood/client/client.d b/source/birchwood/client/client.d index 8a56150..74fd7b1 100644 --- a/source/birchwood/client/client.d +++ b/source/birchwood/client/client.d @@ -139,7 +139,8 @@ public class Client : Thread if(commandReply.getReplyType() == ReplyType.RPL_ISUPPORT) { - logger.log("Take a look:\n\n"~commandReply.getParams()); + string params = commandReply.getParams(); + logger.log("RPL_ISUPPORT_PARAMS:\n\n"~params); } } From 1a89396ba8ed6b239784011624ad941cdbf645d6 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Sat, 18 Mar 2023 11:38:12 +0200 Subject: [PATCH 10/40] Messages - Temporarily disabled Dlog `debug_` calls --- source/birchwood/protocol/messages.d | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/birchwood/protocol/messages.d b/source/birchwood/protocol/messages.d index 1e29dc1..2213db8 100644 --- a/source/birchwood/protocol/messages.d +++ b/source/birchwood/protocol/messages.d @@ -428,7 +428,7 @@ public final class Message bool hasTrailer; string[] paramsSplit = splitting(params, hasTrailer); - logger.debug_("ParamsSPlit direct:", paramsSplit); + // logger.debug_("ParamsSPlit direct:", paramsSplit); @@ -440,7 +440,7 @@ public final class Message /* Remove it from the parameters */ paramsSplit = paramsSplit[0..$-1]; - logger.debug_("GOt railer ", trailing); + // logger.debug_("GOt railer ", trailing); } ppPairs = paramsSplit; @@ -461,7 +461,7 @@ public final class Message /* Save the trailing */ ppTrailing = trailing; - logger.debug_("ppTrailing: ", ppTrailing); + // logger.debug_("ppTrailing: ", ppTrailing); } } From 4b43174c209fb1abf4cb72342aa27dc76eb8b938 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Sat, 18 Mar 2023 11:38:38 +0200 Subject: [PATCH 11/40] Client - Print the key-value pairs from `RPL_ISUPPORT` out --- source/birchwood/client/client.d | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/source/birchwood/client/client.d b/source/birchwood/client/client.d index 32c789c..c26bfba 100644 --- a/source/birchwood/client/client.d +++ b/source/birchwood/client/client.d @@ -159,6 +159,12 @@ public class Client : Thread // logger.log("<<<>>>"); // logger.log(); + import std.stdio; + writeln("Support stuff: ", commandReply.getKVPairs()); + + + + } From 17c81bd1b009fc3fcc63dea70c3ac85d5a1e40ad Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Sat, 18 Mar 2023 11:45:38 +0200 Subject: [PATCH 12/40] Client - Store all learnt key-value pairs into `string[string] attrs` for now --- source/birchwood/client/client.d | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/source/birchwood/client/client.d b/source/birchwood/client/client.d index ddb3271..eda9dcd 100644 --- a/source/birchwood/client/client.d +++ b/source/birchwood/client/client.d @@ -163,13 +163,29 @@ public class Client : Thread writeln("Support stuff: ", commandReply.getKVPairs()); - + testing(commandReply.getKVPairs()); } } + private string[string] attrs; + private void testing(string[string] newData) + { + foreach(string key; newData.keys()) + { + attrs[key] = newData[key]; + } + + foreach(string key; attrs.keys()) + { + logger.debug_("Attribute name:", key); + logger.debug_("Attribute value:", attrs[key]); + } + } + + /** * Joins the requested channel * From 357deeb5e41c8b7e4bfacb2b5a16d474e434ff75 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Sat, 25 Mar 2023 13:01:02 +0200 Subject: [PATCH 13/40] ConnInfo - Added a `string[string]` key-value pair named `db` to hold the parameters learnt from `RPL_ISUPPORT`s - Added `updateDB(string, string)` to add an entry to the `db` - Added `getDB(string)` to fetch a value from the `db` (if it doesn't exist then an empty string `""` is returned) --- source/birchwood/config/conninfo.d | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/source/birchwood/config/conninfo.d b/source/birchwood/config/conninfo.d index c9d01f0..934fc98 100644 --- a/source/birchwood/config/conninfo.d +++ b/source/birchwood/config/conninfo.d @@ -40,6 +40,12 @@ public shared struct ConnectionInfo */ public const string quitMessage; + /** + * Key-value pairs learnt from the + * server + */ + private string[string] db; + /* TODO: before publishing change this bulk size */ /** @@ -116,6 +122,26 @@ public shared struct ConnectionInfo this.fakeLag = fakeLag; } + public void updateDB(string key, string value) + { + db[key] = value; + } + + public string getDB(string key) + { + // TODO: Do existence check + if(key in db) + { + return db[key]; + } + else + { + // TODO: Should throw an exception + return ""; + } + } + + /** * Creates a ConnectionInfo struct representing a client configuration which * can be provided to the Client class to create a new connection based on its From c53fc034d23b6c08b4dc51525fd9ff5060685bab Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Sat, 25 Mar 2023 13:01:35 +0200 Subject: [PATCH 14/40] Client - Update the `ConnInfo`'s `db` on `RPL_ISUPPORT` --- source/birchwood/client/client.d | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/source/birchwood/client/client.d b/source/birchwood/client/client.d index a1f8986..09b87a0 100644 --- a/source/birchwood/client/client.d +++ b/source/birchwood/client/client.d @@ -189,7 +189,13 @@ public class Client : Thread testing(commandReply.getKVPairs()); - + /* Fetch and parse the received key-value pairs */ + string[string] receivedKV = commandReply.getKVPairs(); + foreach(string key; receivedKV.keys()) + { + /* Update the db */ + connInfo.updateDB(key, receivedKV[key]); + } } } From fdcbcfeda4b37375a085e54f8a1583e58804abc4 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Sat, 25 Mar 2023 13:05:04 +0200 Subject: [PATCH 15/40] ConnInfo - `getDB(string)` will now throw `BirchwoodException` with `ErrorType.DB_KEY_NOT_FOUND` if the key is not found Exceptions - Added member `DB_KEY_NOT_FOUND` to `ErrorType` enum --- source/birchwood/client/exceptions.d | 7 ++++++- source/birchwood/config/conninfo.d | 3 +-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/source/birchwood/client/exceptions.d b/source/birchwood/client/exceptions.d index db01916..1005708 100644 --- a/source/birchwood/client/exceptions.d +++ b/source/birchwood/client/exceptions.d @@ -66,7 +66,12 @@ public enum ErrorType * If invalid parameters are passed * to any of the text formatting functions */ - INVALID_FORMATTING + INVALID_FORMATTING, + + /** + * If a key-lookup in the ConnInfo failed + */ + DB_KEY_NOT_FOUND } /** diff --git a/source/birchwood/config/conninfo.d b/source/birchwood/config/conninfo.d index 934fc98..c6e921b 100644 --- a/source/birchwood/config/conninfo.d +++ b/source/birchwood/config/conninfo.d @@ -136,8 +136,7 @@ public shared struct ConnectionInfo } else { - // TODO: Should throw an exception - return ""; + throw new BirchwoodException(ErrorType.DB_KEY_NOT_FOUND, "Could not find key '"~key~"'"); } } From 03c887c39ad8286073a0335dae2f6da71a7eefb7 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Sat, 25 Mar 2023 13:05:35 +0200 Subject: [PATCH 16/40] ConnInfo - Removed TODO for `getDB(string)` --- source/birchwood/config/conninfo.d | 1 - 1 file changed, 1 deletion(-) diff --git a/source/birchwood/config/conninfo.d b/source/birchwood/config/conninfo.d index c6e921b..73b9839 100644 --- a/source/birchwood/config/conninfo.d +++ b/source/birchwood/config/conninfo.d @@ -129,7 +129,6 @@ public shared struct ConnectionInfo public string getDB(string key) { - // TODO: Do existence check if(key in db) { return db[key]; From 5979387e8738a249725e8176105abe96d47bbdfa Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Sat, 25 Mar 2023 13:06:06 +0200 Subject: [PATCH 17/40] Client - Removed testing code that looped through a separate `db`-like structure --- source/birchwood/client/client.d | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/source/birchwood/client/client.d b/source/birchwood/client/client.d index 09b87a0..0d33aa7 100644 --- a/source/birchwood/client/client.d +++ b/source/birchwood/client/client.d @@ -186,9 +186,6 @@ public class Client : Thread import std.stdio; writeln("Support stuff: ", commandReply.getKVPairs()); - - testing(commandReply.getKVPairs()); - /* Fetch and parse the received key-value pairs */ string[string] receivedKV = commandReply.getKVPairs(); foreach(string key; receivedKV.keys()) @@ -200,22 +197,6 @@ public class Client : Thread } } - private string[string] attrs; - private void testing(string[string] newData) - { - foreach(string key; newData.keys()) - { - attrs[key] = newData[key]; - } - - foreach(string key; attrs.keys()) - { - logger.debug_("Attribute name:", key); - logger.debug_("Attribute value:", attrs[key]); - } - } - - /** * Joins the requested channel * From 245939824ee84a885d32c3eee4e515150bab567c Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Sat, 25 Mar 2023 13:07:53 +0200 Subject: [PATCH 18/40] Client - Log which key-value pair was added --- source/birchwood/client/client.d | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/birchwood/client/client.d b/source/birchwood/client/client.d index 0d33aa7..2954f35 100644 --- a/source/birchwood/client/client.d +++ b/source/birchwood/client/client.d @@ -191,7 +191,9 @@ public class Client : Thread foreach(string key; receivedKV.keys()) { /* Update the db */ - connInfo.updateDB(key, receivedKV[key]); + string value = receivedKV[key]; + connInfo.updateDB(key, value); + logger.log("Updated key in db '"~key~"' with value '"~value~"'"); } } From 1015a4ec1cd8b914ca4e3a51127e62350183208c Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Sat, 25 Mar 2023 13:35:11 +0200 Subject: [PATCH 19/40] Exceptions - Added new enum member `NICKNAME_TOO_LONG` to `ErrorType` --- source/birchwood/client/exceptions.d | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/source/birchwood/client/exceptions.d b/source/birchwood/client/exceptions.d index 1005708..7258c38 100644 --- a/source/birchwood/client/exceptions.d +++ b/source/birchwood/client/exceptions.d @@ -71,7 +71,13 @@ public enum ErrorType /** * If a key-lookup in the ConnInfo failed */ - DB_KEY_NOT_FOUND + DB_KEY_NOT_FOUND, + + /** + * If the requested nickname (via /NICK) is + * too long + */ + NICKNAME_TOO_LONG } /** From 9ca98ac6644e97f0c689e14e5f6f7c4b8b1e4279 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Sat, 25 Mar 2023 13:37:18 +0200 Subject: [PATCH 20/40] ConnectionInfo - Updated `string getDB(string)` to `T getDB(T)(string)` which will now attempt conversion to type `T`, on failure to do so it will return `T.init` ConnInfo - Added `setDefaults(ref ConnectionInfo)` which will set defaults in the `db`, namely so far it sets the `MAXNICKLEN` to `9` as per rfc1459 Package (`birchwood.config`) - Now publically imports `setDefaults()` --- source/birchwood/config/conninfo.d | 28 ++++++++++++++++++++++++++-- source/birchwood/config/package.d | 2 +- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/source/birchwood/config/conninfo.d b/source/birchwood/config/conninfo.d index 73b9839..a4427fe 100644 --- a/source/birchwood/config/conninfo.d +++ b/source/birchwood/config/conninfo.d @@ -5,6 +5,7 @@ module birchwood.config.conninfo; import std.socket : SocketException, Address, getAddress; import birchwood.client.exceptions; +import std.conv : to, ConvException; /** * Represents the connection details for a server @@ -127,11 +128,25 @@ public shared struct ConnectionInfo db[key] = value; } - public string getDB(string key) + public T getDB(T)(string key) { + import std.stdio; + writeln("GETDB: '"~key~"' with len ", key.length); if(key in db) { - return db[key]; + /* Attempt conversion into T */ + try + { + /* Fetch and convert */ + T value = to!(T)(db[key]); + return value; + } + /* If conversion to type T fails */ + catch(ConvException e) + { + /* Return the initial value for such a paremeter */ + return T.init; + } } else { @@ -205,4 +220,13 @@ public shared struct ConnectionInfo } } +} + +public void setDefaults(ref ConnectionInfo connInfo) +{ + /* Set the `MAXNICKLEN` to a default of 9 */ + connInfo.updateDB("MAXNICKLEN", "9"); + assert(connInfo.getDB!(ulong)("MAXNICKLEN") == 9); + import std.stdio; + writeln("MAXKAK: ", connInfo.getDB!(ulong)("MAXNICKLEN")); } \ No newline at end of file diff --git a/source/birchwood/config/package.d b/source/birchwood/config/package.d index 1bb8dfd..82b1e2d 100644 --- a/source/birchwood/config/package.d +++ b/source/birchwood/config/package.d @@ -6,4 +6,4 @@ module birchwood.config; /** * Connection information */ -public import birchwood.config.conninfo : ConnectionInfo; \ No newline at end of file +public import birchwood.config.conninfo : ConnectionInfo, setDefaults; \ No newline at end of file From ea3f6ec5cb994ec8d4ed89afe42b20cff91df4c2 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Sat, 25 Mar 2023 13:38:49 +0200 Subject: [PATCH 21/40] Client - Just import `birchwood.config` package rather - Call `setDefaults(this.connInfo)` to assign default `db` values - `nick(string)` will now fetch the maximum nickname length and ensure the provided nickname is in said bounds, if not then a `BirchwoodException` with `ErrorType` `NICKNAME_TOO_LONG` is thrown Unit tests - Updated unit test to test the updated value of `MAXNICKLEN` (which on BonoboNET is 30) --- source/birchwood/client/client.d | 40 ++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/source/birchwood/client/client.d b/source/birchwood/client/client.d index b464570..0a5c0e9 100644 --- a/source/birchwood/client/client.d +++ b/source/birchwood/client/client.d @@ -8,7 +8,7 @@ import core.sync.mutex : Mutex; import core.thread : Thread, dur; import std.string; import eventy : EventyEvent = Event, Engine, EventType, Signal; -import birchwood.config : ConnectionInfo; +import birchwood.config; import birchwood.client.exceptions : BirchwoodException, ErrorType; import birchwood.protocol.messages : Message, encodeMessage, decodeMessage, isValidText; @@ -80,6 +80,11 @@ public class Client : Thread */ this.receiver = new ReceiverThread(this); this.sender = new SenderThread(this); + + /** + * Set defaults in db + */ + setDefaults(this.connInfo); } /** @@ -212,9 +217,21 @@ public class Client : Thread /* Ensure no illegal characters in nick name */ if(isValidText(nickname)) { - /* Set the nick */ - Message nickMessage = new Message("", "NICK", nickname); - sendMessage(nickMessage); + // TODO: We could investigate this later if we want to be safer + ulong maxNickLen = connInfo.getDB!(ulong)("MAXNICKLEN"); + + /* If the username's lenght is within the allowed bounds */ + if(nickname.length <= maxNickLen) + { + /* Set the nick */ + Message nickMessage = new Message("", "NICK", nickname); + sendMessage(nickMessage); + } + /* If not */ + else + { + throw new BirchwoodException(ErrorType.NICKNAME_TOO_LONG); + } } else { @@ -1176,6 +1193,21 @@ public class Client : Thread */ client.leaveChannel(["#birchwoodLeave2"]); + + /** + * Definately by now we would have learnt the new MAXNICLEN + * which on BonoboNET is 30, hence the below should work + */ + try + { + client.nick("birchwood123456789123456789123"); + assert(true); + } + catch(BirchwoodException e) + { + assert(false); + } + // TODO: Don't forget to re-enable this when done testing! Thread.sleep(dur!("seconds")(15)); client.quit(); From fa9de6dad5f28f4fcc22e02949fdd3856cf96539 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Sat, 25 Mar 2023 14:11:03 +0200 Subject: [PATCH 22/40] ConnectionInfo - Made field `nickname` public - Added public fields `username` and `realname` - Updated constructor to take in additional parameters `username` and `realname` Client - Calling `connect()` on a `Client` object will now call `doAuth()` which will do `/NICK` and `/USER` for you automatically (no need to do it manually anymore) - The newly added `doAuth()` will take `hostname=username` from `connInfo.username`, it will set `servername` to `"bogus.net"` and `realname==connInfo.realname` - Added `user(username, hostname, servername, realname)` --- source/birchwood/client/client.d | 39 +++++++++++++++++++++++++----- source/birchwood/config/conninfo.d | 24 +++++++++++++----- 2 files changed, 51 insertions(+), 12 deletions(-) diff --git a/source/birchwood/client/client.d b/source/birchwood/client/client.d index 0a5c0e9..bd97bc2 100644 --- a/source/birchwood/client/client.d +++ b/source/birchwood/client/client.d @@ -813,6 +813,9 @@ public class Client : Thread /* Start the socket read-decode loop */ this.start(); + + // TODO: We should add a call to NICK followed by USER here + doAuth(); } catch(SocketOSException e) { @@ -826,6 +829,26 @@ public class Client : Thread } } + private void doAuth() + { + Thread.sleep(dur!("seconds")(2)); + nick(connInfo.nickname); + + Thread.sleep(dur!("seconds")(2)); + // TODO: Note I am making hostname the same as username always (is this okay?) + // TODO: Note I am making the servername always bogus.net + user(connInfo.username, connInfo.username, "bogus.net", connInfo.realname); + } + + public void user(string username, string hostname, string servername, string realname) + { + // TODO: Implement me properly with all required checks + + /* User message */ + Message userMessage = new Message("", "USER", username~" "~hostname~" "~servername~" "~":"~realname); + sendMessage(userMessage); + } + /** * Adds a given message onto the receieve queue for @@ -1067,7 +1090,7 @@ public class Client : Thread //freenode: 149.28.246.185 //snootnet: 178.62.125.123 //bonobonet: fd08:8441:e254::5 - ConnectionInfo connInfo = ConnectionInfo.newConnection("worcester.community.networks.deavmi.assigned.network", 6667, "testBirchwood"); + ConnectionInfo connInfo = ConnectionInfo.newConnection("worcester.community.networks.deavmi.assigned.network", 6667, "birchwood", "doggie", "Tristan B. Kildaire"); // // Set the fakelag to 1 second // connInfo.setFakeLag(1); @@ -1080,12 +1103,16 @@ public class Client : Thread // TODO: The below should all be automatic, maybe once IRCV3 is done // ... we should automate sending in NICK and USER stuff - Thread.sleep(dur!("seconds")(2)); - // client.command(new Message("", "NICK", "birchwood")); // TODO: add nickcommand - client.nick("birchwood"); + // Thread.sleep(dur!("seconds")(2)); + // client.nick("birchwood"); + + // Thread.sleep(dur!("seconds")(2)); + // client.command(new Message("", "USER", "doggie doggie irc.frdeenode.net :Tristan B. Kildaire")); + // client.user("doggie", "doggie", "irc.frdeenode.net", "Tristan B. Kildaire"); + + + - Thread.sleep(dur!("seconds")(2)); - client.command(new Message("", "USER", "doggie doggie irc.frdeenode.net :Tristan B. Kildaire")); Thread.sleep(dur!("seconds")(4)); // client.command(new Message("", "JOIN", "#birchwood")); diff --git a/source/birchwood/config/conninfo.d b/source/birchwood/config/conninfo.d index a4427fe..cd0f50a 100644 --- a/source/birchwood/config/conninfo.d +++ b/source/birchwood/config/conninfo.d @@ -21,7 +21,17 @@ public shared struct ConnectionInfo /** * Nickname to use */ - private string nickname; + public string nickname; + + /** + * Username + */ + public string username; + + /** + * Real name + */ + public string realname; /** * Size to use to dequeue bytes @@ -59,11 +69,13 @@ public shared struct ConnectionInfo * bulkReadSize = the dequeue read size * quitMessage = the message to use when quitting */ - private this(Address addrInfo, string nickname, ulong bulkReadSize = 20, string quitMessage = "birchwood client disconnecting...") + private this(Address addrInfo, string nickname, string username, string realname, ulong bulkReadSize = 20, string quitMessage = "birchwood client disconnecting...") { // NOTE: Not sure if much mutable in Address anyways this.addrInfo = cast(shared Address)addrInfo; this.nickname = nickname; + this.username = username; + this.realname = realname; this.bulkReadSize = bulkReadSize; this.quitMessage = quitMessage; @@ -167,7 +179,7 @@ public shared struct ConnectionInfo * * Returns: ConnectionInfo for this server */ - public static ConnectionInfo newConnection(string hostname, ushort port, string nickname) + public static ConnectionInfo newConnection(string hostname, ushort port, string nickname, string username, string realname) { try { @@ -183,7 +195,7 @@ public shared struct ConnectionInfo /* TODO: Add feature to choose which address to use, prefer v4 or v6 type of thing */ Address chosenAddress = addrInfo[0]; - return ConnectionInfo(chosenAddress, nickname); + return ConnectionInfo(chosenAddress, nickname, username, realname); } catch(SocketException e) { @@ -201,7 +213,7 @@ public shared struct ConnectionInfo { try { - newConnection("1.", 21, "deavmi"); + newConnection("1.", 21, "deavmi", "thedeavmi", "Tristan Brice Birchwood Kildaire"); assert(false); } catch(BirchwoodException e) @@ -211,7 +223,7 @@ public shared struct ConnectionInfo try { - newConnection("1.1.1.1", 21, ""); + newConnection("1.1.1.1", 21, "", "thedeavmi", "Tristan Brice Birchwood Kildaire"); assert(false); } catch(BirchwoodException e) From 02d25517b9e620a075358b373ae06d74b68a87d4 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Sat, 25 Mar 2023 14:17:55 +0200 Subject: [PATCH 23/40] Client - `doAuth()` now takes in a default argument `doAuth(string = "bogus.net")` --- source/birchwood/client/client.d | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/birchwood/client/client.d b/source/birchwood/client/client.d index bd97bc2..de90643 100644 --- a/source/birchwood/client/client.d +++ b/source/birchwood/client/client.d @@ -829,7 +829,7 @@ public class Client : Thread } } - private void doAuth() + private void doAuth(string servername = "bogus.net") { Thread.sleep(dur!("seconds")(2)); nick(connInfo.nickname); @@ -837,7 +837,7 @@ public class Client : Thread Thread.sleep(dur!("seconds")(2)); // TODO: Note I am making hostname the same as username always (is this okay?) // TODO: Note I am making the servername always bogus.net - user(connInfo.username, connInfo.username, "bogus.net", connInfo.realname); + user(connInfo.username, connInfo.username, servername, connInfo.realname); } public void user(string username, string hostname, string servername, string realname) From a23636483c59ae3c324aae2ec279ea653c81882f Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Sat, 25 Mar 2023 14:18:51 +0200 Subject: [PATCH 24/40] Client - Updated comment for call to `doAuth()` --- source/birchwood/client/client.d | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/birchwood/client/client.d b/source/birchwood/client/client.d index de90643..cd784dc 100644 --- a/source/birchwood/client/client.d +++ b/source/birchwood/client/client.d @@ -814,7 +814,7 @@ public class Client : Thread /* Start the socket read-decode loop */ this.start(); - // TODO: We should add a call to NICK followed by USER here + /* Do the /NICK and /USER handshake */ doAuth(); } catch(SocketOSException e) From 919e4583005e5b225dee4203b74ad5cf113b35c6 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Sat, 25 Mar 2023 14:20:51 +0200 Subject: [PATCH 25/40] Client - Added documentation to `doAuth(string)` and `user(string.s tring, string, string)` --- source/birchwood/client/client.d | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/source/birchwood/client/client.d b/source/birchwood/client/client.d index cd784dc..042a055 100644 --- a/source/birchwood/client/client.d +++ b/source/birchwood/client/client.d @@ -829,6 +829,12 @@ public class Client : Thread } } + /** + * Performs the /NICK and /USER handshake + * + * Params: + * servername = the servername to use (default: bogus.net) + */ private void doAuth(string servername = "bogus.net") { Thread.sleep(dur!("seconds")(2)); @@ -840,6 +846,15 @@ public class Client : Thread user(connInfo.username, connInfo.username, servername, connInfo.realname); } + /** + * Performs user identification + * + * Params: + * username = the username to identify with + * hostname = the hostname to use + * servername = the servername to use + * realname = your realname + */ public void user(string username, string hostname, string servername, string realname) { // TODO: Implement me properly with all required checks From 357d8ed133b51db2472f8b56d8e5be1c2a827077 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Sat, 25 Mar 2023 14:23:14 +0200 Subject: [PATCH 26/40] Client - Clarified behaviour of `hostname==username` in `doAuth(string)` --- source/birchwood/client/client.d | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/birchwood/client/client.d b/source/birchwood/client/client.d index 042a055..e464dd6 100644 --- a/source/birchwood/client/client.d +++ b/source/birchwood/client/client.d @@ -830,7 +830,10 @@ public class Client : Thread } /** - * Performs the /NICK and /USER handshake + * Performs the /NICK and /USER handshake. + * + * This method will set the hostname to be equal to the chosen + * username in the ConnectionInfo struct * * Params: * servername = the servername to use (default: bogus.net) From 4c3afb5027243a0b591b60cf5c987c666d4f470a Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Sat, 25 Mar 2023 14:24:42 +0200 Subject: [PATCH 27/40] ConnInfo - Added documentation for `setDefaults(ref ConnectionInfo)` - Removed assertion and debug print --- source/birchwood/config/conninfo.d | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/source/birchwood/config/conninfo.d b/source/birchwood/config/conninfo.d index cd0f50a..4c780c9 100644 --- a/source/birchwood/config/conninfo.d +++ b/source/birchwood/config/conninfo.d @@ -234,11 +234,15 @@ public shared struct ConnectionInfo } } +/** + * Sets the default values as per rfc1459 in the + * key-value pair DB + * + * Params: + * connInfo = a reference to the ConnectionInfo struct to update + */ public void setDefaults(ref ConnectionInfo connInfo) { /* Set the `MAXNICKLEN` to a default of 9 */ connInfo.updateDB("MAXNICKLEN", "9"); - assert(connInfo.getDB!(ulong)("MAXNICKLEN") == 9); - import std.stdio; - writeln("MAXKAK: ", connInfo.getDB!(ulong)("MAXNICKLEN")); } \ No newline at end of file From 1da039dcb2c85b2b9d84bea54f1a9dc6fe020fbd Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Sat, 25 Mar 2023 14:26:32 +0200 Subject: [PATCH 28/40] ConnectionInfo - Added documentation to `T getDB(T)(string)` and `updateDB(string, string)` --- source/birchwood/config/conninfo.d | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/source/birchwood/config/conninfo.d b/source/birchwood/config/conninfo.d index 4c780c9..3f24fc4 100644 --- a/source/birchwood/config/conninfo.d +++ b/source/birchwood/config/conninfo.d @@ -135,11 +135,27 @@ public shared struct ConnectionInfo this.fakeLag = fakeLag; } + /** + * Update a value in the key-value pair database + * + * Params: + * key = the key to set + * value = the value to set to + */ public void updateDB(string key, string value) { db[key] = value; } + /** + * Retrieve a value from the key-value pair database + * + * Params: + * key = the key to lookup + * Returns: the value as type T, if not able to convert then T.init + * Throws: + * BirchwoodException if the key is not found + */ public T getDB(T)(string key) { import std.stdio; From fe578c74b8f0500706e03aa73843c092493c4b0d Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Sat, 25 Mar 2023 14:26:44 +0200 Subject: [PATCH 29/40] ConnectioNInfo - Removed debug print in `getDB(string)` --- source/birchwood/config/conninfo.d | 2 -- 1 file changed, 2 deletions(-) diff --git a/source/birchwood/config/conninfo.d b/source/birchwood/config/conninfo.d index 3f24fc4..8960a54 100644 --- a/source/birchwood/config/conninfo.d +++ b/source/birchwood/config/conninfo.d @@ -158,8 +158,6 @@ public shared struct ConnectionInfo */ public T getDB(T)(string key) { - import std.stdio; - writeln("GETDB: '"~key~"' with len ", key.length); if(key in db) { /* Attempt conversion into T */ From a48b515d2e5e4f1ccf2d1defab65932918e38811 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Wed, 5 Apr 2023 08:26:25 +0200 Subject: [PATCH 30/40] Receiver - Removed now-completed TODO --- source/birchwood/client/receiver.d | 4 ---- 1 file changed, 4 deletions(-) diff --git a/source/birchwood/client/receiver.d b/source/birchwood/client/receiver.d index 3b964ab..a5007eb 100644 --- a/source/birchwood/client/receiver.d +++ b/source/birchwood/client/receiver.d @@ -104,10 +104,6 @@ public final class ReceiverThread : Thread * an event depending on the type of message * * Handles PINGs along with normal messages - * - * TODO: Our high load average is from here - * ... it is getting lock a lot and spinning here - * ... we should use libsnooze to avoid this */ private void recvHandlerFunc() { From 19c1c06bc434a74d42e378bb0834d35bf32660af Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Wed, 5 Apr 2023 08:26:58 +0200 Subject: [PATCH 31/40] Client - Removed now-completed TODO --- source/birchwood/client/client.d | 1 - 1 file changed, 1 deletion(-) diff --git a/source/birchwood/client/client.d b/source/birchwood/client/client.d index e464dd6..604ab6b 100644 --- a/source/birchwood/client/client.d +++ b/source/birchwood/client/client.d @@ -1103,7 +1103,6 @@ public class Client : Thread unittest { - /* FIXME: Get domaina name resolution support */ // ConnectionInfo connInfo = ConnectionInfo.newConnection("irc.freenode.net", 6667, "testBirchwood"); //freenode: 149.28.246.185 //snootnet: 178.62.125.123 From c89ae255025fb8e7e47e809e3baf80755c5fdd2b Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Wed, 5 Apr 2023 08:27:37 +0200 Subject: [PATCH 32/40] Client - Added a comment --- source/birchwood/client/client.d | 1 + 1 file changed, 1 insertion(+) diff --git a/source/birchwood/client/client.d b/source/birchwood/client/client.d index 604ab6b..177c63a 100644 --- a/source/birchwood/client/client.d +++ b/source/birchwood/client/client.d @@ -1115,6 +1115,7 @@ public class Client : Thread // Create a new Client Client client = new Client(connInfo); + // Authenticate client.connect(); From cf23797f998d1aebb2eddd3af885481c86494fdf Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Thu, 1 Jun 2023 15:59:38 +0200 Subject: [PATCH 33/40] Unit test - Hang for testing ping-pong --- source/birchwood/client/client.d | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/source/birchwood/client/client.d b/source/birchwood/client/client.d index 177c63a..616dc68 100644 --- a/source/birchwood/client/client.d +++ b/source/birchwood/client/client.d @@ -1254,7 +1254,13 @@ public class Client : Thread } // TODO: Don't forget to re-enable this when done testing! - Thread.sleep(dur!("seconds")(15)); - client.quit(); + Thread.sleep(dur!("seconds")(4)); + client.joinChannel("#birchwood"); + while(true) + { + Thread.sleep(dur!("seconds")(15)); + } + + // client.quit(); } } \ No newline at end of file From 2b5da1eb9a9cb8dc461b37257e4a6828c31ad072 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Fri, 2 Jun 2023 19:29:53 +0200 Subject: [PATCH 34/40] Client - In the `loop()` (the read loop) if built in `unittest` mode then log the read count/status and the current data after the PEEK'd read --- source/birchwood/client/client.d | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/source/birchwood/client/client.d b/source/birchwood/client/client.d index 616dc68..3a1c563 100644 --- a/source/birchwood/client/client.d +++ b/source/birchwood/client/client.d @@ -1012,9 +1012,14 @@ public class Client : Thread /* Receieve at most 512 bytes (as per RFC) */ ptrdiff_t bytesRead = socket.receive(currentData, SocketFlags.PEEK); - import std.stdio; - // writeln(bytesRead); - // writeln(currentData); + version(unittest) + { + import std.stdio; + writeln("(peek) bytesRead: '", bytesRead, "' (status var or count)"); + writeln("(peek) currentData: '", currentData, "'"); + } + + /* FIXME: CHECK BYTES READ FOR SOCKET ERRORS! */ @@ -1088,7 +1093,7 @@ public class Client : Thread scratch.length = bytesRead; this.socket.receive(scratch); - + /* TODO: Yield here and in other places before continue */ From 8199b8b2a4a15a27c8d757c346bf8c72483f80f3 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Mon, 5 Jun 2023 21:04:44 +0200 Subject: [PATCH 35/40] Client - When the remote host closes the connection and we are in `unittest` build then purposefully crash --- source/birchwood/client/client.d | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/source/birchwood/client/client.d b/source/birchwood/client/client.d index 3a1c563..5e05c72 100644 --- a/source/birchwood/client/client.d +++ b/source/birchwood/client/client.d @@ -1017,6 +1017,13 @@ public class Client : Thread import std.stdio; writeln("(peek) bytesRead: '", bytesRead, "' (status var or count)"); writeln("(peek) currentData: '", currentData, "'"); + + // On remote end closing connection + if(bytesRead == 0) + { + writeln("About to do the panic!"); + *cast(byte*)0 = 2; + } } From 27704617a77d3bbae4add09419baf1fd5d20a5a6 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Mon, 12 Jun 2023 08:23:22 +0200 Subject: [PATCH 36/40] Receiver - Added a TODO to catch the `InterruptedException` here --- source/birchwood/client/receiver.d | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/birchwood/client/receiver.d b/source/birchwood/client/receiver.d index a5007eb..f4f8e9e 100644 --- a/source/birchwood/client/receiver.d +++ b/source/birchwood/client/receiver.d @@ -126,6 +126,8 @@ public final class ReceiverThread : Thread // TODO: See above notes about libsnooze behaviour due // ... to usage in our context + + // TODO: Catch InterruptedException here receiveEvent.wait(); // TODO: Catch any exceptions from libsnooze From 68a8fc74aefbb06d40922ac77b1f7cb1e7daf6c8 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Mon, 12 Jun 2023 08:23:36 +0200 Subject: [PATCH 37/40] Sender - Added a TODO to catch the `InterruptedException` here --- source/birchwood/client/sender.d | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/birchwood/client/sender.d b/source/birchwood/client/sender.d index c51c423..0e7f121 100644 --- a/source/birchwood/client/sender.d +++ b/source/birchwood/client/sender.d @@ -116,6 +116,8 @@ public final class SenderThread : Thread // TODO: See above notes about libsnooze behaviour due // ... to usage in our context + + // TODO: Catch InterruptedException here sendEvent.wait(); // TODO: Catch any exceptions from libsnooze // TODO: After the above call have a once-off call to `ensure()` here From f6069ed25449ce4807ffcdefef98e8cb6c705871 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Mon, 12 Jun 2023 17:52:42 +0200 Subject: [PATCH 38/40] Sender - When `wait()` has an `InterruptedException` then go back to the loop again (retry the `wait()`) - On `SnoozeError` (for now) we also do the same even though we should stop the loop Receiver - When `wait()` has an `InterruptedException` then go back to the loop again (retry the `wait()`) - On `SnoozeError` (for now) we also do the same even though we should stop the loop Dub - Upgraded to `libsnooze` version `1.0.0-beta` --- dub.json | 2 +- source/birchwood/client/receiver.d | 30 +++++++++++++++++++++++++++--- source/birchwood/client/sender.d | 30 ++++++++++++++++++++++++++++-- 3 files changed, 56 insertions(+), 6 deletions(-) diff --git a/dub.json b/dub.json index a2f3e25..f77c423 100644 --- a/dub.json +++ b/dub.json @@ -7,7 +7,7 @@ "dependencies": { "dlog": "0.3.19", "eventy": "0.4.0", - "libsnooze": "0.3.3" + "libsnooze": "1.0.0-beta" }, "description": "A sane IRC framework for the D language", "license": "LGPL-3.0", diff --git a/source/birchwood/client/receiver.d b/source/birchwood/client/receiver.d index f4f8e9e..43600a5 100644 --- a/source/birchwood/client/receiver.d +++ b/source/birchwood/client/receiver.d @@ -20,6 +20,11 @@ import std.string : indexOf; import birchwood.client.events : PongEvent, IRCEvent; import std.string : cmp; +version(unittest) +{ + import std.stdio : writeln; +} + /** * Manages the receive queue and performs * message parsing and event triggering @@ -126,9 +131,28 @@ public final class ReceiverThread : Thread // TODO: See above notes about libsnooze behaviour due // ... to usage in our context - - // TODO: Catch InterruptedException here - receiveEvent.wait(); // TODO: Catch any exceptions from libsnooze + try + { + receiveEvent.wait(); + } + catch(InterruptedException e) + { + version(unittest) + { + writeln("wait() interrupted"); + } + continue; + } + catch(SnoozeError e) + { + // TODO: This should crash and end + version(unittest) + { + writeln("wait() had an error"); + } + continue; + } + diff --git a/source/birchwood/client/sender.d b/source/birchwood/client/sender.d index 0e7f121..4d4b632 100644 --- a/source/birchwood/client/sender.d +++ b/source/birchwood/client/sender.d @@ -14,6 +14,11 @@ import libsnooze; import birchwood.client; +version(unittest) +{ + import std.stdio : writeln; +} + /** * Manages the send queue */ @@ -116,9 +121,30 @@ public final class SenderThread : Thread // TODO: See above notes about libsnooze behaviour due // ... to usage in our context + try + { + sendEvent.wait(); + } + catch(InterruptedException e) + { + version(unittest) + { + writeln("wait() interrupted"); + } + continue; + } + catch(SnoozeError e) + { + // TODO: This should crash and end + version(unittest) + { + writeln("wait() had an error"); + } + continue; + } + + - // TODO: Catch InterruptedException here - sendEvent.wait(); // TODO: Catch any exceptions from libsnooze // TODO: After the above call have a once-off call to `ensure()` here // ... which then only runs once and sets a `ready` flag for the Client From dc5d0f9f4a7066131296fed463003ef9644c9e65 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Tue, 13 Jun 2023 20:30:10 +0200 Subject: [PATCH 39/40] Receiver - Catch more specific exception, `FatalException` rather than `SnoozeError` - Adjusted error message printed out in unittest-builds on occurence of such an exception Sender - Catch more specific exception, `FatalException` rather than `SnoozeError` - Adjusted error message printed out in unittest-builds on occurence of such an exception --- source/birchwood/client/receiver.d | 4 ++-- source/birchwood/client/sender.d | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/source/birchwood/client/receiver.d b/source/birchwood/client/receiver.d index 43600a5..a847660 100644 --- a/source/birchwood/client/receiver.d +++ b/source/birchwood/client/receiver.d @@ -143,12 +143,12 @@ public final class ReceiverThread : Thread } continue; } - catch(SnoozeError e) + catch(FatalException e) { // TODO: This should crash and end version(unittest) { - writeln("wait() had an error"); + writeln("wait() had a FATAL error!!!!!!!!!!!"); } continue; } diff --git a/source/birchwood/client/sender.d b/source/birchwood/client/sender.d index 4d4b632..df6481f 100644 --- a/source/birchwood/client/sender.d +++ b/source/birchwood/client/sender.d @@ -133,12 +133,12 @@ public final class SenderThread : Thread } continue; } - catch(SnoozeError e) + catch(FatalException e) { // TODO: This should crash and end version(unittest) { - writeln("wait() had an error"); + writeln("wait() had a FATAL error!!!!!!!!!!!"); } continue; } From d924a91d2115028e68678b9fb7d0338eeb828ff0 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Wed, 21 Jun 2023 11:02:45 +0200 Subject: [PATCH 40/40] Sender - Removed completed TODO --- source/birchwood/client/sender.d | 3 --- 1 file changed, 3 deletions(-) diff --git a/source/birchwood/client/sender.d b/source/birchwood/client/sender.d index df6481f..0de1df0 100644 --- a/source/birchwood/client/sender.d +++ b/source/birchwood/client/sender.d @@ -95,9 +95,6 @@ public final class SenderThread : Thread /** * The send queue worker function - * - * TODO: Same issue as recvHandlerFunc - * ... we should I/O wait (sleep) here */ private void sendHandlerFunc() {