Skip to content

Latest commit

 

History

History
116 lines (83 loc) · 2.34 KB

File metadata and controls

116 lines (83 loc) · 2.34 KB

x-optimizer

High-performance routing decision engine for DNS/IP-based rule matching.

What is it?

Unix daemon that performs fast domain and IP lookups against routing rules. Accepts IPC requests via JSON over Unix socket.

Features

  • O(N) suffix domain matching (single-pass trie traversal)
  • IPv4 CIDR matching
  • 95% memory efficient (optimized Patricia trie)
  • Atomic hot-reload of rules
  • JSON IPC protocol

Usage

make
./build/xoptimizer -s /tmp/xoptimizer.sock

Test connection:

echo '{"type":"ping"}' | socat - UNIX-CONNECT:/tmp/xoptimizer.sock
echo '{"type":"lookup","domain":"example.com"}' | socat - UNIX-CONNECT:/tmp/xoptimizer.sock

Rules file

One entry per line:

example.com
1.2.3.0/24
PROXY: test.org
DIRECT: local.example

Lines starting with # are ignored.

IPC Protocol

JSON over Unix socket.

Commands

PING - Check service availability:

{"type":"ping"}

Response: {"pong": true, "code": 0}

LOOKUP

{"type":"lookup","domain":"example.com"}

Response: {"action": "DIRECT", "code": 0}

STATS

{"type":"stats"}

Response: {"domain_count": 100, "cidr_count": 50, "code": 0}

RELOAD

{"type":"reload"}

Installation (systemd)

make
sudo make install
sudo systemctl start xoptimizer

Configuration

  • SOCKET_PATH: Unix socket location (default: /run/xoptimizer/ipc.sock)
  • RULES_FILE: Path to rules file (default: /etc/xoptimizer/rules.txt)
  • ARENA_SIZE: Memory pool size (default: 32MB)

Edit include/optimizer.h to change defaults and recompile.

Performance

  • Memory: ~56 bytes per trie node (vs 2080 with standard array-based approach)
  • Lookup: O(N) single-pass traversal
  • Startup: <100ms for 100K rules sudo systemctl daemon-reload sudo systemctl enable --now xoptimizer-rules-update.timer sudo systemctl status xoptimizer-rules-update.timer

## Service mode

A baseline `systemd` unit is provided in this repo:

- `xoptimizer.service`

For production, keep environment-specific overrides in your private infra repo.

### Minimal systemd setup

```bash
sudo cp xoptimizer.service /etc/systemd/system/xoptimizer.service
sudo systemctl daemon-reload
sudo systemctl enable --now xoptimizer
sudo systemctl status xoptimizer

Status

Stable core daemon with hot-reloadable rules and an external updater.