UDP support
Co-authored-by: Julien Salleyron <julien.salleyron@gmail.com>
This commit is contained in:
parent
8988c8f9af
commit
115d42e0f0
72 changed files with 4730 additions and 321 deletions
|
@ -22,11 +22,13 @@ type Configuration struct {
|
|||
Services map[string]*ServiceInfo `json:"services,omitempty"`
|
||||
TCPRouters map[string]*TCPRouterInfo `json:"tcpRouters,omitempty"`
|
||||
TCPServices map[string]*TCPServiceInfo `json:"tcpServices,omitempty"`
|
||||
UDPRouters map[string]*UDPRouterInfo `json:"udpRouters,omitempty"`
|
||||
UDPServices map[string]*UDPServiceInfo `json:"updServices,omitempty"`
|
||||
}
|
||||
|
||||
// NewConfig returns a Configuration initialized with the given conf. It never returns nil.
|
||||
func NewConfig(conf dynamic.Configuration) *Configuration {
|
||||
if conf.HTTP == nil && conf.TCP == nil {
|
||||
if conf.HTTP == nil && conf.TCP == nil && conf.UDP == nil {
|
||||
return &Configuration{}
|
||||
}
|
||||
|
||||
|
@ -74,6 +76,22 @@ func NewConfig(conf dynamic.Configuration) *Configuration {
|
|||
}
|
||||
}
|
||||
|
||||
if conf.UDP != nil {
|
||||
if len(conf.UDP.Routers) > 0 {
|
||||
runtimeConfig.UDPRouters = make(map[string]*UDPRouterInfo, len(conf.UDP.Routers))
|
||||
for k, v := range conf.UDP.Routers {
|
||||
runtimeConfig.UDPRouters[k] = &UDPRouterInfo{UDPRouter: v, Status: StatusEnabled}
|
||||
}
|
||||
}
|
||||
|
||||
if len(conf.UDP.Services) > 0 {
|
||||
runtimeConfig.UDPServices = make(map[string]*UDPServiceInfo, len(conf.UDP.Services))
|
||||
for k, v := range conf.UDP.Services {
|
||||
runtimeConfig.UDPServices[k] = &UDPServiceInfo{UDPService: v, Status: StatusEnabled}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return runtimeConfig
|
||||
}
|
||||
|
||||
|
@ -158,6 +176,34 @@ func (c *Configuration) PopulateUsedBy() {
|
|||
|
||||
sort.Strings(c.TCPServices[k].UsedBy)
|
||||
}
|
||||
|
||||
for routerName, routerInfo := range c.UDPRouters {
|
||||
// lazily initialize Status in case caller forgot to do it
|
||||
if routerInfo.Status == "" {
|
||||
routerInfo.Status = StatusEnabled
|
||||
}
|
||||
|
||||
providerName := getProviderName(routerName)
|
||||
if providerName == "" {
|
||||
logger.WithField(log.RouterName, routerName).Error("udp router name is not fully qualified")
|
||||
continue
|
||||
}
|
||||
|
||||
serviceName := getQualifiedName(providerName, routerInfo.UDPRouter.Service)
|
||||
if _, ok := c.UDPServices[serviceName]; !ok {
|
||||
continue
|
||||
}
|
||||
c.UDPServices[serviceName].UsedBy = append(c.UDPServices[serviceName].UsedBy, routerName)
|
||||
}
|
||||
|
||||
for k, serviceInfo := range c.UDPServices {
|
||||
// lazily initialize Status in case caller forgot to do it
|
||||
if serviceInfo.Status == "" {
|
||||
serviceInfo.Status = StatusEnabled
|
||||
}
|
||||
|
||||
sort.Strings(c.UDPServices[k].UsedBy)
|
||||
}
|
||||
}
|
||||
|
||||
func contains(entryPoints []string, entryPointName string) bool {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue