Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

iroh-p2p

БесплатноБез исполняемых скриптовНе проверен

Build modern peer-to-peer applications with Iroh. QUIC-based P2P networking, hole punching, content distribution, and decentralized data synchronization.

plurigridот plurigrid★ 73 звезды на GitHub

Об этом скилле

Iroh P2P Development

Build decentralized, peer-to-peer applications with Iroh — a modern Rust P2P library based on QUIC with automatic hole punching, relay fallback, and content distribution.

What is Iroh?

Iroh is a nextgen P2P library that implements:

  • 🔗 Direct P2P connections via QUIC (UDP-based, faster than TCP)
  • 🔄 Automatic hole punching (NAT traversal without complexity)
  • 📡 Relay fallback (works even behind restrictive firewalls)
  • 📦 Content distribution (iroh-blobs for KB-TB transfers)
  • 📝 Document sync (iroh-docs for collaborative state)
  • 💬 Gossip protocol (iroh-gossip for message broadcasting)

Iroh represents data sovereignty: users control their own nodes, direct connections replace central servers, and data stays decentralized.


Quick Start Project

1. Initialize Iroh Project

cargo new my_p2p_app
cd my_p2p_app

# Add dependencies
cargo add [email protected]
cargo add tokio --features full
cargo add anyhow
cargo add tracing tracing-subscriber

2. Create a Basic P2P Node

use anyhow::Result;

#[tokio::main]
async fn main() -> Result<()> {
    // Spawn an Iroh node with all services
    let node = iroh::node::Builder::default()
        .spawn()
        .await?;

    println!("✅ P2P node started!");
    println!("  📦 Blobs:  Available");
    println!("  📝 Docs:   Available");
    println!("  💬 Gossip: Available");

    // Keep running
    println!("\n⏳ Running... (Ctrl+C to stop)");
    tokio::signal::ctrl_c().await?;
    println!("👋 Shutting down...");

    Ok(())
}

3. Build and Run

cargo build --release
./target/release/my_p2p_app

Core Concepts

Node Identity

Every Iroh node has a node ID (public key) that other peers can connect to:

// Access node ID through services
let node_id = node.blobs.node_id().await?;
println!("My node ID: {}", node_id);

// Share this with other peers to establish connections

Services

Iroh provides modular services you can use independently:

📦 iroh-bytes (Content Distribution)

Transfer files/blobs between peers (KB to TB):

// Publish a blob
let hash = node.blobs.add_bytes(b"Hello, P2P!").await?;

// Access via peer's node ID
let peer_id = "..."; // from other peer
let content = node.blobs.get_bytes(hash).await?;

📝 iroh-docs (Document Sync)

Sync structured data between peers with conflict-free resolution:

// Create a document (CRDT-based)
let doc = node.docs.create().await?;

// Write data
doc.set_bytes(b"key", b"value").await?;

// Other peers auto-sync

💬 iroh-gossip (Message Broadcasting)

Broadcast messages across a P2P network (publish/subscribe):

// Subscribe to a topic
let topic = "alerts".as_bytes();
let mut sub = node.gossip.subscribe(topic.clone()).await?;

// Publish a message
node.gossip.publish(topic.clone(), b"New alert!").await?;

// Receive messages
while let Ok(msg) = sub.next().await {
    println!("Received: {}", String::from_utf8_lossy(&msg));
}

Architecture Patterns

Pattern 1: Direct Peer Connections

Connect to a peer by their node ID:

// Dial a peer directly
let peer_id = "..."; // node ID of another peer
let connection = node.net.connect(peer_id).await?;

// Use connection for RPC, streaming, etc.

Pattern 2: Distributed Content Discovery

Use Iroh's DHT (Distributed Hash Table) for peer discovery:

// Announce your content
let hash = node.blobs.add_bytes(data).await?;

// Other peers query DHT to find providers
// Iroh handles this automatically

Pattern 3: Relay Fallback

When direct connections fail (firewall), Iroh falls back to relays:

// Configured automatically - no code needed
// If direct connection fails → relay takes over
// User experiences seamless P2P

Real-World Patterns

1. File Sync Between Two Peers

// Peer A: Share a file
let path = "/path/to/file.txt";
let bytes = std::fs::read(path)?;
let hash = node.blobs.add_bytes(&bytes).await?;
println!("Share this hash: {}", hash);

// Peer B: Receive the file
let hash = "..."; // from Peer A
let bytes = node.blobs.get_bytes(hash).await?;
std::fs::write("/path/to/downloaded.txt", bytes)?;

2. Live Collaboration (Docs + Gossip)

// Create shared document
let doc = node.docs.create().await?;

// Publish document ID via gossip
let doc_id = doc.id().to_string();
node.gossip.publish(b"shared_docs", doc_id.as_bytes()).await?;

// All peers subscribe and sync the doc
// Concurrent edits merge automatically (CRDT)

3. Distributed Cache

// Cache data in blobs, announce via gossip
let cache_entry = serde_json::to_vec(&data)?;
let hash = node.blobs.add_bytes(&cache_entry).await?;

// Broadcast availability
node.gossip.publish(b"cache_updates", hash.as_ref()).await?;

// Peers can fetch via hash

Deployment Considerations

1. NAT/Firewall Handling

Iroh handles NAT traver

Полный SKILL.md на GitHub

Установить iroh-p2p в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

examples/basic-node.rs

FAQ

Что делает скилл iroh-p2p?

Build modern peer-to-peer applications with Iroh. QUIC-based P2P networking, hole punching, content distribution, and decentralized data synchronization.

Как установить скилл iroh-p2p?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл iroh-p2p запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить iroh-p2p с