20 lines
898 B
C#
20 lines
898 B
C#
|
|
namespace MusicBridge.Agent.Network;
|
||
|
|
|
||
|
|
// Data for a future DNS-SD publisher. Does not open sockets or advertise pairing secrets.
|
||
|
|
internal sealed record DiscoveryDescriptor(int ProtocolVersion, string AgentId, string ServiceType, string InstanceName)
|
||
|
|
{
|
||
|
|
public static DiscoveryDescriptor Create(string certificateSha256)
|
||
|
|
{
|
||
|
|
if (certificateSha256.Length != 64 || !certificateSha256.All(Uri.IsHexDigit))
|
||
|
|
throw new ArgumentException("Неверный идентификатор сертификата.");
|
||
|
|
var id = certificateSha256.ToUpperInvariant();
|
||
|
|
return new(1, id, "_musicbridge._tcp.local.", "MusicBridge-" + id[..12]);
|
||
|
|
}
|
||
|
|
|
||
|
|
public IReadOnlyDictionary<string, string> TxtRecords() => new Dictionary<string, string>
|
||
|
|
{
|
||
|
|
["v"] = ProtocolVersion.ToString(System.Globalization.CultureInfo.InvariantCulture),
|
||
|
|
["id"] = AgentId
|
||
|
|
};
|
||
|
|
}
|