|  | @@ -1,74 +1,16 @@
 | 
											
												
													
														|  |  package app
 |  |  package app
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | 
 |  | +// Context of a function call from proxy to app.
 | 
											
												
													
														|  |  type Context interface {
 |  |  type Context interface {
 | 
											
												
													
														|  |  	CallerTag() string
 |  |  	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 {
 |  | 
 | 
											
												
													
														|  | -		this.packetDispatcher = packetDispatcher
 |  | 
 | 
											
												
													
														|  | -	}
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -	if dnsCache, ok := object.(DnsCacheWithContext); ok {
 |  | 
 | 
											
												
													
														|  | -		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
 |  | 
 | 
											
												
													
														|  | -}
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -func (this *Space) HasDnsCache() bool {
 |  | 
 | 
											
												
													
														|  | -	return this.dnsCache != nil
 |  | 
 | 
											
												
													
														|  | -}
 |  | 
 | 
											
												
													
														|  | 
 |  | +// A Space contains all apps that may be available in a V2Ray runtime.
 | 
											
												
													
														|  | 
 |  | +// Caller must check the availability of an app by calling HasXXX before getting its instance.
 | 
											
												
													
														|  | 
 |  | +type Space interface {
 | 
											
												
													
														|  | 
 |  | +	HasPacketDispatcher() bool
 | 
											
												
													
														|  | 
 |  | +	PacketDispatcher() PacketDispatcher
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -func (this *Space) DnsCache() DnsCache {
 |  | 
 | 
											
												
													
														|  | -	return this.dnsCache
 |  | 
 | 
											
												
													
														|  | 
 |  | +	HasDnsCache() bool
 | 
											
												
													
														|  | 
 |  | +	DnsCache() DnsCache
 | 
											
												
													
														|  |  }
 |  |  }
 |