|  | @@ -1,13 +1,16 @@
 | 
	
		
			
				|  |  |  package registry
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -import "v2ray.com/core/common/loader"
 | 
	
		
			
				|  |  | +import (
 | 
	
		
			
				|  |  | +	"v2ray.com/core/common/loader"
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -var (
 | 
	
		
			
				|  |  | -	inboundConfigCreatorCache = loader.ConfigCreatorCache{}
 | 
	
		
			
				|  |  | -	inboundConfigCache        loader.ConfigLoader
 | 
	
		
			
				|  |  | +	"github.com/golang/protobuf/proto"
 | 
	
		
			
				|  |  | +	"github.com/golang/protobuf/ptypes"
 | 
	
		
			
				|  |  | +	"github.com/golang/protobuf/ptypes/any"
 | 
	
		
			
				|  |  | +)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +var (
 | 
	
		
			
				|  |  | +	inboundConfigCreatorCache  = loader.ConfigCreatorCache{}
 | 
	
		
			
				|  |  |  	outboundConfigCreatorCache = loader.ConfigCreatorCache{}
 | 
	
		
			
				|  |  | -	outboundConfigCache        loader.ConfigLoader
 | 
	
		
			
				|  |  |  )
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  func RegisterInboundConfig(protocol string, creator loader.ConfigCreator) error {
 | 
	
	
		
			
				|  | @@ -18,10 +21,24 @@ func RegisterOutboundConfig(protocol string, creator loader.ConfigCreator) error
 | 
	
		
			
				|  |  |  	return outboundConfigCreatorCache.RegisterCreator(protocol, creator)
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -func CreateInboundConfig(protocol string, data []byte) (interface{}, error) {
 | 
	
		
			
				|  |  | -	return inboundConfigCache.LoadWithID(data, protocol)
 | 
	
		
			
				|  |  | +func MarshalInboundConfig(protocol string, settings *any.Any) (interface{}, error) {
 | 
	
		
			
				|  |  | +	config, err := inboundConfigCreatorCache.CreateConfig(protocol)
 | 
	
		
			
				|  |  | +	if err != nil {
 | 
	
		
			
				|  |  | +		return nil, err
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +	if err := ptypes.UnmarshalAny(settings, config.(proto.Message)); err != nil {
 | 
	
		
			
				|  |  | +		return nil, err
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +	return config, nil
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -func CreateOutboundConfig(protocol string, data []byte) (interface{}, error) {
 | 
	
		
			
				|  |  | -	return outboundConfigCache.LoadWithID(data, protocol)
 | 
	
		
			
				|  |  | +func MarshalOutboundConfig(protocol string, settings *any.Any) (interface{}, error) {
 | 
	
		
			
				|  |  | +	config, err := outboundConfigCreatorCache.CreateConfig(protocol)
 | 
	
		
			
				|  |  | +	if err != nil {
 | 
	
		
			
				|  |  | +		return nil, err
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +	if err := ptypes.UnmarshalAny(settings, config.(proto.Message)); err != nil {
 | 
	
		
			
				|  |  | +		return nil, err
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +	return config, nil
 | 
	
		
			
				|  |  |  }
 |