dns.go 806 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package dns
  2. import (
  3. "net"
  4. "github.com/v2ray/v2ray-core/app"
  5. )
  6. const (
  7. APP_ID = app.ID(2)
  8. )
  9. // A DnsCache is an internal cache of DNS resolutions.
  10. type Server interface {
  11. Get(domain string) []net.IP
  12. }
  13. type dnsServerWithContext interface {
  14. Get(context app.Context, domain string) []net.IP
  15. }
  16. type contextedDnsServer struct {
  17. context app.Context
  18. dnsCache dnsServerWithContext
  19. }
  20. func (this *contextedDnsServer) Get(domain string) []net.IP {
  21. return this.dnsCache.Get(this.context, domain)
  22. }
  23. func CreateDNSServer(rawConfig interface{}) (Server, error) {
  24. return nil, nil
  25. }
  26. func init() {
  27. app.Register(APP_ID, func(context app.Context, obj interface{}) interface{} {
  28. dcContext := obj.(dnsServerWithContext)
  29. return &contextedDnsServer{
  30. context: context,
  31. dnsCache: dcContext,
  32. }
  33. })
  34. }