1
Instalación en tu proyecto
El Protocolo Orzatty (PO) se distribuye como un paquete llamado 'Crate' en el ecosistema Rust. Para usarlo, simplemente debes agregarlo a la mochila de herramientas de tu proyecto, que se llama `Cargo.toml`.
Abre el archivo `Cargo.toml` de tu proyecto y añade estas líneas justo debajo de `[dependencies]`.
# Cargo.toml
[dependencies]
po-node = { git = "https://github.com/orzattyholding/po.git" }
tokio = { version = "1.0", features = ["full"] }
💡 Para que lo entiendas súper fácil: Imagina que estás armando un LEGO impresionante. `Cargo.toml` es la lista de compras que le das a tu mamá. Le estás pidiendo la caja de fichas "po-node" (que trae todas las funciones para hablar con el protocolo) y "tokio" (que es el motorcito que permite hacer varias cosas al mismo tiempo sin trabarse).
2
Iniciar un Servidor (Crear la puerta)
Para que dos computadoras se hablen, una tiene que estar escuchando (como un oyente de radio esperando una llamada). En PO, crear un servidor toma exactamente 1 línea de código.
Crea un archivo llamado `src/server.rs` y pon este código:
use po_node::Po;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// 1. Abrimos el puerto 4433. ¡Ya estamos escuchando!
let mut server = Po::bind(4433).await?;
println!("Servidor Orzatty escuchando en modo E2EE...");
// 2. Nos quedamos en un ciclo eterno esperando que lleguen paquetes
while let Some((canal, datos)) = server.recv().await? {
let mensaje_texto = String::from_utf8_lossy(&datos);
println!("¡Recibimos un paquete!: {}", mensaje_texto);
}
Ok(())
}
💡 Para que lo entiendas súper fácil: Imagina que abriste la puerta número 4433 de tu casa. Te quedas sentado esperando a que un cartero te lance un sobre negro blindado por debajo de la puerta (`server.recv()`). El protocolo abre el candado cripotográfico, saca el papelito de adentro y lo lee.
3
Conectar un Cliente (Lanzar el misil de datos)
Ahora que el servidor está escuchando en la puerta 4433, necesitamos que otra computadora (o un programa distinto) llame a esa puerta para establecer el túnel secreto cifrado. ¡Felicidades! A diferencia de los sistemas tradicionales como WebSockets, con Orzatty Protocol tú NO creas candados manuales. La matemática ED25519 crea el candado y la llave automáticamente.
Crea un archivo llamado `src/client.rs` y pon esto:
use po_node::Po;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// 1. Conectarnos a la computadora que está en nuestro mismo cuarto (127.0.0.1)
let mut client = Po::connect("127.0.0.1:4433").await?;
// 2. ¡Lanzar la data cifrada!
let contenido = b"Este es un secreto corporativo de Orzatty";
client.send(contenido).await?;
println!("¡Paquete enviado a hiper-velocidad!");
Ok(())
}
💡 Para que lo entiendas súper fácil: Piensa que `Po::connect` manda construir un tubo de acero impenetrable desde tu casa hasta la casa 127.0.0.1. Por fuera el tubo se ve gris, nadie sabe qué hay adentro. Cuando usas `client.send()`, metes una esfera por el tubo que viaja rapidísimo. Solo el que está del otro lado sabe cómo abrir la esfera.
4
Modo "Batch" (Para enviar 10 Mil Mensajes por Segundo) 🚀
Si eres un Arquitecto de Sistemas intentando escalar, `send` normal cifrará 1 por 1 los mensajes. Si vas a inundar la red con miles de paquetes pequeños (Telemetría de juegos, IA), tienes que usar `send_batch()`.
Esto junta muchos paquetes chiquitos, los mete todos en una gran caja fuerte matemática de ChaCha20, cifra la caja enorme una sola vez y la manda como una bestia de carga.
use po_node::Po;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut client = Po::connect("127.0.0.1:4433").await?;
// Creamos 5,000 mensajitos pequeños
let mut batch_de_mensajes = Vec::new();
for _ in 0..5000 {
batch_de_mensajes.push(b"telemetria_diminuta".as_slice());
}
// Usamos el optimizador! (Aumento de velocidad de 4.8x)
client.send_batch(&batch_de_mensajes).await?;
Ok(())
}
💡 Para que lo entiendas súper fácil: Imagina que tienes 5,000 chocolates y le vas a poner una envoltura y un moño a cada uno. Tardarías toda la vida. `send_batch` mete los 5,000 chcolates en una caja de cartón gigante, le pone un solo moño gigante a la caja y la lanza de un solo tiro. ¡Menos trabajo para tu computadora, más velocidad para ti!
1
Installation in your project
Protocol Orzatty (PO) is distributed as a 'Crate' within the Rust ecosystem. To use it, simply add it to your project's toolbag, which is called `Cargo.toml`.
Open your `Cargo.toml` file and add these lines right under `[dependencies]`.
# Cargo.toml
[dependencies]
po-node = { git = "https://github.com/orzattyholding/po.git" }
tokio = { version = "1.0", features = ["full"] }
💡 To make it super easy to understand: Imagine you're putting together an awesome LEGO set. `Cargo.toml` is the shopping list you give your mom. You're asking her for the "po-node" brick box (which brings all the network functions) and the "tokio" engine (which allows doing many things at the same time without freezing).
2
Starting a Server (Creating the door)
For two computers to talk, one has to be listening (like a radio listener waiting for a call). In PO, creating a server takes exactly 1 line of code.
Create a file named `src/server.rs` and paste this code:
use po_node::Po;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// 1. We open port 4433. We are listening!
let mut server = Po::bind(4433).await?;
println!("Orzatty Server listening in E2EE mode...");
// 2. We stay in an eternal loop waiting for packets to arrive
while let Some((channel, data)) = server.recv().await? {
let msg_text = String::from_utf8_lossy(&data);
println!("Received packet!: {}", msg_text);
}
Ok(())
}
💡 To make it super easy to understand: Imagine you opened door number 4433 in your house. You sit there waiting for a mailman to slide a black armored envelope under the door (`server.recv()`). The protocol unlocks the cryptographic padlock, pulls the paper out and reads it.
3
Connecting a Client (Launching the data missile)
Now that the server is listening on port 4433, we need another computer to knock on that door to establish the encrypted secret tunnel. Congratulations! Unlike traditional systems like WebSockets, with Orzatty Protocol you DO NOT create manual certificates. The ED25519 mathematics create the lock and key automatically.
Create a file named `src/client.rs` and paste this:
use po_node::Po;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// 1. Connect to the local machine (127.0.0.1)
let mut client = Po::connect("127.0.0.1:4433").await?;
// 2. Launch encrypted data!
let content = b"This is an Orzatty corporate secret";
client.send(content).await?;
println!("Packet sent at hyper-speed!");
Ok(())
}
💡 To make it super easy to understand: Think of `Po::connect` as building an impenetrable steel tube from your house to house 127.0.0.1. From the outside, the tube looks gray, nobody knows what's inside. When you use `client.send()`, you shoot a sphere through the tube very fast. Only the person on the other side knows how to open it.
4
"Batch" Mode (To send 10 Thousand Messages per Second) 🚀
If you are a Systems Architect trying to scale, regular `send` will encrypt messages 1 by 1. If you are going to flood the network with thousands of tiny packets, you must use `send_batch()`.
This groups many tiny packets, puts them all in a big ChaCha20 mathematical safe, encrypts the huge safe once, and sends it as a beast of burden.
use po_node::Po;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut client = Po::connect("127.0.0.1:4433").await?;
// We create 5,000 tiny messages
let mut message_batch = Vec::new();
for _ in 0..5000 {
message_batch.push(b"tiny_telemetry".as_slice());
}
// We use the optimizer! (4.8x speed boost)
client.send_batch(&message_batch).await?;
Ok(())
}
💡 To make it super easy to understand: Imagine you have 5,000 chocolates and you're going to put a wrapper and a bow on each one. It would take a lifetime. `send_batch` puts all 5,000 chocolates in a giant cardboard box, ties one giant bow around the box, and ships it all at once. Less work for your computer, more speed for you!