MCPcopy
hub / github.com/syncthing/syncthing / generateClusterConfigRLocked

Method generateClusterConfigRLocked

lib/model/model.go:2590–2664  ·  view source on GitHub ↗
(device protocol.DeviceID)

Source from the content-addressed store, hash-verified

2588}
2589
2590func (m *model) generateClusterConfigRLocked(device protocol.DeviceID) (*protocol.ClusterConfig, map[string]string) {
2591 message := &protocol.ClusterConfig{}
2592 folders := m.cfg.FolderList()
2593 passwords := make(map[string]string, len(folders))
2594 for _, folderCfg := range folders {
2595 if !folderCfg.SharedWith(device) {
2596 continue
2597 }
2598
2599 encryptionToken, hasEncryptionToken := m.folderEncryptionPasswordTokens[folderCfg.ID]
2600 if folderCfg.Type == config.FolderTypeReceiveEncrypted && !hasEncryptionToken {
2601 // We haven't gotten a token for us yet and without one the other
2602 // side can't validate us - pretend we don't have the folder yet.
2603 continue
2604 }
2605
2606 protocolFolder := protocol.Folder{
2607 ID: folderCfg.ID,
2608 Label: folderCfg.Label,
2609 }
2610
2611 // Even if we aren't paused, if we haven't started the folder yet
2612 // pretend we are. Otherwise the remote might get confused about
2613 // the missing index info (and drop all the info). We will send
2614 // another cluster config once the folder is started.
2615 if folderCfg.Paused {
2616 protocolFolder.StopReason = protocol.FolderStopReasonPaused
2617 }
2618
2619 nextDevice:
2620 for _, folderDevice := range folderCfg.Devices {
2621 deviceCfg, _ := m.cfg.Device(folderDevice.DeviceID)
2622
2623 protocolDevice := protocol.Device{
2624 ID: deviceCfg.DeviceID,
2625 Name: deviceCfg.Name,
2626 Addresses: deviceCfg.Addresses,
2627 Compression: deviceCfg.Compression.ToProtocol(),
2628 CertName: deviceCfg.CertName,
2629 Introducer: deviceCfg.Introducer,
2630 }
2631
2632 if deviceCfg.DeviceID == m.id && hasEncryptionToken {
2633 protocolDevice.EncryptionPasswordToken = encryptionToken
2634 } else if folderDevice.EncryptionPassword != "" {
2635 // For encrypted/untrusted devices we send the encryption
2636 // token and prepare the password. We do not send any
2637 // information about untrusted devices to _other_ devices,
2638 // as they are not normal peers sharing the folder and we
2639 // don't want things like the introducer features to kick in
2640 // for them.
2641 if folderDevice.DeviceID == device {
2642 protocolDevice.EncryptionPasswordToken = protocol.PasswordToken(m.keyGen, folderCfg.ID, folderDevice.EncryptionPassword)
2643 passwords[folderCfg.ID] = folderDevice.EncryptionPassword
2644 } else {
2645 continue nextDevice
2646 }
2647 }

Callers 2

promoteConnectionsMethod · 0.95
generateClusterConfigMethod · 0.95

Calls 7

PasswordTokenFunction · 0.92
SharedWithMethod · 0.80
ToProtocolMethod · 0.80
FolderListMethod · 0.65
DeviceMethod · 0.65
GetIndexIDMethod · 0.65
GetDeviceSequenceMethod · 0.65

Tested by

no test coverage detected