Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Documentation for Implementation of IPK25-CHAT protocol

Author: Dalibor Detko

Motivation

The main motivation behind this project was to enhance my skills and deeper understanding of network communication by implementing client application protocol that is built on top of the transport layer protocols (TCP and UDP). This protocol solves many bottlenecks that come with each transport layer protocol and provides command line interface that ensures easy communication.

Overview of the problem

As stated before, the goal of this project is to implement a client application protocol IPK25-CHAT. This application enables users to chat with themselves, you can join other chatting channels.There is also basic authentication with secret token. This protocol implementation comes in 2 variants: TCP and UDP. Each has its own limitations and this protocol built on top of them tries to solve them. The main challenges were for example : Packet loss (the message did not arrive from sender to receiver), Packet deduplication (receiver got the same message multiple times) or Malformed packet handling (receiver got packet that is not in complience with defined rules of IPK25-CHAT protocol).

Implementation

Implementation of this protocol is mainly object-oriented, hence UdpClient and TcpClient classes were created. Firstly, we need to parse all arguments used by user. For this, I chose to use CommandLineParser library. On top of all required flags defined by protocol, -q flag is used for enabling development mode that was used mainly while testing application. For receiving messages from server, StartReceiverThread function was created. It creates new thread, so it does not take up all resources from main thread, where all the main logic is executing. By using StreamReader class, we solve problems with receiving multiple messages in one packet, or problems with packet fragmentation that occur in TCP based communication. For graceful termination between client and server, I leveraged socket.Shutdown and socket.Close functions, these ensure that connection is properly disconnected and no RST flag is sent. Furthermore, another thread is initalized that listens for shutdown with CTRL+C (or cmd+C on mac). Main part of the client is switch statement that serves role as finite state machine which chooses what function will be executed based on user input. When checking for confirmations and replies from server, I used simple while loop with Thread.Sleep(), which ensures this loop does not take all resources and application continues smoothly.

Testing

For testing, I used mainly custom built servers using netcat. Netcat provides a simple way to test several functionalities of the IPK25-CHAT protocol. Furthermore, I used reference server anton5.fit.vutbr.cz provided by NESFIT organization (DISCLAIMER: this server does not serve as primary source of testing and my implementation does not completely rely on it since it does not meet all specifications of the protol).


What was tested

  • Sending of the packets from client to server
  • Receiving of packets from server to client
  • How application resolves malformed packets
  • Packet loss and deduplication cases
  • Compatibility with both local and remote targets.

Why it was tested

The goal of the testing was to ensure that:

  • To ensure correct message printing on stdin based on specifications of protocol
  • To ensure correct behaviour of application in error state

How it was tested

  • Each application protocol was manually opened using netcat (nc) on localhost.

Testing Environment

  • OS: Ubuntu 22.04 LTS
  • Tested Tool: ipk25chat-client (custom implementation)
  • Reference Tool: nc
  • Network Interface: lo (loopback) and tun0 (FIT VPN)
  • Privileges: No special privileges were required

Test 1: Correct message format

What was tested
Tests retransmission, correct connection to server (UDP) Setup

nc -u -l 1234

Program

./ipk25chat-client -s localhost -p 1234 -t udp
/auth xdetkod00 adasda adasdads

Program Output

ERROR: No confirmation received for message 0

Reference Output

xdetkod00adasdadsadasdaxdetkod00adasdadsadasdaxdetkod00adasdadsadasdaxdetkod00adasdadsadasda

What was tested
Tests correct message format, connection to servet (TCP), testing 5s interval for reply to come to client Setup

nc -l 1234

Program

./ipk25chat-client -s localhost -p 1234 -t tcp -r 1
/auth xdetkod00 asdads dasasd

Program Output

ERROR: Message not delivered

Reference Output

AUTH xdetkod00 AS dasasd USING asdads
ERR FROM dasasd IS Message not delivered

Structure of the Project

All source code is located in /src directory, where i splitted logic into several sub-directories, tcp part of the application is located in TcpClient, udp in UdpClient. InternetClient is class that serves for address translation. There is also /utils directory, where I have defined class for argument parsing and enums used throughout the application for better code readability. In the root directory, Makefile is located which creates executable binary file used for executing application.

Use of Artificial Intelligence during implementation a writing documentation

I hereby declare, that no generative AI (such as ChatGPT, Gemini, etc.) was used during development, except for following cases:

  1. Formating comments in the codebase : Copilot helped me to correctly format comments in the code, the content is altough purely my work.
  2. GetIPv4FromInterface(string interfaceName) function in InternetClient.cs file. I confess, that this function was built with use of AI, the reason was that this function is not part of the required functionality, hence should not be treated that harshly. The function itself is not total copy-paste, but ChatGPT helped me build it.
  3. Initial research : When starting with project, I wanted to make a design of architecture I will later implement, I used ChatGPT for asking questions about general theory (for example, what is packet loss, how is it generally solved, what is best library for argument parsing etc). NO Blocks of code were copy-pasted from any source of large language model apart ones stated above. Theory was of course double checked either from resources provided by university, RFC documents, etc.

Content of the documentation is purely my work and Artificial Intelligence did not help me with anything related to this.

Bibliography

RFC 793 - TCP

POSTEL, Jon. RFC 793 - Transmission Control Protocol [online]. IETF, 1981 [cit.2025-04-20]. Available from: https://www.ietf.org/rfc/rfc793.txt

Original specification of the Transmission Control Protocol (TCP) by the IETF.

RFC 768 - UDP

POSTEL, Jon. RFC 768 - User Datagram Protocol [online]. IETF, 1981 [cit.2025-04-20]. Available from: https://www.ietf.org/rfc/rfc768.txt

Definition of the UDP protocol, including format and characteristics.

CommandLineParser - Microsoft

MICROSOFT Command-line parsing for .NET [online]. Microsoft Learn, 2024 [cit.2025-04-20]. Available from: https://learn.microsoft.com/en-us/dotnet/api/microsoft.codeanalysis.commandlineparser?view=roslyn-dotnet-4.9.0

Command line parsing library used in this project.


Using Threads and Threading - Microsoft

MICROSOFT Using threads and threading in .NET [online]. Microsoft Learn, 2024 [cit. 2025-04-20]. Available from: https://learn.microsoft.com/en-us/dotnet/standard/threading/using-threads-and-threading.

Article describing threading techniques in C#.


StreamReader Class - Microsoft

MICROSOFT System.IO.StreamReader Class [online]. Microsoft Learn, 2024 [cit. 2025-04-20]. Available from: https://learn.microsoft.com/en-us/dotnet/api/system.io.streamreader?view=net-9.0

Provides a way to read characters from a byte stream in a particular encoding. Used in project for reading stream.

Netcat (nc) - OpenBSD

OPENBSD Netcat (nc): Feature-rich network utility [online]. OpenBSD, 2024 [cit. 2025-04-20]. Available from: https://man.openbsd.org/nc

Technology used for testing.

GitHub Copilot - GitHub

GITHUB GitHub Copilot: Your AI pair programmer [online]. GitHub, 2024 [cit. 2025-04-20]. Available from: https://github.com/features/copilot

LLM integrated into IDE used for formatting comments.


ChatGPT - OpenAI

OPENAI ChatGPT: AI language model [online]. OpenAI, 2024 [cit. 2025-04-20]. Available from: https://chat.openai.com/

Large Language Model used for general theory.


About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages