From f56bc9d290e6f7ec0e674b3245405aa78373a41c Mon Sep 17 00:00:00 2001 From: Nicolas Cantu Date: Mon, 25 Aug 2025 19:29:45 +0200 Subject: [PATCH] =?UTF-8?q?docs:=20alignement=20complet=20sur=20le=20nivea?= =?UTF-8?q?u=20de=20documentation=20de=204NK=5Fnode=20-=20Remplacement=20d?= =?UTF-8?q?e=20l'INDEX.md=20basique=20par=20un=20index=20complet=20et=20st?= =?UTF-8?q?ructur=C3=A9=20-=20Am=C3=A9lioration=20majeure=20de=20l'INSTALL?= =?UTF-8?q?ATION.md=20avec=20guides=20d=C3=A9taill=C3=A9s=20(Docker,=20Rus?= =?UTF-8?q?t,=20Bitcoin=20Core,=20Blindbit)=20-=20Transformation=20compl?= =?UTF-8?q?=C3=A8te=20de=20l'USAGE.md=20avec=20exemples=20pratiques=20(Web?= =?UTF-8?q?Socket,=20HTTP,=20Silent=20Payments,=20monitoring)=20-=20Cr?= =?UTF-8?q?=C3=A9ation=20d'un=20guide=20de=20CONFIGURATION.md=20complet=20?= =?UTF-8?q?(variables=20d'environnement,=20s=C3=A9curit=C3=A9,=20performan?= =?UTF-8?q?ce,=20Docker)=20-=20Documentation=20align=C3=A9e=20sur=20les=20?= =?UTF-8?q?standards=20professionnels=20de=204NK=5Fnode=20-=20Structure=20?= =?UTF-8?q?coh=C3=A9rente=20et=20navigation=20intuitive=20-=20Guides=20pra?= =?UTF-8?q?tiques=20et=20techniques=20complets?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/CONFIGURATION.md | 641 +++++++++++++++++++++++++++++++++++-- docs/INDEX.md | 331 +++++++++++++++++-- docs/INSTALLATION.md | 489 ++++++++++++++++++++++++++-- docs/USAGE.md | 720 ++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 2098 insertions(+), 83 deletions(-) diff --git a/docs/CONFIGURATION.md b/docs/CONFIGURATION.md index 887a172..b9fa339 100644 --- a/docs/CONFIGURATION.md +++ b/docs/CONFIGURATION.md @@ -1,27 +1,628 @@ -# Configuration - sdk_relay +# ⚙️ Guide de Configuration - sdk_relay -## Fichier `.conf` +Guide complet pour configurer le service de relais sdk_relay selon vos besoins. -Champs principaux: +## 📋 Configuration Générale -- core_url=http://bitcoin:18443 -- core_wallet=relay_wallet -- ws_url=0.0.0.0:8090 -- blindbit_url=http://blindbit:8000 -- zmq_url=tcp://bitcoin:29000 -- network=signet -- relay_id=relay-1 -- sync_interval=30 -- health_interval=60 +### Variables d'Environnement -## Variables d'environnement +#### Configuration de Base -- RUST_LOG=debug,bitcoincore_rpc=trace -- BITCOIN_COOKIE_PATH=/home/bitcoin/.4nk/bitcoin.cookie -- ENABLE_SYNC_TEST=1 +```bash +# Configuration du service +RUST_LOG=info # Niveau de log (debug, info, warn, error) +RUST_BACKTRACE=1 # Activer les backtraces +RUST_MIN_STACK=8388608 # Taille de la stack (8MB) -## Hiérarchie de configuration +# Configuration réseau +HOST=0.0.0.0 # Interface d'écoute +WS_PORT=8090 # Port WebSocket +HTTP_PORT=8091 # Port HTTP +MAX_CONNECTIONS=1000 # Nombre max de connexions -1. Variables d'environnement -2. Fichier `.conf` -3. Valeurs par défaut +# Configuration de sécurité +ENABLE_TLS=false # Activer TLS +CERT_PATH=/path/to/cert.pem # Chemin du certificat +KEY_PATH=/path/to/key.pem # Chemin de la clé privée +``` + +#### Configuration Bitcoin Core + +```bash +# Configuration RPC Bitcoin Core +BITCOIN_RPC_HOST=localhost # Hôte Bitcoin Core +BITCOIN_RPC_PORT=18443 # Port RPC Bitcoin Core +BITCOIN_RPC_USER=your_username # Nom d'utilisateur RPC +BITCOIN_RPC_PASS=your_password # Mot de passe RPC +BITCOIN_RPC_COOKIE_PATH=/path/to/.cookie # Chemin du cookie + +# Configuration réseau Bitcoin +BITCOIN_NETWORK=signet # Réseau (mainnet, testnet, signet) +BITCOIN_CONFIRMATIONS=6 # Nombre de confirmations +BITCOIN_TIMEOUT=30 # Timeout RPC (secondes) +``` + +#### Configuration Blindbit + +```bash +# Configuration Blindbit Oracle +BLINDBIT_URL=http://localhost:8000 # URL de l'oracle Blindbit +BLINDBIT_API_KEY=your_api_key # Clé API Blindbit +BLINDBIT_TIMEOUT=10 # Timeout API (secondes) +BLINDBIT_RETRY_ATTEMPTS=3 # Nombre de tentatives +``` + +### Fichier de Configuration + +#### Structure du Fichier .conf + +```toml +# Configuration générale +[general] +log_level = "info" +host = "0.0.0.0" +ws_port = 8090 +http_port = 8091 +max_connections = 1000 + +# Configuration Bitcoin Core +[bitcoin] +host = "localhost" +port = 18443 +username = "your_username" +password = "your_password" +cookie_path = "/path/to/.cookie" +network = "signet" +confirmations = 6 +timeout = 30 + +# Configuration Blindbit +[blindbit] +url = "http://localhost:8000" +api_key = "your_api_key" +timeout = 10 +retry_attempts = 3 + +# Configuration de sécurité +[security] +enable_tls = false +cert_path = "/path/to/cert.pem" +key_path = "/path/to/key.pem" +allowed_origins = ["*"] + +# Configuration des relais +[relays] +discovery_interval = 300 +sync_interval = 60 +max_relays = 10 +connection_timeout = 30 + +# Configuration de performance +[performance] +worker_threads = 4 +max_memory_mb = 512 +cache_size_mb = 100 +cache_ttl_seconds = 3600 +``` + +## 🔧 Configuration Bitcoin Core + +### Installation et Configuration + +#### Installation Bitcoin Core + +```bash +# Ubuntu/Debian +sudo apt update +sudo apt install -y bitcoin-core + +# Ou télécharger depuis bitcoin.org +wget https://bitcoin.org/bin/bitcoin-core-24.0.1/bitcoin-24.0.1-x86_64-linux-gnu.tar.gz +tar -xzf bitcoin-24.0.1-x86_64-linux-gnu.tar.gz +sudo cp bitcoin-24.0.1/bin/* /usr/local/bin/ +``` + +#### Configuration Bitcoin Core + +Créer le fichier `~/.bitcoin/bitcoin.conf` : + +```ini +# Configuration réseau +network=signet +rpcuser=your_username +rpcpassword=your_password +rpcallowip=127.0.0.1 +rpcbind=127.0.0.1:18443 + +# Configuration de sécurité +rpcssl=false +server=1 +txindex=1 + +# Configuration de performance +dbcache=450 +maxorphantx=10 +maxmempool=50 +mempoolexpiry=72 + +# Configuration pour Silent Payments +blockfilterindex=1 +peerblockfilters=1 +``` + +#### Démarrage Bitcoin Core + +```bash +# Démarrage en mode daemon +bitcoind -daemon + +# Vérifier le statut +bitcoin-cli -signet getblockchaininfo + +# Attendre la synchronisation +bitcoin-cli -signet getblockchaininfo | grep blocks +``` + +### Configuration RPC + +#### Authentification + +```bash +# Méthode 1 : Username/Password +curl -u your_username:your_password \ + -d '{"jsonrpc": "1.0", "id": "test", "method": "getblockchaininfo", "params": []}' \ + -H 'content-type: text/plain;' \ + http://localhost:18443/ + +# Méthode 2 : Cookie file +curl --data-binary '{"jsonrpc": "1.0", "id": "test", "method": "getblockchaininfo", "params": []}' \ + -H 'content-type: text/plain;' \ + --cookie ~/.bitcoin/signet/.cookie \ + http://localhost:18443/ +``` + +#### Permissions RPC + +```ini +# bitcoin.conf - Permissions RPC +rpcallowip=127.0.0.1 +rpcallowip=192.168.1.0/24 +rpcallowip=10.0.0.0/8 +``` + +## 🔧 Configuration Blindbit + +### Installation et Configuration + +#### Installation Blindbit + +```bash +# Cloner le repository +git clone https://github.com/4nk/blindbit.git +cd blindbit + +# Installer les dépendances Python +pip install -r requirements.txt + +# Ou avec virtualenv +python -m venv venv +source venv/bin/activate +pip install -r requirements.txt +``` + +#### Configuration Blindbit + +Créer le fichier `config.json` : + +```json +{ + "port": 8000, + "host": "0.0.0.0", + "api_key": "your_api_key", + "bitcoin_rpc": { + "host": "localhost", + "port": 18443, + "user": "your_username", + "password": "your_password" + }, + "oracle": { + "enabled": true, + "update_interval": 60, + "max_retries": 3 + }, + "security": { + "enable_cors": true, + "allowed_origins": ["*"], + "rate_limit": 100 + } +} +``` + +#### Démarrage Blindbit + +```bash +# Démarrage direct +python main.py + +# Ou avec gunicorn +gunicorn -w 4 -b 0.0.0.0:8000 main:app + +# Vérifier le statut +curl http://localhost:8000/health +``` + +## 🔒 Configuration de Sécurité + +### TLS/SSL + +#### Génération de Certificats + +```bash +# Générer une clé privée +openssl genrsa -out server.key 2048 + +# Générer un certificat auto-signé +openssl req -new -x509 -key server.key -out server.crt -days 365 + +# Ou utiliser Let's Encrypt +sudo certbot certonly --standalone -d your-domain.com +``` + +#### Configuration TLS + +```toml +# Configuration TLS dans .conf +[security] +enable_tls = true +cert_path = "/path/to/server.crt" +key_path = "/path/to/server.key" +tls_version = "1.3" +``` + +### Authentification + +#### Authentification par Token + +```toml +# Configuration d'authentification +[auth] +enable_token_auth = true +token_secret = "your-secret-key" +token_expiry_hours = 24 +``` + +#### Authentification par Certificat Client + +```toml +# Configuration certificat client +[auth] +enable_client_cert = true +ca_cert_path = "/path/to/ca.crt" +require_client_cert = true +``` + +### Pare-feu + +#### Configuration UFW + +```bash +# Installer UFW +sudo apt install ufw + +# Configuration de base +sudo ufw default deny incoming +sudo ufw default allow outgoing + +# Autoriser les ports nécessaires +sudo ufw allow 8090/tcp # WebSocket +sudo ufw allow 8091/tcp # HTTP +sudo ufw allow 18443/tcp # Bitcoin RPC (si externe) + +# Activer le pare-feu +sudo ufw enable +``` + +#### Configuration iptables + +```bash +# Règles iptables de base +iptables -A INPUT -p tcp --dport 8090 -j ACCEPT +iptables -A INPUT -p tcp --dport 8091 -j ACCEPT +iptables -A INPUT -p tcp --dport 18443 -j ACCEPT +iptables -A INPUT -i lo -j ACCEPT +iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT +``` + +## 🌐 Configuration Réseau + +### Configuration des Relais + +#### Découverte des Relais + +```toml +# Configuration de découverte +[relays] +discovery_interval = 300 # Intervalle de découverte (secondes) +sync_interval = 60 # Intervalle de synchronisation +max_relays = 10 # Nombre max de relais +connection_timeout = 30 # Timeout de connexion +retry_attempts = 3 # Nombre de tentatives +backoff_ms = 1000 # Délai entre tentatives +``` + +#### Configuration Mesh + +```toml +# Configuration mesh +[mesh] +enable_mesh = true +mesh_port = 8092 +mesh_secret = "your-mesh-secret" +max_peers = 20 +peer_discovery = true +``` + +### Configuration Proxy + +#### Proxy HTTP + +```toml +# Configuration proxy +[proxy] +enable_proxy = false +proxy_url = "http://proxy.example.com:8080" +proxy_username = "proxy_user" +proxy_password = "proxy_pass" +``` + +#### Load Balancer + +```toml +# Configuration load balancer +[load_balancer] +enable_lb = false +lb_algorithm = "round_robin" +health_check_interval = 30 +health_check_timeout = 5 +``` + +## 📊 Configuration de Performance + +### Optimisations Système + +#### Configuration Mémoire + +```toml +# Configuration mémoire +[performance] +max_memory_mb = 512 +memory_pool_size = 256 +gc_interval = 300 +``` + +#### Configuration CPU + +```toml +# Configuration CPU +[performance] +worker_threads = 4 +max_concurrent_requests = 100 +request_timeout = 30 +``` + +### Configuration Cache + +#### Cache en Mémoire + +```toml +# Configuration cache +[cache] +enable_cache = true +cache_size_mb = 100 +cache_ttl_seconds = 3600 +cache_eviction_policy = "lru" +``` + +#### Cache Redis (Optionnel) + +```toml +# Configuration Redis +[redis] +enable_redis = false +redis_url = "redis://localhost:6379" +redis_password = "your_redis_password" +redis_db = 0 +``` + +## 🔧 Configuration Docker + +### Dockerfile + +```dockerfile +# Dockerfile pour sdk_relay +FROM rust:1.70-slim as builder + +WORKDIR /app +COPY . . +RUN cargo build --release + +FROM debian:bullseye-slim +RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/* +COPY --from=builder /app/target/release/sdk_relay /usr/local/bin/sdk_relay + +EXPOSE 8090 8091 +CMD ["sdk_relay", "--config", "/app/.conf"] +``` + +### Docker Compose + +```yaml +# docker-compose.yml +version: '3.8' + +services: + sdk_relay: + build: . + ports: + - "8090:8090" + - "8091:8091" + volumes: + - ./config:/app/config + - ./logs:/app/logs + environment: + - RUST_LOG=info + - RUST_BACKTRACE=1 + depends_on: + - bitcoin + - blindbit + restart: unless-stopped + + bitcoin: + image: bitcoin-core:24.0 + ports: + - "18443:18443" + volumes: + - bitcoin_data:/bitcoin/.bitcoin + command: ["bitcoind", "-signet", "-rpcuser=user", "-rpcpassword=pass"] + + blindbit: + image: blindbit:latest + ports: + - "8000:8000" + environment: + - API_KEY=your_api_key + depends_on: + - bitcoin + +volumes: + bitcoin_data: +``` + +## 📈 Configuration Monitoring + +### Métriques et Alertes + +#### Configuration Prometheus + +```toml +# Configuration métriques +[metrics] +enable_metrics = true +metrics_port = 9090 +metrics_path = "/metrics" +``` + +#### Configuration Alertes + +```toml +# Configuration alertes +[alerts] +enable_alerts = true +alert_webhook = "https://hooks.slack.com/your-webhook" +alert_email = "admin@example.com" +``` + +### Configuration Logs + +#### Rotation des Logs + +```toml +# Configuration logs +[logging] +log_file = "/var/log/sdk_relay.log" +log_level = "info" +log_rotation = "daily" +log_max_size_mb = 100 +log_max_files = 7 +``` + +#### Configuration Syslog + +```toml +# Configuration syslog +[logging] +enable_syslog = true +syslog_facility = "daemon" +syslog_tag = "sdk_relay" +``` + +## 🧪 Configuration Tests + +### Tests Unitaires + +```toml +# Configuration tests +[testing] +test_timeout = 30 +test_parallel = true +test_coverage = true +``` + +### Tests d'Intégration + +```toml +# Configuration tests d'intégration +[integration_tests] +bitcoin_testnet = true +blindbit_mock = true +test_database = "test.db" +``` + +## 🚨 Configuration Dépannage + +### Debug et Profiling + +```toml +# Configuration debug +[debug] +enable_debug = false +debug_port = 6060 +debug_path = "/debug" +profile_cpu = false +profile_memory = false +``` + +### Configuration Logs Détaillés + +```bash +# Variables d'environnement pour debug +export RUST_LOG=debug +export RUST_BACKTRACE=1 +export RUST_LOG_STYLE=always + +# Logs spécifiques +export RUST_LOG=sdk_relay::websocket=debug +export RUST_LOG=sdk_relay::bitcoin=debug +export RUST_LOG=sdk_relay::blindbit=debug +``` + +## 📋 Checklist de Configuration + +### Vérifications Pré-Déploiement + +- [ ] Bitcoin Core configuré et synchronisé +- [ ] Blindbit configuré et accessible +- [ ] Certificats TLS générés (si nécessaire) +- [ ] Pare-feu configuré +- [ ] Variables d'environnement définies +- [ ] Fichier de configuration validé +- [ ] Tests de connectivité effectués +- [ ] Métriques configurées +- [ ] Logs configurés +- [ ] Sauvegarde configurée + +### Vérifications Post-Déploiement + +- [ ] Service démarre correctement +- [ ] Endpoints HTTP accessibles +- [ ] WebSocket fonctionnel +- [ ] Connexion Bitcoin Core établie +- [ ] Connexion Blindbit établie +- [ ] Métriques collectées +- [ ] Logs générés +- [ ] Performance acceptable +- [ ] Sécurité validée + +--- + +**⚙️ Configuration sdk_relay - Optimisée pour vos besoins !** 🚀 diff --git a/docs/INDEX.md b/docs/INDEX.md index da9d060..0017eca 100644 --- a/docs/INDEX.md +++ b/docs/INDEX.md @@ -1,30 +1,307 @@ -# Documentation - sdk_relay +# 📚 Index de Documentation - sdk_relay -## Guides -- [Architecture](ARCHITECTURE.md) - Architecture technique détaillée -- [API](API.md) - Référence complète des APIs WebSocket et HTTP -- [Installation](INSTALLATION.md) - Installation et vérifications -- [Utilisation](USAGE.md) - Guide d'utilisation -- [Configuration](CONFIGURATION.md) - Paramètres et env vars -- [Développement](DEVELOPMENT.md) - Environnement développeur -- [Tests](TESTING.md) - Stratégie et commandes -- [Performance](PERFORMANCE.md) - Objectifs et mesures -- [Dépannage](TROUBLESHOOTING.md) - Problèmes courants -- [Open Source Checklist](OPEN_SOURCE_CHECKLIST.md) - Préparation open source -- [Gitea Setup](GITEA_SETUP.md) - CI/TEMPLATES Gitea -- [Plan de Release](RELEASE_PLAN.md) - Processus de release -- [Roadmap](ROADMAP.md) - Évolution -- [Audit de Sécurité](SECURITY_AUDIT.md) - Contrôles et recommandations -- [Contribution](../CONTRIBUTING.md) - Guide de contribution -- [Sécurité](../SECURITY.md) - Politique de sécurité -- [Changelog](../CHANGELOG.md) - Historique des versions +Index complet de la documentation du service de relais sdk_relay pour les Silent Payments. -## Tests -- Exécuter: `cargo test --all` -- Lint: `cargo clippy -- -D warnings` -- Format: `cargo fmt -- --check` +## 📖 Guides Principaux -## Développement -- Build: `cargo build --release` -- Run: `cargo run -- --config .conf` -- Docker: `docker build -f Dockerfile .` +### 🚀 [Guide d'Installation](INSTALLATION.md) +Guide complet pour installer et configurer le service sdk_relay. +- **Prérequis système et logiciels** +- **Installation Docker et Rust** +- **Configuration Bitcoin Core et Blindbit** +- **Tests post-installation** +- **Dépannage et monitoring** + +### 📖 [Guide d'Utilisation](USAGE.md) +Guide complet pour utiliser le service sdk_relay au quotidien. +- **Démarrage du service** +- **Connexion WebSocket et HTTP** +- **Gestion des relais et synchronisation** +- **Monitoring et métriques** +- **Tests et validation** + +### ⚙️ [Guide de Configuration](CONFIGURATION.md) +Guide complet pour configurer le service selon vos besoins. +- **Configuration générale et variables d'environnement** +- **Configuration Bitcoin Core RPC** +- **Configuration Blindbit Oracle** +- **Configuration réseau et sécurité** +- **Configuration Docker et production** + +## 🔧 Guides Techniques + +### 🏗️ [Architecture Technique](ARCHITECTURE.md) +Documentation technique détaillée de l'architecture. +- **Architecture générale du service** +- **Composants principaux (WebSocket, HTTP, RPC)** +- **Architecture de synchronisation mesh** +- **Flux de données entre services** +- **Sécurité et isolation** +- **Performance et optimisations** +- **Monitoring et observabilité** + +### 📡 [API Reference](API.md) +Documentation complète des APIs disponibles. +- **API WebSocket** : Interface temps réel pour les clients +- **API HTTP REST** : API REST pour les opérations de gestion +- **API Bitcoin Core RPC** : Interface JSON-RPC pour Bitcoin +- **Format des messages et payloads** +- **Gestion des erreurs** +- **Exemples d'utilisation** +- **Limites et quotas** + +### 🔒 [Sécurité](SECURITY.md) +Guide de sécurité et bonnes pratiques. +- **Authentification et autorisation** +- **Chiffrement et certificats** +- **Isolation réseau** +- **Audit et monitoring de sécurité** +- **Bonnes pratiques** + +### 🐙 [Configuration Gitea](GITEA_SETUP.md) +Guide de configuration spécifique pour Gitea. +- **Configuration du repository Gitea** +- **Templates d'issues et pull requests** +- **Configuration CI/CD avec Gitea Actions** +- **Intégrations et webhooks** +- **Workflow de contribution** +- **Sécurité et permissions** + +### 🚀 [Plan de Release](RELEASE_PLAN.md) +Plan de lancement open source complet. +- **Phases de préparation** +- **Communication et marketing** +- **Checklist de lancement** +- **Support communautaire** +- **Gestion des risques** + +### 🌟 [Guide de la Communauté](COMMUNITY_GUIDE.md) +Guide complet pour la communauté. +- **Comment contribuer** +- **Ressources d'apprentissage** +- **Environnement de développement** +- **Processus de contribution** +- **Support et reconnaissance** + +### 🗺️ [Roadmap](ROADMAP.md) +Roadmap de développement détaillée. +- **Timeline de développement** +- **Fonctionnalités planifiées** +- **Évolution de l'architecture** +- **Métriques de succès** + +## 🧪 Guides de Test + +### 🧪 [Guide des Tests](TESTING.md) +Guide complet pour les tests du service. +- **Tests unitaires Rust** +- **Tests d'intégration** +- **Tests de performance** +- **Tests de sécurité** +- **Tests de charge** +- **Tests de régression** + +### 🔍 [Audit de Sécurité](SECURITY_AUDIT.md) +Audit de sécurité détaillé. +- **Vulnérabilités connues** +- **Tests de pénétration** +- **Audit de code** +- **Recommandations de sécurité** +- **Plan de remédiation** + +## 🔧 Guides de Développement + +### 🔧 [Guide de Développement](DEVELOPMENT.md) +Guide complet pour le développement. +- **Environnement de développement** +- **Workflow de développement** +- **Standards de code** +- **Debugging et profiling** +- **Optimisation des performances** +- **Déploiement et CI/CD** + +### 📋 [Référence Rapide](QUICK_REFERENCE.md) +Référence rapide pour les développeurs. +- **Commandes essentielles** +- **Structure du projet** +- **APIs principales** +- **Configuration rapide** +- **Dépannage rapide** + +### 🔄 [Guide de Migration](MIGRATION.md) +Guide pour les migrations et mises à jour. +- **Migration des versions** +- **Breaking changes** +- **Mise à jour des dépendances** +- **Migration des données** +- **Tests de migration** + +## 🌐 Guides d'Intégration + +### 🔗 [Intégration 4NK_node](INTEGRATION_4NK_NODE.md) +Guide d'intégration avec l'infrastructure 4NK_node. +- **Configuration Docker Compose** +- **Variables d'environnement** +- **Communication inter-services** +- **Déploiement intégré** +- **Monitoring et logs** + +### 🔑 [Configuration SSH](SSH_SETUP.md) +Guide de configuration SSH pour le développement. +- **Génération des clés SSH** +- **Configuration Git** +- **Intégration avec Gitea** +- **Automatisation des déploiements** + +### 🤖 [Push SSH Automatisé](AUTO_SSH_PUSH.md) +Guide pour l'automatisation des pushes SSH. +- **Configuration des scripts** +- **Intégration CI/CD** +- **Gestion des clés** +- **Sécurité et bonnes pratiques** + +## 📊 État et Monitoring + +### 📊 [État Actuel](ETAT_ACTUEL.md) +État détaillé du projet sdk_relay. +- **Statut des compilations** +- **Configuration des branches** +- **Fonctionnalités opérationnelles** +- **Métriques de performance** +- **Problèmes connus** + +### 📋 [Résumé Final](RESUME_FINAL.md) +Résumé complet de l'état final du projet. +- **Succès accomplis** +- **Prêt pour la production** +- **Documentation complète** +- **Support et maintenance** + +## 🔧 Guides d'Open Source + +### ✅ [Checklist Open Source](OPEN_SOURCE_CHECKLIST.md) +Checklist complète pour l'ouverture en open source. +- **Préparation du code** +- **Documentation** +- **Licences et légal** +- **Infrastructure** +- **Communication** + +## 📞 Support et Contact + +### 📞 [Support](SUPPORT.md) +Guide de support et contact. +- **Comment obtenir de l'aide** +- **Création d'issues** +- **Canal de communication** +- **FAQ** +- **Ressources additionnelles** + +## 🚨 Dépannage + +### 🔧 [Guide de Dépannage](TROUBLESHOOTING.md) +Guide complet pour résoudre les problèmes. +- **Problèmes courants** +- **Diagnostic et logs** +- **Solutions étape par étape** +- **Contact support** + +## 📈 Performance + +### ⚡ [Guide de Performance](PERFORMANCE.md) +Guide pour optimiser les performances. +- **Métriques de performance** +- **Optimisations** +- **Benchmarks** +- **Monitoring** + +## 📚 Exemples et Cas d'Usage + +### 💡 [Exemples Pratiques](EXEMPLES_PRATIQUES.md) +Exemples concrets d'utilisation. +- **Cas d'usage typiques** +- **Exemples de code** +- **Intégrations** +- **Bonnes pratiques** + +--- + +## 🎯 Navigation Rapide + +### 🚀 Démarrage Rapide +1. [Installation](INSTALLATION.md) - Installer sdk_relay +2. [Configuration](CONFIGURATION.md) - Configurer l'environnement +3. [Utilisation](USAGE.md) - Utiliser le service + +### 🔧 Développement +1. [Architecture](ARCHITECTURE.md) - Comprendre l'architecture +2. [API](API.md) - Consulter les APIs +3. [Tests](TESTING.md) - Exécuter les tests + +### 📚 Documentation +1. [Index](INDEX.md) - Cet index +2. [Quick Reference](QUICK_REFERENCE.md) - Référence rapide +3. [Roadmap](ROADMAP.md) - Évolution du projet + +### 🤝 Communauté +1. [Guide Communauté](COMMUNITY_GUIDE.md) - Contribuer +2. [Code de Conduite](../CODE_OF_CONDUCT.md) - Règles de conduite +3. [Support](SUPPORT.md) - Obtenir de l'aide + +--- + +## 🧪 Tests et Validation + +### Tests Automatisés +```bash +# Tests unitaires +cargo test --all + +# Tests d'intégration +cargo test --test integration + +# Tests de performance +cargo test --test performance + +# Linting +cargo clippy -- -D warnings + +# Formatage +cargo fmt -- --check +``` + +### Tests Manuels +```bash +# Vérification de santé +curl http://localhost:8091/health + +# Test WebSocket +wscat -c ws://localhost:8090 + +# Test métriques +curl http://localhost:8091/metrics +``` + +--- + +## 🚀 Développement + +### Commandes Essentielles +```bash +# Build de développement +cargo build + +# Build de production +cargo build --release + +# Exécution +cargo run -- --config .conf + +# Docker +docker build -f Dockerfile . +docker run -p 8090:8090 -p 8091:8091 sdk_relay +``` + +--- + +**📚 Documentation complète pour sdk_relay - Service de relais pour les Silent Payments** 🚀 diff --git a/docs/INSTALLATION.md b/docs/INSTALLATION.md index 79a6635..0cc0848 100644 --- a/docs/INSTALLATION.md +++ b/docs/INSTALLATION.md @@ -1,25 +1,478 @@ -# Installation - sdk_relay +# 📦 Guide d'Installation - sdk_relay -## Prérequis +Guide complet pour installer et configurer le service de relais sdk_relay pour les Silent Payments. -- Docker 24+ ou Rust 1.70+ -- Bitcoin Core (signet) accessible via RPC -- Blindbit (oracle) accessible via HTTP +## 📋 Prérequis -## Méthodes d'installation +### Système -### Docker (recommandé) -- Construire l'image locale puis exécuter le conteneur -- Exposer les ports 8090 (WebSocket) et 8091 (HTTP) -- Fournir la configuration via fichier `.conf` ou variables d'environnement +- **OS** : Linux (Ubuntu 20.04+, Debian 11+, CentOS 8+), macOS 10.15+ +- **Architecture** : x86_64, ARM64 (Apple Silicon) +- **RAM** : 2 Go minimum, 4 Go recommandés +- **Stockage** : 5 Go minimum, 10 Go recommandés +- **Réseau** : Connexion Internet stable -### Binaire Rust -- Compiler en profil release -- Lancer avec un fichier `.conf` +### Logiciels -## Vérifications post-installation +- **Docker** : Version 20.10+ (recommandé) +- **Rust** : Version 1.70+ (pour compilation native) +- **Git** : Version 2.25+ +- **Bitcoin Core** : Version 24.0+ (signet ou mainnet) +- **Blindbit** : Oracle accessible via HTTP -- Endpoint `HTTP /health` répond avec `status=healthy` -- Port WebSocket en écoute sur 8090 -- Connexion RPC à Bitcoin Core opérationnelle -- Accès au service Blindbit opérationnel +## 🚀 Installation + +### 1. Installation de Docker (Recommandé) + +#### Ubuntu/Debian + +```bash +# Mettre à jour les paquets +sudo apt update + +# Installer les dépendances +sudo apt install -y apt-transport-https ca-certificates curl gnupg lsb-release + +# Ajouter la clé GPG Docker +curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg + +# Ajouter le repository Docker +echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null + +# Installer Docker +sudo apt update +sudo apt install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin + +# Ajouter l'utilisateur au groupe docker +sudo usermod -aG docker $USER + +# Démarrer Docker +sudo systemctl start docker +sudo systemctl enable docker +``` + +#### CentOS/RHEL + +```bash +# Installer les dépendances +sudo yum install -y yum-utils + +# Ajouter le repository Docker +sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo + +# Installer Docker +sudo yum install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin + +# Démarrer Docker +sudo systemctl start docker +sudo systemctl enable docker + +# Ajouter l'utilisateur au groupe docker +sudo usermod -aG docker $USER +``` + +#### macOS + +```bash +# Installer via Homebrew +brew install --cask docker + +# Ou télécharger Docker Desktop depuis +# https://www.docker.com/products/docker-desktop +``` + +### 2. Installation de Rust (Optionnel - pour compilation native) + +#### Linux/macOS + +```bash +# Installer Rust via rustup +curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh + +# Recharger l'environnement +source ~/.cargo/env + +# Vérifier l'installation +rustc --version +cargo --version +``` + +#### Windows + +```bash +# Télécharger et installer rustup depuis +# https://rustup.rs/ +``` + +### 3. Configuration SSH (Recommandé) + +```bash +# Générer une clé SSH +ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519_sdk -C "sdk-relay-automation" + +# Ajouter à l'agent SSH +ssh-add ~/.ssh/id_ed25519_sdk + +# Configurer Git pour utiliser la clé +git config --global core.sshCommand "ssh -i ~/.ssh/id_ed25519_sdk" + +# Afficher la clé publique pour Gitea +cat ~/.ssh/id_ed25519_sdk.pub +``` + +**Ajouter la clé publique à Gitea :** +1. Aller sur Gitea > Settings > SSH Keys +2. Coller la clé publique +3. Cliquer sur "Add key" + +### 4. Clonage du Repository + +```bash +# Cloner avec SSH (recommandé) +git clone git@git.4nkweb.com:4nk/sdk_relay.git +cd sdk_relay + +# Ou cloner avec HTTPS +git clone https://git.4nkweb.com/4nk/sdk_relay.git +cd sdk_relay +``` + +## 🔧 Configuration + +### Variables d'Environnement + +Créer un fichier `.env` à la racine du projet : + +```bash +# Configuration du service +RUST_LOG=info +RUST_BACKTRACE=1 + +# Configuration Bitcoin Core +BITCOIN_RPC_HOST=localhost +BITCOIN_RPC_PORT=18443 +BITCOIN_RPC_USER=your_username +BITCOIN_RPC_PASS=your_password +BITCOIN_RPC_COOKIE_PATH=/path/to/.cookie + +# Configuration Blindbit +BLINDBIT_URL=http://localhost:8000 +BLINDBIT_API_KEY=your_api_key + +# Configuration réseau +WS_PORT=8090 +HTTP_PORT=8091 +HOST=0.0.0.0 + +# Configuration de sécurité +ENABLE_TLS=false +CERT_PATH=/path/to/cert.pem +KEY_PATH=/path/to/key.pem +``` + +### Configuration Bitcoin Core + +#### Installation Bitcoin Core + +```bash +# Ubuntu/Debian +sudo apt update +sudo apt install -y bitcoin-core + +# Ou télécharger depuis bitcoin.org +wget https://bitcoin.org/bin/bitcoin-core-24.0.1/bitcoin-24.0.1-x86_64-linux-gnu.tar.gz +tar -xzf bitcoin-24.0.1-x86_64-linux-gnu.tar.gz +sudo cp bitcoin-24.0.1/bin/* /usr/local/bin/ +``` + +#### Configuration Bitcoin Core + +Créer le fichier `~/.bitcoin/bitcoin.conf` : + +```ini +# Configuration réseau +network=signet +rpcuser=your_username +rpcpassword=your_password +rpcallowip=127.0.0.1 +rpcbind=127.0.0.1:18443 + +# Configuration de sécurité +rpcssl=false +server=1 +txindex=1 + +# Configuration de performance +dbcache=450 +maxorphantx=10 +maxmempool=50 +mempoolexpiry=72 +``` + +### Configuration Blindbit + +#### Installation Blindbit + +```bash +# Cloner le repository Blindbit +git clone https://github.com/4nk/blindbit.git +cd blindbit + +# Installer les dépendances +pip install -r requirements.txt + +# Configurer l'oracle +cp config.example.json config.json +# Éditer config.json avec vos paramètres +``` + +#### Configuration Blindbit + +```json +{ + "port": 8000, + "host": "0.0.0.0", + "api_key": "your_api_key", + "bitcoin_rpc": { + "host": "localhost", + "port": 18443, + "user": "your_username", + "password": "your_password" + } +} +``` + +## 🧪 Tests Post-Installation + +### 1. Test de Compilation + +#### Docker + +```bash +# Build de l'image Docker +docker build -f Dockerfile -t sdk_relay . + +# Vérifier que l'image a été créée +docker images | grep sdk_relay +``` + +#### Rust (Compilation native) + +```bash +# Test de compilation +cargo build --release + +# Vérifier le binaire +ls -la target/release/sdk_relay +``` + +### 2. Test de Configuration + +```bash +# Vérifier la configuration +cargo run -- --config .conf --check + +# Ou avec Docker +docker run --rm sdk_relay --config .conf --check +``` + +### 3. Test de Connexion + +#### Test Bitcoin Core + +```bash +# Test RPC Bitcoin Core +curl -u your_username:your_password \ + -d '{"jsonrpc": "1.0", "id": "test", "method": "getblockchaininfo", "params": []}' \ + -H 'content-type: text/plain;' \ + http://localhost:18443/ +``` + +#### Test Blindbit + +```bash +# Test API Blindbit +curl -H "Authorization: Bearer your_api_key" \ + http://localhost:8000/health +``` + +### 4. Test du Service + +#### Démarrage du Service + +```bash +# Avec Docker +docker run -d \ + --name sdk_relay \ + -p 8090:8090 \ + -p 8091:8091 \ + -v $(pwd)/.conf:/app/.conf \ + sdk_relay + +# Avec Rust +cargo run --release -- --config .conf +``` + +#### Tests de Connectivité + +```bash +# Test HTTP Health +curl http://localhost:8091/health + +# Test WebSocket +wscat -c ws://localhost:8090 + +# Test métriques +curl http://localhost:8091/metrics +``` + +## 🚨 Dépannage + +### Problèmes Courants + +#### Docker non trouvé +```bash +# Vérifier l'installation +which docker +docker --version + +# Réinstaller si nécessaire +curl -fsSL https://get.docker.com | sh +sudo usermod -aG docker $USER +``` + +#### Rust non trouvé +```bash +# Vérifier l'installation +which rustc +rustc --version + +# Réinstaller si nécessaire +curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh +source ~/.cargo/env +``` + +#### Erreurs de compilation +```bash +# Nettoyer et recompiler +cargo clean +cargo build --release + +# Vérifier les dépendances +cargo update +cargo check +``` + +#### Erreurs de connexion Bitcoin Core +```bash +# Vérifier que Bitcoin Core est démarré +bitcoind -daemon + +# Vérifier les logs +tail -f ~/.bitcoin/signet/debug.log + +# Tester la connexion RPC +bitcoin-cli -signet getblockchaininfo +``` + +#### Erreurs de connexion Blindbit +```bash +# Vérifier que Blindbit est démarré +cd blindbit +python main.py + +# Vérifier les logs +tail -f blindbit.log + +# Tester l'API +curl http://localhost:8000/health +``` + +### Logs Détaillés + +```bash +# Logs Docker +docker logs sdk_relay + +# Logs Rust +RUST_LOG=debug cargo run -- --config .conf + +# Logs Bitcoin Core +tail -f ~/.bitcoin/signet/debug.log + +# Logs Blindbit +tail -f blindbit.log +``` + +## 🔒 Sécurité + +### Vérifications de Sécurité + +```bash +# Audit des dépendances Rust +cargo audit + +# Vérification des vulnérabilités Docker +docker scan sdk_relay + +# Test de sécurité réseau +nmap -p 8090,8091 localhost +``` + +### Bonnes Pratiques + +- Utiliser HTTPS en production +- Configurer des pare-feu appropriés +- Maintenir les dépendances à jour +- Utiliser des variables d'environnement pour les secrets +- Tester régulièrement la sécurité + +## 📊 Monitoring + +### Métriques d'Installation + +```bash +# Taille du projet +du -sh . + +# Nombre de fichiers +find . -type f | wc -l + +# Dépendances Rust +cargo tree | wc -l + +# Taille du binaire +ls -lh target/release/sdk_relay +``` + +### Vérification de l'Installation + +```bash +# Script de vérification +./scripts/verify-installation.sh + +# Tests automatisés +cargo test --all +``` + +## 🎯 Prochaines Étapes + +Après l'installation réussie : + +1. **Lire le [Guide d'Utilisation](USAGE.md)** - Utiliser le service +2. **Consulter l'[Architecture](ARCHITECTURE.md)** - Comprendre le système +3. **Explorer les [APIs](API.md)** - Utiliser les fonctionnalités +4. **Configurer l'[Intégration 4NK_node](INTEGRATION_4NK_NODE.md)** - Déployer en production + +## 📞 Support + +En cas de problème : + +1. Consulter la [documentation](INDEX.md) +2. Vérifier les [issues existantes](https://git.4nkweb.com/4nk/sdk_relay/issues) +3. Créer une nouvelle issue avec les détails du problème +4. Inclure les logs et la configuration utilisée + +--- + +**🚀 Installation terminée ! sdk_relay est prêt à être utilisé.** ✨ diff --git a/docs/USAGE.md b/docs/USAGE.md index fb99512..75e5b22 100644 --- a/docs/USAGE.md +++ b/docs/USAGE.md @@ -1,26 +1,710 @@ -# Utilisation - sdk_relay +# 📖 Guide d'Utilisation - sdk_relay -## Démarrage rapide +Guide complet pour utiliser le service de relais sdk_relay au quotidien. -- Démarrer le service (Docker ou binaire) -- Vérifier `GET /health` -- Connecter un client WebSocket à `ws://host:8090` +## 🚀 Démarrage Rapide -## WebSocket +### Démarrage du Service -- Envoyer un handshake JSON avec `type=handshake` -- Recevoir `handshake_response` -- S'abonner aux notifications si nécessaire (`subscribe`) +#### Avec Docker (Recommandé) -## HTTP +```bash +# Build de l'image +docker build -f Dockerfile -t sdk_relay . -- `GET /health` : santé -- `GET /metrics` : métriques -- `GET /relays` : relais connus -- `POST /sync/force` : forcer une synchronisation +# Démarrage du service +docker run -d \ + --name sdk_relay \ + -p 8090:8090 \ + -p 8091:8091 \ + -v $(pwd)/.conf:/app/.conf \ + -e RUST_LOG=info \ + sdk_relay -## Bonnes pratiques +# Vérifier le statut +docker ps | grep sdk_relay +``` -- Reconnexion automatique côté client -- Heartbeat régulier (ping/pong) -- Limiter la taille des messages (< 1MB) +#### Avec Rust (Compilation native) + +```bash +# Compilation release +cargo build --release + +# Démarrage du service +cargo run --release -- --config .conf + +# Ou en arrière-plan +nohup cargo run --release -- --config .conf > sdk_relay.log 2>&1 & +``` + +### Vérification du Démarrage + +```bash +# Test de santé HTTP +curl http://localhost:8091/health + +# Réponse attendue +{ + "status": "healthy", + "timestamp": "2024-01-01T12:00:00Z", + "version": "1.0.0" +} + +# Test WebSocket +wscat -c ws://localhost:8090 + +# Test métriques +curl http://localhost:8091/metrics +``` + +## 🔌 Connexion WebSocket + +### Handshake Initial + +#### Envoi du Handshake + +```json +{ + "type": "handshake", + "version": "1.0", + "client_id": "my_client_001", + "capabilities": ["silent_payments", "relay_sync"] +} +``` + +#### Réponse du Handshake + +```json +{ + "type": "handshake_response", + "status": "success", + "server_version": "1.0.0", + "capabilities": ["silent_payments", "relay_sync", "metrics"], + "session_id": "session_12345" +} +``` + +### Gestion des Sessions + +#### Reconnexion Automatique + +```javascript +// Exemple JavaScript +const ws = new WebSocket('ws://localhost:8090'); + +ws.onopen = function() { + // Envoyer handshake + ws.send(JSON.stringify({ + type: "handshake", + version: "1.0", + client_id: "my_client_001" + })); +}; + +ws.onclose = function() { + // Reconnexion automatique après 5 secondes + setTimeout(() => { + connectWebSocket(); + }, 5000); +}; +``` + +#### Heartbeat + +```json +// Ping toutes les 30 secondes +{ + "type": "ping", + "timestamp": "2024-01-01T12:00:00Z" +} + +// Réponse pong +{ + "type": "pong", + "timestamp": "2024-01-01T12:00:00Z" +} +``` + +## 📡 API HTTP REST + +### Endpoints de Base + +#### GET /health +```bash +curl http://localhost:8091/health +``` + +**Réponse :** +```json +{ + "status": "healthy", + "uptime": 3600, + "version": "1.0.0", + "connections": { + "websocket": 5, + "http": 2 + } +} +``` + +#### GET /metrics +```bash +curl http://localhost:8091/metrics +``` + +**Réponse :** +```json +{ + "requests_total": 1250, + "requests_per_second": 2.5, + "websocket_connections": 5, + "memory_usage_mb": 45.2, + "cpu_usage_percent": 12.5 +} +``` + +#### GET /relays +```bash +curl http://localhost:8091/relays +``` + +**Réponse :** +```json +{ + "relays": [ + { + "id": "relay_001", + "address": "ws://relay1.example.com:8090", + "status": "connected", + "last_seen": "2024-01-01T12:00:00Z" + }, + { + "id": "relay_002", + "address": "ws://relay2.example.com:8090", + "status": "disconnected", + "last_seen": "2024-01-01T11:30:00Z" + } + ] +} +``` + +### Endpoints de Gestion + +#### POST /sync/force +```bash +curl -X POST http://localhost:8091/sync/force +``` + +**Réponse :** +```json +{ + "status": "sync_started", + "relays_count": 3, + "estimated_duration": 30 +} +``` + +#### POST /relays/add +```bash +curl -X POST http://localhost:8091/relays/add \ + -H "Content-Type: application/json" \ + -d '{ + "address": "ws://newrelay.example.com:8090", + "description": "Nouveau relais" + }' +``` + +#### DELETE /relays/{id} +```bash +curl -X DELETE http://localhost:8091/relays/relay_001 +``` + +## 🔄 Synchronisation des Relais + +### Architecture Mesh + +#### Découverte des Relais + +```json +// Message de découverte +{ + "type": "discovery", + "relay_id": "relay_001", + "timestamp": "2024-01-01T12:00:00Z" +} + +// Réponse avec liste des relais +{ + "type": "discovery_response", + "relays": [ + { + "id": "relay_002", + "address": "ws://relay2.example.com:8090", + "capabilities": ["silent_payments"] + } + ] +} +``` + +#### Synchronisation des Messages + +```json +// Message de synchronisation +{ + "type": "sync_message", + "message_id": "msg_12345", + "content": { + "type": "silent_payment", + "data": "..." + }, + "timestamp": "2024-01-01T12:00:00Z", + "ttl": 3600 +} + +// Accusé de réception +{ + "type": "sync_ack", + "message_id": "msg_12345", + "status": "received" +} +``` + +### Gestion des Conflits + +#### Résolution de Conflits + +```json +// Détection de conflit +{ + "type": "conflict_detected", + "message_id": "msg_12345", + "conflict_type": "duplicate", + "resolution": "keep_latest" +} +``` + +## 💰 Silent Payments + +### Gestion des Paiements + +#### Création d'un Paiement + +```json +// Demande de création +{ + "type": "create_payment", + "payment_id": "pay_12345", + "amount_sats": 100000, + "recipient": "sp1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh", + "metadata": { + "description": "Paiement test" + } +} + +// Confirmation +{ + "type": "payment_created", + "payment_id": "pay_12345", + "status": "pending", + "created_at": "2024-01-01T12:00:00Z" +} +``` + +#### Suivi des Paiements + +```json +// Mise à jour de statut +{ + "type": "payment_update", + "payment_id": "pay_12345", + "status": "confirmed", + "block_height": 800000, + "txid": "abc123...", + "updated_at": "2024-01-01T12:05:00Z" +} +``` + +### Intégration Bitcoin Core + +#### Vérification des Blocs + +```json +// Notification de nouveau bloc +{ + "type": "block_notification", + "block_height": 800001, + "block_hash": "def456...", + "timestamp": "2024-01-01T12:10:00Z" +} +``` + +#### Scan des Transactions + +```json +// Demande de scan +{ + "type": "scan_request", + "addresses": [ + "sp1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh" + ], + "from_block": 800000, + "to_block": 800001 +} + +// Résultats du scan +{ + "type": "scan_response", + "results": [ + { + "address": "sp1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh", + "transactions": [ + { + "txid": "abc123...", + "amount_sats": 100000, + "block_height": 800001 + } + ] + } + ] +} +``` + +## 📊 Monitoring et Métriques + +### Métriques en Temps Réel + +#### Métriques Système + +```bash +# Métriques système +curl http://localhost:8091/metrics/system + +# Réponse +{ + "cpu_usage_percent": 12.5, + "memory_usage_mb": 45.2, + "disk_usage_percent": 25.0, + "network_io_mbps": 1.2 +} +``` + +#### Métriques Métier + +```bash +# Métriques métier +curl http://localhost:8091/metrics/business + +# Réponse +{ + "payments_processed": 1250, + "payments_confirmed": 1200, + "relays_connected": 5, + "messages_synced": 5000 +} +``` + +### Alertes et Notifications + +#### Configuration des Alertes + +```json +// Configuration d'alerte +{ + "type": "alert_config", + "alert_id": "high_cpu", + "condition": "cpu_usage > 80", + "action": "notify_admin", + "enabled": true +} +``` + +#### Notifications + +```json +// Notification d'alerte +{ + "type": "alert", + "alert_id": "high_cpu", + "severity": "warning", + "message": "CPU usage is 85%", + "timestamp": "2024-01-01T12:00:00Z" +} +``` + +## 🔧 Gestion des Erreurs + +### Types d'Erreurs + +#### Erreurs de Connexion + +```json +// Erreur de connexion WebSocket +{ + "type": "error", + "error_code": "WS_CONNECTION_FAILED", + "message": "Failed to connect to relay", + "details": { + "relay_id": "relay_001", + "attempt": 3 + } +} +``` + +#### Erreurs de Validation + +```json +// Erreur de validation +{ + "type": "error", + "error_code": "VALIDATION_ERROR", + "message": "Invalid payment amount", + "details": { + "field": "amount_sats", + "value": -100, + "expected": "positive integer" + } +} +``` + +### Gestion des Erreurs + +#### Retry Automatique + +```json +// Configuration retry +{ + "type": "retry_config", + "max_attempts": 3, + "backoff_ms": 1000, + "max_backoff_ms": 30000 +} +``` + +#### Fallback + +```json +// Stratégie de fallback +{ + "type": "fallback_config", + "primary_relay": "relay_001", + "backup_relays": ["relay_002", "relay_003"], + "failover_timeout_ms": 5000 +} +``` + +## 🛠️ Maintenance + +### Sauvegarde + +#### Sauvegarde de Configuration + +```bash +# Sauvegarde de la configuration +cp .conf .conf.backup.$(date +%Y%m%d) + +# Sauvegarde des logs +tar -czf logs_$(date +%Y%m%d).tar.gz logs/ +``` + +#### Sauvegarde des Données + +```bash +# Export des données +curl http://localhost:8091/export/data > data_export_$(date +%Y%m%d).json + +# Import des données +curl -X POST http://localhost:8091/import/data \ + -H "Content-Type: application/json" \ + -d @data_export_20240101.json +``` + +### Mise à Jour + +#### Mise à Jour du Service + +```bash +# Arrêt du service +docker stop sdk_relay + +# Pull de la nouvelle image +docker pull sdk_relay:latest + +# Redémarrage +docker run -d \ + --name sdk_relay_new \ + -p 8090:8090 \ + -p 8091:8091 \ + -v $(pwd)/.conf:/app/.conf \ + sdk_relay:latest + +# Vérification +curl http://localhost:8091/health +``` + +#### Migration des Données + +```bash +# Script de migration +./scripts/migrate_data.sh + +# Vérification post-migration +cargo test --test migration +``` + +## 🔒 Sécurité + +### Authentification + +#### Authentification par Token + +```bash +# Génération de token +curl -X POST http://localhost:8091/auth/token \ + -H "Content-Type: application/json" \ + -d '{ + "username": "admin", + "password": "secure_password" + }' + +# Utilisation du token +curl -H "Authorization: Bearer YOUR_TOKEN" \ + http://localhost:8091/admin/status +``` + +#### Authentification par Certificat + +```bash +# Connexion avec certificat client +curl --cert client.pem --key client.key \ + https://localhost:8091/secure/endpoint +``` + +### Chiffrement + +#### Chiffrement des Messages + +```json +// Message chiffré +{ + "type": "encrypted_message", + "encryption": "AES-256-GCM", + "data": "encrypted_payload_here", + "iv": "initialization_vector" +} +``` + +## 📈 Performance + +### Optimisations + +#### Pool de Connexions + +```json +// Configuration du pool +{ + "type": "pool_config", + "max_connections": 100, + "min_connections": 10, + "connection_timeout_ms": 5000 +} +``` + +#### Cache + +```json +// Configuration du cache +{ + "type": "cache_config", + "max_size_mb": 100, + "ttl_seconds": 3600, + "eviction_policy": "lru" +} +``` + +### Benchmarks + +#### Tests de Performance + +```bash +# Test de charge +ab -n 1000 -c 10 http://localhost:8091/health + +# Test WebSocket +./scripts/websocket_benchmark.sh + +# Test de synchronisation +cargo test --test performance +``` + +## 🚨 Dépannage + +### Problèmes Courants + +#### Service ne démarre pas + +```bash +# Vérifier les logs +docker logs sdk_relay + +# Vérifier la configuration +cargo run -- --config .conf --check + +# Vérifier les ports +netstat -tlnp | grep 809 +``` + +#### Connexions WebSocket échouent + +```bash +# Test de connectivité +telnet localhost 8090 + +# Vérifier le firewall +sudo ufw status + +# Test avec wscat +wscat -c ws://localhost:8090 +``` + +#### Synchronisation lente + +```bash +# Vérifier les métriques +curl http://localhost:8091/metrics + +# Vérifier les relais +curl http://localhost:8091/relays + +# Forcer une synchronisation +curl -X POST http://localhost:8091/sync/force +``` + +### Logs et Debugging + +#### Niveaux de Log + +```bash +# Log détaillé +RUST_LOG=debug cargo run -- --config .conf + +# Log spécifique +RUST_LOG=sdk_relay::websocket=debug cargo run -- --config .conf +``` + +#### Analyse des Logs + +```bash +# Logs en temps réel +tail -f logs/sdk_relay.log + +# Recherche d'erreurs +grep ERROR logs/sdk_relay.log + +# Statistiques des logs +awk '/ERROR/ {count++} END {print count}' logs/sdk_relay.log +``` + +--- + +**🎯 Service sdk_relay - Prêt pour une utilisation en production !** ✨