Browse Source

Configurable local announcement port (fixes #256)

Jakob Borg 11 years ago
parent
commit
ae0193b724
4 changed files with 7 additions and 7 deletions
  1. 1 1
      cmd/syncthing/main.go
  2. 1 0
      config/config.go
  3. 3 0
      config/config_test.go
  4. 2 6
      discover/discover.go

+ 1 - 1
cmd/syncthing/main.go

@@ -615,7 +615,7 @@ next:
 }
 
 func discovery(extPort int) *discover.Discoverer {
-	disc, err := discover.NewDiscoverer(myID, cfg.Options.ListenAddress)
+	disc, err := discover.NewDiscoverer(myID, cfg.Options.ListenAddress, cfg.Options.LocalAnnPort)
 	if err != nil {
 		l.Warnf("No discovery possible (%v)", err)
 		return nil

+ 1 - 0
config/config.go

@@ -55,6 +55,7 @@ type OptionsConfiguration struct {
 	GlobalAnnServer    string   `xml:"globalAnnounceServer" default:"announce.syncthing.net:22025"`
 	GlobalAnnEnabled   bool     `xml:"globalAnnounceEnabled" default:"true"`
 	LocalAnnEnabled    bool     `xml:"localAnnounceEnabled" default:"true"`
+	LocalAnnPort       int      `xml:"localAnnouncePort" default:"21025"`
 	ParallelRequests   int      `xml:"parallelRequests" default:"16"`
 	MaxSendKbps        int      `xml:"maxSendKbps"`
 	RescanIntervalS    int      `xml:"rescanIntervalS" default:"60"`

+ 3 - 0
config/config_test.go

@@ -14,6 +14,7 @@ func TestDefaultValues(t *testing.T) {
 		GlobalAnnServer:    "announce.syncthing.net:22025",
 		GlobalAnnEnabled:   true,
 		LocalAnnEnabled:    true,
+		LocalAnnPort:       21025,
 		ParallelRequests:   16,
 		MaxSendKbps:        0,
 		RescanIntervalS:    60,
@@ -145,6 +146,7 @@ func TestOverriddenValues(t *testing.T) {
         <globalAnnounceServer>syncthing.nym.se:22025</globalAnnounceServer>
         <globalAnnounceEnabled>false</globalAnnounceEnabled>
         <localAnnounceEnabled>false</localAnnounceEnabled>
+        <localAnnouncePort>42123</localAnnouncePort>
         <parallelRequests>32</parallelRequests>
         <maxSendKbps>1234</maxSendKbps>
         <rescanIntervalS>600</rescanIntervalS>
@@ -161,6 +163,7 @@ func TestOverriddenValues(t *testing.T) {
 		GlobalAnnServer:    "syncthing.nym.se:22025",
 		GlobalAnnEnabled:   false,
 		LocalAnnEnabled:    false,
+		LocalAnnPort:       42123,
 		ParallelRequests:   32,
 		MaxSendKbps:        1234,
 		RescanIntervalS:    600,

+ 2 - 6
discover/discover.go

@@ -13,10 +13,6 @@ import (
 	"github.com/calmh/syncthing/buffers"
 )
 
-const (
-	AnnouncementPort = 21025
-)
-
 type Discoverer struct {
 	myID             string
 	listenAddrs      []string
@@ -42,8 +38,8 @@ var (
 // When we hit this many errors in succession, we stop.
 const maxErrors = 30
 
-func NewDiscoverer(id string, addresses []string) (*Discoverer, error) {
-	b, err := beacon.New(21025)
+func NewDiscoverer(id string, addresses []string, localPort int) (*Discoverer, error) {
+	b, err := beacon.New(localPort)
 	if err != nil {
 		return nil, err
 	}