dns.go 724 B

123456789101112131415161718192021222324252627282930313233343536373839
  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 init() {
  24. app.Register(APP_ID, func(context app.Context, obj interface{}) interface{} {
  25. dcContext := obj.(dnsServerWithContext)
  26. return &contextedDnsServer{
  27. context: context,
  28. dnsCache: dcContext,
  29. }
  30. })
  31. }