1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-25 17:05:23 +00:00
v2fly/app/dns/dns.go
2016-05-16 00:25:34 -07:00

40 lines
724 B
Go

package dns
import (
"net"
"github.com/v2ray/v2ray-core/app"
)
const (
APP_ID = app.ID(2)
)
// A DnsCache is an internal cache of DNS resolutions.
type Server interface {
Get(domain string) []net.IP
}
type dnsServerWithContext interface {
Get(context app.Context, domain string) []net.IP
}
type contextedDnsServer struct {
context app.Context
dnsCache dnsServerWithContext
}
func (this *contextedDnsServer) Get(domain string) []net.IP {
return this.dnsCache.Get(this.context, domain)
}
func init() {
app.Register(APP_ID, func(context app.Context, obj interface{}) interface{} {
dcContext := obj.(dnsServerWithContext)
return &contextedDnsServer{
context: context,
dnsCache: dcContext,
}
})
}