space.go 1.2 KB

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