// AddConnection adds a new peer connection to the model. An initial index will // be sent to the connected peer, thereafter index updates whenever the local // folder changes. func (m *Model) AddConnection(rawConn io.Closer, protoConn protocol.Connection) { deviceID := protoConn.ID() m.pmut.Lock() if _, ok := m.protoConn[deviceID]; ok { panic("add existing device") } m.protoConn[deviceID] = protoConn if _, ok := m.rawConn[deviceID]; ok { panic("add existing device") } m.rawConn[deviceID] = rawConn cm := m.clusterConfig(deviceID) protoConn.ClusterConfig(cm) m.fmut.RLock() for _, folder := range m.deviceFolders[deviceID] { fs := m.folderFiles[folder] go sendIndexes(protoConn, folder, fs, m.folderIgnores[folder]) } m.fmut.RUnlock() m.pmut.Unlock() m.deviceWasSeen(deviceID) }