コード例 #1
0
ファイル: handler_cache.go プロジェクト: xyz12810/v2ray-core
func CreateInboundHandler(name string, space app.Space, config interface{}, meta *proxy.InboundHandlerMeta) (proxy.InboundHandler, error) {
	creator, found := inboundFactories[name]
	if !found {
		return nil, errors.New("Proxy|Registry: Unknown inbound name: " + name)
	}
	if meta.StreamSettings == nil {
		meta.StreamSettings = &internet.StreamConfig{
			Network: creator.StreamCapability().Get(0),
		}
	} else {
		if !creator.StreamCapability().HasNetwork(meta.StreamSettings.Network) {
			return nil, errors.New("Proxy|Registry: Invalid network: " + meta.StreamSettings.Network.String())
		}
	}

	return creator.Create(space, config, meta)
}
コード例 #2
0
ファイル: handler_cache.go プロジェクト: DZLZHCODE/v2ray-core
func CreateInboundHandler(name string, space app.Space, rawConfig []byte, meta *proxy.InboundHandlerMeta) (proxy.InboundHandler, error) {
	creator, found := inboundFactories[name]
	if !found {
		return nil, common.ErrObjectNotFound
	}
	if meta.StreamSettings == nil {
		meta.StreamSettings = &internet.StreamSettings{
			Type: creator.StreamCapability(),
		}
	} else {
		meta.StreamSettings.Type &= creator.StreamCapability()
	}

	if len(rawConfig) > 0 {
		proxyConfig, err := CreateInboundConfig(name, rawConfig)
		if err != nil {
			return nil, err
		}
		return creator.Create(space, proxyConfig, meta)
	}
	return creator.Create(space, nil, meta)
}