Пример #1
0
        DNSEntity GetDNS(String key, DNSEntity request)
        {
            // 批量请求父级代理
            var dic = DNSClient.QueryAll(_Clients, request);

            if (dic.Count == 0)
            {
                return(null);
            }

            DNSEntity rs = null;

            foreach (var item in dic)
            {
                rs = item.Value;
                var nc = item.Key.Client;

                WriteLog("{0} GetDNS {1}", nc.Remote, rs);

                if (OnNew != null)
                {
                    var e = new DNSEventArgs {
                        Request = request, Response = item.Value, Session = nc
                    };
                    OnNew(this, e);
                }
            }

            return(rs);
        }
Пример #2
0
        /// <summary>启动服务</summary>
        protected override void OnStart()
        {
            // 如果没有设置父级DNS,则使用本地DNS
            var ps = Parents;

            if (ps.Count == 0)
            {
                ps.AddRange(GetLocalDNS());
            }

            base.OnStart();

            // 准备连接
            _Clients = new List <DNSClient>();
            foreach (var item in Parents.ToArray())
            {
                var nc = new DNSClient(item);
                TaskEx.Run(() =>
                {
                    if (nc.Open())
                    {
                        WriteLog("已连接父级DNS:{0}", nc.Client.Remote);
                        lock (_Clients) { _Clients.Add(nc); }
                    }
                });
            }
        }