mirror of
https://github.com/octoleo/syncthing.git
synced 2024-12-22 10:58:57 +00:00
### Purpose When generating a new `config.xml` file with default options, the GUI address is populated with a hard-coded default value of `127.0.0.1:8384`, except for a random free port if that default one is occupied. This is independent from the GUI configuration default address defined in the protobuf description. More importantly, it ignores any `STGUIADDRESS` override given via environment variable or command-line option, thus probing for the default port instead of the one specified via override. The `ProbeFreePorts()` function now respects the override, by reading the `GUIConfiguration.Address()` method instead of using hard-coded defaults. When not calling `ProbeFreePorts()`, the override should still be persisted rather than the default address. This happens only when generating a fresh default `config.xml`, never on an existing one.
This commit is contained in:
parent
e82ed6e3d3
commit
65d0ca8aa9
@ -49,7 +49,6 @@ var (
|
|||||||
"dynamic+https://relays.syncthing.net/endpoint",
|
"dynamic+https://relays.syncthing.net/endpoint",
|
||||||
netutil.AddressURL("quic", net.JoinHostPort("0.0.0.0", strconv.Itoa(DefaultQUICPort))),
|
netutil.AddressURL("quic", net.JoinHostPort("0.0.0.0", strconv.Itoa(DefaultQUICPort))),
|
||||||
}
|
}
|
||||||
DefaultGUIPort = 8384
|
|
||||||
// DefaultDiscoveryServersV4 should be substituted when the configuration
|
// DefaultDiscoveryServersV4 should be substituted when the configuration
|
||||||
// contains <globalAnnounceServer>default-v4</globalAnnounceServer>.
|
// contains <globalAnnounceServer>default-v4</globalAnnounceServer>.
|
||||||
DefaultDiscoveryServersV4 = []string{
|
DefaultDiscoveryServersV4 = []string{
|
||||||
@ -116,11 +115,19 @@ func New(myID protocol.DeviceID) Configuration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (cfg *Configuration) ProbeFreePorts() error {
|
func (cfg *Configuration) ProbeFreePorts() error {
|
||||||
port, err := getFreePort("127.0.0.1", DefaultGUIPort)
|
guiHost, guiPort, err := net.SplitHostPort(cfg.GUI.Address())
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("get default port (GUI): %w", err)
|
||||||
|
}
|
||||||
|
port, err := strconv.Atoi(guiPort)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("convert default port (GUI): %w", err)
|
||||||
|
}
|
||||||
|
port, err = getFreePort(guiHost, port)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("get free port (GUI): %w", err)
|
return fmt.Errorf("get free port (GUI): %w", err)
|
||||||
}
|
}
|
||||||
cfg.GUI.RawAddress = fmt.Sprintf("127.0.0.1:%d", port)
|
cfg.GUI.RawAddress = net.JoinHostPort(guiHost, strconv.Itoa(port))
|
||||||
|
|
||||||
port, err = getFreePort("0.0.0.0", DefaultTCPPort)
|
port, err = getFreePort("0.0.0.0", DefaultTCPPort)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -63,6 +63,8 @@ func DefaultConfig(path string, myID protocol.DeviceID, evLogger events.Logger,
|
|||||||
|
|
||||||
if skipPortProbing {
|
if skipPortProbing {
|
||||||
l.Infoln("Using default network port numbers instead of probing for free ports")
|
l.Infoln("Using default network port numbers instead of probing for free ports")
|
||||||
|
// Record address override initially
|
||||||
|
newCfg.GUI.RawAddress = newCfg.GUI.Address()
|
||||||
} else if err := newCfg.ProbeFreePorts(); err != nil {
|
} else if err := newCfg.ProbeFreePorts(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user