|
|
@@ -23,6 +23,7 @@ type DomainRecord struct {
|
|
|
type CacheServer struct {
|
|
|
sync.RWMutex
|
|
|
space app.Space
|
|
|
+ hosts map[string]net.IP
|
|
|
records map[string]*DomainRecord
|
|
|
servers []NameServer
|
|
|
}
|
|
|
@@ -31,6 +32,7 @@ func NewCacheServer(space app.Space, config *Config) *CacheServer {
|
|
|
server := &CacheServer{
|
|
|
records: make(map[string]*DomainRecord),
|
|
|
servers: make([]NameServer, len(config.NameServers)),
|
|
|
+ hosts: config.Hosts,
|
|
|
}
|
|
|
space.InitializeApplication(func() error {
|
|
|
if !space.HasApp(dispatcher.APP_ID) {
|
|
|
@@ -46,6 +48,9 @@ func NewCacheServer(space app.Space, config *Config) *CacheServer {
|
|
|
server.servers[idx] = NewUDPNameServer(ns, dispatcher)
|
|
|
}
|
|
|
}
|
|
|
+ if len(config.NameServers) == 0 {
|
|
|
+ server.servers = append(server.servers, &LocalNameServer{})
|
|
|
+ }
|
|
|
return nil
|
|
|
})
|
|
|
return server
|
|
|
@@ -67,6 +72,10 @@ func (this *CacheServer) GetCached(domain string) []net.IP {
|
|
|
}
|
|
|
|
|
|
func (this *CacheServer) Get(domain string) []net.IP {
|
|
|
+ if ip, found := this.hosts[domain]; found {
|
|
|
+ return []net.IP{ip}
|
|
|
+ }
|
|
|
+
|
|
|
domain = dns.Fqdn(domain)
|
|
|
ips := this.GetCached(domain)
|
|
|
if ips != nil {
|