(conn protocol.Connection, cm *protocol.ClusterConfig)
| 1201 | } |
| 1202 | |
| 1203 | func (m *model) ClusterConfig(conn protocol.Connection, cm *protocol.ClusterConfig) error { |
| 1204 | deviceID := conn.DeviceID() |
| 1205 | |
| 1206 | if cm.Secondary { |
| 1207 | // No handling of secondary connection ClusterConfigs; they merely |
| 1208 | // indicate the connection is ready to start. |
| 1209 | l.Debugf("Skipping secondary ClusterConfig from %v at %s", deviceID.Short(), conn) |
| 1210 | return nil |
| 1211 | } |
| 1212 | |
| 1213 | // Check the peer device's announced folders against our own. Emits events |
| 1214 | // for folders that we don't expect (unknown or not shared). |
| 1215 | // Also, collect a list of folders we do share, and if he's interested in |
| 1216 | // temporary indexes, subscribe the connection. |
| 1217 | |
| 1218 | l.Debugf("Handling ClusterConfig from %v at %s", deviceID.Short(), conn) |
| 1219 | indexHandlerRegistry := m.ensureIndexHandler(conn) |
| 1220 | |
| 1221 | deviceCfg, ok := m.cfg.Device(deviceID) |
| 1222 | if !ok { |
| 1223 | l.Debugf("Device %s disappeared from config while processing cluster-config", deviceID.Short()) |
| 1224 | return errDeviceUnknown |
| 1225 | } |
| 1226 | |
| 1227 | // Assemble the device information from the connected device about |
| 1228 | // themselves and us for all folders. |
| 1229 | ccDeviceInfos := make(map[string]*clusterConfigDeviceInfo, len(cm.Folders)) |
| 1230 | for _, folder := range cm.Folders { |
| 1231 | info := &clusterConfigDeviceInfo{} |
| 1232 | for _, dev := range folder.Devices { |
| 1233 | switch dev.ID { |
| 1234 | case m.id: |
| 1235 | info.local = dev |
| 1236 | case deviceID: |
| 1237 | info.remote = dev |
| 1238 | } |
| 1239 | if info.local.ID != protocol.EmptyDeviceID && info.remote.ID != protocol.EmptyDeviceID { |
| 1240 | break |
| 1241 | } |
| 1242 | } |
| 1243 | if info.remote.ID == protocol.EmptyDeviceID { |
| 1244 | slog.Warn("Device sent cluster-config without the device info for the remote", folder.LogAttr(), deviceID.LogAttr()) |
| 1245 | return errMissingRemoteInClusterConfig |
| 1246 | } |
| 1247 | if info.local.ID == protocol.EmptyDeviceID { |
| 1248 | slog.Warn("Device sent cluster-config without the device info for us locally", folder.LogAttr(), deviceID.LogAttr()) |
| 1249 | return errMissingLocalInClusterConfig |
| 1250 | } |
| 1251 | ccDeviceInfos[folder.ID] = info |
| 1252 | } |
| 1253 | |
| 1254 | for _, info := range ccDeviceInfos { |
| 1255 | if deviceCfg.Introducer && info.local.Introducer { |
| 1256 | slog.Error("Remote is an introducer to us, and we are to them - only one should be introducer to the other, see https://docs.syncthing.net/users/introducer.html", deviceCfg.DeviceID.LogAttr()) |
| 1257 | } |
| 1258 | break |
| 1259 | } |
| 1260 |
nothing calls this directly
no test coverage detected