Repository: syncthing/syncthing
File: lib/model/model.go (Go)

Code before:
	numFolders := len(m.folderCfgs)
	m.fmut.RUnlock()

	if folderCfg.Hashers > 0 {
		// Specific value set in the config, use that.
		return folderCfg.Hashers
	}

	if runtime.GOOS == "windows" || runtime.GOOS == "darwin" {
		// Interactive operating systems; don't load the system too heavily by
		// default.
		return 1
	}

	// For other operating systems and architectures, lets try to get some
	// work done... Divide the available CPU cores among the configured
	// folders.
	if perFolder := runtime.GOMAXPROCS(-1) / numFolders; perFolder > 0 {
		return perFolder
	}

	return 1
}

// generateClusterConfig returns a ClusterConfigMessage that is correct for
// the given peer device
func (m *model) generateClusterConfig(device protocol.DeviceID) (protocol.ClusterConfig, map[string]string) {
	var message protocol.ClusterConfig

	m.fmut.RLock()
	defer m.fmut.RUnlock()

	folders := m.cfg.FolderList()
	passwords := make(map[string]string, len(folders))
	for _, folderCfg := range folders {
		if !folderCfg.SharedWith(device) {
			continue
		}

		var encryptionToken []byte
		var hasEncryptionToken bool
		if folderCfg.Type == config.FolderTypeReceiveEncrypted {
			if encryptionToken, hasEncryptionToken = m.folderEncryptionPasswordTokens[folderCfg.ID]; !hasEncryptionToken {
				// We haven't gotten a token for us yet and without
				// one the other side can't validate us - pretend
				// we don't have the folder yet.
				continue
			}
		}

		protocolFolder := protocol.Folder{

Review comment (suggestion):
```suggestion
// generateClusterConfig returns a ClusterConfigMessage and the set of folder passwords for
// the given peer device
```

Code after:
	numFolders := len(m.folderCfgs)
	m.fmut.RUnlock()

	if folderCfg.Hashers > 0 {
		// Specific value set in the config, use that.
		return folderCfg.Hashers
	}

	if runtime.GOOS == "windows" || runtime.GOOS == "darwin" {
		// Interactive operating systems; don't load the system too heavily by
		// default.
		return 1
	}

	// For other operating systems and architectures, lets try to get some
	// work done... Divide the available CPU cores among the configured
	// folders.
	if perFolder := runtime.GOMAXPROCS(-1) / numFolders; perFolder > 0 {
		return perFolder
	}

	return 1
}

// generateClusterConfig returns a ClusterConfigMessage that is correct and the
// set of folder passwords for the given peer device
func (m *model) generateClusterConfig(device protocol.DeviceID) (protocol.ClusterConfig, map[string]string) {
	var message protocol.ClusterConfig

	m.fmut.RLock()
	defer m.fmut.RUnlock()

	folders := m.cfg.FolderList()
	passwords := make(map[string]string, len(folders))
	for _, folderCfg := range folders {
		if !folderCfg.SharedWith(device) {
			continue
		}

		var encryptionToken []byte
		var hasEncryptionToken bool
		if folderCfg.Type == config.FolderTypeReceiveEncrypted {
			if encryptionToken, hasEncryptionToken = m.folderEncryptionPasswordTokens[folderCfg.ID]; !hasEncryptionToken {
				// We haven't gotten a token for us yet and without
				// one the other side can't validate us - pretend
				// we don't have the folder yet.
				continue
			}
		}

		protocolFolder := protocol.Folder{