Skip to content

Commit e74c967

Browse files
author
Hugo Laloge
committed
Merge remote-tracking branch 'upstream/main' into feature/endpoint-auto-update
2 parents 782021d + ffbe455 commit e74c967

File tree

92 files changed

+2595
-1105
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+2595
-1105
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ jobs:
116116
- name: Clippy zenoh
117117
run: cargo +stable clippy -p zenoh --all-targets -- --deny warnings
118118

119+
- name: Clippy zenoh internal_config
120+
run: cargo +stable clippy -p zenoh --all-targets --features internal_config -- --deny warnings
121+
119122
- name: Clippy zenoh unstable
120123
run: cargo +stable clippy -p zenoh --all-targets --features unstable -- --deny warnings
121124

@@ -189,7 +192,10 @@ jobs:
189192
- name: Install latest nextest
190193
uses: taiki-e/install-action@nextest
191194

192-
- name: Run tests
195+
- name: Run tests stable
196+
run: cargo nextest run -p zenoh -F internal_config
197+
198+
- name: Run tests with unstable
193199
run: cargo nextest run -F test -F internal_config --exclude zenoh-examples --exclude zenoh-plugin-example --workspace
194200

195201
- name: Rename junit test report

Cargo.lock

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ const_format = "0.2.33"
9494
criterion = "0.5"
9595
crossbeam-utils = "0.8.20"
9696
crossbeam-queue = "0.3.12"
97+
crossbeam-channel = "0.5"
98+
static_assertions = "1.1.0"
9799
derive_more = { version = "1.0.0", features = ["as_ref"] }
98100
derive-new = "0.7.0"
99101
tracing-subscriber = { version = "0.3", features = ["json", "env-filter"] }
@@ -107,7 +109,7 @@ getrandom = { version = "0.2" }
107109
hashbrown = "0.14"
108110
hex = { version = "0.4.3", default-features = false } # Default features are disabled due to usage in no_std crates
109111
hmac = { version = "0.12.1", features = ["std"] }
110-
home = "=0.5.9"
112+
home = "0.5.9"
111113
http-types = "2.12.0"
112114
humantime = "2.1.0"
113115
itertools = "0.13.0"
@@ -196,6 +198,7 @@ z-serial = "0.3.1"
196198
either = "1.13.0"
197199
prost = "0.13.2"
198200
tls-listener = { version = "0.11.0", features = ["rustls-ring"] }
201+
windows-sys = { version = "0.59.0", features = ["Win32_Foundation", "Win32_Networking_WinSock", "Win32_System_IO"] }
199202
zenoh-ext = { version = "=1.4.0", path = "zenoh-ext", default-features = false }
200203
zenoh-shm = { version = "=1.4.0", path = "commons/zenoh-shm" }
201204
zenoh-result = { version = "=1.4.0", path = "commons/zenoh-result", default-features = false }

commons/zenoh-config/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,8 @@ validated_struct::validator! {
357357
#[doc(hidden)]
358358
Config {
359359
/// The Zenoh ID of the instance. This ID MUST be unique throughout your Zenoh infrastructure and cannot exceed 16 bytes of length. If left unset, a random u128 will be generated.
360-
id: ZenohId,
360+
/// If not specified a random Zenoh ID will be generated upon session creation.
361+
id: Option<ZenohId>,
361362
/// The metadata of the instance. Arbitrary json data available from the admin space
362363
metadata: Value,
363364
/// The node's mode ("router" (default value in `zenohd`), "peer" or "client").

commons/zenoh-shm/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ num_cpus = { workspace = true, optional = true }
4646
thread-priority = { workspace = true }
4747
stabby = { workspace = true }
4848
crossbeam-queue = { workspace = true }
49+
crossbeam-channel = { workspace = true }
50+
static_assertions = { workspace = true }
4951

5052
[target.'cfg(unix)'.dependencies]
5153
advisory-lock = { workspace = true }

commons/zenoh-shm/src/api/buffer/traits.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,20 @@
1212
// ZettaScale Zenoh Team, <[email protected]>
1313
//
1414

15-
use std::ops::{Deref, DerefMut};
15+
use std::{
16+
num::NonZeroUsize,
17+
ops::{Deref, DerefMut},
18+
};
19+
20+
use crate::api::provider::types::MemoryLayout;
21+
22+
/// Errors for buffer relayouting operation.
23+
#[zenoh_macros::unstable_doc]
24+
#[derive(Debug)]
25+
pub enum BufferRelayoutError {
26+
IncompatibleAlignment,
27+
SizeTooBig,
28+
}
1629

1730
#[zenoh_macros::unstable_doc]
1831
pub trait ShmBuf: Deref<Target = [u8]> + AsRef<[u8]> {
@@ -22,3 +35,12 @@ pub trait ShmBuf: Deref<Target = [u8]> + AsRef<[u8]> {
2235

2336
#[zenoh_macros::unstable_doc]
2437
pub trait ShmBufMut: ShmBuf + DerefMut + AsMut<[u8]> {}
38+
39+
#[zenoh_macros::unstable_doc]
40+
pub trait OwnedShmBuf: ShmBuf {
41+
#[zenoh_macros::unstable_doc]
42+
fn try_resize(&mut self, new_size: NonZeroUsize) -> Option<()>;
43+
44+
#[zenoh_macros::unstable_doc]
45+
fn try_relayout(&mut self, new_layout: MemoryLayout) -> Result<(), BufferRelayoutError>;
46+
}

commons/zenoh-shm/src/api/buffer/zshm.rs

Lines changed: 50 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@
1515
use core::ops::Deref;
1616
use std::{
1717
borrow::{Borrow, BorrowMut},
18-
ops::DerefMut,
18+
num::NonZeroUsize,
1919
};
2020

2121
use zenoh_buffers::{ZBuf, ZSlice};
2222

23-
use super::{traits::ShmBuf, zshmmut::zshmmut};
24-
use crate::ShmBufInner;
23+
use super::{
24+
traits::{BufferRelayoutError, OwnedShmBuf, ShmBuf},
25+
zshmmut::{zshmmut, ZShmMut},
26+
};
27+
use crate::{api::provider::types::MemoryLayout, ShmBufInner};
2528

2629
/// An immutable SHM buffer
2730
#[zenoh_macros::unstable_doc]
@@ -35,9 +38,23 @@ impl ShmBuf for ZShm {
3538
}
3639
}
3740

41+
impl OwnedShmBuf for ZShm {
42+
fn try_resize(&mut self, new_size: NonZeroUsize) -> Option<()> {
43+
// Safety: this is safe because ZShm is an owned representation of SHM buffer and thus
44+
// is guaranteed not to be wrapped into ZSlice (see ShmBufInner::try_resize comment)
45+
unsafe { self.0.try_resize(new_size) }
46+
}
47+
48+
fn try_relayout(&mut self, new_layout: MemoryLayout) -> Result<(), BufferRelayoutError> {
49+
// Safety: this is safe because ZShm is an owned representation of SHM buffer and thus
50+
// is guaranteed not to be wrapped into ZSlice (see ShmBufInner::try_relayout comment)
51+
unsafe { self.0.try_relayout(new_layout) }
52+
}
53+
}
54+
3855
impl PartialEq<&zshm> for ZShm {
3956
fn eq(&self, other: &&zshm) -> bool {
40-
self.0 == other.0 .0
57+
self.0 == other.0
4158
}
4259
}
4360

@@ -71,12 +88,6 @@ impl AsRef<[u8]> for ZShm {
7188
}
7289
}
7390

74-
impl From<ShmBufInner> for ZShm {
75-
fn from(value: ShmBufInner) -> Self {
76-
Self(value)
77-
}
78-
}
79-
8091
impl From<ZShm> for ZSlice {
8192
fn from(value: ZShm) -> Self {
8293
value.0.into()
@@ -89,6 +100,17 @@ impl From<ZShm> for ZBuf {
89100
}
90101
}
91102

103+
impl TryFrom<ZShm> for ZShmMut {
104+
type Error = ZShm;
105+
106+
fn try_from(value: ZShm) -> Result<Self, Self::Error> {
107+
match value.0.is_unique() && value.0.is_valid() {
108+
true => Ok(Self(value.0)),
109+
false => Err(value),
110+
}
111+
}
112+
}
113+
92114
impl TryFrom<&mut ZShm> for &mut zshmmut {
93115
type Error = ();
94116

@@ -109,57 +131,47 @@ impl TryFrom<&mut ZShm> for &mut zshmmut {
109131
#[derive(Debug, PartialEq, Eq)]
110132
#[allow(non_camel_case_types)]
111133
#[repr(transparent)]
112-
pub struct zshm(ZShm);
113-
114-
impl ToOwned for zshm {
115-
type Owned = ZShm;
134+
pub struct zshm(ShmBufInner);
116135

117-
fn to_owned(&self) -> Self::Owned {
118-
self.0.clone()
119-
}
120-
}
121-
122-
impl PartialEq<ZShm> for &zshm {
123-
fn eq(&self, other: &ZShm) -> bool {
124-
self.0 .0 == other.0
136+
impl ShmBuf for zshm {
137+
fn is_valid(&self) -> bool {
138+
self.0.is_valid()
125139
}
126140
}
127141

128142
impl Deref for zshm {
129-
type Target = ZShm;
143+
type Target = [u8];
130144

131145
fn deref(&self) -> &Self::Target {
132-
&self.0
146+
self.0.as_ref()
133147
}
134148
}
135149

136-
impl DerefMut for zshm {
137-
fn deref_mut(&mut self) -> &mut Self::Target {
138-
&mut self.0
150+
impl AsRef<[u8]> for zshm {
151+
fn as_ref(&self) -> &[u8] {
152+
self
139153
}
140154
}
141155

142-
impl From<&ShmBufInner> for &zshm {
143-
fn from(value: &ShmBufInner) -> Self {
144-
// SAFETY: ZShm, ZShmMut, zshm and zshmmut are #[repr(transparent)]
145-
// to ShmBufInner type, so it is safe to transmute them in any direction
146-
unsafe { core::mem::transmute(value) }
156+
impl ToOwned for zshm {
157+
type Owned = ZShm;
158+
159+
fn to_owned(&self) -> Self::Owned {
160+
self.0.clone().into()
147161
}
148162
}
149163

150-
impl From<&mut ShmBufInner> for &mut zshm {
151-
fn from(value: &mut ShmBufInner) -> Self {
152-
// SAFETY: ZShm, ZShmMut, zshm and zshmmut are #[repr(transparent)]
153-
// to ShmBufInner type, so it is safe to transmute them in any direction
154-
unsafe { core::mem::transmute(value) }
164+
impl PartialEq<ZShm> for &zshm {
165+
fn eq(&self, other: &ZShm) -> bool {
166+
self.0 == other.0
155167
}
156168
}
157169

158170
impl TryFrom<&mut zshm> for &mut zshmmut {
159171
type Error = ();
160172

161173
fn try_from(value: &mut zshm) -> Result<Self, Self::Error> {
162-
match value.0 .0.is_unique() && value.0 .0.is_valid() {
174+
match value.0.is_unique() && value.0.is_valid() {
163175
true => {
164176
// SAFETY: ZShm, ZShmMut, zshm and zshmmut are #[repr(transparent)]
165177
// to ShmBufInner type, so it is safe to transmute them in any direction

0 commit comments

Comments
 (0)