Example #1
0
        protected override bool Receive(object message)
        {
            var resolve = message as Dns.Resolve;

            if (resolve != null)
            {
                var answer = _cache.Cached(resolve.Name);
                if (answer == null)
                {
                    try
                    {
                        //TODO: IP6
                        answer = Dns.Resolved.Create(resolve.Name, System.Net.Dns.GetHostEntry(resolve.Name).AddressList.Where(x => x.AddressFamily == AddressFamily.InterNetwork));
                        _cache.Put(answer, _positiveTtl);
                    }
                    catch (SocketException ex)
                    {
                        if (ex.SocketErrorCode != SocketError.HostNotFound)
                        {
                            throw;
                        }
                        answer = new Dns.Resolved(resolve.Name, Enumerable.Empty <IPAddress>(), Enumerable.Empty <IPAddress>());
                        _cache.Put(answer, _negativeTtl);
                    }
                }
                Sender.Tell(answer);
                return(true);
            }
            return(false);
        }
Example #2
0
            public Cache Put(Dns.Resolved answer, long ttl)
            {
                var until = _clock() + ttl;

                _queue.Add(new ExpiryEntry(answer.Name, until));
                _cache.Add(answer.Name, new CacheEntry(answer, until));
                return(this);
            }
Example #3
0
        /// <summary>
        /// TBD
        /// </summary>
        /// <param name="r">TBD</param>
        /// <param name="ttl">TBD</param>
        /// <returns>TBD</returns>
        internal void Put(Dns.Resolved r, long ttl)
        {
            var c = _cache.Value;

            if (!_cache.CompareAndSet(c, c.Put(r, ttl)))
            {
                Put(r, ttl);
            }
        }
Example #4
0
            public Cache Put(Dns.Resolved answer, long ttl)
            {
                var until = _clock() + ttl;

                var cache = new Dictionary <string, CacheEntry>(_cache);

                cache[answer.Name] = new CacheEntry(answer, until);

                return(new Cache(
                           queue: new SortedSet <ExpiryEntry>(_queue, new ExpiryEntryComparer())
                {
                    new ExpiryEntry(answer.Name, until)
                },
                           cache: cache,
                           clock: _clock));
            }
Example #5
0
 public CacheEntry(Dns.Resolved answer, long until)
 {
     Answer = answer;
     Until  = until;
 }