Skip to content

Commit 97368e5

Browse files
committed
refactor: [#255] extract binding collection logic into separate method
- Extract collect_bindings() private method from validate() - Improves Single Responsibility Principle compliance - Makes validate() method more focused on conflict detection - Better separation of concerns: collection vs validation
1 parent 16ade4a commit 97368e5

1 file changed

Lines changed: 23 additions & 13 deletions

File tree

  • src/domain/tracker/config

src/domain/tracker/config/mod.rs

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,28 @@ impl TrackerConfig {
210210
/// assert!(config.validate().is_ok());
211211
/// ```
212212
pub fn validate(&self) -> Result<(), TrackerConfigError> {
213-
// Collect all binding addresses with their service names
213+
let bindings = self.collect_bindings();
214+
215+
// Check for duplicates
216+
for (binding, services) in bindings {
217+
if services.len() > 1 {
218+
return Err(TrackerConfigError::DuplicateSocketAddress {
219+
address: *binding.socket(),
220+
protocol: binding.protocol(),
221+
services,
222+
});
223+
}
224+
}
225+
226+
Ok(())
227+
}
228+
229+
/// Collects all binding addresses with their service names
230+
///
231+
/// Creates a map of binding addresses (socket + protocol) to service names.
232+
/// This allows identifying which services are attempting to bind to the same
233+
/// socket address with the same protocol.
234+
fn collect_bindings(&self) -> HashMap<BindingAddress, Vec<String>> {
214235
let mut bindings: HashMap<BindingAddress, Vec<String>> = HashMap::new();
215236

216237
// Add UDP trackers
@@ -245,18 +266,7 @@ impl TrackerConfig {
245266
.or_default()
246267
.push("Health Check API".to_string());
247268

248-
// Check for duplicates
249-
for (binding, services) in bindings {
250-
if services.len() > 1 {
251-
return Err(TrackerConfigError::DuplicateSocketAddress {
252-
address: *binding.socket(),
253-
protocol: binding.protocol(),
254-
services,
255-
});
256-
}
257-
}
258-
259-
Ok(())
269+
bindings
260270
}
261271
}
262272

0 commit comments

Comments
 (0)