286 lines
6.4 KiB
Markdown
286 lines
6.4 KiB
Markdown
# Test End-to-End Agent Rust
|
|
|
|
Documentation pour tester l'agent Mesh Rust avec transferts fichiers et terminal.
|
|
|
|
## Prérequis
|
|
|
|
- **Serveur Mesh** running sur `localhost:8000` (ou autre)
|
|
- **2 agents** compilés et configurés
|
|
- **Réseau LAN** ou localhost pour les tests
|
|
|
|
## Compilation
|
|
|
|
```bash
|
|
cd agent
|
|
cargo build --release
|
|
```
|
|
|
|
Le binaire sera disponible dans `target/release/mesh-agent`.
|
|
|
|
## Configuration
|
|
|
|
Créer un fichier `~/.config/mesh/agent.toml` :
|
|
|
|
```toml
|
|
device_id = "device-123"
|
|
server_url = "http://localhost:8000"
|
|
ws_url = "ws://localhost:8000/ws"
|
|
auth_token = "your-jwt-token"
|
|
quic_port = 5000
|
|
```
|
|
|
|
## Scenario 1: Mode Daemon (Production)
|
|
|
|
### Terminal 1 - Agent A
|
|
```bash
|
|
# Lancer l'agent en mode daemon
|
|
RUST_LOG=info ./mesh-agent run
|
|
|
|
# Ou avec la commande par défaut
|
|
RUST_LOG=info ./mesh-agent
|
|
```
|
|
|
|
### Terminal 2 - Agent B
|
|
```bash
|
|
# Utiliser un port QUIC différent
|
|
# Modifier agent.toml: quic_port = 5001
|
|
RUST_LOG=info ./mesh-agent run
|
|
```
|
|
|
|
**Résultat attendu** :
|
|
- ✓ Connexion WebSocket au serveur
|
|
- ✓ P2P_HELLO/P2P_OK handshake
|
|
- ✓ QUIC endpoint listening
|
|
- ✓ Logs: "Mesh Agent started successfully"
|
|
|
|
## Scenario 2: Transfert Fichier Direct
|
|
|
|
### Étape 1: Créer un fichier test
|
|
|
|
```bash
|
|
# Créer un fichier de 1MB
|
|
dd if=/dev/urandom of=test_file.bin bs=1M count=1
|
|
|
|
# Ou un fichier texte
|
|
echo "Hello from Mesh Agent!" > test.txt
|
|
```
|
|
|
|
### Étape 2: Agent B en mode réception (daemon)
|
|
|
|
```bash
|
|
# Terminal 1
|
|
RUST_LOG=info ./mesh-agent run
|
|
```
|
|
|
|
### Étape 3: Agent A envoie le fichier
|
|
|
|
```bash
|
|
# Terminal 2
|
|
RUST_LOG=info ./mesh-agent send-file \
|
|
--session-id "session_abc123" \
|
|
--peer-addr "192.168.1.100:5001" \
|
|
--token "token_xyz" \
|
|
--file test_file.bin
|
|
```
|
|
|
|
**Résultat attendu** :
|
|
- Agent A logs :
|
|
```
|
|
Connecting to peer...
|
|
P2P connection established
|
|
Sending file...
|
|
✓ File sent successfully!
|
|
Size: 1.00 MB
|
|
Duration: 0.25s
|
|
Speed: 4.00 MB/s
|
|
```
|
|
|
|
- Agent B logs :
|
|
```
|
|
Incoming QUIC connection from 192.168.1.50
|
|
P2P_HELLO received: session_id=session_abc123
|
|
P2P handshake successful
|
|
Receiving file: test_file.bin (1048576 bytes)
|
|
File received successfully: test_file.bin (1048576 bytes)
|
|
```
|
|
|
|
- **Hash vérification** : Blake3 hash identique
|
|
|
|
### Étape 4: Vérifier l'intégrité
|
|
|
|
```bash
|
|
# Sur Agent B (récepteur)
|
|
blake3sum received_file.bin
|
|
|
|
# Comparer avec Agent A (envoyeur)
|
|
blake3sum test_file.bin
|
|
```
|
|
|
|
Les hash doivent être **identiques**.
|
|
|
|
## Scenario 3: Terminal Sharing
|
|
|
|
### Étape 1: Agent B en mode réception
|
|
|
|
```bash
|
|
# Terminal 1
|
|
RUST_LOG=info ./mesh-agent run
|
|
```
|
|
|
|
### Étape 2: Agent A partage son terminal
|
|
|
|
```bash
|
|
# Terminal 2
|
|
RUST_LOG=info ./mesh-agent share-terminal \
|
|
--session-id "terminal_session_456" \
|
|
--peer-addr "192.168.1.100:5001" \
|
|
--token "token_terminal" \
|
|
--cols 120 \
|
|
--rows 30
|
|
```
|
|
|
|
**Résultat attendu** :
|
|
- Agent A logs :
|
|
```
|
|
Connecting to peer...
|
|
P2P connection established
|
|
Starting terminal session...
|
|
PTY created: 120x30, shell: /bin/bash
|
|
Press Ctrl+C to stop sharing
|
|
```
|
|
|
|
- Agent B logs :
|
|
```
|
|
Incoming QUIC connection from 192.168.1.50
|
|
Accepting bidirectional stream for terminal output
|
|
Terminal output: $ ls -la
|
|
Terminal output: drwxr-xr-x ...
|
|
```
|
|
|
|
- **Ctrl+C** sur Agent A arrête le partage
|
|
|
|
## Scenario 4: Test LAN avec 2 machines physiques
|
|
|
|
### Machine A (192.168.1.50)
|
|
|
|
```bash
|
|
# Configurer agent.toml
|
|
device_id = "laptop-alice"
|
|
quic_port = 5000
|
|
|
|
# Lancer daemon
|
|
./mesh-agent run
|
|
```
|
|
|
|
### Machine B (192.168.1.100)
|
|
|
|
```bash
|
|
# Configurer agent.toml
|
|
device_id = "desktop-bob"
|
|
quic_port = 5000
|
|
|
|
# Envoyer fichier vers Alice
|
|
./mesh-agent send-file \
|
|
--session-id "session_lan_test" \
|
|
--peer-addr "192.168.1.50:5000" \
|
|
--token "token_from_server" \
|
|
--file /path/to/large_file.zip
|
|
```
|
|
|
|
**Firewall** : Ouvrir port UDP 5000 sur les deux machines.
|
|
|
|
## Debugging
|
|
|
|
### Activer les logs détaillés
|
|
|
|
```bash
|
|
# Niveau DEBUG
|
|
RUST_LOG=debug ./mesh-agent run
|
|
|
|
# Niveau TRACE (très verbeux)
|
|
RUST_LOG=trace ./mesh-agent run
|
|
|
|
# Filtrer par module
|
|
RUST_LOG=mesh_agent::p2p=debug ./mesh-agent run
|
|
```
|
|
|
|
### Vérifier les stats QUIC
|
|
|
|
Les logs montreront automatiquement :
|
|
- RTT (Round Trip Time)
|
|
- Congestion window
|
|
- Bytes sent/received
|
|
- Lost packets
|
|
|
|
### Tester la connectivité QUIC
|
|
|
|
```bash
|
|
# Sur Agent B
|
|
sudo tcpdump -i any udp port 5000
|
|
|
|
# Sur Agent A, envoyer fichier
|
|
# Observer les paquets QUIC dans tcpdump
|
|
```
|
|
|
|
## Checklist de Validation MVP
|
|
|
|
- [ ] **Compilation** : `cargo build --release` sans erreurs
|
|
- [ ] **Tests** : `cargo test` passe tous les tests
|
|
- [ ] **Daemon** : Agent se connecte au serveur WebSocket
|
|
- [ ] **QUIC Endpoint** : Accepte connexions entrantes
|
|
- [ ] **P2P Handshake** : P2P_HELLO/P2P_OK fonctionne
|
|
- [ ] **File Transfer** : Fichier 1MB transféré avec succès
|
|
- [ ] **Hash Verification** : Blake3 hash identique
|
|
- [ ] **Terminal Sharing** : Output streaming fonctionne
|
|
- [ ] **CLI** : `--help` affiche toutes les commandes
|
|
- [ ] **Logs** : Pas de secrets (tokens, passwords) dans les logs
|
|
- [ ] **Performance** : Transfert >1MB/s sur LAN
|
|
|
|
## Troubleshooting
|
|
|
|
### Erreur: "Connection refused"
|
|
|
|
- Vérifier que le serveur Mesh est running
|
|
- Vérifier `server_url` et `ws_url` dans `agent.toml`
|
|
- Vérifier firewall/iptables
|
|
|
|
### Erreur: "Token validation failed"
|
|
|
|
- Le session_token est expiré (TTL: 60-180s)
|
|
- Demander un nouveau token au serveur
|
|
- Vérifier l'horloge système (NTP)
|
|
|
|
### Erreur: "No route to host" (QUIC)
|
|
|
|
- Vérifier firewall UDP sur le port QUIC
|
|
- Tester avec `nc -u <ip> <port>`
|
|
- Vérifier que les deux agents sont sur le même réseau
|
|
|
|
### Performances lentes
|
|
|
|
- Vérifier MTU réseau (`ip link show`)
|
|
- Augmenter la congestion window si nécessaire
|
|
- Tester avec fichiers plus petits d'abord
|
|
|
|
## Métriques de Performance Attendues
|
|
|
|
| Taille Fichier | Réseau | Vitesse Attendue |
|
|
|----------------|--------------|------------------|
|
|
| 1 MB | Localhost | > 100 MB/s |
|
|
| 1 MB | LAN Gigabit | > 50 MB/s |
|
|
| 100 MB | LAN Gigabit | > 100 MB/s |
|
|
| 1 GB | LAN Gigabit | > 200 MB/s |
|
|
|
|
## Notes de Sécurité
|
|
|
|
- **Trust via session_token** : Le certificat TLS est auto-signé, le trust est établi via le session_token du serveur
|
|
- **Tokens éphémères** : TTL court (60-180s) pour limiter la fenêtre d'attaque
|
|
- **Terminal read-only par défaut** : Input nécessite capability `has_control`
|
|
- **Pas de secrets en logs** : Les tokens ne sont jamais loggés en clair
|
|
|
|
## Support
|
|
|
|
Pour reporter des bugs ou demander de l'aide :
|
|
- GitHub Issues : https://github.com/mesh-team/mesh/issues
|
|
- Documentation : docs/AGENT.md
|