Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Hanzo LibP2P Relay Manager
A LibP2P relay server implementation for the Hanzo network with automatic external IP detection for cloud deployments.
Features
- 🌐 Automatic External IP Detection: Detects public IP addresses for proper external peer connectivity
- 🔄 Multi-transport Support: Both TCP and QUIC protocols with fallback support
- 📡 Gossipsub Messaging: Efficient peer-to-peer message propagation
- 🔍 Kademlia DHT: Distributed peer discovery and routing
- 🛡️ Relay Protocol: Allows peers to connect through the relay server
- ☁️ Cloud-Ready: Optimized for Google Cloud Platform and other cloud providers
Google Cloud Deployment
Problem Solved
When deploying LibP2P relay servers on Google Cloud Platform using Container-Optimized OS with --network="host", the container cannot automatically detect the VM's public IP address. This prevents external peers from connecting to the relay server.
This implementation solves the problem by:
- External IP Detection: Automatically detects the Google Cloud VM's public IP using multiple fallback services
- Address Advertisement: Properly advertises external addresses to the LibP2P network
- Cloud Integration: Seamless operation with Google Cloud's networking model
Deployment Example
# Dockerfile for Google Cloud deployment
FROM rust:1.75 as builder
WORKDIR /app
COPY . .
RUN cargo build --release --bin hanzo-libp2p-relayer
FROM debian:bookworm-slim
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
COPY --from=builder /app/target/release/hanzo-libp2p-relayer /usr/local/bin/
EXPOSE 9090
CMD ["hanzo-libp2p-relayer"]
# Deploy to Google Cloud with host networking
Usage
Basic Setup
use RelayManager;
use SigningKey;
async
Environment Variables
RELAY_PORT: Port to listen on (default: 9090)NODE_NAME: Identity name for the relay serverIDENTITY_SECRET_KEY: Ed25519 private key for node identity
External IP Detection
The relay manager automatically detects external IP addresses using multiple services for reliability:
- httpbin.org/ip - Primary service (JSON response)
- api.ipify.org - Fallback service (plain text)
- ifconfig.me/ip - Secondary fallback
- icanhazip.com - Tertiary fallback
Detection Process
- Attempts each service with a 5-second timeout
- Parses response format (JSON or plain text)
- Validates IP address format
- Returns first successful detection
- Gracefully handles failures and continues without external IP if all services fail
Network Architecture
┌─────────────────────────────────────────────────────────┐
│ Google Cloud VM │
│ ┌─────────────────────────────────────────────────────┐│
│ │ Container (--network=host) ││
│ │ ┌─────────────────────────────────────────────────┐││
│ │ │ LibP2P Relay Manager │││
│ │ │ │││
│ │ │ • Binds to 0.0.0.0:9090 (all interfaces) │││
│ │ │ • Detects external IP: 203.0.113.42 │││
│ │ │ • Advertises: /ip4/203.0.113.42/tcp/9090 │││
│ │ │ /ip4/203.0.113.42/udp/9090/quic │││
│ │ └─────────────────────────────────────────────────┘││
│ └─────────────────────────────────────────────────────┘│
│ │
│ Internal IP: 10.128.0.42 │
│ External IP: 203.0.113.42 │
└─────────────────────────────────────────────────────────┘
│
│ Firewall allows :9090
│
▼
┌─────────────────────────────────────────────────────────┐
│ Internet Peers │
│ │
│ Connect to: /ip4/203.0.113.42/tcp/9090 │
│ /ip4/203.0.113.42/udp/9090/quic-v1 │
└─────────────────────────────────────────────────────────┘
Logging and Monitoring
The relay manager provides detailed logging for monitoring:
🌐 External address confirmed and advertised: /ip4/203.0.113.42/tcp/9090
📍 Connection established with peer: 12D3KooW...
⚠️ External address expired: /ip4/203.0.113.42/tcp/9090
Key log messages:
- External IP detection attempts and results
- Address advertisement confirmations
- Peer connection events
- Relay reservation acceptances
- Kademlia DHT updates
Security Considerations
- Uses Ed25519 signatures for peer authentication
- Supports TLS encryption through QUIC transport
- Validates all incoming peer connections
- Implements rate limiting through connection limits
Troubleshooting
External IP Detection Fails
If external IP detection fails:
- Check internet connectivity from the container
- Verify firewall allows outbound HTTPS (ports 80/443)
- Check if IP detection services are accessible
- The relay will still function with local addresses only
Google Cloud Specific Issues
-
Firewall Rules: Ensure the relay port is open:
-
Container-Optimized OS: Use
--network="host"for direct IP access -
External IP Assignment: Ensure the VM has an external IP assigned
Dependencies
libp2p0.55.0+ - Core LibP2P networkingreqwest0.11+ - HTTP client for IP detectiontokio- Async runtimeserde_json- JSON parsing for IP detection services
License
This project is licensed under the same terms as the main Hanzo Node project.