public DateTime? EndPointsResolvedAt;               // The time an attempt was made to resolve the A records for the SRV.

        public SIPDNSServiceResult(SIPServicesEnum sipService, int order, int ttl, string data, int port, DateTime resolvedAt)
        {
            SIPService = sipService;
            Order = order;
            TTL = ttl;
            Data = data;
            Port = port;
            ResolvedAt = resolvedAt;
        }
Exemplo n.º 2
0
        public DateTime?EndPointsResolvedAt;                // The time an attempt was made to resolve the A records for the SRV.

        public SIPDNSServiceResult(SIPServicesEnum sipService, int order, int ttl, string data, int port, DateTime resolvedAt)
        {
            SIPService = sipService;
            Order      = order;
            TTL        = ttl;
            Data       = data;
            Port       = port;
            ResolvedAt = resolvedAt;
        }
Exemplo n.º 3
0
        public DateTime?EndPointsResolvedAt;                // The time an attempt was made to resolve the A records for the SRV.

        public SIPDNSServiceResult(SIPServicesEnum sipService, int priority, int weight, int ttl, string data, int port, DateTime resolvedAt)
        {
            SIPService = sipService;
            Priority   = priority;
            Weight     = weight;
            TTL        = ttl;
            Data       = data;
            Port       = port;
            ResolvedAt = resolvedAt;
        }
        public DateTime? EndPointsResolvedAt;               // The time an attempt was made to resolve the A records for the SRV.

        public SIPDNSServiceResult(SIPServicesEnum sipService, int priority, int weight, int ttl, string data, int port, DateTime resolvedAt)
        {
            SIPService = sipService;
            Priority = priority;
            Weight = weight;
            TTL = ttl;
            Data = data;
            Port = port;
            ResolvedAt = resolvedAt;
        }
Exemplo n.º 5
0
        public void AddSRVResult(SIPServicesEnum service, RecordSRV srvRecord)
        {
            //logger.Debug("Adding record for " + URI.ToString() + " " + srvRecord.ToString() + ".");
            SIPDNSServiceResult sipSRVResult = new SIPDNSServiceResult(service, srvRecord.Priority, srvRecord.RR.TTL, srvRecord.Target, srvRecord.Port, DateTime.Now);

            if (SIPSRVResults == null)
            {
                SIPSRVResults = new List <SIPDNSServiceResult>()
                {
                    sipSRVResult
                };
            }
            else
            {
                SIPSRVResults.Add(sipSRVResult);
            }
        }
Exemplo n.º 6
0
        public static void DNSSRVRecordLookup(SIPSchemesEnum scheme, SIPProtocolsEnum protocol, string host, bool async,
                                              ref SIPDNSLookupResult lookupResult)
        {
            SIPServicesEnum reqdNAPTRService = SIPServicesEnum.none;

            if (scheme == SIPSchemesEnum.sip && protocol == SIPProtocolsEnum.udp)
            {
                reqdNAPTRService = SIPServicesEnum.sipudp;
            }
            else if (scheme == SIPSchemesEnum.sip && protocol == SIPProtocolsEnum.tcp)
            {
                reqdNAPTRService = SIPServicesEnum.siptcp;
            }
            else if (scheme == SIPSchemesEnum.sips && protocol == SIPProtocolsEnum.tcp)
            {
                reqdNAPTRService = SIPServicesEnum.sipstcp;
            }
            else if (scheme == SIPSchemesEnum.sip && protocol == SIPProtocolsEnum.tls)
            {
                reqdNAPTRService = SIPServicesEnum.siptls;
            }

            // If there are NAPTR records available see if there is a matching one for the SIP scheme and protocol required.
            SIPDNSServiceResult naptrService = null;

            if (lookupResult.SIPNAPTRResults != null && lookupResult.SIPNAPTRResults.Count > 0)
            {
                if (reqdNAPTRService != SIPServicesEnum.none &&
                    lookupResult.SIPNAPTRResults.ContainsKey(reqdNAPTRService))
                {
                    naptrService = lookupResult.SIPNAPTRResults[reqdNAPTRService];
                }
            }

            // Construct the SRV target to lookup depending on whether an NAPTR record was available or not.
            string srvLookup = null;

            if (naptrService != null)
            {
                srvLookup = naptrService.Data;
            }
            else
            {
                srvLookup = "_" + scheme.ToString() + "._" + protocol.ToString() + "." + host;
            }
        }
Exemplo n.º 7
0
        public readonly DateTime ValidUntil;                // rj2: Time when DNS-Result becomes invalid, ResolveTime + TimeToLive-Seconds, Member for easy comparison

        public SIPDNSServiceResult(SIPServicesEnum sipService, int priority, int weight, uint ttl, string data, int port, DateTime resolvedAt)
        {
            SIPService = sipService;
            Priority   = priority;
            Weight     = weight;
            TTL        = ttl;
            Data       = data;
            Port       = port;
            ResolvedAt = resolvedAt;
            if (ttl != 0)
            {
                ValidUntil = resolvedAt.AddSeconds(ttl);
            }
            else
            {
                ValidUntil = DateTime.MaxValue;
            }
        }
Exemplo n.º 8
0
        public void AddNAPTRResult(RecordNAPTR naptrRecord)
        {
            //logger.Debug("Checking NAPTR record for " + URI.ToString() + " " + naptrRecord.ToString() + ".");

            SIPServicesEnum sipServicesEnum = SIPServicesEnum.none;

            if (naptrRecord.Service == SIPDNSManager.NAPTR_SIP_UDP_SERVICE)
            {
                sipServicesEnum = SIPServicesEnum.sipudp;
            }
            else if (naptrRecord.Service == SIPDNSManager.NAPTR_SIP_TCP_SERVICE)
            {
                sipServicesEnum = SIPServicesEnum.siptcp;
            }
            else if (naptrRecord.Service == SIPDNSManager.NAPTR_SIPS_TCP_SERVICE)
            {
                sipServicesEnum = SIPServicesEnum.sipstcp;
            }

            if (sipServicesEnum != SIPServicesEnum.none)
            {
                //logger.Debug(" adding NAPTR lookup result for " + URI.ToString() + " of " + naptrRecord.ToString() + ".");
                SIPDNSServiceResult sipNAPTRResult = new SIPDNSServiceResult(sipServicesEnum, naptrRecord.Order, naptrRecord.RR.TTL, naptrRecord.Replacement, 0, DateTime.Now);

                if (SIPNAPTRResults == null)
                {
                    SIPNAPTRResults = new Dictionary <SIPServicesEnum, SIPDNSServiceResult>()
                    {
                        { sipServicesEnum, sipNAPTRResult }
                    };
                }
                else
                {
                    SIPNAPTRResults.Add(sipServicesEnum, sipNAPTRResult);
                }
            }
        }
Exemplo n.º 9
0
        public static void DNSSRVRecordLookup(SIPSchemesEnum scheme, SIPProtocolsEnum protocol, string host, bool async, ref SIPDNSLookupResult lookupResult)
        {
            SIPServicesEnum reqdNAPTRService = SIPServicesEnum.none;

            if (scheme == SIPSchemesEnum.sip && protocol == SIPProtocolsEnum.udp)
            {
                reqdNAPTRService = SIPServicesEnum.sipudp;
            }
            else if (scheme == SIPSchemesEnum.sip && protocol == SIPProtocolsEnum.tcp)
            {
                reqdNAPTRService = SIPServicesEnum.siptcp;
            }
            else if (scheme == SIPSchemesEnum.sips && protocol == SIPProtocolsEnum.tcp)
            {
                reqdNAPTRService = SIPServicesEnum.sipstcp;
            }
            else if (scheme == SIPSchemesEnum.sip && protocol == SIPProtocolsEnum.tls)
            {
                reqdNAPTRService = SIPServicesEnum.siptls;
            }

            // If there are NAPTR records available see if there is a matching one for the SIP scheme and protocol required.
            SIPDNSServiceResult naptrService = null;

            if (lookupResult.SIPNAPTRResults != null && lookupResult.SIPNAPTRResults.Count > 0)
            {
                if (reqdNAPTRService != SIPServicesEnum.none && lookupResult.SIPNAPTRResults.ContainsKey(reqdNAPTRService))
                {
                    naptrService = lookupResult.SIPNAPTRResults[reqdNAPTRService];
                }
            }

            // Construct the SRV target to lookup depending on whether an NAPTR record was available or not.
            string srvLookup = null;

            if (naptrService != null)
            {
                srvLookup = naptrService.Data;
            }
            else
            {
                srvLookup = "_" + scheme.ToString() + "._" + protocol.ToString() + "." + host;
            }

            SIPMonitorLogEvent(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.Unknown, SIPMonitorEventTypesEnum.DNS, "SIP DNS SRV record lookup requested for " + srvLookup + ".", null));

            DNSResponse srvRecordResponse = DNSManager.Lookup(srvLookup, DNSQType.SRV, DNS_LOOKUP_TIMEOUT, null, true, async);

            if (srvRecordResponse == null && async)
            {
                SIPMonitorLogEvent(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.Unknown, SIPMonitorEventTypesEnum.DNS, "SIP DNS SRV record lookup pending for " + srvLookup + ".", null));
                lookupResult.Pending = true;
            }
            else if (srvRecordResponse.Timedout)
            {
                SIPMonitorLogEvent(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.Unknown, SIPMonitorEventTypesEnum.DNS, "SIP DNS SRV record lookup timed out for " + srvLookup + ".", null));
                lookupResult.SRVTimedoutAt = DateTime.Now;
            }
            else if (srvRecordResponse.Error != null)
            {
                SIPMonitorLogEvent(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.Unknown, SIPMonitorEventTypesEnum.DNS, "SIP DNS SRV record lookup for " + srvLookup + " returned error of " + lookupResult.LookupError + ".", null));
            }
            else if (srvRecordResponse.Error == null && srvRecordResponse.RecordSRV != null && srvRecordResponse.RecordSRV.Length > 0)
            {
                foreach (RecordSRV srvRecord in srvRecordResponse.RecordSRV)
                {
                    SIPDNSServiceResult sipSRVResult = new SIPDNSServiceResult(reqdNAPTRService, srvRecord.Priority, srvRecord.Weight, srvRecord.RR.TTL, srvRecord.Target, srvRecord.Port, DateTime.Now);
                    lookupResult.AddSRVResult(sipSRVResult);
                    SIPMonitorLogEvent(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.Unknown, SIPMonitorEventTypesEnum.DNS, "SIP DNS SRV record found for " + srvLookup + ", result " + srvRecord.Target + " " + srvRecord.Port + ".", null));
                }
            }
            else
            {
                SIPMonitorLogEvent(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.Unknown, SIPMonitorEventTypesEnum.DNS, "SIP DNS no SRV records found for " + srvLookup + ".", null));
            }
        }
Exemplo n.º 10
0
        public static void DNSSRVRecordLookup(SIPSchemesEnum scheme, SIPProtocolsEnum protocol, string host, bool async, ref SIPDNSLookupResult lookupResult)
        {
            SIPServicesEnum reqdNAPTRService = SIPServicesEnum.none;

            if (scheme == SIPSchemesEnum.sip && protocol == SIPProtocolsEnum.udp)
            {
                reqdNAPTRService = SIPServicesEnum.sipudp;
            }
            else if (scheme == SIPSchemesEnum.sip && protocol == SIPProtocolsEnum.tcp)
            {
                reqdNAPTRService = SIPServicesEnum.siptcp;
            }
            else if (scheme == SIPSchemesEnum.sips && protocol == SIPProtocolsEnum.tcp)
            {
                reqdNAPTRService = SIPServicesEnum.sipstcp;
            }
            //rj2 2018-10-17: this looks wrong, but the www says: if sips then protocol is _tcp not _tls
            else if (scheme == SIPSchemesEnum.sips && protocol == SIPProtocolsEnum.tls)
            {
                reqdNAPTRService = SIPServicesEnum.sipstcp;
            }
            else if (scheme == SIPSchemesEnum.sip && protocol == SIPProtocolsEnum.tls)
            {
                reqdNAPTRService = SIPServicesEnum.siptls;
            }

            // If there are NAPTR records available see if there is a matching one for the SIP scheme and protocol required.
            // this works best (only works) if protocol in sip-uri matches sip-service of NAPTRRecord
            SIPDNSServiceResult naptrService = null;

            if (lookupResult.SIPNAPTRResults != null && lookupResult.SIPNAPTRResults.Count > 0)
            {
                if (reqdNAPTRService != SIPServicesEnum.none && lookupResult.SIPNAPTRResults.ContainsKey(reqdNAPTRService))
                {
                    naptrService = lookupResult.SIPNAPTRResults[reqdNAPTRService];
                }
            }

            // Construct the SRV target to lookup depending on whether an NAPTR record was available or not.
            string srvLookup = null;

            if (naptrService != null)
            {
                srvLookup = naptrService.Data;
            }
            else
            {
                if (scheme == SIPSchemesEnum.sips)
                {
                    srvLookup = SIPDNSConstants.SRV_SIPS_TCP_QUERY_PREFIX + host;
                }
                else
                {
                    srvLookup = "_" + scheme.ToString() + "._" + protocol.ToString() + "." + host;
                }
            }

            SIPMonitorLogEvent(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.Unknown, SIPMonitorEventTypesEnum.DNS, "SIP DNS SRV record lookup requested for " + srvLookup + ".", null));

            DNSResponse srvRecordResponse = DNSManager.Lookup(srvLookup, QType.SRV, DNS_LOOKUP_TIMEOUT, null, true, async);

            if (srvRecordResponse == null && async)
            {
                SIPMonitorLogEvent(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.Unknown, SIPMonitorEventTypesEnum.DNS, "SIP DNS SRV record lookup pending for " + srvLookup + ".", null));
                lookupResult.Pending = true;
            }
            else if (srvRecordResponse.Timedout)
            {
                SIPMonitorLogEvent(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.Unknown, SIPMonitorEventTypesEnum.DNS, "SIP DNS SRV record lookup timed out for " + srvLookup + ".", null));
                lookupResult.SRVTimedoutAt = DateTime.Now;
            }
            else if (!string.IsNullOrWhiteSpace(srvRecordResponse.Error))
            {
                SIPMonitorLogEvent(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.Unknown, SIPMonitorEventTypesEnum.DNS, "SIP DNS SRV record lookup for " + srvLookup + " returned error of " + lookupResult.LookupError + ".", null));
            }
            else if (string.IsNullOrWhiteSpace(srvRecordResponse.Error) && srvRecordResponse.RecordSRV != null && srvRecordResponse.RecordSRV.Length > 0)
            {
                foreach (RecordSRV srvRecord in srvRecordResponse.RecordSRV)
                {
                    SIPDNSServiceResult sipSRVResult = new SIPDNSServiceResult(reqdNAPTRService, srvRecord.PRIORITY, srvRecord.WEIGHT, srvRecord.RR.TTL, srvRecord.TARGET, srvRecord.PORT, DateTime.Now);
                    lookupResult.AddSRVResult(sipSRVResult);
                    SIPMonitorLogEvent(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.Unknown, SIPMonitorEventTypesEnum.DNS, "SIP DNS SRV record found for " + srvLookup + ", result " + srvRecord.TARGET + " " + srvRecord.PORT + ".", null));
                }
            }
            else
            {
                SIPMonitorLogEvent(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.Unknown, SIPMonitorEventTypesEnum.DNS, "SIP DNS no SRV records found for " + srvLookup + ".", null));
            }
        }
        public void AddSRVResult(SIPServicesEnum service, RecordSRV srvRecord)
        {
            //logger.Debug("Adding record for " + URI.ToString() + " " + srvRecord.ToString() + ".");
            SIPDNSServiceResult sipSRVResult = new SIPDNSServiceResult(service, srvRecord.Priority, srvRecord.RR.TTL, srvRecord.Target, srvRecord.Port, DateTime.Now);

            if (SIPSRVResults == null)
            {
                SIPSRVResults = new List<SIPDNSServiceResult>() { sipSRVResult };
            }
            else
            {
                SIPSRVResults.Add(sipSRVResult);
            }
        }