scion_stack/path/strategy/policy.rs
1// Copyright 2025 Anapaya Systems
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Path policies allow for the selection of paths based on certain criteria.
16//!
17//! For example, filtering out paths that go through certain ASes or paths.
18
19use scion_proto::path::Path;
20
21/// Path policies allow for the selection of paths based on certain criteria.
22pub trait PathPolicy: 'static + Send + Sync {
23 /// Returns true if the path should be considered for selection.
24 fn predicate(&self, path: &Path) -> bool;
25}
26
27// Allow using scion_proto path policies directly
28impl<T: scion_proto::path::policy::PathPolicy> PathPolicy for T {
29 fn predicate(&self, path: &Path) -> bool {
30 <Self as scion_proto::path::policy::PathPolicy>::path_allowed(self, path).unwrap_or(false) // If the policy cannot be evaluated, the path is not allowed
31 }
32}