mirror of
https://github.com/octoleo/syncthing.git
synced 2025-02-02 11:58:28 +00:00
Config option to enable/disable UPnP
This commit is contained in:
parent
9fb60d6935
commit
a08cba9c85
File diff suppressed because one or more lines are too long
@ -51,6 +51,7 @@ type OptionsConfiguration struct {
|
|||||||
ReconnectIntervalS int `xml:"reconnectionIntervalS" default:"60"`
|
ReconnectIntervalS int `xml:"reconnectionIntervalS" default:"60"`
|
||||||
MaxChangeKbps int `xml:"maxChangeKbps" default:"1000"`
|
MaxChangeKbps int `xml:"maxChangeKbps" default:"1000"`
|
||||||
StartBrowser bool `xml:"startBrowser" default:"true"`
|
StartBrowser bool `xml:"startBrowser" default:"true"`
|
||||||
|
UPnPEnabled bool `xml:"upnpEnabled" default:"true"`
|
||||||
|
|
||||||
Deprecated_ReadOnly bool `xml:"readOnly,omitempty"`
|
Deprecated_ReadOnly bool `xml:"readOnly,omitempty"`
|
||||||
Deprecated_GUIEnabled bool `xml:"guiEnabled,omitempty"`
|
Deprecated_GUIEnabled bool `xml:"guiEnabled,omitempty"`
|
||||||
|
@ -19,6 +19,7 @@ func TestDefaultValues(t *testing.T) {
|
|||||||
ReconnectIntervalS: 60,
|
ReconnectIntervalS: 60,
|
||||||
MaxChangeKbps: 1000,
|
MaxChangeKbps: 1000,
|
||||||
StartBrowser: true,
|
StartBrowser: true,
|
||||||
|
UPnPEnabled: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg, err := readConfigXML(bytes.NewReader(nil))
|
cfg, err := readConfigXML(bytes.NewReader(nil))
|
||||||
@ -149,6 +150,7 @@ func TestOverriddenValues(t *testing.T) {
|
|||||||
<reconnectionIntervalS>6000</reconnectionIntervalS>
|
<reconnectionIntervalS>6000</reconnectionIntervalS>
|
||||||
<maxChangeKbps>2345</maxChangeKbps>
|
<maxChangeKbps>2345</maxChangeKbps>
|
||||||
<startBrowser>false</startBrowser>
|
<startBrowser>false</startBrowser>
|
||||||
|
<upnpEnabled>false</upnpEnabled>
|
||||||
</options>
|
</options>
|
||||||
</configuration>
|
</configuration>
|
||||||
`)
|
`)
|
||||||
@ -164,6 +166,7 @@ func TestOverriddenValues(t *testing.T) {
|
|||||||
ReconnectIntervalS: 6000,
|
ReconnectIntervalS: 6000,
|
||||||
MaxChangeKbps: 2345,
|
MaxChangeKbps: 2345,
|
||||||
StartBrowser: false,
|
StartBrowser: false,
|
||||||
|
UPnPEnabled: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg, err := readConfigXML(bytes.NewReader(data))
|
cfg, err := readConfigXML(bytes.NewReader(data))
|
||||||
|
@ -234,32 +234,8 @@ func main() {
|
|||||||
// UPnP
|
// UPnP
|
||||||
|
|
||||||
var externalPort = 0
|
var externalPort = 0
|
||||||
if len(cfg.Options.ListenAddress) == 1 {
|
if cfg.Options.UPnPEnabled {
|
||||||
_, portStr, err := net.SplitHostPort(cfg.Options.ListenAddress[0])
|
externalPort = setupUPnP()
|
||||||
if err != nil {
|
|
||||||
warnln(err)
|
|
||||||
} else {
|
|
||||||
// Set up incoming port forwarding, if necessary and possible
|
|
||||||
port, _ := strconv.Atoi(portStr)
|
|
||||||
igd, err := upnp.Discover()
|
|
||||||
if err == nil {
|
|
||||||
for i := 0; i < 10; i++ {
|
|
||||||
err := igd.AddPortMapping(upnp.TCP, port+i, port, "syncthing", 0)
|
|
||||||
if err == nil {
|
|
||||||
externalPort = port + i
|
|
||||||
infoln("Created UPnP port mapping - external port", externalPort)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if externalPort == 0 {
|
|
||||||
warnln("Failed to create UPnP port mapping")
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
infof("No UPnP IGD device found, no port mapping created (%v)", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
warnln("Multiple listening addresses; not attempting UPnP port mapping")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Routine to connect out to configured nodes
|
// Routine to connect out to configured nodes
|
||||||
@ -290,6 +266,38 @@ func main() {
|
|||||||
<-stop
|
<-stop
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setupUPnP() int {
|
||||||
|
var externalPort = 0
|
||||||
|
if len(cfg.Options.ListenAddress) == 1 {
|
||||||
|
_, portStr, err := net.SplitHostPort(cfg.Options.ListenAddress[0])
|
||||||
|
if err != nil {
|
||||||
|
warnln(err)
|
||||||
|
} else {
|
||||||
|
// Set up incoming port forwarding, if necessary and possible
|
||||||
|
port, _ := strconv.Atoi(portStr)
|
||||||
|
igd, err := upnp.Discover()
|
||||||
|
if err == nil {
|
||||||
|
for i := 0; i < 10; i++ {
|
||||||
|
err := igd.AddPortMapping(upnp.TCP, port+i, port, "syncthing", 0)
|
||||||
|
if err == nil {
|
||||||
|
externalPort = port + i
|
||||||
|
infoln("Created UPnP port mapping - external port", externalPort)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if externalPort == 0 {
|
||||||
|
warnln("Failed to create UPnP port mapping")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
infof("No UPnP IGD device found, no port mapping created (%v)", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
warnln("Multiple listening addresses; not attempting UPnP port mapping")
|
||||||
|
}
|
||||||
|
return externalPort
|
||||||
|
}
|
||||||
|
|
||||||
func resetRepositories() {
|
func resetRepositories() {
|
||||||
suffix := fmt.Sprintf(".syncthing-reset-%d", time.Now().UnixNano())
|
suffix := fmt.Sprintf(".syncthing-reset-%d", time.Now().UnixNano())
|
||||||
for _, repo := range cfg.Repositories {
|
for _, repo := range cfg.Repositories {
|
||||||
|
@ -32,6 +32,7 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http) {
|
|||||||
{id: 'GlobalAnnEnabled', descr: 'Global Announce', type: 'bool', restart: true},
|
{id: 'GlobalAnnEnabled', descr: 'Global Announce', type: 'bool', restart: true},
|
||||||
{id: 'LocalAnnEnabled', descr: 'Local Announce', type: 'bool', restart: true},
|
{id: 'LocalAnnEnabled', descr: 'Local Announce', type: 'bool', restart: true},
|
||||||
{id: 'StartBrowser', descr: 'Start Browser', type: 'bool'},
|
{id: 'StartBrowser', descr: 'Start Browser', type: 'bool'},
|
||||||
|
{id: 'UPnPEnabled', descr: 'Enable UPnP', type: 'bool'},
|
||||||
];
|
];
|
||||||
|
|
||||||
$scope.guiSettings = [
|
$scope.guiSettings = [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user