controller.go 987 B

123456789101112131415161718192021222324252627282930313233343536
  1. package controller
  2. import (
  3. "github.com/v2ray/v2ray-core/app"
  4. "github.com/v2ray/v2ray-core/app/internal"
  5. )
  6. // A SpaceController is supposed to be used by a shell to create Spaces. It should not be used
  7. // directly by proxies.
  8. type SpaceController struct {
  9. packetDispatcher internal.PacketDispatcherWithContext
  10. dnsCache internal.DnsCacheWithContext
  11. pubsub internal.PubsubWithContext
  12. }
  13. func New() *SpaceController {
  14. return new(SpaceController)
  15. }
  16. func (this *SpaceController) Bind(object interface{}) {
  17. if packetDispatcher, ok := object.(internal.PacketDispatcherWithContext); ok {
  18. this.packetDispatcher = packetDispatcher
  19. }
  20. if dnsCache, ok := object.(internal.DnsCacheWithContext); ok {
  21. this.dnsCache = dnsCache
  22. }
  23. if pubsub, ok := object.(internal.PubsubWithContext); ok {
  24. this.pubsub = pubsub
  25. }
  26. }
  27. func (this *SpaceController) ForContext(tag string) app.Space {
  28. return internal.NewSpace(tag, this.packetDispatcher, this.dnsCache, this.pubsub)
  29. }