Skip to content

laxyyza/chitychat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Table of Contents

  1. Chity Chat
  2. Chat App Features
  3. Web Server Features
  4. Web Server Limitations
  5. Current Web Server Challenges
  6. Planned Features
  7. Learning Experience
  8. Project Directory Structure
  9. Build Web Server
  10. Coding Style

Chity Chat

This is a simple Chat App with the purpose of learning.

  • Fullstack Project
    • Frontend: In JavaScript, HTML and CSS. (My first time)
    • Backend: Custom web server written in C.

Though the front-end is my initial venture into web development, the standout feature lies in the C-written backend.

Chat App Features

  • Private/Public Groups: Users have the option to join public groups or enter private ones using specific codes.
  • Real-time Communication: Messages are sent and received instantly.
  • Real-time User Staus Updates: Instantly see if users comes online and offline.

Web Server Features

  • HTTP/1.1 Parsing: Basic parsing with support for GET and POST requests.
  • Web Sockets Implementation: Real-time communication support.
  • SSL/TLS via OpenSSL: Secure connections.
  • Password Security: Salting and hashing using SHA512.
  • I/O Multiplexing: Utilizes epoll(7) for efficient I/O.
  • Database Management: Uses PostgreSQL for SQL database.
  • Session Management: Users receive session IDs for persistent login.
  • Multi-Threaded: Utilizes a thread pool to efficiently manage concurrent events.
  • IP Versions: Supports both IPv4 and IPv6.

Web Server limitations

  • Exclusively designed for this Chat App.
  • Basic HTTP Parsing: Limited to handling only GET and POST requests.
  • Monolithic Architecture: Combines web server and chat server functionalities within a single process.

Current Web Server Challenges

  • Experiences significant slowdowns with only approximately 100 concurrent users. Fixed.
  • Encounters unexpected errors when multiple clients disconnect simultaneously. Fixed.
  • Worker threads are heavly I/O bound to PostgreSQL. Non-blocking postgres connection maybe?
  • Faces potential deadlock issues during high load, resulting in server unresponsiveness.

Planned Features

  • Private Groups: Invitation-only groups.
    • Mark group as private, only group members can get it.
    • Implement Invite Codes
    • Implement Invite Links
  • Group Member Roles: Admins, mods, etc.
  • User Account Management: Change username, display name, bio, and password.
  • Deletion: Ability to delete accounts, messages, and groups.
    • Delete messages.
    • Delete accounts.
    • Detete groups.
  • Direct Messaging (DM): Private messaging between users (Create Private Group with only 2 users).
  • Enhanced Messaging: Send photos, videos, files, reply to messages, and edit messages.
    • Front-end implementation (images)
      • Add images and paste image from clipboard.
    • Back-end implementation (images)
  • Mobile Compatibility: Improve usability on mobile devices.
  • URL Parameters Support: Support HTTP URL parameters.
  • Real-Time User Status Management: Online, Offline, Away, busy, typing, etc.
    • User Online/Offline
    • Typing.
    • User set status
  • Upload File Management: Avoid duplication user files.
    • Default profile pic
  • Real-Time User Profile Updates: Receive instant updates for user profile changes like usernames, display names, bio, and profile pictures.
    • Profile pictures.
    • Username / Displayname
    • Bio

Learning experience

Through building Chity Chat, I learned:

  • Web Server Implementation:
    • HTTP
    • Web Sockets
    • SSL/TLS
    • Multi-Threading
  • SQL Database Usage with SQLite3, later PostgreSQL.
  • Frontend Development with JavaScript, HTML, and CSS.
  • Password Security with SHA512 hashing.

Project Directory Structure

# chitychat's root
/
├── server/        # Server/Backend 
│   ├── src/       # Server C source code
│   ├── include/   # Server Header Files
│   └── sql/       # SQL schema and queries
│
├── client/        # Client/Frontend
│   ├── public/    # Default Public Directory & Website source code
│   └── headless/  # Headless client; bot source code
│
└── tests/         # Currently only have load_balance_bots.sh

Build Web Server

Note

Exclusively for Linux.

Dependencies

  • clang
  • json-c
  • libmagic
  • postgresql
  • openssl
  • meson

Dependencies Package Names

  • Arch: json-c file postgresql openssl meson clang
  • Debian: libjson-c-dev libmagic-dev postgresql postgresql-client libpq-dev libssl-dev meson clang

Clone repo and cd into:

git clone https://github.com/laxyyza/chitychat.git && cd chitychat

Setup build directory:

CC=clang meson setup build/

Compile:

ninja -C build/

Executable name: chitychat inside build/

After compilation: PostgreSQL and SSL certificates.

PostgreSQL:

Read the Arch Wiki (or your distro wiki) for setting up PostgreSQL.

After you setup PostgreSQL, create a PostgreSQL database called: chitychat

sudo -u postgres createdb chitychat

SSL certificates:

Generate self-signed SSL keys: (in project's root directory)

Note

Your browser will display a warning when using self-signed SSL keys.

openssl req -x509 -newkey rsa:4096 -keyout server/server.key -out server/server.crt -days 365 -nodes

Now you should be done, and execute build/chitychat server.

Config file: server/config.json

In your browser: https://localhost:8080 or https:// + ip address + :8080

Change port in config file or use --port arguments. See build/chitychat --help

Coding Style