You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
v2ray-core/app/space.go

75 lines
1.5 KiB

package app
type Context interface {
CallerTag() string
}
type contextImpl struct {
callerTag string
}
func (this *contextImpl) CallerTag() string {
return this.callerTag
}
type SpaceController struct {
packetDispatcher PacketDispatcherWithContext
dnsCache DnsCacheWithContext
}
func NewSpaceController() *SpaceController {
return new(SpaceController)
}
func (this *SpaceController) Bind(object interface{}) {
if packetDispatcher, ok := object.(PacketDispatcherWithContext); ok {
9 years ago
this.packetDispatcher = packetDispatcher
}
if dnsCache, ok := object.(DnsCacheWithContext); ok {
9 years ago
this.dnsCache = dnsCache
}
}
func (this *SpaceController) ForContext(tag string) *Space {
return newSpace(this, &contextImpl{callerTag: tag})
}
type Space struct {
packetDispatcher PacketDispatcher
dnsCache DnsCache
}
func newSpace(controller *SpaceController, context Context) *Space {
space := new(Space)
if controller.packetDispatcher != nil {
space.packetDispatcher = &contextedPacketDispatcher{
context: context,
packetDispatcher: controller.packetDispatcher,
}
}
if controller.dnsCache != nil {
space.dnsCache = &contextedDnsCache{
context: context,
dnsCache: controller.dnsCache,
}
}
return space
}
func (this *Space) HasPacketDispatcher() bool {
return this.packetDispatcher != nil
}
func (this *Space) PacketDispatcher() PacketDispatcher {
return this.packetDispatcher
}
9 years ago
func (this *Space) HasDnsCache() bool {
return this.dnsCache != nil
}
func (this *Space) DnsCache() DnsCache {
return this.dnsCache
}