Skip to content

WebRTC Integration

FuryMesh leverages WebRTC technology to enable direct peer-to-peer file transfers without requiring centralized servers for data exchange. This document provides an overview of the WebRTC implementation in FuryMesh.

Architecture Overview

The WebRTC implementation in FuryMesh consists of several key components:

  1. WebRTC Manager: Handles connection establishment and management
  2. WebRTC Messaging: Manages message exchange over data channels
  3. WebRTC Transfer Manager: Coordinates file transfers between peers
  4. WebRTC Transport Adapter: Bridges the file system with WebRTC components

These components work together to provide a seamless peer-to-peer file sharing experience.

Connection Establishment

FuryMesh uses a signaling mechanism to establish WebRTC connections between peers:

  1. Peers discover each other through the DHT (Distributed Hash Table)
  2. The signaling process exchanges SDP offers/answers and ICE candidates
  3. Once connected, peers communicate directly through WebRTC data channels

File Transfer Process

The file transfer process using WebRTC follows these steps:

  1. File Request: A peer requests a file from another peer
  2. Metadata Exchange: The source peer sends file metadata (size, chunks, etc.)
  3. Chunk Requests: The requesting peer requests individual chunks
  4. Data Transfer: Chunks are transferred directly between peers
  5. Reassembly: The receiving peer reassembles the file from chunks

Error Handling and Recovery

FuryMesh implements robust error handling for WebRTC transfers:

  • Connection Monitoring: Continuously monitors connection state
  • Timeout Handling: Implements timeouts for stalled transfers
  • Retry Mechanism: Automatically retries failed chunk transfers
  • Multi-peer Fallback: Can request chunks from multiple peers if available

Performance Optimizations

Several optimizations ensure efficient file transfers:

  • Chunk Selection Strategies: Implements various strategies for requesting chunks
  • Concurrent Transfers: Supports multiple simultaneous chunk transfers
  • Buffer Management: Optimizes memory usage during transfers
  • Binary Serialization: Uses FlatBuffers for efficient message encoding

Security Considerations

WebRTC connections in FuryMesh are secured through:

  • Encrypted Data Channels: All WebRTC data channels use DTLS encryption
  • Optional Content Encryption: File content can be additionally encrypted
  • Peer Authentication: Verifies peer identity during connection establishment

Configuration Options

FuryMesh allows customization of WebRTC behavior through configuration:

webrtc:
  stun_servers:
    - "stun:stun.l.google.com:19302"
    - "stun:stun1.l.google.com:19302"
  turn_servers: []
  username: ""
  credential: ""
  ice_timeout: 30
  max_retries: 3

transfer:
  chunk_size: 1048576  # 1MB
  max_concurrent_chunks: 5
  retry_interval: 5s
  max_retries: 3
  idle_timeout: 30s
  buffer_size: 10

Debugging and Monitoring

FuryMesh provides tools for debugging WebRTC connections:

  • Connection State Logging: Logs connection state changes
  • Transfer Statistics: Tracks transfer progress and performance
  • Metrics Collection: Gathers metrics on message exchange and data transfer