Пример #1
0
        /// <summary>
        ///   Creates a new instance of the <see cref="ServiceProfile"/> class
        ///   with the specified details.
        /// </summary>
        /// <param name="instanceName">
        ///    A unique identifier for the specific service instance.
        /// </param>
        /// <param name="serviceName">
        ///   The <see cref="ServiceName">name</see> of the service.
        /// </param>
        /// <param name="port">
        ///   The TCP/UDP port of the service.
        /// </param>
        /// <param name="addresses">
        ///   The IP addresses of the specific service instance. If <b>null</b> then
        ///   <see cref="MulticastService.GetIPAddresses"/> is used.
        /// </param>
        /// <remarks>
        ///   The SRV, TXT and A/AAAA resoruce records are added to the <see cref="Resources"/>.
        /// </remarks>
        public ServiceProfile(string instanceName, string serviceName, ushort port, IEnumerable <IPAddress> addresses = null)
        {
            InstanceName = instanceName;
            ServiceName  = serviceName;
            var fqn = FullyQualifiedName;

            var simpleServiceName = ServiceName
                                    .Replace("._tcp", "")
                                    .Replace("._udp", "")
                                    .TrimStart('_');

            HostName = $"{InstanceName}.{simpleServiceName}.{Domain}";
            Resources.Add(new SRVRecord
            {
                Name   = fqn,
                Port   = port,
                Target = HostName
            });
            Resources.Add(new TXTRecord
            {
                Name    = fqn,
                Strings = { "txtvers=1" }
            });

            foreach (var address in addresses ?? MulticastService.GetLinkLocalAddresses())
            {
                Resources.Add(AddressRecord.Create(HostName, address));
            }
        }
Пример #2
0
        /// <summary>
        ///   Creates a new instance of the <see cref="ServiceProfile"/> class
        ///   with the specified details.
        /// </summary>
        /// <param name="instanceName">
        ///    A unique identifier for the specific service instance.
        /// </param>
        /// <param name="serviceName">
        ///   The <see cref="ServiceName">name</see> of the service.
        /// </param>
        /// <param name="port">
        ///   The TCP/UDP port of the service.
        /// </param>
        /// <param name="addresses">
        ///   The IP addresses of the specific service instance. If <b>null</b> then
        ///   <see cref="MulticastService.GetIPAddresses"/> is used.
        /// </param>
        /// <remarks>
        ///   The SRV, TXT and A/AAAA resoruce records are added to the <see cref="Resources"/>.
        /// </remarks>
        public ServiceProfile(DomainName instanceName, DomainName serviceName, ushort port, IEnumerable <IPAddress> addresses = null)
        {
            InstanceName = instanceName;
            ServiceName  = serviceName;
            var fqn = FullyQualifiedName;

            var simpleServiceName = new DomainName(ServiceName.ToString()
                                                   .Replace("._tcp", "")
                                                   .Replace("._udp", "")
                                                   .Trim('_')
                                                   .Replace("_", "-"));

            HostName = DomainName.Join(InstanceName, simpleServiceName, Domain);
            Resources.Add(new SRVRecord
            {
                Name   = fqn,
                Port   = port,
                Target = HostName
            });
            Resources.Add(new TXTRecord
            {
                Name    = fqn,
                Strings = { "txtvers=1" }
            });

            foreach (var address in addresses ?? MulticastService.GetIPAddresses())
            {
                Resources.Add(AddressRecord.Create(HostName, address));
            }
        }
Пример #3
0
        public void Create()
        {
            var rr = AddressRecord.Create("foo", IPAddress.Loopback);

            Assert.AreEqual("foo", rr.Name);
            Assert.AreEqual(DnsType.A, rr.Type);
            Assert.AreEqual(IPAddress.Loopback, rr.Address);

            rr = AddressRecord.Create("foo", IPAddress.IPv6Loopback);
            Assert.AreEqual("foo", rr.Name);
            Assert.AreEqual(DnsType.AAAA, rr.Type);
            Assert.AreEqual(IPAddress.IPv6Loopback, rr.Address);
        }
Пример #4
0
        public void AuthorityRecords()
        {
            var msg = new Message();

            msg.AuthorityRecords.Add(AddressRecord.Create("foo", IPAddress.Loopback));
            var originalLength = msg.Length();

            msg.AuthorityRecords.Add(AddressRecord.Create("foo", IPAddress.Loopback));
            msg.AdditionalRecords.Add(AddressRecord.Create("foo", IPAddress.Loopback));
            msg.AdditionalRecords.Add(AddressRecord.Create("foo", IPAddress.Loopback));

            msg.Truncate(originalLength);
            Assert.AreEqual(originalLength, msg.Length());
            Assert.AreEqual(0, msg.AdditionalRecords.Count);
            Assert.AreEqual(1, msg.AuthorityRecords.Count);
            Assert.IsFalse(msg.TC);
        }