MCPcopy Create free account
hub / github.com/chirpstack/chirpstack / update_gateway_configuration

Method update_gateway_configuration

chirpstack/src/uplink/stats.rs:229–318  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

227 }
228
229 async fn update_gateway_configuration(&self) -> Result<()> {
230 trace!("Updating gateway configuration");
231
232 if !self.stats.metadata.contains_key("concentratord_version") {
233 trace!("Gateway configuration only works with Concentratord, skipping");
234 return Ok(());
235 }
236
237 let gw = self.gateway.as_ref().unwrap();
238 let region_config_id = self
239 .stats
240 .metadata
241 .get("region_config_id")
242 .cloned()
243 .unwrap_or_default();
244
245 let gateway_conf = config::get_region_gateway(&region_config_id)?;
246 if gateway_conf.channels.is_empty() {
247 trace!("Skipping gateway configuration, channels is empty");
248 return Ok(());
249 }
250
251 // get gw config version
252 let gw_config_version = self
253 .stats
254 .metadata
255 .get("config_version")
256 .cloned()
257 .unwrap_or_default();
258
259 // We use the Hash trait to generate the config version.
260 let mut hasher = DefaultHasher::new();
261 gw.stats_interval_secs.hash(&mut hasher);
262 gateway_conf.channels.hash(&mut hasher);
263 let hash = format!("{:x}", hasher.finish());
264
265 if gw_config_version == hash {
266 trace!(config_version = %hash, "Config version is equal, no need for config update");
267 return Ok(());
268 }
269
270 info!(current_config_version = %gw_config_version, desired_config_version = %hash, "Updating gateway configuration");
271
272 let gw_conf = gw::GatewayConfiguration {
273 gateway_id: self.stats.gateway_id.clone(),
274 gateway_id_legacy: self.stats.gateway_id_legacy.clone(),
275 version: hash,
276 channels: gateway_conf
277 .channels
278 .iter()
279 .map(|c| gw::ChannelConfiguration {
280 frequency: c.frequency,
281 modulation_legacy: match c.modulation {
282 config::GatewayChannelModulation::LORA => common::Modulation::Lora,
283 config::GatewayChannelModulation::FSK => common::Modulation::Fsk,
284 }
285 .into(),
286 modulation_config: Some(match c.modulation {

Callers 1

_handleMethod · 0.80

Calls 9

get_region_gatewayFunction · 0.85
LoraModulationConfigStruct · 0.85
FskModulationConfigStruct · 0.85
send_configurationFunction · 0.85
unwrapMethod · 0.80
as_refMethod · 0.80
iterMethod · 0.80
getMethod · 0.45
intoMethod · 0.45

Tested by

no test coverage detected