space.go 942 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package internal
  2. import (
  3. "github.com/v2ray/v2ray-core/app"
  4. )
  5. type Space struct {
  6. packetDispatcher PacketDispatcherWithContext
  7. dnsCache DnsCacheWithContext
  8. tag string
  9. }
  10. func NewSpace(tag string, packetDispatcher PacketDispatcherWithContext, dnsCache DnsCacheWithContext) *Space {
  11. return &Space{
  12. tag: tag,
  13. packetDispatcher: packetDispatcher,
  14. dnsCache: dnsCache,
  15. }
  16. }
  17. func (this *Space) HasPacketDispatcher() bool {
  18. return this.packetDispatcher != nil
  19. }
  20. func (this *Space) PacketDispatcher() app.PacketDispatcher {
  21. return &contextedPacketDispatcher{
  22. packetDispatcher: this.packetDispatcher,
  23. context: &contextImpl{
  24. callerTag: this.tag,
  25. },
  26. }
  27. }
  28. func (this *Space) HasDnsCache() bool {
  29. return this.dnsCache != nil
  30. }
  31. func (this *Space) DnsCache() app.DnsCache {
  32. return &contextedDnsCache{
  33. dnsCache: this.dnsCache,
  34. context: &contextImpl{
  35. callerTag: this.tag,
  36. },
  37. }
  38. }