Wideband autonomous SDR analysis engine forked from sdr-visual-suite
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

81 строка
2.5KB

  1. package pipeline
  2. import "strings"
  3. // SurveillanceDetectionPolicy describes how surveillance levels are governed for detection.
  4. type SurveillanceDetectionPolicy struct {
  5. DerivedDetection string `json:"derived_detection"`
  6. DerivedDetectionEnabled bool `json:"derived_detection_enabled"`
  7. DerivedDetectionReason string `json:"derived_detection_reason,omitempty"`
  8. PrimaryRole string `json:"primary_role"`
  9. DerivedRole string `json:"derived_role"`
  10. SupportRole string `json:"support_role"`
  11. PresentationRole string `json:"presentation_role"`
  12. }
  13. func normalizeDerivedDetection(mode string) string {
  14. switch strings.ToLower(strings.TrimSpace(mode)) {
  15. case "on", "true", "enabled", "enable":
  16. return "on"
  17. case "off", "false", "disabled", "disable":
  18. return "off"
  19. case "auto", "":
  20. return "auto"
  21. default:
  22. return "auto"
  23. }
  24. }
  25. func strategyIsMulti(strategy string) bool {
  26. switch strings.ToLower(strings.TrimSpace(strategy)) {
  27. case "multi-resolution", "multi", "multi-res", "multi_res":
  28. return true
  29. default:
  30. return strings.Contains(strings.ToLower(strategy), "multi")
  31. }
  32. }
  33. // SurveillanceDetectionPolicyFromPolicy derives detection governance from policy intent/profile.
  34. func SurveillanceDetectionPolicyFromPolicy(policy Policy) SurveillanceDetectionPolicy {
  35. mode := normalizeDerivedDetection(policy.SurveillanceDerivedDetection)
  36. enabled := false
  37. reason := ""
  38. switch mode {
  39. case "on":
  40. enabled = true
  41. reason = "config"
  42. case "off":
  43. enabled = false
  44. reason = "config"
  45. default:
  46. if !strategyIsMulti(policy.SurveillanceStrategy) {
  47. enabled = false
  48. reason = "strategy"
  49. } else {
  50. intent := strings.ToLower(strings.TrimSpace(policy.Intent))
  51. profile := strings.ToLower(strings.TrimSpace(policy.Profile))
  52. modeName := strings.ToLower(strings.TrimSpace(policy.Mode))
  53. switch {
  54. case strings.Contains(profile, "archive") || strings.Contains(intent, "archive") || strings.Contains(intent, "triage") || strings.Contains(modeName, "archive"):
  55. enabled = false
  56. reason = "archive"
  57. case strings.Contains(profile, "legacy") || strings.Contains(modeName, "legacy"):
  58. enabled = false
  59. reason = "legacy"
  60. default:
  61. enabled = true
  62. reason = "strategy"
  63. }
  64. }
  65. }
  66. return SurveillanceDetectionPolicy{
  67. DerivedDetection: mode,
  68. DerivedDetectionEnabled: enabled,
  69. DerivedDetectionReason: reason,
  70. PrimaryRole: RoleSurveillancePrimary,
  71. DerivedRole: RoleSurveillanceDerived,
  72. SupportRole: RoleSurveillanceSupport,
  73. PresentationRole: RolePresentation,
  74. }
  75. }