default ports in code

Tried to modify the code so that we can change the default port (8384, 22000, 21027). It seems that these ports are hard coded in the source? is it possible to define the ports somewhere so that changes could be made easily? [I do understand it is possible to modify the config file.]

There is some duplication, but it’s not extreme;

jb@unu:~/s/g/s/syncthing $ git grep 8384 cmd/syncthing/ lib/ | grep -v _test.go 
cmd/syncthing/main.go:	port, err := getFreePort("127.0.0.1", 8384)
lib/config/config.go:		cfg.Options.LocalAnnMCAddr = "[ff12::8384]:21027"
lib/config/guiconfiguration.go:	RawAddress                string `xml:"address" json:"address" default:"127.0.0.1:8384"`
lib/config/optionsconfiguration.go:	LocalAnnMCAddr          string                  `xml:"localAnnounceMCAddr" json:"localAnnounceMCAddr" default:"[ff12::8384]:21027"`
jb@unu:~/s/g/s/syncthing $ git grep 22000 cmd/syncthing/ lib/ | grep -v _test.go 
cmd/syncthing/main.go:	port, err = getFreePort("0.0.0.0", 22000)
cmd/syncthing/main.go:	if port == 22000 {
lib/config/config.go:	DefaultTCPPort = 22000
lib/config/config.go:	// Replace the default listen address "tcp://0.0.0.0:22000" with the
lib/config/config.go:				if addr == "tcp://0.0.0.0:22000" {
lib/config/testdata/example.xml:        <listenAddress>0.0.0.0:22000</listenAddress>
lib/discover/doc.go:		direct: ["tcp://192.0.2.45:22000", "tcp://:22202"],
lib/discover/doc.go:Any empty or unspecified IP addresses (i.e. addresses like tcp://:22000,
lib/discover/doc.go:tcp://0.0.0.0:22000, tcp://[::]:22000) are interpreted as referring to the
jb@unu:~/s/g/s/syncthing $ git grep 21027 cmd/syncthing/ lib/ | grep -v _test.go 
lib/config/config.go:		cfg.Options.LocalAnnMCAddr = "[ff12::8384]:21027"
lib/config/config.go:		cfg.Options.LocalAnnPort = 21027
lib/config/optionsconfiguration.go:	LocalAnnPort            int                     `xml:"localAnnouncePort" json:"localAnnouncePort" default:"21027"`
lib/config/optionsconfiguration.go:	LocalAnnMCAddr          string                  `xml:"localAnnounceMCAddr" json:"localAnnounceMCAddr" default:"[ff12::8384]:21027"`

The occurances in comments and struct tags are necessary, some of the others are historical as part of migrations. You’re welcome to clean this up in a PR if out like. :slight_smile:

Why do you want to change the default ports anyway?

Tried make the changes in the source. (even use a search engine to find all these ports); but when started , it generated again a default config.xml with those 8384 default port. Where should I change the default values in config.xml?

The reason why I want to change the default ports is we run syncthing on default ports for sync. We would like to use syncthing on the same machine to do something at the same time (branching and sharing)

Literally the first line of output in my previous post…