Skip to main content

nym_node_requests/api/v1/network_requester/exit_policy/
models.rs

1// Copyright 2023 - Nym Technologies SA <contact@nymtech.net>
2// SPDX-License-Identifier: Apache-2.0
3
4pub use nym_exit_policy::{
5    AddressPolicy, AddressPolicyAction, AddressPolicyRule, AddressPortPattern, ExitPolicy,
6    PortRange,
7};
8use serde::{Deserialize, Serialize};
9
10#[derive(Serialize, Deserialize, Debug, Clone)]
11#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
12pub struct UsedExitPolicy {
13    /// Flag indicating whether this node uses the below exit policy or
14    /// whether it still relies on the legacy allow lists.
15    pub enabled: bool,
16
17    /// Source URL from which the exit policy was obtained
18    #[cfg_attr(
19        feature = "openapi",
20        schema(example = "https://nymtech.net/.wellknown/network-requester/exit-policy.txt")
21    )]
22    pub upstream_source: String,
23
24    /// Unix timestamp indicating when the exit policy was last updated from the upstream.
25    #[cfg_attr(feature = "openapi", schema(example = 1697731611))]
26    pub last_updated: u64,
27
28    /// The actual policy used by this node.
29    // `ExitPolicy` is a type alias for `AddressPolicy`,
30    // but it seems utoipa is too stupid to realise it by itself
31    #[cfg_attr(feature = "openapi", schema(value_type = Option<AddressPolicy>))]
32    pub policy: Option<ExitPolicy>,
33}
34
35impl Default for UsedExitPolicy {
36    fn default() -> Self {
37        UsedExitPolicy {
38            enabled: false,
39            upstream_source: "".to_string(),
40            last_updated: 0,
41            policy: None,
42        }
43    }
44}