A simple, go-based DNS resolver/caching server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
910 B

8 years ago
package main
import (
"fmt"
"time"
3 years ago
"crypto/md5"
"github.com/miekg/dns"
)
type KeyNotFound struct {
key string
}
func (e KeyNotFound) Error() string {
return e.key + " " + "not found"
}
type KeyExpired struct {
Key string
}
func (e KeyExpired) Error() string {
return e.Key + " " + "expired"
}
type CacheIsFull struct {
}
func (e CacheIsFull) Error() string {
return "Cache is Full"
}
type SerializerError struct {
err error
}
func (e SerializerError) Error() string {
return fmt.Sprintf("Serializer error: got %v", e.err)
}
type Mesg struct {
Msg *dns.Msg
Expire time.Time
}
type Cache interface {
Get(key string) (Msg *dns.Msg, err error)
Set(key string, Msg *dns.Msg) error
8 years ago
Exists(key string) bool
Remove(key string) error
Full() bool
}
func KeyGen(q Question) string {
h := md5.New()
h.Write([]byte(q.String()))
x := h.Sum(nil)
key := fmt.Sprintf("%x", x)
return key
3 years ago
}