- Implement UserCameraAccess entity and CRUD API (issues #131, #133) - Add CameraAccessPanel UI component for granular access management (issue #134) - Implement camera toggle UI (issues #59, #199) - Implement site filtering by user rights (issue #136) - Implement Groups camera access assignment (issue #138) - Implement audit logging for camera access changes (issue #140) - Add comprehensive camera access test coverage (issue #141) - Implement i18n/l10n localization infrastructure (issue #142) - Implement OpenTelemetry metrics infrastructure (issue #14) - Implement Agent GPU worker (issue #76) - Implement Agent remote sensor mode (issue #75) - Fix Docker GPU exposure in compose files (issues #76, #77) - Fix mDNS divergence by extracting shared MdnsClient library (issue #81) - Implement User email confirm/edit UI (issues #88, #89) - Implement Persons UI (issue #11) - Fix E2E test timing issues by increasing circuit delay - Add MdnsClient library with unified unicast/multicast mDNS support - Refactor MdnsProbeService and HomeKitMdnsProbe to use shared client - Add GroupCameraAccess entity for group-based camera access - Add comprehensive camera access test coverage - Add i18n localization infrastructure with fr/en support - Add Docker GPU exposure for NVIDIA/AMD/Intel - Update Docker compose files with GPU device exposure - Fix mDNS divergence between Central unicast and Agent multicast - Fix E2E test timing issues with increased circuit delay All 1700+ tests pass (unit + integration)
81 lines
2.7 KiB
C#
81 lines
2.7 KiB
C#
using System.Net;
|
|
using Heimdall.Mdns;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace Heimdall.Infrastructure.Services.Discovery;
|
|
|
|
/// <summary>
|
|
/// mDNS / HomeKit probe implementation using the shared MdnsClient.
|
|
/// Sends unicast DNS-SD queries to the target IP:5353 to discover
|
|
/// HomeKit Accessory Protocol (_hap._tcp) and other camera services.
|
|
/// </summary>
|
|
public sealed class MdnsProbeService : IMdnsProbeService
|
|
{
|
|
private readonly IMdnsClient _mdnsClient;
|
|
private readonly ILogger<MdnsProbeService> _logger;
|
|
|
|
public MdnsProbeService(IMdnsClient mdnsClient, ILogger<MdnsProbeService> logger)
|
|
{
|
|
_mdnsClient = mdnsClient;
|
|
_logger = logger;
|
|
}
|
|
|
|
public async Task<HomeKitDeviceInfo?> ProbeAsync(string ipAddress, CancellationToken ct = default)
|
|
{
|
|
try
|
|
{
|
|
_logger.LogDebug("mDNS unicast probing {Ip}", ipAddress);
|
|
|
|
var target = IPAddress.Parse(ipAddress);
|
|
var result = await _mdnsClient.ProbeUnicastAsync(target, ct: ct).ConfigureAwait(false);
|
|
|
|
if (result is null)
|
|
return null;
|
|
|
|
// If the client already parsed HomeKit info, use it
|
|
if (result.HomeKitInfo is not null)
|
|
return ConvertToLocalHomeKitDeviceInfo(result.HomeKitInfo);
|
|
|
|
// Otherwise parse from raw result
|
|
return ParseHomeKitInfo(result);
|
|
}
|
|
catch (OperationCanceledException) when (ct.IsCancellationRequested)
|
|
{
|
|
throw;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogWarning(ex, "mDNS unicast probe error for {Ip}", ipAddress);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
private static HomeKitDeviceInfo? ParseHomeKitInfo(MdnsProbeResult result)
|
|
{
|
|
if (result.TxtRecords is null)
|
|
return null;
|
|
|
|
var name = result.InstanceName?.Split('.')[0] ?? "HomeKit Camera";
|
|
var deviceId = result.TxtRecords.GetValueOrDefault("id")
|
|
?? $"{result.Target}/{(result.TxtRecords.GetValueOrDefault("md") ?? "unknown")}";
|
|
var model = result.TxtRecords.GetValueOrDefault("md") ?? "Unknown";
|
|
var category = result.TxtRecords.GetValueOrDefault("c#") ?? "0";
|
|
var isPaired = result.TxtRecords.GetValueOrDefault("s#") != "0";
|
|
|
|
if (!int.TryParse(category, out var cat))
|
|
return null;
|
|
|
|
return new HomeKitDeviceInfo(name, deviceId, model, cat, isPaired, result.Port ?? MdnsConstants.Port);
|
|
}
|
|
|
|
private static HomeKitDeviceInfo ConvertToLocalHomeKitDeviceInfo(Heimdall.Mdns.HomeKitDeviceInfo source)
|
|
{
|
|
return new HomeKitDeviceInfo(
|
|
source.Name,
|
|
source.DeviceId,
|
|
source.Model,
|
|
source.Category,
|
|
source.IsPaired,
|
|
source.Port);
|
|
}
|
|
} |