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

Code before:
	} else if cfg.Paused {
		l.Debugf("%v for paused folder (ID %q) sent from device %q.", op, folder, deviceID)
		return errors.Wrap(ErrFolderPaused, folder)
	}

	m.pmut.RLock()
	indexHandler, ok := m.indexHandlers[deviceID]
	m.pmut.RUnlock()
	if !ok {
		// This should be impossible, as an index handler always exists for an
		// open connection, and this method can't be called on a closed
		// connection
		m.evLogger.Log(events.Failure, "index sender does not exist for connection on which indexes were received")
		l.Debugf("%v for folder (ID %q) sent from device %q: missing index handler", op, folder, deviceID)
		return errors.Wrap(errors.New("index handler missing"), folder)
	}

	return indexHandler.ReceiveIndex(folder, fs, update, op)
}

type clusterConfigDeviceInfo struct {
	local, remote protocol.Device
}

type ClusterConfigReceivedEventData struct {
	ID string `json:"id"`
}

func (m *model) ClusterConfig(deviceID protocol.DeviceID, cm protocol.ClusterConfig) error {
	// Check the peer device's announced folders against our own. Emits events
	// for folders that we don't expect (unknown or not shared).
	// Also, collect a list of folders we do share, and if he's interested in
	// temporary indexes, subscribe the connection.

	l.Debugf("Handling ClusterConfig from %v", deviceID.Short())

	m.pmut.RLock()
	indexHandlerRegistry, ok := m.indexHandlers[deviceID]
	m.pmut.RUnlock()
	if !ok {
		panic("bug: ClusterConfig called on closed or nonexistent connection")
	}

	deviceCfg, ok := m.cfg.Device(deviceID)
	if !ok {
		l.Debugln("Device disappeared from config while processing cluster-config")
		return errDeviceUnknown
	}

	// Assemble the device information from the connected device about
	// themselves and us for all folders.

Review comment (suggestion):
Same here: I'd leave the `protocol.DeviceID` type here and leave conversion to string to marshalling (already happening by default through `.MarshalText`).

Code after:
	} else if cfg.Paused {
		l.Debugf("%v for paused folder (ID %q) sent from device %q.", op, folder, deviceID)
		return errors.Wrap(ErrFolderPaused, folder)
	}

	m.pmut.RLock()
	indexHandler, ok := m.indexHandlers[deviceID]
	m.pmut.RUnlock()
	if !ok {
		// This should be impossible, as an index handler always exists for an
		// open connection, and this method can't be called on a closed
		// connection
		m.evLogger.Log(events.Failure, "index sender does not exist for connection on which indexes were received")
		l.Debugf("%v for folder (ID %q) sent from device %q: missing index handler", op, folder, deviceID)
		return errors.Wrap(errors.New("index handler missing"), folder)
	}

	return indexHandler.ReceiveIndex(folder, fs, update, op)
}

type clusterConfigDeviceInfo struct {
	local, remote protocol.Device
}

type ClusterConfigReceivedEventData struct {
	Device protocol.DeviceID `json:"device"`
}

func (m *model) ClusterConfig(deviceID protocol.DeviceID, cm protocol.ClusterConfig) error {
	// Check the peer device's announced folders against our own. Emits events
	// for folders that we don't expect (unknown or not shared).
	// Also, collect a list of folders we do share, and if he's interested in
	// temporary indexes, subscribe the connection.

	l.Debugf("Handling ClusterConfig from %v", deviceID.Short())

	m.pmut.RLock()
	indexHandlerRegistry, ok := m.indexHandlers[deviceID]
	m.pmut.RUnlock()
	if !ok {
		panic("bug: ClusterConfig called on closed or nonexistent connection")
	}

	deviceCfg, ok := m.cfg.Device(deviceID)
	if !ok {
		l.Debugln("Device disappeared from config while processing cluster-config")
		return errDeviceUnknown
	}

	// Assemble the device information from the connected device about
	// themselves and us for all folders.