1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-28 18:25:23 +00:00
v2fly/app/dns/dns.go

44 lines
806 B
Go
Raw Normal View History

2015-12-06 10:00:10 +00:00
package dns
import (
"net"
2015-12-10 22:55:39 +00:00
"github.com/v2ray/v2ray-core/app"
2015-12-06 10:00:10 +00:00
)
2016-01-31 16:01:28 +00:00
const (
APP_ID = app.ID(2)
)
2015-12-06 10:00:10 +00:00
2016-01-31 16:01:28 +00:00
// A DnsCache is an internal cache of DNS resolutions.
2016-05-16 06:09:28 +00:00
type Server interface {
Get(domain string) []net.IP
2015-12-06 10:00:10 +00:00
}
2016-05-16 06:09:28 +00:00
type dnsServerWithContext interface {
Get(context app.Context, domain string) []net.IP
2015-12-06 10:00:10 +00:00
}
2016-05-16 06:09:28 +00:00
type contextedDnsServer struct {
2016-01-31 16:01:28 +00:00
context app.Context
2016-05-16 06:09:28 +00:00
dnsCache dnsServerWithContext
2015-12-06 10:00:10 +00:00
}
2016-05-16 06:09:28 +00:00
func (this *contextedDnsServer) Get(domain string) []net.IP {
2016-01-31 16:01:28 +00:00
return this.dnsCache.Get(this.context, domain)
2015-12-06 10:00:10 +00:00
}
2016-05-16 06:09:28 +00:00
func CreateDNSServer(rawConfig interface{}) (Server, error) {
return nil, nil
2015-12-06 10:00:10 +00:00
}
2016-01-31 16:01:28 +00:00
func init() {
2016-05-11 19:05:58 +00:00
app.Register(APP_ID, func(context app.Context, obj interface{}) interface{} {
2016-05-16 06:09:28 +00:00
dcContext := obj.(dnsServerWithContext)
return &contextedDnsServer{
2016-01-31 16:01:28 +00:00
context: context,
dnsCache: dcContext,
}
})
2015-12-06 10:00:10 +00:00
}