Libraries, Messages and Programs screaming at you

Published at Feb 2, 2024

#openirc#java

Welcome back! To start off this week, I kind of broke my head on trying to think of tests that would make sense. At first, I overshot it almost as much - or maybe even more - than you might expect until I realized that it’s not actually my job to check for errors other developers might make. After that it was a lot easier, since I focused more on the errors and mistakes that can happen in my code - which already are plenty.

Since the IRC Protocol is text-based (meaning that the server and the client just send each other letters in a certain formatted way) I started with implementing that. For now everytime the server reads a message, it forwards it to the part of the code that handles the tokenization. Tokenization is just an intermediate step where the message gets broken down into different parts (the Tokens) so it’s easier for the rest of the program to handle the message. When the message is tokenized, it gets send to another part of the program (called the CommandHandler since it - you might have guessed it - handles commands) to do stuff with the message, like deciding which command to execute, if a response (just a fancy way of saying answer) needs to be send etc.

While writing the early steps of the CommandHandler, I took a deeper dive into the RFC specification and just wrote down every possible command the server and client need to know (which are about 130 alone in the RFC1459, and I honestly have no clue how many more there will be in the other five RFC’s), and i realized that i will definitely need a way to load them automatically, because the alternative would have been to build a huge and resource consuming branching mechanic. That is where i got a hint to take a look into another library (libraries are amazing, they allow you to not reinvent the wheel, but use the wheels other people created) called “classgraph”. Classgraph allows me to just throw all the single files I created for the commands into a folder, and read the whole folder into the program on runtime. After the import of the files, I just throw them into a table for later usage, which is where the CommandHandler comes back into play.

When the CommandHandler receives a message with a command, it looks into that table and - if the command exists - executes the command. If the command does not exist… well. For now it just screams at me in a Java fashion and goes like “Critical Error occurred, you are stupid, i want that command, why is it not where you promised it would be?”, but otherwise ignores the fact that it could not find it and keeps sailing as it should. I will need to implement some kind of routine that is fine with not having the requested command and instead tell me what I should consider implementing as well, instead of going full rage mode.

While debugging all this nonsense, I realized that a lot of errors that occurred behind the scenes actually just got eaten by a different library, which I use for the networking stuff (again, why reinvent the wheel?), which really frustrated me, because it made debugging and developing so much harder and slower. So I reached out to the maintainer of the networking library (called opennetlib), requested a fix for this issue and two days later I was able to download the patch, which was amazing. But that also showed me that I definitely need some way to give me some kind of debugging output, so I used the intermediate time to set up some simple logging.

And that is the current state of the project. In summary: I now have a simple server that accepts clients, reads whatever they throw at it, logs the stuff clients throw at it to the console, every now and then screams at me, but otherwise runs stable. I still need to implement all the commands and the stuff that comes with it, but we are making progress here!

Congratulations, you managed to stay awake during the full post! Yes, for real this is the end. Thanks for reading it so far and I hope you had fun doing so. I will keep you updated again next week. Enjoy your weekend!

References: