MCPcopy
hub / github.com/syncthing/syncthing / ensureIndexHandler

Method ensureIndexHandler

lib/model/model.go:1341–1374  ·  view source on GitHub ↗
(conn protocol.Connection)

Source from the content-addressed store, hash-verified

1339}
1340
1341func (m *model) ensureIndexHandler(conn protocol.Connection) *indexHandlerRegistry {
1342 deviceID := conn.DeviceID()
1343 connID := conn.ConnectionID()
1344
1345 m.mut.Lock()
1346 defer m.mut.Unlock()
1347
1348 indexHandlerRegistry, ok := m.indexHandlers.Get(deviceID)
1349 if ok && indexHandlerRegistry.conn.ConnectionID() == connID {
1350 // This is an existing and proper index handler for this connection.
1351 return indexHandlerRegistry
1352 }
1353
1354 if ok {
1355 // A handler exists, but it's for another connection than the one we
1356 // now got a ClusterConfig on. This should be unusual as it means
1357 // the other side has decided to start using a new primary
1358 // connection but we haven't seen it close yet. Ideally it will
1359 // close shortly by itself...
1360 slog.Warn("Abandoning old index handler in favour of new connection", deviceID.LogAttr(), slog.String("old", indexHandlerRegistry.conn.ConnectionID()), slog.String("new", connID))
1361 m.indexHandlers.RemoveAndWait(deviceID, 0)
1362 }
1363
1364 // Create a new index handler for this device.
1365 indexHandlerRegistry = newIndexHandlerRegistry(conn, m.sdb, m.deviceDownloads[deviceID], m.evLogger)
1366 for id, fcfg := range m.folderCfgs {
1367 l.Debugln("Registering folder", id, "for", deviceID.Short())
1368 runner, _ := m.folderRunners.Get(id)
1369 indexHandlerRegistry.RegisterFolderState(fcfg, runner)
1370 }
1371 m.indexHandlers.Add(deviceID, indexHandlerRegistry)
1372
1373 return indexHandlerRegistry
1374}
1375
1376func (m *model) getIndexHandlerRLocked(conn protocol.Connection) (*indexHandlerRegistry, bool) {
1377 // Reads from index handlers, which requires the mutex to be read locked

Callers 1

ClusterConfigMethod · 0.95

Calls 12

newIndexHandlerRegistryFunction · 0.85
UnlockMethod · 0.80
RemoveAndWaitMethod · 0.80
DebuglnMethod · 0.80
ShortMethod · 0.80
RegisterFolderStateMethod · 0.80
DeviceIDMethod · 0.65
ConnectionIDMethod · 0.65
GetMethod · 0.65
StringMethod · 0.65
LogAttrMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected