Skip to content
Back to skills

Rust Network Module

ASecurity

Scaffold new Rust async networking modules for the nat464-sidecar project. Use when adding TCP/UDP listeners, protocol handlers, proxies, or translation modules. Triggers: 'scaffold module', 'add new module', 'create listener', 'create proxy', 'add protocol handler', 'new networking module', 'scaffold UDP', 'add ICMP translation'.

  • 4 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added May 28, 2026
ai-agentsrustgobash

Works with

  • cli

Security analysis

A100/100

Pro scans all 6 files and shows the line behind each finding

Scanned May 28, 2026

npx -y skills add fakoli/fakoli-plugins --skill rust-network-module --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Rust Network Module?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Rust Network Module
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/fakoli-rust-network-module/badge)](https://www.skillsdirectory.com/skills/fakoli-rust-network-module)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: rust-network-module
description: "Scaffold new Rust async networking modules for the nat464-sidecar project. Use when adding TCP/UDP listeners, protocol handlers, proxies, or translation modules. Triggers: 'scaffold module', 'add new module', 'create listener', 'create proxy', 'add protocol handler', 'new networking module', 'scaffold UDP', 'add ICMP translation'."
---

# Rust Network Module Scaffolding

Scaffold new async networking modules following nat464-sidecar's established patterns.

## Workflow

### 1. Determine Module Type

| Type | Pattern | Example |
|------|---------|---------|
| **Listener** | Accept connections, spawn handler tasks | `proxy/inbound.rs` |
| **Protocol handler** | Parse/serialize protocol messages | `socks5/handshake.rs` |
| **Relay/proxy** | Bidirectional byte forwarding between streams | `proxy/copy.rs`, `socks5/relay.rs` |
| **Resolver/racer** | DNS resolution, connection racing | `happy_eyeballs/resolver.rs`, `racer.rs` |
| **HTTP server** | Hyper-based HTTP endpoint | `health.rs` |

### 2. Create Module Files

Every module is a directory under `src/` with `mod.rs` + implementation files.

```
src/<module_name>/
├── mod.rs           # Re-exports, shared types/constants
├── <primary>.rs     # Main logic
└── (optional).rs    # Additional files as needed
```

Register in parent: add `pub mod <module_name>;` to `src/main.rs` or parent `mod.rs`.

### 3. Apply Project Conventions

See [references/patterns.md](references/patterns.md) for the full pattern catalog with code templates.

**Key conventions:**
- `pub async fn run_<name>(port: u16, ...) -> anyhow::Result<()>` for server entry points
- `tokio::spawn` per connection, errors logged inside spawn (never crash the server)
- `tracing` structured fields: `debug!` per-connection, `info!` lifecycle, `error!` failures
- `anyhow::Result` everywhere, `anyhow::bail!` for protocol errors
- In-module `#[cfg(test)] mod tests` with `test_pair()` helper for TCP stream pairs
- Tests bind to port 0 for random allocation

### 4. Add to Cargo.toml If Needed

Only add dependencies if the new module requires crates not already in Cargo.toml. Current deps: `tokio`, `clap`, `tracing`, `tracing-subscriber`, `hyper`, `hyper-util`, `http-body-util`, `tokio-util`, `anyhow`, `thiserror`.

### 5. Wire Into main.rs

Add the new server to `tokio::try_join!` in `main.rs` if it runs as a long-lived server. Add CLI flags to `config.rs` if the module needs configuration.

### 6. Verify

```bash
cargo build          # Compiles
cargo test           # All tests pass
cargo clippy -- -W clippy::all  # No new warnings
```

## Module Templates

Use the asset templates as starting points:

| Template | Use For |
|----------|---------|
| `assets/listener.rs.tmpl` | TCP/UDP listener with spawn-per-connection |
| `assets/protocol.rs.tmpl` | Protocol parser with handshake + types |
| `assets/mod.rs.tmpl` | Module root with constants and re-exports |
| `assets/tests.rs.tmpl` | Test block with `test_pair()` helper |

Files in this skill

  • SKILL.md3 KB
  • assets/listener.rs.tmpl812 B
  • assets/mod.rs.tmpl222 B
  • assets/protocol.rs.tmpl893 B
  • assets/tests.rs.tmpl1.4 KB
  • references/patterns.md6.7 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.