Add initial proxy support. Fixes openziti/fabric#775

This commit is contained in:
Paul Lorenz
2023-08-16 12:12:40 -04:00
parent 4e18a63325
commit 33a443c264
3 changed files with 29 additions and 12 deletions
+13
View File
@@ -138,6 +138,7 @@ type Config struct {
InitialDelay time.Duration
}
}
Proxy *transport.ProxyConfiguration
Plugins []string
src map[interface{}]interface{}
path string
@@ -712,6 +713,18 @@ func LoadConfig(path string) (*Config, error) {
}
}
if value, found := cfgmap[transport.KeyProxy]; found {
if proxyMap, ok := value.(map[interface{}]interface{}); ok {
proxyConfig, err := transport.LoadProxyConfiguration(proxyMap)
if err != nil {
return nil, err
}
cfg.Proxy = proxyConfig
} else {
pfxlog.Logger().Warn("invalid proxy configuration, must be map")
}
}
return cfg, nil
}
+14 -3
View File
@@ -389,7 +389,15 @@ func (self *Router) registerComponents() error {
self.metricsRegistry,
self.xlinkRegistry,
)
self.xlinkFactories["transport"] = xlink_transport.NewFactory(xlinkAccepter, xlinkChAccepter, self.config.Transport, self.xlinkRegistry, self.metricsRegistry)
linkTransportConfig := map[interface{}]interface{}{}
for k, v := range self.config.Transport {
linkTransportConfig[k] = v
}
linkTransportConfig[transport.KeyCachedProxyConfiguration] = self.config.Proxy
linkTransportConfig[transport.KeyProtocol] = append(transport.Configuration(self.config.Transport).Protocols(), "ziti-link")
self.xlinkFactories["transport"] = xlink_transport.NewFactory(xlinkAccepter, xlinkChAccepter, linkTransportConfig, self.xlinkRegistry, self.metricsRegistry)
xgress.GlobalRegistry().Register("proxy", xgress_proxy.NewFactory(self.config.Id, self.ctrls, self.config.Transport))
xgress.GlobalRegistry().Register("proxy_udp", xgress_proxy_udp.NewFactory(self.ctrls))
@@ -462,7 +470,7 @@ func (self *Router) startXlinkListeners() {
}
if factory, found := self.xlinkFactories[binding]; found {
lmap["protocol"] = "ziti-link"
lmap[transport.KeyProtocol] = "ziti-link"
listener, err := factory.CreateListener(self.config.Id, self.forwarder, lmap)
if err != nil {
logrus.Fatalf("error creating Xlink listener (%v)", err)
@@ -602,7 +610,10 @@ func (self *Router) connectToController(addr transport.Address, bindHandler chan
dialer := channel.NewReconnectingDialerWithHandlerAndLocalBinding(self.config.Id, addr, self.config.Ctrl.LocalBinding, attributes, reconnectHandler)
bindHandler = channel.BindHandlers(bindHandler, self.ctrlBindhandler)
tcfg := transport.Configuration{"protocol": "ziti-ctrl"}
tcfg := transport.Configuration{
transport.KeyProtocol: "ziti-ctrl",
transport.KeyCachedProxyConfiguration: self.config.Proxy,
}
ch, err := channel.NewChannelWithTransportConfiguration("ctrl", dialer, bindHandler, self.config.Ctrl.Options, tcfg)
if err != nil {
return fmt.Errorf("error connecting ctrl (%v)", err)
+2 -9
View File
@@ -50,21 +50,14 @@ func (self channelType) String() string {
func NewFactory(accepter xlink.Acceptor,
bindHandlerFactory BindHandlerFactory,
c transport.Configuration,
tcfg transport.Configuration,
xlinkRegistry xlink.Registry,
metricsRegistry metrics.Registry) xlink.Factory {
cfg := make(transport.Configuration)
for k, v := range c {
cfg[k] = v
}
cfg["protocol"] = append(c.Protocols(), "ziti-link")
return &factory{
acceptor: accepter,
bindHandlerFactory: bindHandlerFactory,
transportConfig: cfg,
transportConfig: tcfg,
xlinkRegistry: xlinkRegistry,
metricsRegistry: metricsRegistry,
}