Skip to content

Commit

Permalink
add allowed origin queryable option (#936)
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisBiryukov91 authored Mar 4, 2025
1 parent af53af3 commit 89acbaa
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
11 changes: 10 additions & 1 deletion include/zenoh_commons.h
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,14 @@ typedef struct z_queryable_options_t {
* The completeness of the Queryable.
*/
bool complete;
#if defined(Z_FEATURE_UNSTABLE_API)
/**
* @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release.
* Restricts the matching requests that will be received by this Queryable to the ones
* that have the compatible allowed_destination.
*/
enum zc_locality_t allowed_origin;
#endif
} z_queryable_options_t;
/**
* Options passed to the `z_declare_subscriber()` function.
Expand All @@ -438,7 +446,8 @@ typedef struct z_subscriber_options_t {
#endif
#if defined(Z_FEATURE_UNSTABLE_API)
/**
* Restricts the matching publications that will be received by this Subscribers to the ones
* @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release.
* Restricts the matching publications that will be received by this Subscriber to the ones
* that have the compatible allowed_destination.
*/
enum zc_locality_t allowed_origin;
Expand Down
19 changes: 16 additions & 3 deletions src/queryable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ use crate::{
z_closure_query_call, z_closure_query_loan, z_congestion_control_t, z_loaned_bytes_t,
z_loaned_encoding_t, z_loaned_keyexpr_t, z_loaned_session_t, z_moved_bytes_t,
z_moved_closure_query_t, z_moved_encoding_t, z_moved_queryable_t, z_priority_t, z_timestamp_t,
z_view_string_from_substr, z_view_string_t,
z_view_string_from_substr, z_view_string_t, zc_locality_t,
};
#[cfg(feature = "unstable")]
use crate::{z_entity_global_id_t, z_moved_source_info_t};
use crate::{z_entity_global_id_t, z_moved_source_info_t, zc_locality_default};
decl_c_type!(
owned(z_owned_queryable_t, option Queryable<()>),
loaned(z_loaned_queryable_t),
Expand Down Expand Up @@ -128,12 +128,21 @@ pub extern "C" fn z_query_clone(dst: &mut MaybeUninit<z_owned_query_t>, this_: &
pub struct z_queryable_options_t {
/// The completeness of the Queryable.
pub complete: bool,
#[cfg(feature = "unstable")]
/// @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release.
/// Restricts the matching requests that will be received by this Queryable to the ones
/// that have the compatible allowed_destination.
pub allowed_origin: zc_locality_t,
}
/// Constructs the default value for `z_query_reply_options_t`.
#[no_mangle]
#[allow(clippy::missing_safety_doc)]
pub extern "C" fn z_queryable_options_default(this_: &mut MaybeUninit<z_queryable_options_t>) {
this_.write(z_queryable_options_t { complete: false });
this_.write(z_queryable_options_t {
complete: false,
#[cfg(feature = "unstable")]
allowed_origin: zc_locality_default(),
});
}

/// Represents the set of options that can be applied to a query reply,
Expand Down Expand Up @@ -245,6 +254,10 @@ fn _declare_queryable_inner<'a, 'b>(
let mut builder = session.declare_queryable(keyexpr);
if let Some(options) = options {
builder = builder.complete(options.complete);
#[cfg(feature = "unstable")]
{
builder = builder.allowed_origin(options.allowed_origin.into())
}
}
let queryable = builder.callback(move |query| {
let mut owned_query = Some(query);
Expand Down
3 changes: 2 additions & 1 deletion src/subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ pub struct z_subscriber_options_t {
/// Dummy field to avoid having fieldless struct
pub _0: u8,
#[cfg(feature = "unstable")]
/// Restricts the matching publications that will be received by this Subscribers to the ones
/// @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release.
/// Restricts the matching publications that will be received by this Subscriber to the ones
/// that have the compatible allowed_destination.
pub allowed_origin: zc_locality_t,
}
Expand Down

0 comments on commit 89acbaa

Please sign in to comment.