implement cache eviction

This commit is contained in:
Miek Gieben 2012-08-08 11:52:54 +02:00
parent f335343759
commit d6cc21a0aa
2 changed files with 4 additions and 5 deletions

View File

@ -48,7 +48,6 @@ func NewCache() *Cache {
func (c *Cache) Evict() {
// A bit tedious, keys() -> find() -> remove()
for _, key := range c.Radix.Keys() {
log.Printf("look for key %s\n", key)
node := c.Radix.Find(key)
if node == nil {
continue
@ -56,7 +55,7 @@ func (c *Cache) Evict() {
if time.Since(node.Value.(*Packet).ttl) > TTL {
c.Radix.Remove(key)
if *flaglog {
log.Printf("fsk-shield: evicting %s\n", key)
log.Printf("fks-shield: evicting %s\n", key)
}
}
}

View File

@ -18,6 +18,9 @@ var (
func serve(w dns.ResponseWriter, r *dns.Msg, c *Cache) {
// only do queries not dynamic updates
if *flaglog {
log.Printf("fks-shield: query")
}
if p := c.Find(r); p != nil {
dns.RawSetId(p, r.MsgHdr.Id)
w.WriteBuf(p)
@ -26,9 +29,6 @@ func serve(w dns.ResponseWriter, r *dns.Msg, c *Cache) {
// Cache miss
client := new(dns.Client)
if p, e := client.Exchange(r, *server); e == nil {
if *flaglog {
log.Printf("fks-shield: cache miss")
}
// TODO(mg): If r has edns0 and p has not we create a mismatch here
w.Write(p)
c.Insert(p)