Clone the inner regorus engine for per-tunnel L7 evaluation. With the `arc` feature enabled, this shares compiled policy via Arc and only duplicates interpreter state (~microseconds). The cloned engine can be used without Mutex contention.
(&self, expected_generation: u64)
| 613 | /// and only duplicates interpreter state (~microseconds). The cloned |
| 614 | /// engine can be used without Mutex contention. |
| 615 | pub fn clone_engine_for_tunnel(&self, expected_generation: u64) -> Result<TunnelPolicyEngine> { |
| 616 | let engine = self |
| 617 | .engine |
| 618 | .lock() |
| 619 | .map_err(|_| miette::miette!("OPA engine lock poisoned"))?; |
| 620 | let generation = self.current_generation(); |
| 621 | if generation != expected_generation { |
| 622 | return Err(miette::miette!( |
| 623 | "policy changed before L7 tunnel started [expected_generation:{expected_generation} current_generation:{generation}]" |
| 624 | )); |
| 625 | } |
| 626 | Ok(TunnelPolicyEngine { |
| 627 | engine: Mutex::new(engine.clone()), |
| 628 | generation_guard: PolicyGenerationGuard { |
| 629 | captured_generation: generation, |
| 630 | current_generation: Arc::clone(&self.generation), |
| 631 | }, |
| 632 | }) |
| 633 | } |
| 634 | } |
| 635 | |
| 636 | /// Convert a `regorus::Value` to a string, handling various types. |