Exemple #1
0
func convertV11V12(cfg *Configuration) {
	// Change listen address schema
	for i, addr := range cfg.Options.ListenAddress {
		if len(addr) > 0 && !strings.HasPrefix(addr, "tcp://") {
			cfg.Options.ListenAddress[i] = util.Address("tcp", addr)
		}
	}

	for i, device := range cfg.Devices {
		for j, addr := range device.Addresses {
			if addr != "dynamic" && addr != "" {
				cfg.Devices[i].Addresses[j] = util.Address("tcp", addr)
			}
		}
	}

	// Use new discovery server
	var newDiscoServers []string
	var useDefault bool
	for _, addr := range cfg.Options.GlobalAnnServers {
		if addr == "udp4://announce.syncthing.net:22026" {
			useDefault = true
		} else if addr == "udp6://announce-v6.syncthing.net:22026" {
			useDefault = true
		} else {
			newDiscoServers = append(newDiscoServers, addr)
		}
	}
	if useDefault {
		newDiscoServers = append(newDiscoServers, "default")
	}
	cfg.Options.GlobalAnnServers = newDiscoServers

	// Use new multicast group
	if cfg.Options.LocalAnnMCAddr == "[ff32::5222]:21026" {
		cfg.Options.LocalAnnMCAddr = "[ff12::8384]:21027"
	}

	// Use new local discovery port
	if cfg.Options.LocalAnnPort == 21025 {
		cfg.Options.LocalAnnPort = 21027
	}

	// Set MaxConflicts to unlimited
	for i := range cfg.Folders {
		cfg.Folders[i].MaxConflicts = -1
	}

	cfg.Version = 12
}
Exemple #2
0
func (s *Service) addresses(includePrivateIPV4 bool) []string {
	var addrs []string

	// Grab our listen addresses from the config. Unspecified ones are passed
	// on verbatim (to be interpreted by a global discovery server or local
	// discovery peer). Public addresses are passed on verbatim. Private
	// addresses are filtered.
	for _, addrStr := range s.cfg.Options().ListenAddress {
		addrURL, err := url.Parse(addrStr)
		if err != nil {
			l.Infoln("Listen address", addrStr, "is invalid:", err)
			continue
		}
		addr, err := net.ResolveTCPAddr(addrURL.Scheme, addrURL.Host)
		if err != nil {
			l.Infoln("Listen address", addrStr, "is invalid:", err)
			continue
		}

		if addr.IP == nil || addr.IP.IsUnspecified() {
			// Address like 0.0.0.0:22000 or [::]:22000 or :22000; include as is.
			addrs = append(addrs, util.Address(addrURL.Scheme, addr.String()))
		} else if isPublicIPv4(addr.IP) || isPublicIPv6(addr.IP) {
			// A public address; include as is.
			addrs = append(addrs, util.Address(addrURL.Scheme, addr.String()))
		} else if includePrivateIPV4 && addr.IP.To4().IsGlobalUnicast() {
			// A private IPv4 address.
			addrs = append(addrs, util.Address(addrURL.Scheme, addr.String()))
		}
	}

	// Get an external port mapping from the upnpService, if it has one. If so,
	// add it as another unspecified address.
	if s.upnpService != nil {
		if port := s.upnpService.ExternalPort(); port != 0 {
			addrs = append(addrs, fmt.Sprintf("tcp://:%d", port))
		}
	}

	return addrs
}