Welcome to NoirChat - a minimalist and private web chat designed for straightforward and secure communication using long polling. It is lightweight, fast, and designed for easy deployment on your system, whether Windows, Linux, or within the anonymous I2P network.
Technical Overview: NoirChat uses long polling for real-time message delivery. The client polls the server for new messages, and the server holds the request for up to 25 seconds waiting for updates. This approach ensures reliable message delivery while maintaining simplicity and compatibility with I2P network.
Demo: noirchat.i2p
- Real-time Messaging: Uses long polling with 25-second timeouts for reliable message delivery.
- Message Storage: SQLite database for message persistence, keeping last 100 messages.
- Rate Limiting: Redis-based protection against spam and message flooding.
- Security Features:
- Content Security Policy (CSP)
- X-Content-Type-Options and X-Frame-Options
- httpOnly cookies with SameSite=Lax
- Token-based authentication
- Privacy Focused: Easily deployable on a private server or within I2P network.
- Cross-Platform: Works on Windows and Linux, with I2P network support.
- Minimalist Interface: Clean, dark theme with adaptive text input.
- Mobile Support: Optimized for both desktop and mobile browsers.
Before installation, ensure you have:
- Python 3.x
- pip (Python package installer)
- Redis (for message queuing and rate limiting)
- SQLite3 (included with Python, used for message storage)
Choose the version appropriate for your operating system:
Windows Version
-
Clone the repository:
git clone https://github.com/ugine-bor/NoirChat.git cd NoirChat -
Create a Python virtual environment (recommended):
python -m venv venv venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Configure environment variables:
- Copy
.env.exampleto.env. - Edit
.envto specify required settings (secret key, Redis ports, message sizes, etc.). - It is crucial to set
KEYin.envto a strong, randomly generated string.
- Copy
-
Start the Redis server:
- Ensure the Redis server is running and accessible on the port specified in
.env(default is6379). - Redis for Windows can be downloaded from the official Redis website.
- Ensure the Redis server is running and accessible on the port specified in
-
Launch NoirChat:
run.bat
-
Access NoirChat in a web browser:
- Navigate to
http://localhost:[MAIN_PORT](default port is7654unless modified in.env).
- Navigate to
@echo off
setlocal
REM Activate virtual environment if not already active
if not defined VIRTUAL_ENV (
echo Activating virtual environment...
call venv\Scripts\activate
)
echo Starting NoirChat...
python main.py
endlocalLinux Version
-
Clone the repository:
git clone https://github.com/ugine-bor/NoirChat.git cd NoirChat -
Create a Python virtual environment (recommended):
python3 -m venv venv source venv/bin/activate -
Install dependencies:
pip install -r requirements.txt
-
Configure environment variables:
- Copy
.env.exampleto.env. - Edit
.envto specify required settings (secret key, Redis ports, message sizes, etc.). - It is crucial to set
KEYin.envto a strong, randomly generated string.
- Copy
-
Start the Redis server:
- Ensure the Redis server is running and accessible on the port specified in
.env(default is6379). - Install Redis if not already installed using your system's package manager (
e.g.,
sudo apt-get install redis-serverfor Debian/Ubuntu).
- Ensure the Redis server is running and accessible on the port specified in
-
Launch NoirChat:
chmod +x run.sh ./run.sh
-
Access NoirChat in a web browser:
- Navigate to
http://localhost:[MAIN_PORT](default port is7654unless modified in.env).
- Navigate to
#!/bin/bash
# Activate virtual environment if not already active
if [ -z "$VIRTUAL_ENV" ]; then
echo "Activating virtual environment..."
source venv/bin/activate
fi
echo "Starting NoirChat..."
python3 main.pyLinux I2P Version
Important: This version is intended for running NoirChat within the anonymous I2P network. Ensure you have the I2P router installed and configured before proceeding.
-
Follow the Linux installation steps (above):
- Complete the instructions in the "Linux Version" section to install dependencies and create a virtual environment.
-
Configure environment variables for I2P:
- In the
.envfile, modify the following variables:HOST=127.0.0.1(or0.0.0.0if chat access is needed from within I2P but not from the local machine).MAIN_PORT=[choose a free port, e.g., 7000](or another port that does not conflict with other I2P services).- Ensure
REDIS_PORTandREDIS_HOSTmatch your Redis server settings if it is running within I2P.
- In the
-
Start the Redis server in I2P (optional, for local Redis in I2P):
- Configure and run a Redis server if you intend to use it locally within your I2P environment. For simplicity, it's often feasible to use a Redis instance running outside I2P, but consider the privacy implications.
-
Launch NoirChat for I2P:
chmod +x run_i2p.sh ./run_i2p.sh
-
Access NoirChat in an I2P browser:
- Use a browser configured for I2P (e.g., the I2P browser or Tor Browser with I2P proxy settings).
- Navigate to
http://[your I2P domain name].i2p:[MAIN_PORT](orhttp://127.0.0.1:[MAIN_PORT]for local testing).
#!/bin/bash
# Activate virtual environment if not already active
if [ -z "$VIRTUAL_ENV" ]; then
echo "Activating virtual environment..."
source venv/bin/activate
fi
echo "Starting NoirChat in I2P mode..."
python3 main.pyImportant for I2P:
- Privacy: Running within I2P enhances privacy, but understanding I2P's operation and properly configuring your router and browser is essential.
- Performance: Performance within I2P may be slower compared to a standard network.
- Accessibility: For other I2P users to access your chat, you need to configure I2P hosting and publicize
your
.i2pdomain.
The chat implements a robust real-time messaging system using long polling:
-
Message Delivery:
- Client sends GET request to
/poll?since=<timestamp> - Server holds request for up to 25 seconds waiting for new messages
- Messages are delivered immediately when available
- Empty response after timeout if no new messages
- Client starts new polling request after each response
- Client sends GET request to
-
Storage:
- Messages are stored in SQLite database
- Redis used for message queuing and rate limiting
- Last 100 messages kept in message history
-
Security:
- Token-based authentication with signed tokens
- httpOnly cookies with SameSite=Lax
- Content Security Policy (CSP) headers
- X-Frame-Options: DENY
- X-Content-Type-Options: nosniff
- Rate limiting per user token
NoirChat is configured via environment variables, set in the .env file.
| Variable | Description | Default Value |
|---|---|---|
MAIN_PORT |
Flask application port | 5000 |
REDIS_PORT |
Redis server port | 6379 |
MESSAGE_SIZE |
Max message length in chars | 2000 |
MESSAGE_EXPIRE |
Rate limit time in seconds | 1800 |
COOKIE_LIFE |
Cookie lifetime in seconds | 2592000 |
KEY |
Flask secret key | Must change! |
To modify configuration:
- Copy
.env.exampleto.env. - Edit
.envwith any text editor. - Restart NoirChat for changes to take effect.
No contact ¯\_(ツ)_/¯
Thank you for using NoirChat.