Clean up code inside the configuration loaders
This commit is contained in:
@@ -170,32 +170,10 @@ func (c Configuration) Verify() error {
|
|||||||
|
|
||||||
// Common returns common settings
|
// Common returns common settings
|
||||||
func (c Configuration) Common() Common {
|
func (c Configuration) Common() Common {
|
||||||
dialer := c.Dialer
|
|
||||||
|
|
||||||
if dialer == nil {
|
|
||||||
dialer = network.TCPDial()
|
|
||||||
}
|
|
||||||
|
|
||||||
if c.OnlyAllowPresetRemotes {
|
|
||||||
accessList := make(network.AllowedHosts, len(c.Presets))
|
|
||||||
|
|
||||||
for _, k := range c.Presets {
|
|
||||||
accessList[k.Host] = struct{}{}
|
|
||||||
}
|
|
||||||
|
|
||||||
dialer = network.AccessControlDial(accessList, dialer)
|
|
||||||
}
|
|
||||||
|
|
||||||
dialTimeout := c.DialTimeout
|
|
||||||
|
|
||||||
if dialTimeout <= 1*time.Second {
|
|
||||||
dialTimeout = 1 * time.Second
|
|
||||||
}
|
|
||||||
|
|
||||||
return Common{
|
return Common{
|
||||||
HostName: c.HostName,
|
HostName: c.HostName,
|
||||||
SharedKey: c.SharedKey,
|
SharedKey: c.SharedKey,
|
||||||
Dialer: dialer,
|
Dialer: c.Dialer,
|
||||||
DialTimeout: c.DialTimeout,
|
DialTimeout: c.DialTimeout,
|
||||||
Presets: c.Presets,
|
Presets: c.Presets,
|
||||||
OnlyAllowPresetRemotes: c.OnlyAllowPresetRemotes,
|
OnlyAllowPresetRemotes: c.OnlyAllowPresetRemotes,
|
||||||
|
|||||||
@@ -57,6 +57,10 @@ func Enviro() Loader {
|
|||||||
Socks5: parseEviro("SSHWIFTY_SOCKS5"),
|
Socks5: parseEviro("SSHWIFTY_SOCKS5"),
|
||||||
Socks5User: parseEviro("SSHWIFTY_SOCKS5_USER"),
|
Socks5User: parseEviro("SSHWIFTY_SOCKS5_USER"),
|
||||||
Socks5Password: parseEviro("SSHWIFTY_SOCKS5_PASSWORD"),
|
Socks5Password: parseEviro("SSHWIFTY_SOCKS5_PASSWORD"),
|
||||||
|
Servers: nil,
|
||||||
|
Presets: nil,
|
||||||
|
OnlyAllowPresetRemotes: len(
|
||||||
|
parseEviro("SSHWIFTY_ONLYALLOWPRESETREMOTES")) > 0,
|
||||||
}.build()
|
}.build()
|
||||||
|
|
||||||
if cfgErr != nil {
|
if cfgErr != nil {
|
||||||
@@ -122,8 +126,7 @@ func Enviro() Loader {
|
|||||||
DialTimeout: time.Duration(cfg.DialTimeout) * time.Second,
|
DialTimeout: time.Duration(cfg.DialTimeout) * time.Second,
|
||||||
Servers: []Server{cfgSer.build()},
|
Servers: []Server{cfgSer.build()},
|
||||||
Presets: presets,
|
Presets: presets,
|
||||||
OnlyAllowPresetRemotes: len(
|
OnlyAllowPresetRemotes: cfg.OnlyAllowPresetRemotes,
|
||||||
parseEviro("SSHWIFTY_ONLYALLOWPRESETREMOTES")) > 0,
|
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -144,6 +144,20 @@ func (f fileCfgCommon) build() (fileCfgCommon, network.Dial, error) {
|
|||||||
dialer = sDial
|
dialer = sDial
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if f.OnlyAllowPresetRemotes {
|
||||||
|
accessList := make(network.AllowedHosts, len(f.Presets))
|
||||||
|
|
||||||
|
for _, k := range f.Presets {
|
||||||
|
if len(k.Host) <= 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
accessList[k.Host] = struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
|
dialer = network.AccessControlDial(accessList, dialer)
|
||||||
|
}
|
||||||
|
|
||||||
return fileCfgCommon{
|
return fileCfgCommon{
|
||||||
HostName: f.HostName,
|
HostName: f.HostName,
|
||||||
SharedKey: f.SharedKey,
|
SharedKey: f.SharedKey,
|
||||||
|
|||||||
Reference in New Issue
Block a user