Azreyo 11d28a297f Update server.c
feat: Major server enhancements and build system
- Implemented file caching system with LRU eviction
- Added thread pool for connection handling
- Improved MIME type detection and security headers
- Added rate limiting per IP address
- Enhanced logging system with rotation
- Added proper signal handling and graceful shutdown
- Implemented SSL/TLS support with modern cipher suites
- Added license (MIT) and disclaimer
- Fixed CSS/JS MIME type issues
- Optimized socket configuration
- Added sendfile() optimization
- Improved error handling and memory management

Technical changes:
- Set TCP_NODELAY and optimized socket buffers
- Implemented epoll-based async I/O
- Added file cache with 1MB max file size
- Set 100MB max log file size with rotation
- Added thread pool with 32 max threads
- Implemented rate limiting (100 requests/60s)
- Added proper MIME type detection
- Fixed CSP headers for external resources
- Added comprehensive input sanitization
- Improved SSL context configuration
- Added proper resource cleanup
2025-02-12 20:18:54 +01:00
2025-02-08 22:59:48 +01:00
2025-02-08 22:57:59 +01:00
2025-02-09 23:55:15 +01:00
2025-02-12 20:12:16 +01:00
2025-02-12 20:13:05 +01:00
2025-02-12 19:51:14 +01:00
2025-02-12 20:14:17 +01:00
2025-02-12 20:14:02 +01:00
2025-02-12 20:18:54 +01:00
2025-02-12 20:14:48 +01:00
2025-02-08 22:58:48 +01:00

Carbon HTTP Server

A high-performance HTTP/HTTPS server written in C for Linux systems, featuring advanced security, caching, and async I/O.

Core Features

  • Multi-threaded HTTP/HTTPS server with epoll-based async I/O
  • SSL/TLS support with automatic HTTP to HTTPS redirection
  • Advanced rate limiting and DDoS protection
  • File caching system for improved performance
  • Thread pooling for efficient connection handling
  • Comprehensive security headers and MIME type detection
  • JSON-based configuration
  • Detailed logging system with rotation

Security Features

  • Buffer overflow prevention
  • Path traversal protection
  • Input sanitization
  • SSL/TLS with modern cipher suites
  • Security headers (CSP, HSTS, X-Frame-Options, etc.)
  • Rate limiting per IP
  • Automatic HTTPS redirection

Performance Features

  • Epoll-based asynchronous I/O
  • Thread pool for connection handling
  • File caching system
  • SendFile() optimization for file transfers
  • Keep-alive connection support
  • TCP optimization (NODELAY, buffer sizes)

Build Instructions

Prerequisites

# Install required dependencies
sudo apt-get update
sudo apt-get install -y \
    build-essential \
    libssl-dev \
    libcjson-dev \
    libmagic-dev \
    pkg-config

Compilation

# Using Make (recommended)
make        # Normal build
make debug  # Debug build
make release # Optimized release build

# Manual compilation
gcc server.c config_parser.c server_config.c -o server \
    -D_GNU_SOURCE \
    -Wall -Wextra -O2 \
    -lssl -lcrypto -lpthread -lmagic -lcjson

SSL Certificate Setup

# Create certificates directory
mkdir -p certs

# Generate self-signed certificate
openssl req -x509 -newkey rsa:2048 \
    -keyout certs/key.pem \
    -out certs/cert.pem \
    -days 365 -nodes

Configuration

Create server.json:

{
    "port": 8080,
    "use_https": true,
    "log_file": "/var/log/carbon-server/server.log",
    "verbose": true,
    "max_threads": 32,
    "cache_size": 100,
    "rate_limit": {
        "window": 60,
        "max_requests": 100
    }
}

Directory Structure

mkdir -p www/{css,js,images}

Running the Server

# Allow ports
sudo ufw allow 8080/tcp  # HTTP
sudo ufw allow 443/tcp   # HTTPS

# Run the server
./server

Planned Features

Feature Priority Status
WebSocket Support Medium
User Authentication High
API Documentation Medium
Load Balancing Low
Security Audits Medium

Contributing

  1. Fork the repository
  2. Create your feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Security

While this server implements various security measures, it's recommended to:

  • Use a reverse proxy (like Nginx) in production
  • Obtain proper SSL certificates (Let's Encrypt)
  • Regularly update dependencies
  • Monitor server logs
  • Conduct security audits

Acknowledgments

  • OpenSSL for SSL/TLS support
  • cJSON for configuration parsing
  • libmagic for MIME type detection
Description
Http and https server made in C with high response time, secured connections and reliable server.
https://carbonc.eu Readme 411 KiB
Languages
C 79.7%
HTML 15.5%
Shell 2.1%
Makefile 1.7%
Dockerfile 1%