3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-23 03:02:48 +01:00

Merge pull request #795 from slingamn/issue794_nolisten

fix #794
This commit is contained in:
Shivaram Lingamneni 2020-02-22 20:06:46 -08:00 committed by GitHub
commit d77e6c1a28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -313,10 +313,7 @@ type Config struct {
Listeners map[string]listenerConfigBlock Listeners map[string]listenerConfigBlock
UnixBindMode os.FileMode `yaml:"unix-bind-mode"` UnixBindMode os.FileMode `yaml:"unix-bind-mode"`
TorListeners TorListenersConfig `yaml:"tor-listeners"` TorListeners TorListenersConfig `yaml:"tor-listeners"`
// Listen and TLSListeners are the legacy style: // they get parsed into this internal representation:
Listen []string
TLSListeners map[string]TLSListenConfig `yaml:"tls-listeners"`
// either way, the result is this:
trueListeners map[string]listenerConfig trueListeners map[string]listenerConfig
STS STSConfig STS STSConfig
LookupHostnames *bool `yaml:"lookup-hostnames"` LookupHostnames *bool `yaml:"lookup-hostnames"`
@ -558,49 +555,28 @@ func loadTlsConfig(config TLSListenConfig) (tlsConfig *tls.Config, err error) {
// prepareListeners populates Config.Server.trueListeners // prepareListeners populates Config.Server.trueListeners
func (conf *Config) prepareListeners() (err error) { func (conf *Config) prepareListeners() (err error) {
listeners := make(map[string]listenerConfig) if len(conf.Server.Listeners) == 0 {
if 0 < len(conf.Server.Listeners) {
for addr, block := range conf.Server.Listeners {
var lconf listenerConfig
lconf.Tor = block.Tor
lconf.STSOnly = block.STSOnly
if lconf.STSOnly && !conf.Server.STS.Enabled {
return fmt.Errorf("%s is configured as a STS-only listener, but STS is disabled", addr)
}
if block.TLS.Cert != "" {
tlsConfig, err := loadTlsConfig(block.TLS)
if err != nil {
return err
}
lconf.TLSConfig = tlsConfig
lconf.ProxyBeforeTLS = block.TLS.Proxy
}
listeners[addr] = lconf
}
} else if 0 < len(conf.Server.Listen) {
log.Printf("WARNING: configuring listeners via the legacy `server.listen` config option")
log.Printf("This will be removed in a later release: you should update to use `server.listeners`")
torListeners := make(map[string]bool, len(conf.Server.TorListeners.Listeners))
for _, addr := range conf.Server.TorListeners.Listeners {
torListeners[addr] = true
}
for _, addr := range conf.Server.Listen {
var lconf listenerConfig
lconf.Tor = torListeners[addr]
tlsListenConf, ok := conf.Server.TLSListeners[addr]
if ok {
tlsConfig, err := loadTlsConfig(tlsListenConf)
if err != nil {
return err
}
lconf.TLSConfig = tlsConfig
}
listeners[addr] = lconf
}
} else {
return fmt.Errorf("No listeners were configured") return fmt.Errorf("No listeners were configured")
} }
conf.Server.trueListeners = listeners
conf.Server.trueListeners = make(map[string]listenerConfig)
for addr, block := range conf.Server.Listeners {
var lconf listenerConfig
lconf.Tor = block.Tor
lconf.STSOnly = block.STSOnly
if lconf.STSOnly && !conf.Server.STS.Enabled {
return fmt.Errorf("%s is configured as a STS-only listener, but STS is disabled", addr)
}
if block.TLS.Cert != "" {
tlsConfig, err := loadTlsConfig(block.TLS)
if err != nil {
return err
}
lconf.TLSConfig = tlsConfig
lconf.ProxyBeforeTLS = block.TLS.Proxy
}
conf.Server.trueListeners[addr] = lconf
}
return nil return nil
} }