// This file is @generated by prost-build.
/// Predicate for selecting relays.
///
/// This message is used to specify the constraints that should be applied
/// when selecting relays, along with a context that may affect the selection
/// behavior.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Predicate {
    #[prost(oneof = "predicate::Context", tags = "1, 2, 3, 4")]
    pub context: ::core::option::Option<predicate::Context>,
}
/// Nested message and enum types in `Predicate`.
pub mod predicate {
    #[derive(Clone, PartialEq, ::prost::Oneof)]
    pub enum Context {
        /// Get matching relays for singlehop configuration.
        #[prost(message, tag = "1")]
        Singlehop(super::EntryConstraints),
        /// Get matching relays with automatic multihop when necessary.
        ///
        /// If the entry-specific constraints are not met for a given relay but an
        /// alternative entry node can be selected that matches the constraints, the
        /// relay will still be returned as a viable exit node. Connecting to the
        /// relay will result in a implicit multihop connection.
        #[prost(message, tag = "2")]
        Autohop(super::EntryConstraints),
        /// Get matching entry relays for multihop.
        #[prost(message, tag = "3")]
        Entry(super::MultiHopConstraints),
        /// Get matching exit relays for multihop.
        #[prost(message, tag = "4")]
        Exit(super::MultiHopConstraints),
    }
}
/// Constraints that apply to relays for singlehop or the first hop
/// in a multihop configuration.
///
/// These include all the of `ExitConstraints`, and a few entry
/// specific features.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct EntryConstraints {
    #[prost(message, optional, tag = "1")]
    pub general_constraints: ::core::option::Option<ExitConstraints>,
    /// -- Entry specific constraints --
    #[prost(message, optional, tag = "2")]
    pub obfuscation_settings: ::core::option::Option<
        super::management_interface::ObfuscationSettings,
    >,
    #[prost(message, optional, tag = "3")]
    pub daita_settings: ::core::option::Option<
        super::management_interface::DaitaSettings,
    >,
    #[prost(enumeration = "super::management_interface::IpVersion", optional, tag = "4")]
    pub ip_version: ::core::option::Option<i32>,
}
/// Constraints that apply to the second hop in a multihop configuration.
/// This is a subset of `EntryConstraints`.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ExitConstraints {
    #[prost(message, optional, tag = "1")]
    pub location: ::core::option::Option<
        super::management_interface::LocationConstraint,
    >,
    /// Only show exit locations operated by these providers.
    ///
    /// Constructing this parameter with 0 providers means that no filtering is
    /// done based on the provider. I.e. relays from all providers are shown.
    #[prost(message, repeated, tag = "2")]
    pub providers: ::prost::alloc::vec::Vec<Provider>,
    #[prost(enumeration = "super::management_interface::Ownership", tag = "3")]
    pub ownership: i32,
}
/// Constraints for both hops in a multihop configuration.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct MultiHopConstraints {
    #[prost(message, optional, tag = "1")]
    pub entry: ::core::option::Option<EntryConstraints>,
    #[prost(message, optional, tag = "2")]
    pub exit: ::core::option::Option<ExitConstraints>,
}
/// The result of the relay selection algorithm.
///
/// Contains the list of relays matching a predicate and the list of relays
/// that were discarded when evaluating a predicate.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct RelayPartitions {
    /// List of relays matching a predicate.
    #[prost(message, repeated, tag = "1")]
    pub matches: ::prost::alloc::vec::Vec<Relay>,
    /// List of relays that were discarded when evaluating the same predicate.
    #[prost(message, repeated, tag = "2")]
    pub discards: ::prost::alloc::vec::Vec<DiscardedRelay>,
}
/// A relay from the relay list.
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct Relay {
    /// A hostname that uniquely identifies a single VPN relay.
    ///
    /// It is the full hostname, e.g. `se-got-wg-101`.
    /// This can *NOT* be a location, e.g. `se` or `se-got`.
    #[prost(string, tag = "1")]
    pub hostname: ::prost::alloc::string::String,
}
/// A relay which was discarded when evaluating some predicate, and why.
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct DiscardedRelay {
    /// Relay that was discarded.
    #[prost(message, optional, tag = "1")]
    pub relay: ::core::option::Option<Relay>,
    /// The list of constraints that did not match the relay.
    ///
    /// This can be interpreted as a list of criteria necessary
    /// to unblock the relay from being selectable.
    #[prost(message, optional, tag = "2")]
    pub why: ::core::option::Option<IncompatibleConstraints>,
}
/// Set of constraints that prevents the relay from being selected.
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct IncompatibleConstraints {
    /// The relay is currently offline.
    #[prost(bool, tag = "1")]
    pub inactive: bool,
    /// The relay does not reside in the given location.
    #[prost(bool, tag = "2")]
    pub location: bool,
    /// The relay is not hosted by the given provider.
    #[prost(bool, tag = "3")]
    pub providers: bool,
    /// The relay ownership does not match.
    #[prost(bool, tag = "4")]
    pub ownership: bool,
    /// The relay cannot be connected to with the requested ip version.
    #[prost(bool, tag = "5")]
    pub ip_version: bool,
    /// The relay does not run DAITA.
    #[prost(bool, tag = "6")]
    pub daita: bool,
    /// The requested obfuscation method is not available.
    #[prost(bool, tag = "7")]
    pub obfuscation: bool,
    /// The relay cannot be connected to via the requested port.
    #[prost(bool, tag = "8")]
    pub port: bool,
    /// This relay is already used for the other hop (entry/exit).
    #[prost(bool, tag = "9")]
    pub conflict_with_other_hop: bool,
}
/// A hosting provider.
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct Provider {
    /// The name of the provider.
    #[prost(string, tag = "1")]
    pub name: ::prost::alloc::string::String,
}
/// Generated client implementations.
pub mod relay_selector_service_client {
    #![allow(
        unused_variables,
        dead_code,
        missing_docs,
        clippy::wildcard_imports,
        clippy::let_unit_value,
    )]
    use tonic::codegen::*;
    use tonic::codegen::http::Uri;
    /// Relay Selector service.
    ///
    /// This API is used to query which relays are selectable for a set of filters,
    /// and to provide information about about how to unblock discarded relays.
    #[derive(Debug, Clone)]
    pub struct RelaySelectorServiceClient<T> {
        inner: tonic::client::Grpc<T>,
    }
    impl RelaySelectorServiceClient<tonic::transport::Channel> {
        /// Attempt to create a new client by connecting to a given endpoint.
        pub async fn connect<D>(dst: D) -> Result<Self, tonic::transport::Error>
        where
            D: TryInto<tonic::transport::Endpoint>,
            D::Error: Into<StdError>,
        {
            let conn = tonic::transport::Endpoint::new(dst)?.connect().await?;
            Ok(Self::new(conn))
        }
    }
    impl<T> RelaySelectorServiceClient<T>
    where
        T: tonic::client::GrpcService<tonic::body::Body>,
        T::Error: Into<StdError>,
        T::ResponseBody: Body<Data = Bytes> + std::marker::Send + 'static,
        <T::ResponseBody as Body>::Error: Into<StdError> + std::marker::Send,
    {
        pub fn new(inner: T) -> Self {
            let inner = tonic::client::Grpc::new(inner);
            Self { inner }
        }
        pub fn with_origin(inner: T, origin: Uri) -> Self {
            let inner = tonic::client::Grpc::with_origin(inner, origin);
            Self { inner }
        }
        pub fn with_interceptor<F>(
            inner: T,
            interceptor: F,
        ) -> RelaySelectorServiceClient<InterceptedService<T, F>>
        where
            F: tonic::service::Interceptor,
            T::ResponseBody: Default,
            T: tonic::codegen::Service<
                http::Request<tonic::body::Body>,
                Response = http::Response<
                    <T as tonic::client::GrpcService<tonic::body::Body>>::ResponseBody,
                >,
            >,
            <T as tonic::codegen::Service<
                http::Request<tonic::body::Body>,
            >>::Error: Into<StdError> + std::marker::Send + std::marker::Sync,
        {
            RelaySelectorServiceClient::new(InterceptedService::new(inner, interceptor))
        }
        /// Compress requests with the given encoding.
        ///
        /// This requires the server to support it otherwise it might respond with an
        /// error.
        #[must_use]
        pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
            self.inner = self.inner.send_compressed(encoding);
            self
        }
        /// Enable decompressing responses.
        #[must_use]
        pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
            self.inner = self.inner.accept_compressed(encoding);
            self
        }
        /// Limits the maximum size of a decoded message.
        ///
        /// Default: `4MB`
        #[must_use]
        pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
            self.inner = self.inner.max_decoding_message_size(limit);
            self
        }
        /// Limits the maximum size of an encoded message.
        ///
        /// Default: `usize::MAX`
        #[must_use]
        pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
            self.inner = self.inner.max_encoding_message_size(limit);
            self
        }
        /// Partition the available relays by a predicate. The predicate can be
        /// derived from the current settings or a set of future settings changes
        /// before they are applied.
        ///
        /// Returns a list of matching relays. For each connection using the given
        /// constraints, one/a pair of these relays will be selected at random.
        ///
        /// Also returns a list of non-matching relays along with the set of
        /// constraints/conditions that made them unavailable.
        pub async fn partition_relays(
            &mut self,
            request: impl tonic::IntoRequest<super::Predicate>,
        ) -> std::result::Result<
            tonic::Response<super::RelayPartitions>,
            tonic::Status,
        > {
            self.inner
                .ready()
                .await
                .map_err(|e| {
                    tonic::Status::unknown(
                        format!("Service was not ready: {}", e.into()),
                    )
                })?;
            let codec = tonic_prost::ProstCodec::default();
            let path = http::uri::PathAndQuery::from_static(
                "/mullvad_daemon.relay_selector.RelaySelectorService/PartitionRelays",
            );
            let mut req = request.into_request();
            req.extensions_mut()
                .insert(
                    GrpcMethod::new(
                        "mullvad_daemon.relay_selector.RelaySelectorService",
                        "PartitionRelays",
                    ),
                );
            self.inner.unary(req, path, codec).await
        }
    }
}
/// Generated server implementations.
pub mod relay_selector_service_server {
    #![allow(
        unused_variables,
        dead_code,
        missing_docs,
        clippy::wildcard_imports,
        clippy::let_unit_value,
    )]
    use tonic::codegen::*;
    /// Generated trait containing gRPC methods that should be implemented for use with RelaySelectorServiceServer.
    #[async_trait]
    pub trait RelaySelectorService: std::marker::Send + std::marker::Sync + 'static {
        /// Partition the available relays by a predicate. The predicate can be
        /// derived from the current settings or a set of future settings changes
        /// before they are applied.
        ///
        /// Returns a list of matching relays. For each connection using the given
        /// constraints, one/a pair of these relays will be selected at random.
        ///
        /// Also returns a list of non-matching relays along with the set of
        /// constraints/conditions that made them unavailable.
        async fn partition_relays(
            &self,
            request: tonic::Request<super::Predicate>,
        ) -> std::result::Result<tonic::Response<super::RelayPartitions>, tonic::Status>;
    }
    /// Relay Selector service.
    ///
    /// This API is used to query which relays are selectable for a set of filters,
    /// and to provide information about about how to unblock discarded relays.
    #[derive(Debug)]
    pub struct RelaySelectorServiceServer<T> {
        inner: Arc<T>,
        accept_compression_encodings: EnabledCompressionEncodings,
        send_compression_encodings: EnabledCompressionEncodings,
        max_decoding_message_size: Option<usize>,
        max_encoding_message_size: Option<usize>,
    }
    impl<T> RelaySelectorServiceServer<T> {
        pub fn new(inner: T) -> Self {
            Self::from_arc(Arc::new(inner))
        }
        pub fn from_arc(inner: Arc<T>) -> Self {
            Self {
                inner,
                accept_compression_encodings: Default::default(),
                send_compression_encodings: Default::default(),
                max_decoding_message_size: None,
                max_encoding_message_size: None,
            }
        }
        pub fn with_interceptor<F>(
            inner: T,
            interceptor: F,
        ) -> InterceptedService<Self, F>
        where
            F: tonic::service::Interceptor,
        {
            InterceptedService::new(Self::new(inner), interceptor)
        }
        /// Enable decompressing requests with the given encoding.
        #[must_use]
        pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
            self.accept_compression_encodings.enable(encoding);
            self
        }
        /// Compress responses with the given encoding, if the client supports it.
        #[must_use]
        pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
            self.send_compression_encodings.enable(encoding);
            self
        }
        /// Limits the maximum size of a decoded message.
        ///
        /// Default: `4MB`
        #[must_use]
        pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
            self.max_decoding_message_size = Some(limit);
            self
        }
        /// Limits the maximum size of an encoded message.
        ///
        /// Default: `usize::MAX`
        #[must_use]
        pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
            self.max_encoding_message_size = Some(limit);
            self
        }
    }
    impl<T, B> tonic::codegen::Service<http::Request<B>>
    for RelaySelectorServiceServer<T>
    where
        T: RelaySelectorService,
        B: Body + std::marker::Send + 'static,
        B::Error: Into<StdError> + std::marker::Send + 'static,
    {
        type Response = http::Response<tonic::body::Body>;
        type Error = std::convert::Infallible;
        type Future = BoxFuture<Self::Response, Self::Error>;
        fn poll_ready(
            &mut self,
            _cx: &mut Context<'_>,
        ) -> Poll<std::result::Result<(), Self::Error>> {
            Poll::Ready(Ok(()))
        }
        fn call(&mut self, req: http::Request<B>) -> Self::Future {
            match req.uri().path() {
                "/mullvad_daemon.relay_selector.RelaySelectorService/PartitionRelays" => {
                    #[allow(non_camel_case_types)]
                    struct PartitionRelaysSvc<T: RelaySelectorService>(pub Arc<T>);
                    impl<
                        T: RelaySelectorService,
                    > tonic::server::UnaryService<super::Predicate>
                    for PartitionRelaysSvc<T> {
                        type Response = super::RelayPartitions;
                        type Future = BoxFuture<
                            tonic::Response<Self::Response>,
                            tonic::Status,
                        >;
                        fn call(
                            &mut self,
                            request: tonic::Request<super::Predicate>,
                        ) -> Self::Future {
                            let inner = Arc::clone(&self.0);
                            let fut = async move {
                                <T as RelaySelectorService>::partition_relays(
                                        &inner,
                                        request,
                                    )
                                    .await
                            };
                            Box::pin(fut)
                        }
                    }
                    let accept_compression_encodings = self.accept_compression_encodings;
                    let send_compression_encodings = self.send_compression_encodings;
                    let max_decoding_message_size = self.max_decoding_message_size;
                    let max_encoding_message_size = self.max_encoding_message_size;
                    let inner = self.inner.clone();
                    let fut = async move {
                        let method = PartitionRelaysSvc(inner);
                        let codec = tonic_prost::ProstCodec::default();
                        let mut grpc = tonic::server::Grpc::new(codec)
                            .apply_compression_config(
                                accept_compression_encodings,
                                send_compression_encodings,
                            )
                            .apply_max_message_size_config(
                                max_decoding_message_size,
                                max_encoding_message_size,
                            );
                        let res = grpc.unary(method, req).await;
                        Ok(res)
                    };
                    Box::pin(fut)
                }
                _ => {
                    Box::pin(async move {
                        let mut response = http::Response::new(
                            tonic::body::Body::default(),
                        );
                        let headers = response.headers_mut();
                        headers
                            .insert(
                                tonic::Status::GRPC_STATUS,
                                (tonic::Code::Unimplemented as i32).into(),
                            );
                        headers
                            .insert(
                                http::header::CONTENT_TYPE,
                                tonic::metadata::GRPC_CONTENT_TYPE,
                            );
                        Ok(response)
                    })
                }
            }
        }
    }
    impl<T> Clone for RelaySelectorServiceServer<T> {
        fn clone(&self) -> Self {
            let inner = self.inner.clone();
            Self {
                inner,
                accept_compression_encodings: self.accept_compression_encodings,
                send_compression_encodings: self.send_compression_encodings,
                max_decoding_message_size: self.max_decoding_message_size,
                max_encoding_message_size: self.max_encoding_message_size,
            }
        }
    }
    /// Generated gRPC service name
    pub const SERVICE_NAME: &str = "mullvad_daemon.relay_selector.RelaySelectorService";
    impl<T> tonic::server::NamedService for RelaySelectorServiceServer<T> {
        const NAME: &'static str = SERVICE_NAME;
    }
}
