Circuit Relay v2 Implementation and Testing in universal chatting application #1221
IronJam11
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Overview
This document describes the implementation and successful testing of Circuit Relay v2 for NAT traversal in the Python libp2p peer implementation while building for universal chatting application . Circuit Relay enables peers on isolated networks to communicate through an intermediary relay server, addressing common NAT and firewall traversal challenges in peer-to-peer networks.
Demo Video: https://drive.google.com/file/d/1z7AIROEiLH_taQL0v2PgQrdMrrHTWmsa/view?usp=sharing
Component Configuration
Relay Server
--relay-serverflagroom1(isolated from test peers)PeerA
pldg--relay /ip4/172.24.0.2/tcp/4001/p2p/<RELAY_ID>PeerB
pldg-c /ip4/172.25.0.2/tcp/4001/p2p/<RELAY_ID>/p2p-circuit/p2p/<PEER_A_ID>Circuit Relay Address Format
Circuit relay addresses use a standardized multiaddr format:
Example from test:
Implementation Details
Core Components
1. CircuitV2Protocol
2. CircuitV2Transport
/p2p-circuit/multiaddrs3. RelayResourceManager
4. RelayDiscovery
Key Technical Insights
Circuit Address Handling
The standard libp2p
host.connect()method does not handle/p2p-circuit/addresses. The swarm passes these addresses to the base TCP transport, which cannot parse the circuit format. Circuit connections must be established through direct calls to the circuit transport:Auto-Initialization
The implementation automatically detects circuit addresses in connection arguments and initializes the relay transport infrastructure:
Resource Manager Integration
Relay server statistics are accessed through the correct internal attributes:
Enhanced Status Command
The
/statuscommand provides comprehensive relay debugging information:Relay Server View:
Relay Client View:
All Peers:
Test Execution
Docker Environment Setup
Running Test Peers
Step 1: Start Relay Server
docker run -it --rm \ --name relay \ --network networkA \ peer-app:v1 \ --nick Relay \ --topic room1 \ --port 4001 \ --ui \ --relay-server # In separate terminal, connect relay to second network docker network connect networkB relayStep 2: Start PeerA (Relay Client)
Step 3: Start PeerB (Circuit Client)
Command Line Arguments
--relay-server
--relay
-c / --connect
/p2p-circuit/format and uses circuit transport--topic
--ui
Test Results
Successful Outcomes
Relay Reservation Established
Circuit Connection Established
PubSub Communication Verified
pldg) despite network isolationResource Monitoring Working
/statuscommand shows all relay statistics accuratelyPerformance Observations
Connection Establishment Time
Message Latency
Multiaddrs from Test
Relay Server:
PeerA:
Circuit Address (PeerB to PeerA):
Configuration Parameters
Relay Limits
Default resource limits for relay connections:
AutoNAT Configuration
AutoNAT service automatically determines peer reachability:
--no-autonatflagDCUtR Configuration
Direct Connection Upgrade through Relay (hole punching):
--no-dcutrflagTroubleshooting
Common Issues
"Circuit transport not initialized" error
--relayflag or circuit address in-c-caddress contains/p2p-circuit/Reservation denied by relay server
--relay-server)No PubSub messages received
/statuscommand"Already connected to peer" with circuit address
Debug Commands
Check relay status on server:
Shows hosted reservations and active circuits
Check circuit address on client:
Shows relay circuit addresses obtained
List connected peers:
Display full multiaddress:
References
libp2p Specifications:
Implementation:
Beta Was this translation helpful? Give feedback.
All reactions