Allow multiple listenAddresses (fixes #52)
This commit is contained in:
parent
2297e29502
commit
3cb7b8f22b
File diff suppressed because one or more lines are too long
22
config.go
22
config.go
@ -27,7 +27,7 @@ type NodeConfiguration struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type OptionsConfiguration struct {
|
type OptionsConfiguration struct {
|
||||||
ListenAddress string `xml:"listenAddress" default:":22000" ini:"listen-address"`
|
ListenAddress []string `xml:"listenAddress" default:":22000" ini:"listen-address"`
|
||||||
ReadOnly bool `xml:"readOnly" ini:"read-only"`
|
ReadOnly bool `xml:"readOnly" ini:"read-only"`
|
||||||
AllowDelete bool `xml:"allowDelete" default:"true" ini:"allow-delete"`
|
AllowDelete bool `xml:"allowDelete" default:"true" ini:"allow-delete"`
|
||||||
FollowSymlinks bool `xml:"followSymlinks" default:"true" ini:"follow-symlinks"`
|
FollowSymlinks bool `xml:"followSymlinks" default:"true" ini:"follow-symlinks"`
|
||||||
@ -57,6 +57,11 @@ func setDefaults(data interface{}) error {
|
|||||||
case string:
|
case string:
|
||||||
f.SetString(v)
|
f.SetString(v)
|
||||||
|
|
||||||
|
case []string:
|
||||||
|
rv := reflect.MakeSlice(reflect.TypeOf([]string{}), 1, 1)
|
||||||
|
rv.Index(0).SetString(v)
|
||||||
|
f.Set(rv)
|
||||||
|
|
||||||
case int:
|
case int:
|
||||||
i, err := strconv.ParseInt(v, 10, 64)
|
i, err := strconv.ParseInt(v, 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -121,6 +126,20 @@ func writeConfigXML(wr io.Writer, cfg Configuration) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func uniqueStrings(ss []string) []string {
|
||||||
|
var m = make(map[string]bool, len(ss))
|
||||||
|
for _, s := range ss {
|
||||||
|
m[s] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
var us = make([]string, 0, len(m))
|
||||||
|
for k := range m {
|
||||||
|
us = append(us, k)
|
||||||
|
}
|
||||||
|
|
||||||
|
return us
|
||||||
|
}
|
||||||
|
|
||||||
func readConfigXML(rd io.Reader) (Configuration, error) {
|
func readConfigXML(rd io.Reader) (Configuration, error) {
|
||||||
var cfg Configuration
|
var cfg Configuration
|
||||||
|
|
||||||
@ -132,5 +151,6 @@ func readConfigXML(rd io.Reader) (Configuration, error) {
|
|||||||
err = xml.NewDecoder(rd).Decode(&cfg)
|
err = xml.NewDecoder(rd).Decode(&cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cfg.Options.ListenAddress = uniqueStrings(cfg.Options.ListenAddress)
|
||||||
return cfg, err
|
return cfg, err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,7 +11,7 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http) {
|
|||||||
|
|
||||||
// Strings before bools look better
|
// Strings before bools look better
|
||||||
$scope.settings = [
|
$scope.settings = [
|
||||||
{id: 'ListenAddress', descr:"Sync Protocol Listen Address", type: 'string', restart: true},
|
{id: 'ListenStr', descr:"Sync Protocol Listen Addresses", type: 'string', restart: true},
|
||||||
{id: 'GUIAddress', descr: "GUI Listen Address", type: 'string', restart: true},
|
{id: 'GUIAddress', descr: "GUI Listen Address", type: 'string', restart: true},
|
||||||
{id: 'MaxSendKbps', descr: "Outgoing Rate Limit (KBps)", type: 'string', restart: true},
|
{id: 'MaxSendKbps', descr: "Outgoing Rate Limit (KBps)", type: 'string', restart: true},
|
||||||
{id: 'RescanIntervalS', descr: "Rescan Interval (s)", type: 'string', restart: true},
|
{id: 'RescanIntervalS', descr: "Rescan Interval (s)", type: 'string', restart: true},
|
||||||
@ -49,6 +49,7 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http) {
|
|||||||
|
|
||||||
$http.get("/rest/config").success(function (data) {
|
$http.get("/rest/config").success(function (data) {
|
||||||
$scope.config = data;
|
$scope.config = data;
|
||||||
|
$scope.config.Options.ListenStr = $scope.config.Options.ListenAddress.join(", ")
|
||||||
|
|
||||||
var nodes = $scope.config.Repositories[0].Nodes;
|
var nodes = $scope.config.Repositories[0].Nodes;
|
||||||
nodes = nodes.filter(function (x) { return x.NodeID != $scope.myID; });
|
nodes = nodes.filter(function (x) { return x.NodeID != $scope.myID; });
|
||||||
@ -170,6 +171,7 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
$scope.saveSettings = function () {
|
$scope.saveSettings = function () {
|
||||||
|
$scope.config.Options.ListenAddress = $scope.config.Options.ListenStr.split(',').map(function (x) { return x.trim(); });
|
||||||
$http.post('/rest/config', JSON.stringify($scope.config), {headers: {'Content-Type': 'application/json'}});
|
$http.post('/rest/config', JSON.stringify($scope.config), {headers: {'Content-Type': 'application/json'}});
|
||||||
$('#settingsTable').collapse('hide');
|
$('#settingsTable').collapse('hide');
|
||||||
};
|
};
|
||||||
|
|||||||
16
main.go
16
main.go
@ -208,13 +208,16 @@ func main() {
|
|||||||
if verbose {
|
if verbose {
|
||||||
infoln("Listening for incoming connections")
|
infoln("Listening for incoming connections")
|
||||||
}
|
}
|
||||||
go listen(myID, cfg.Options.ListenAddress, m, tlsCfg)
|
for _, addr := range cfg.Options.ListenAddress {
|
||||||
|
go listen(myID, addr, m, tlsCfg)
|
||||||
|
}
|
||||||
|
|
||||||
// Routine to connect out to configured nodes
|
// Routine to connect out to configured nodes
|
||||||
if verbose {
|
if verbose {
|
||||||
infoln("Attempting to connect to other nodes")
|
infoln("Attempting to connect to other nodes")
|
||||||
}
|
}
|
||||||
go connect(myID, cfg.Options.ListenAddress, m, tlsCfg)
|
disc := discovery(cfg.Options.ListenAddress[0])
|
||||||
|
go connect(myID, disc, m, tlsCfg)
|
||||||
|
|
||||||
// Routine to pull blocks from other nodes to synchronize the local
|
// Routine to pull blocks from other nodes to synchronize the local
|
||||||
// repository. Does not run when we are in read only (publish only) mode.
|
// repository. Does not run when we are in read only (publish only) mode.
|
||||||
@ -318,6 +321,9 @@ func printStatsLoop(m *model.Model) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func listen(myID string, addr string, m *model.Model, tlsCfg *tls.Config) {
|
func listen(myID string, addr string, m *model.Model, tlsCfg *tls.Config) {
|
||||||
|
if strings.Contains(trace, "connect") {
|
||||||
|
debugln("NET: Listening on", addr)
|
||||||
|
}
|
||||||
l, err := tls.Listen("tcp", addr, tlsCfg)
|
l, err := tls.Listen("tcp", addr, tlsCfg)
|
||||||
fatalErr(err)
|
fatalErr(err)
|
||||||
|
|
||||||
@ -369,7 +375,7 @@ listen:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func connect(myID string, addr string, m *model.Model, tlsCfg *tls.Config) {
|
func discovery(addr string) *discover.Discoverer {
|
||||||
_, portstr, err := net.SplitHostPort(addr)
|
_, portstr, err := net.SplitHostPort(addr)
|
||||||
fatalErr(err)
|
fatalErr(err)
|
||||||
port, _ := strconv.Atoi(portstr)
|
port, _ := strconv.Atoi(portstr)
|
||||||
@ -392,6 +398,10 @@ func connect(myID string, addr string, m *model.Model, tlsCfg *tls.Config) {
|
|||||||
warnf("No discovery possible (%v)", err)
|
warnf("No discovery possible (%v)", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return disc
|
||||||
|
}
|
||||||
|
|
||||||
|
func connect(myID string, disc *discover.Discoverer, m *model.Model, tlsCfg *tls.Config) {
|
||||||
connOpts := map[string]string{
|
connOpts := map[string]string{
|
||||||
"clientId": "syncthing",
|
"clientId": "syncthing",
|
||||||
"clientVersion": Version,
|
"clientVersion": Version,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user