- Especificación completa del protocolo (PROTOCOL.md) - Referencia de API (API.md) - Implementación crypto: SHA256, ChaCha20-Poly1305 - Device ID con Base32 y verificación Luhn32 - Framing de mensajes (HELLO, PING, DATA, etc.) - Discovery local UDP broadcast - Estructura de conexiones y estados - Build system para Zig 0.15.2 Pendiente: TLS 1.3, STUN, Global Discovery HTTPS, Relay 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
87 lines
4.4 KiB
Markdown
87 lines
4.4 KiB
Markdown
# zcatp2p - Protocolo P2P para comunicación directa entre empresas
|
|
|
|
## Descripción
|
|
|
|
Librería Zig para comunicación P2P segura entre instancias de Simifactu.
|
|
Permite intercambio directo de documentos (facturas, certificados) entre empresas
|
|
sin necesidad de email ni servicios cloud.
|
|
|
|
## Objetivos
|
|
|
|
1. **Seguridad**: E2E cifrado con TLS 1.3 + ChaCha20-Poly1305
|
|
2. **Descentralizado**: Sin servidor central obligatorio
|
|
3. **Sin dependencias externas**: Implementación completa en Zig puro
|
|
4. **Compatible con NAT**: STUN + relay para atravesar firewalls
|
|
|
|
## Arquitectura
|
|
|
|
```
|
|
┌─────────────────────────────────────────────────────────┐
|
|
│ zcatp2p Library │
|
|
├─────────────────────────────────────────────────────────┤
|
|
│ API Layer │
|
|
│ ├── p2p.init() / p2p.deinit() │
|
|
│ ├── p2p.connect(device_id) │
|
|
│ ├── p2p.send(data) │
|
|
│ └── p2p.receive() -> data │
|
|
├─────────────────────────────────────────────────────────┤
|
|
│ Protocol Layer │
|
|
│ ├── Message framing (Header + Payload) │
|
|
│ ├── Compression (LZ4) │
|
|
│ └── Encryption (ChaCha20-Poly1305) │
|
|
├─────────────────────────────────────────────────────────┤
|
|
│ Connection Layer │
|
|
│ ├── TLS 1.3 handshake │
|
|
│ ├── Certificate-based identity │
|
|
│ └── Connection multiplexing │
|
|
├─────────────────────────────────────────────────────────┤
|
|
│ Discovery Layer │
|
|
│ ├── Local: UDP broadcast/multicast │
|
|
│ ├── Global: HTTPS announce/query │
|
|
│ └── Cache de direcciones conocidas │
|
|
├─────────────────────────────────────────────────────────┤
|
|
│ NAT Traversal Layer │
|
|
│ ├── STUN client │
|
|
│ ├── UPnP/NAT-PMP port mapping │
|
|
│ └── Relay fallback │
|
|
└─────────────────────────────────────────────────────────┘
|
|
```
|
|
|
|
## Estructura de archivos
|
|
|
|
```
|
|
zcatp2p/
|
|
├── CLAUDE.md # Este archivo
|
|
├── PROTOCOL.md # Especificación detallada del protocolo
|
|
├── API.md # Documentación de la API
|
|
├── build.zig # Build system
|
|
└── src/
|
|
├── main.zig # Exports públicos
|
|
├── identity.zig # Device ID, certificados
|
|
├── crypto.zig # ChaCha20-Poly1305, SHA256, etc.
|
|
├── tls.zig # TLS 1.3 implementation
|
|
├── protocol.zig # Message framing
|
|
├── discovery.zig # Local + global discovery
|
|
├── stun.zig # STUN client
|
|
├── nat.zig # UPnP/NAT-PMP
|
|
├── relay.zig # Relay protocol
|
|
└── connection.zig # Connection management
|
|
```
|
|
|
|
## Referencias
|
|
|
|
- Syncthing BEP (Block Exchange Protocol): `/mnt/cello2/arno/re/recode/referencias/syncthing/`
|
|
- RFC 5389 (STUN)
|
|
- RFC 8446 (TLS 1.3)
|
|
- RFC 8439 (ChaCha20-Poly1305)
|
|
|
|
## Estado
|
|
|
|
- [ ] Especificación del protocolo
|
|
- [ ] API design
|
|
- [ ] Implementación crypto
|
|
- [ ] Implementación TLS
|
|
- [ ] Implementación discovery
|
|
- [ ] Implementación STUN
|
|
- [ ] Implementación relay
|
|
- [ ] Tests
|