From d5a469a9e3ebf107a2a6da4eaeb5cf453f4a639a Mon Sep 17 00:00:00 2001 From: Michael Ilyin Date: Thu, 15 Jan 2026 18:48:28 +0100 Subject: [PATCH 1/2] transport and link --- src/lib.rs | 2 +- src/session.rs | 129 +++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 127 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 36b64f7a..c008de1f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -72,7 +72,7 @@ pub(crate) mod zenoh { }, sample::{Locality, Sample, SampleKind, SourceInfo}, scouting::{scout, Hello, Scout}, - session::{open, EntityGlobalId, Session, SessionInfo}, + session::{open, EntityGlobalId, Session, SessionInfo, Transport, Link}, time::{Timestamp, TimestampId, NTP64}, ZError, }; diff --git a/src/session.rs b/src/session.rs index 7c3afac6..a2a5c7bb 100644 --- a/src/session.rs +++ b/src/session.rs @@ -22,8 +22,8 @@ use zenoh::{session::EntityId, Wait}; use crate::{ bytes::{Encoding, ZBytes}, cancellation::CancellationToken, - config::{Config, ZenohId}, - handlers::{into_handler, HandlerImpl}, + config::{Config, WhatAmI, ZenohId}, + handlers::{HandlerImpl, into_handler}, key_expr::KeyExpr, liveliness::Liveliness, macros::{build, wrapper}, @@ -32,7 +32,7 @@ use crate::{ query::{Querier, QueryConsolidation, QueryTarget, Queryable, Reply, Selector}, sample::{Locality, SourceInfo}, time::Timestamp, - utils::{duration, wait, IntoPython, MapInto}, + utils::{IntoPython, MapInto, duration, wait}, }; #[pyclass] @@ -307,6 +307,113 @@ pub(crate) fn open(py: Python, config: Config) -> PyResult { wrapper!(zenoh::session::SessionInfo); +wrapper!(zenoh::session::Transport); + +#[pymethods] +impl Transport { + #[getter] + fn zid(&self) -> ZenohId { + (*self.0.zid()).into() + } + + #[getter] + fn whatami(&self) -> WhatAmI { + self.0.whatami().into() + } + + #[getter] + fn is_qos(&self) -> bool { + self.0.is_qos() + } + + #[cfg(feature = "shared-memory")] + #[getter] + fn is_shm(&self) -> bool { + self.0.is_shm() + } + + #[getter] + fn is_multicast(&self) -> bool { + self.0.is_multicast() + } + + fn __eq__(&self, other: &Transport) -> bool { + self.0 == other.0 + } + + fn __repr__(&self) -> String { + format!("{:?}", self.0) + } +} + +wrapper!(zenoh::session::Link); + +#[pymethods] +impl Link { + #[getter] + fn zid(&self) -> ZenohId { + (*self.0.zid()).into() + } + + #[getter] + fn src(&self) -> String { + self.0.src().to_string() + } + + #[getter] + fn dst(&self) -> String { + self.0.dst().to_string() + } + + #[getter] + fn group(&self) -> Option { + self.0.group().map(|g| g.to_string()) + } + + #[getter] + fn mtu(&self) -> u16 { + self.0.mtu() + } + + #[getter] + fn is_streamed(&self) -> bool { + self.0.is_streamed() + } + + #[getter] + fn interfaces<'py>(&self, py: Python<'py>) -> PyResult> { + let list = PyList::empty(py); + for interface in self.0.interfaces() { + list.append(interface)?; + } + Ok(list) + } + + #[getter] + fn auth_identifier(&self) -> Option { + self.0.auth_identifier().map(|s| s.to_string()) + } + + #[getter] + fn priorities(&self) -> Option<(u8, u8)> { + self.0.priorities() + } + + #[getter] + fn reliability(&self) -> Option { + self.0.reliability().map(Into::into) + } + + fn __eq__(&self, other: &Link) -> bool { + self.0 == other.0 + } + + fn __repr__(&self) -> String { + format!("{:?}", self.0) + } + +} + #[pymethods] impl SessionInfo { fn zid(&self, py: Python) -> ZenohId { @@ -329,6 +436,22 @@ impl SessionInfo { Ok(list) } + fn transports<'py>(&self, py: Python<'py>) -> PyResult> { + let list = PyList::empty(py); + for transport in py.allow_threads(|| self.0.transports().wait()) { + list.append(transport.into_pyobject(py))?; + } + Ok(list) + } + + fn links<'py>(&self, py: Python<'py>) -> PyResult> { + let list = PyList::empty(py); + for link in py.allow_threads(|| self.0.links().wait()) { + list.append(link.into_pyobject(py))?; + } + Ok(list) + } + // TODO __repr__ } From 7120c77231d4836fcf3fae61cf4d373041f005f1 Mon Sep 17 00:00:00 2001 From: Michael Ilyin Date: Mon, 19 Jan 2026 11:54:19 +0100 Subject: [PATCH 2/2] rustfmt --- src/lib.rs | 2 +- src/session.rs | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index c008de1f..ea99de38 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -72,7 +72,7 @@ pub(crate) mod zenoh { }, sample::{Locality, Sample, SampleKind, SourceInfo}, scouting::{scout, Hello, Scout}, - session::{open, EntityGlobalId, Session, SessionInfo, Transport, Link}, + session::{open, EntityGlobalId, Link, Session, SessionInfo, Transport}, time::{Timestamp, TimestampId, NTP64}, ZError, }; diff --git a/src/session.rs b/src/session.rs index a2a5c7bb..d4d8819e 100644 --- a/src/session.rs +++ b/src/session.rs @@ -23,7 +23,7 @@ use crate::{ bytes::{Encoding, ZBytes}, cancellation::CancellationToken, config::{Config, WhatAmI, ZenohId}, - handlers::{HandlerImpl, into_handler}, + handlers::{into_handler, HandlerImpl}, key_expr::KeyExpr, liveliness::Liveliness, macros::{build, wrapper}, @@ -32,7 +32,7 @@ use crate::{ query::{Querier, QueryConsolidation, QueryTarget, Queryable, Reply, Selector}, sample::{Locality, SourceInfo}, time::Timestamp, - utils::{IntoPython, MapInto, duration, wait}, + utils::{duration, wait, IntoPython, MapInto}, }; #[pyclass] @@ -411,7 +411,6 @@ impl Link { fn __repr__(&self) -> String { format!("{:?}", self.0) } - } #[pymethods]