rutorrent-flutter icon indicating copy to clipboard operation
rutorrent-flutter copied to clipboard

feat: Add ruTorrent discovery via Zeroconf/mDNS (#75)

Open ananyaaa66 opened this issue 8 months ago β€’ 1 comments

Closes #75

Summary

Adds a native mDNS/DNS-SD discovery feature to the login screen, allowing users to automatically find their ruTorrent servers on the local network without manual IP entry.

Changes

  • [NEW] discovery_service.dart: Implements a lightweight mDNS scanner using raw UDP multicasting to avoid new external dependencies. It scans for the _rutorrent_mobile._tcp.local service type.
    • login_view.dart: Added a 'Discover Servers' button that triggers the discovery process and displays results in a bottom sheet for easy selection and auto-filling of the URL.
    • login_viewmodel.dart: Provides the UI with reactive state from the discovery service.
    • app.dart & app.locator.dart: Registered the new DiscoveryService for dependency injection. This feature expects the ruTorrent server to be configured to advertise itself (e.g., via Avahi) using the _rutorrent_mobile._tcp service type.

Summary by CodeRabbit

  • New Features
    • Added local network server discovery functionality for ruTorrent services.
    • Introduced "Discover Servers on Network" button on the login screen that displays a modal with available servers.
    • Users can now automatically detect and select servers on their local network instead of manual entry.

ananyaaa66 avatar Mar 31 '26 17:03 ananyaaa66

πŸ“ Walkthrough

Walkthrough

This PR introduces local network discovery for ruTorrent servers using mDNS/DNS-SD protocol. A new DiscoveryService performs mDNS queries to find services on the network, and the login view integrates a discovery UI dialog allowing users to discover and select available servers.

Changes

Cohort / File(s) Summary
Dependency Registration
lib/app/app.dart, lib/app/app.locator.dart
Added DiscoveryService as a lazy singleton to the service locator and dependency container.
Discovery Service Implementation
lib/services/functional_services/discovery_service.dart
Introduced DiscoveredServer model and DiscoveryService class with mDNS-based discovery via UDP multicast, DNS response parsing (with name compression and SRV/TXT record extraction), timeout handling, and deduplication of discovered entries.
Login UI Integration
lib/ui/views/login/login_view.dart
Added "Discover Servers on Network" button and a modal bottom sheet dialog that displays discovery state and selectable server list via ValueListenableBuilder.
Login ViewModel
lib/ui/views/login/login_viewmodel.dart
Exposed discoveredServers and isDiscovering reactive getters and added discoverServers() async method to initiate discovery and handle empty-state feedback.

Sequence Diagram

sequenceDiagram
    participant User as User
    participant LoginView as Login View
    participant LoginVM as Login ViewModel
    participant DiscoveryService as Discovery Service
    participant Network as mDNS Network

    User->>LoginView: Tap "Discover Servers on Network"
    LoginView->>LoginVM: discoverServers()
    activate LoginVM
    LoginVM->>DiscoveryService: discover(timeout: 5s)
    activate DiscoveryService
    
    DiscoveryService->>Network: Bind UDP socket & join multicast group
    DiscoveryService->>Network: Send mDNS PTR query
    rect rgba(100, 150, 200, 0.5)
    note over Network: Listen for UDP responses until timeout
    Network-->>DiscoveryService: mDNS response packets
    DiscoveryService->>DiscoveryService: Parse DNS response, extract SRV/TXT records
    DiscoveryService->>DiscoveryService: Deduplicate by (host, port)
    end
    
    DiscoveryService-->>LoginVM: List<DiscoveredServer>
    deactivate DiscoveryService
    LoginVM->>LoginVM: Update discoveredServers ValueNotifier
    LoginVM-->>LoginView: notifyListeners()
    deactivate LoginVM
    
    LoginView->>LoginView: Render discovered servers in modal
    LoginView-->>User: Display list of available servers
    User->>LoginView: Select a server

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Poem

πŸ” Through mDNS whispers the rabbit does quest, Finding servers hidden in the network's nest, With DNS parsing and multicast flair, Discovery is answered in the network air! πŸŽ‰

πŸš₯ Pre-merge checks | βœ… 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR implements mDNS discovery for ruTorrent servers and integrates it into the login interface. However, the PR lacks documentation for Avahi XML sample configuration and TXT record specifications required by issue #75. Add documentation or sample files for Avahi XML configuration and document the TXT record format for protocol/URL metadata as outlined in issue #75.
βœ… Passed checks (4 passed)
Check name Status Explanation
Description Check βœ… Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check βœ… Passed The title accurately describes the main change: adding ruTorrent discovery via Zeroconf/mDNS, which aligns with the primary objective of implementing service discovery.
Out of Scope Changes check βœ… Passed All changes are within scope: DiscoveryService implementation, dependency registration, UI integration, and ViewModel updates all directly support the mDNS discovery feature requested in issue #75.
Docstring Coverage βœ… Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
πŸ§ͺ Generate unit tests (beta)
  • [ ] Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❀️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Mar 31 '26 17:03 coderabbitai[bot]