zcatp2p/examples/basic.zig
reugenio 7e5b16ee15 Inicial: biblioteca zcatp2p para comunicación P2P segura
- 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>
2025-12-15 01:06:30 +01:00

38 lines
1.2 KiB
Zig

//! Ejemplo básico de uso de zcatp2p
const std = @import("std");
const p2p = @import("zcatp2p");
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
const allocator = gpa.allocator();
// Configuración
const config = p2p.Config{
.device_name = "Simifactu-Ejemplo",
.listen_port = 22000,
.local_discovery = true,
.data_dir = "/tmp/zcatp2p-example",
};
// Inicializar
std.debug.print("Inicializando zcatp2p...\n", .{});
var node = try p2p.P2P.init(allocator, config);
defer node.deinit();
// Mostrar nuestro Device ID
var id_buf: [64]u8 = undefined;
const my_id = node.getDeviceIdString(&id_buf);
std.debug.print("Mi Device ID: {s}\n", .{my_id});
// Mostrar estado de NAT
const nat_type = node.getNatType();
std.debug.print("Tipo de NAT: {}\n", .{nat_type});
// Mostrar conexiones activas
std.debug.print("Conexiones activas: {}\n", .{node.connectionCount()});
std.debug.print("\n¡zcatp2p inicializado correctamente!\n", .{});
std.debug.print("Pendiente: implementación completa de TLS, STUN, y relay.\n", .{});
}