1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-07-15 09:44:37 -04:00
v2fly/app/controller/controller.go

42 lines
1.2 KiB
Go

package controller
import (
"github.com/v2ray/v2ray-core/app"
"github.com/v2ray/v2ray-core/app/internal"
)
// A SpaceController is supposed to be used by a shell to create Spaces. It should not be used
// directly by proxies.
type SpaceController struct {
packetDispatcher internal.PacketDispatcherWithContext
dnsCache internal.DnsCacheWithContext
pubsub internal.PubsubWithContext
inboundHandlerManager internal.InboundHandlerManagerWithContext
}
func New() *SpaceController {
return new(SpaceController)
}
func (this *SpaceController) Bind(object interface{}) {
if packetDispatcher, ok := object.(internal.PacketDispatcherWithContext); ok {
this.packetDispatcher = packetDispatcher
}
if dnsCache, ok := object.(internal.DnsCacheWithContext); ok {
this.dnsCache = dnsCache
}
if pubsub, ok := object.(internal.PubsubWithContext); ok {
this.pubsub = pubsub
}
if inboundHandlerManager, ok := object.(internal.InboundHandlerManagerWithContext); ok {
this.inboundHandlerManager = inboundHandlerManager
}
}
func (this *SpaceController) ForContext(tag string) app.Space {
return internal.NewSpace(tag, this.packetDispatcher, this.dnsCache, this.pubsub, this.inboundHandlerManager)
}