space.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. inboundHandlerManager InboundHandlerManagerWithContext
  10. tag string
  11. }
  12. func NewSpace(tag string, packetDispatcher PacketDispatcherWithContext, dnsCache DnsCacheWithContext, pubsub PubsubWithContext, inboundHandlerManager InboundHandlerManagerWithContext) *Space {
  13. return &Space{
  14. tag: tag,
  15. packetDispatcher: packetDispatcher,
  16. dnsCache: dnsCache,
  17. pubsub: pubsub,
  18. inboundHandlerManager: inboundHandlerManager,
  19. }
  20. }
  21. func (this *Space) HasPacketDispatcher() bool {
  22. return this.packetDispatcher != nil
  23. }
  24. func (this *Space) PacketDispatcher() app.PacketDispatcher {
  25. return &contextedPacketDispatcher{
  26. packetDispatcher: this.packetDispatcher,
  27. context: &contextImpl{
  28. callerTag: this.tag,
  29. },
  30. }
  31. }
  32. func (this *Space) HasDnsCache() bool {
  33. return this.dnsCache != nil
  34. }
  35. func (this *Space) DnsCache() app.DnsCache {
  36. return &contextedDnsCache{
  37. dnsCache: this.dnsCache,
  38. context: &contextImpl{
  39. callerTag: this.tag,
  40. },
  41. }
  42. }
  43. func (this *Space) HasPubsub() bool {
  44. return this.pubsub != nil
  45. }
  46. func (this *Space) Pubsub() app.Pubsub {
  47. return &contextedPubsub{
  48. pubsub: this.pubsub,
  49. context: &contextImpl{
  50. callerTag: this.tag,
  51. },
  52. }
  53. }
  54. func (this *Space) HasInboundHandlerManager() bool {
  55. return this.inboundHandlerManager != nil
  56. }
  57. func (this *Space) InboundHandlerManager() app.InboundHandlerManager {
  58. return &inboundHandlerManagerWithContext{
  59. manager: this.inboundHandlerManager,
  60. context: &contextImpl{
  61. callerTag: this.tag,
  62. },
  63. }
  64. }