You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add TURN server configuration support to Phuppi's P2P file sharing feature to enable reliable connections in restricted network environments where direct peer-to-peer connectivity is not possible.
Background
Phuppi's P2P file sharing feature currently uses STUN servers only for ICE candidate discovery. While STUN works well for devices on the same network or with accessible IP addresses, it fails in several common scenarios:
Symmetric NAT - Both peers behind different NAT types
Corporate firewalls - UDP blocked by corporate network policies
Carrier-Grade NAT (CGNAT) - Common on mobile networks
Restrictive firewalls - Only allow HTTP/HTTPS outbound
Users in these scenarios cannot establish P2P connections and see errors like "peer unavailable" or "connection failed".
Feature Requirements
Core Functionality
Requirement
Description
TURN Server Config in Admin UI
Site owner configures TURN in Settings area
Environment Variable Fallback
Optional config via PHUPPI_TURN_* env vars
Fallback Behavior
Use TURN relay when direct P2P fails
Secure Credentials
TURN credentials stored in database, not exposed
Transport Options
Support UDP, TCP, and TLS transports
Graceful Degradation
STUN-only mode if no TURN configured
Configuration
Config Option
Type
Admin UI Key
Env Variable
Description
TURN URL
string
p2p_turn_url
PHUPPI_TURN_URL
TURN server URL (e.g., turn:turn.example.com:3478)
TURN Username
string
p2p_turn_username
PHUPPI_TURN_USERNAME
Username for TURN authentication
TURN Credential
string
p2p_turn_credential
PHUPPI_TURN_CREDENTIAL
Password for TURN authentication
Transport
string
p2p_turn_transport
PHUPPI_TURN_TRANSPORT
Transport: udp (default), tcp, or tls
Configuration Priority
Admin UI Settings (primary) - configured in Settings page
Environment Variables (fallback) - for Docker/non-database deployments
STUN only (default) - gracefully allow failure if neither configured
User Flow
Admin configures TURN server in Settings UI (or uses env vars)
Sender creates P2P share session
ICE negotiation attempts direct connection via STUN
If STUN fails, TURN relay is used automatically (if configured)
If no TURN configured, connection fails gracefully (existing behavior)
Technical Details
Admin UI Location
Add section to existing Settings page at /settings:
Summary
Add TURN server configuration support to Phuppi's P2P file sharing feature to enable reliable connections in restricted network environments where direct peer-to-peer connectivity is not possible.
Background
Phuppi's P2P file sharing feature currently uses STUN servers only for ICE candidate discovery. While STUN works well for devices on the same network or with accessible IP addresses, it fails in several common scenarios:
Users in these scenarios cannot establish P2P connections and see errors like "peer unavailable" or "connection failed".
Feature Requirements
Core Functionality
Configuration
p2p_turn_urlPHUPPI_TURN_URLturn:turn.example.com:3478)p2p_turn_usernamePHUPPI_TURN_USERNAMEp2p_turn_credentialPHUPPI_TURN_CREDENTIALp2p_turn_transportPHUPPI_TURN_TRANSPORTudp(default),tcp, ortlsConfiguration Priority
User Flow
Technical Details
Admin UI Location
Add section to existing Settings page at
/settings:Storage
Settings stored in
app_settingstable:p2p_turn_url| Value:turn:server.com:3478p2p_turn_username| Value:userp2p_turn_credential| Value:passwordp2p_turn_transport| Value:udpICE Server Priority
graph TD A[Start ICE] --> B[Gather STUN candidates] B --> C{Direct P2P possible?} C -->|Yes| D[Use direct connection] C -->|No| E{TURN configured?} E -->|Yes| F[Use TURN relay] E -->|No| G[Connection failed - STUN only]Current Implementation (STUN only)
Located in
src/views/p2p-sender.latte:466-475:Required Changes
src/views/settings.lattesrc/Phuppi/Controllers/SettingsController.phpsrc/views/p2p-sender.lattesrc/views/p2p-receive.latte.env.exampleImplementation
Phase 1: Admin UI
settings.lattePhase 2: Backend
Phase 3: Frontend
p2p-sender.lattep2p-receive.lattePhase 4: Testing
Dependencies
Benefits
Risks
Alternative Approaches Considered
1. Self-Hostored TURN (Coturn)
2. Third-Party TURN Service
3. SOCKS5 Proxy
Recommended: Option 2 (third-party) for initial implementation, with documentation for self-hosting option.
Future Enhancements