예제 #1
0
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
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)
}