├── .cargo └── config.toml ├── .codecov.yml ├── .config └── nextest.toml ├── .dockerignore ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.yml │ ├── config.yml │ ├── new_feature.yml │ └── release.yml ├── release.yml └── workflows │ ├── check-labels.yml │ ├── ci.yml │ ├── pre-release.yml │ ├── release.yml │ └── update-release-project.yml ├── .gitignore ├── .markdownlint.yaml ├── .pre-commit-config.yaml ├── CHANGELOG.md ├── CONTRIBUTING.md ├── CONTRIBUTORS.md ├── Cargo.lock ├── Cargo.toml ├── Cross.toml ├── DEFAULT_CONFIG.json5 ├── LICENSE ├── NOTICE.md ├── README.md ├── _typos.toml ├── ci ├── nostd-check │ ├── Cargo.toml │ ├── rust-toolchain.toml │ └── src │ │ └── bin │ │ └── nostd_check.rs └── valgrind-check │ ├── Cargo.toml │ ├── run.sh │ └── src │ ├── pub_sub │ └── bin │ │ └── z_pub_sub.rs │ └── queryable_get │ └── bin │ └── z_queryable_get.rs ├── clippy.toml ├── commons ├── zenoh-buffers │ ├── Cargo.toml │ ├── README.md │ ├── src │ │ ├── bbuf.rs │ │ ├── lib.rs │ │ ├── slice.rs │ │ ├── vec.rs │ │ ├── zbuf.rs │ │ └── zslice.rs │ └── tests │ │ └── readwrite.rs ├── zenoh-codec │ ├── Cargo.toml │ ├── README.md │ ├── benches │ │ └── codec.rs │ ├── src │ │ ├── common │ │ │ ├── extension.rs │ │ │ └── mod.rs │ │ ├── core │ │ │ ├── encoding.rs │ │ │ ├── locator.rs │ │ │ ├── mod.rs │ │ │ ├── shm.rs │ │ │ ├── timestamp.rs │ │ │ ├── wire_expr.rs │ │ │ ├── zbuf.rs │ │ │ ├── zenohid.rs │ │ │ ├── zint.rs │ │ │ └── zslice.rs │ │ ├── lib.rs │ │ ├── network │ │ │ ├── declare.rs │ │ │ ├── interest.rs │ │ │ ├── mod.rs │ │ │ ├── oam.rs │ │ │ ├── push.rs │ │ │ ├── request.rs │ │ │ └── response.rs │ │ ├── scouting │ │ │ ├── hello.rs │ │ │ ├── mod.rs │ │ │ └── scout.rs │ │ ├── transport │ │ │ ├── batch.rs │ │ │ ├── close.rs │ │ │ ├── fragment.rs │ │ │ ├── frame.rs │ │ │ ├── init.rs │ │ │ ├── join.rs │ │ │ ├── keepalive.rs │ │ │ ├── mod.rs │ │ │ ├── oam.rs │ │ │ └── open.rs │ │ └── zenoh │ │ │ ├── del.rs │ │ │ ├── err.rs │ │ │ ├── mod.rs │ │ │ ├── put.rs │ │ │ ├── query.rs │ │ │ └── reply.rs │ └── tests │ │ └── codec.rs ├── zenoh-collections │ ├── Cargo.toml │ ├── README.md │ └── src │ │ ├── lib.rs │ │ ├── ring_buffer.rs │ │ ├── single_or_box_hashset.rs │ │ ├── single_or_vec.rs │ │ └── stack_buffer.rs ├── zenoh-config │ ├── Cargo.toml │ ├── README.md │ └── src │ │ ├── connection_retry.rs │ │ ├── defaults.rs │ │ ├── include.rs │ │ ├── lib.rs │ │ ├── mode_dependent.rs │ │ ├── qos.rs │ │ └── wrappers.rs ├── zenoh-core │ ├── Cargo.toml │ ├── README.md │ └── src │ │ ├── lib.rs │ │ └── macros.rs ├── zenoh-crypto │ ├── Cargo.toml │ ├── README.md │ └── src │ │ ├── cipher.rs │ │ ├── hmac.rs │ │ ├── lib.rs │ │ └── prng.rs ├── zenoh-keyexpr │ ├── Cargo.toml │ ├── README.md │ ├── benches │ │ └── keyexpr_tree.rs │ └── src │ │ ├── key_expr │ │ ├── borrowed.rs │ │ ├── canon.rs │ │ ├── format │ │ │ ├── mod.rs │ │ │ ├── parsing.rs │ │ │ └── support.rs │ │ ├── fuzzer.rs │ │ ├── include.rs │ │ ├── intersect │ │ │ ├── classical.rs │ │ │ ├── ltr.rs │ │ │ ├── ltr_chunk.rs │ │ │ ├── middle_out.rs │ │ │ └── mod.rs │ │ ├── mod.rs │ │ ├── owned.rs │ │ ├── tests.rs │ │ └── utils.rs │ │ ├── keyexpr_tree │ │ ├── arc_tree.rs │ │ ├── box_tree.rs │ │ ├── impls │ │ │ ├── hashmap_impl.rs │ │ │ ├── keyed_set_impl.rs │ │ │ ├── mod.rs │ │ │ └── vec_set_impl.rs │ │ ├── iters │ │ │ ├── includer.rs │ │ │ ├── inclusion.rs │ │ │ ├── intersection.rs │ │ │ ├── mod.rs │ │ │ └── tree_iter.rs │ │ ├── mod.rs │ │ ├── support.rs │ │ ├── test.rs │ │ └── traits │ │ │ ├── default_impls.rs │ │ │ └── mod.rs │ │ └── lib.rs ├── zenoh-macros │ ├── Cargo.toml │ ├── README.md │ ├── build.rs │ └── src │ │ ├── lib.rs │ │ └── zenoh_runtime_derive.rs ├── zenoh-protocol │ ├── Cargo.toml │ ├── README.md │ └── src │ │ ├── common │ │ ├── extension.rs │ │ └── mod.rs │ │ ├── core │ │ ├── cowstr.rs │ │ ├── encoding.rs │ │ ├── endpoint.rs │ │ ├── locator.rs │ │ ├── mod.rs │ │ ├── parameters.rs │ │ ├── resolution.rs │ │ ├── whatami.rs │ │ └── wire_expr.rs │ │ ├── lib.rs │ │ ├── network │ │ ├── declare.rs │ │ ├── interest.rs │ │ ├── mod.rs │ │ ├── oam.rs │ │ ├── push.rs │ │ ├── request.rs │ │ └── response.rs │ │ ├── scouting │ │ ├── hello.rs │ │ ├── mod.rs │ │ └── scout.rs │ │ ├── transport │ │ ├── close.rs │ │ ├── fragment.rs │ │ ├── frame.rs │ │ ├── init.rs │ │ ├── join.rs │ │ ├── keepalive.rs │ │ ├── mod.rs │ │ ├── oam.rs │ │ └── open.rs │ │ └── zenoh │ │ ├── del.rs │ │ ├── err.rs │ │ ├── mod.rs │ │ ├── put.rs │ │ ├── query.rs │ │ └── reply.rs ├── zenoh-result │ ├── Cargo.toml │ ├── README.md │ └── src │ │ └── lib.rs ├── zenoh-runtime │ ├── Cargo.toml │ ├── README.md │ └── src │ │ └── lib.rs ├── zenoh-shm │ ├── Cargo.toml │ ├── README.md │ ├── build.rs │ ├── src │ │ ├── api │ │ │ ├── buffer │ │ │ │ ├── mod.rs │ │ │ │ ├── traits.rs │ │ │ │ ├── zshm.rs │ │ │ │ └── zshmmut.rs │ │ │ ├── cleanup.rs │ │ │ ├── client │ │ │ │ ├── mod.rs │ │ │ │ ├── shm_client.rs │ │ │ │ └── shm_segment.rs │ │ │ ├── client_storage │ │ │ │ └── mod.rs │ │ │ ├── common │ │ │ │ ├── mod.rs │ │ │ │ └── types.rs │ │ │ ├── mod.rs │ │ │ ├── protocol_implementations │ │ │ │ ├── mod.rs │ │ │ │ └── posix │ │ │ │ │ ├── mod.rs │ │ │ │ │ ├── posix_shm_client.rs │ │ │ │ │ ├── posix_shm_provider_backend.rs │ │ │ │ │ ├── posix_shm_segment.rs │ │ │ │ │ └── protocol_id.rs │ │ │ └── provider │ │ │ │ ├── chunk.rs │ │ │ │ ├── mod.rs │ │ │ │ ├── shm_provider.rs │ │ │ │ ├── shm_provider_backend.rs │ │ │ │ └── types.rs │ │ ├── cleanup.rs │ │ ├── header │ │ │ ├── chunk_header.rs │ │ │ └── mod.rs │ │ ├── init.rs │ │ ├── lib.rs │ │ ├── metadata │ │ │ ├── allocated_descriptor.rs │ │ │ ├── descriptor.rs │ │ │ ├── mod.rs │ │ │ ├── segment.rs │ │ │ ├── storage.rs │ │ │ └── subscription.rs │ │ ├── posix_shm │ │ │ ├── array.rs │ │ │ ├── cleanup.rs │ │ │ ├── mod.rs │ │ │ ├── segment.rs │ │ │ └── struct_in_shm.rs │ │ ├── reader.rs │ │ ├── shm │ │ │ ├── mod.rs │ │ │ ├── unix.rs │ │ │ └── windows.rs │ │ ├── version.rs │ │ └── watchdog │ │ │ ├── confirmator.rs │ │ │ ├── mod.rs │ │ │ ├── periodic_task.rs │ │ │ └── validator.rs │ └── tests │ │ ├── common │ │ └── mod.rs │ │ ├── metadata.rs │ │ ├── periodic_task.rs │ │ ├── posix_array.rs │ │ ├── posix_segment.rs │ │ ├── posix_shm_provider.rs │ │ └── shm.rs ├── zenoh-sync │ ├── Cargo.toml │ ├── README.md │ └── src │ │ ├── cache.rs │ │ ├── condition.rs │ │ ├── event.rs │ │ ├── fifo_queue.rs │ │ ├── lib.rs │ │ ├── lifo_queue.rs │ │ ├── mvar.rs │ │ ├── object_pool.rs │ │ └── signal.rs ├── zenoh-task │ ├── Cargo.toml │ ├── README.md │ └── src │ │ └── lib.rs └── zenoh-util │ ├── Cargo.toml │ ├── README.md │ ├── src │ ├── ffi │ │ ├── mod.rs │ │ └── win.rs │ ├── lib.rs │ ├── lib_loader.rs │ ├── lib_search_dirs.rs │ ├── log.rs │ ├── net │ │ └── mod.rs │ ├── time_range.rs │ └── timer.rs │ └── tests │ └── zresult.rs ├── deny.toml ├── examples ├── Cargo.toml ├── README.md ├── build.rs ├── examples │ ├── example.proto │ ├── z_alloc_shm.rs │ ├── z_bytes.rs │ ├── z_bytes_shm.rs │ ├── z_delete.rs │ ├── z_formats.rs │ ├── z_forward.rs │ ├── z_get.rs │ ├── z_get_liveliness.rs │ ├── z_get_shm.rs │ ├── z_info.rs │ ├── z_liveliness.rs │ ├── z_ping.rs │ ├── z_ping_shm.rs │ ├── z_pong.rs │ ├── z_posix_shm_provider.rs │ ├── z_pub.rs │ ├── z_pub_shm.rs │ ├── z_pub_shm_thr.rs │ ├── z_pub_thr.rs │ ├── z_pull.rs │ ├── z_put.rs │ ├── z_put_float.rs │ ├── z_querier.rs │ ├── z_queryable.rs │ ├── z_queryable_shm.rs │ ├── z_scout.rs │ ├── z_storage.rs │ ├── z_sub.rs │ ├── z_sub_liveliness.rs │ ├── z_sub_shm.rs │ └── z_sub_thr.rs └── src │ └── lib.rs ├── io ├── zenoh-link-commons │ ├── Cargo.toml │ ├── README.md │ └── src │ │ ├── dscp.rs │ │ ├── lib.rs │ │ ├── listener.rs │ │ ├── multicast.rs │ │ ├── tcp.rs │ │ ├── tls.rs │ │ └── unicast.rs ├── zenoh-link │ ├── Cargo.toml │ ├── README.md │ └── src │ │ └── lib.rs ├── zenoh-links │ ├── README.md │ ├── zenoh-link-quic │ │ ├── Cargo.toml │ │ ├── README.md │ │ └── src │ │ │ ├── lib.rs │ │ │ ├── unicast.rs │ │ │ └── utils.rs │ ├── zenoh-link-serial │ │ ├── Cargo.toml │ │ ├── README.md │ │ └── src │ │ │ ├── lib.rs │ │ │ └── unicast.rs │ ├── zenoh-link-tcp │ │ ├── Cargo.toml │ │ ├── README.md │ │ └── src │ │ │ ├── lib.rs │ │ │ ├── unicast.rs │ │ │ └── utils.rs │ ├── zenoh-link-tls │ │ ├── Cargo.toml │ │ ├── README.md │ │ └── src │ │ │ ├── lib.rs │ │ │ ├── unicast.rs │ │ │ └── utils.rs │ ├── zenoh-link-udp │ │ ├── Cargo.toml │ │ ├── README.md │ │ └── src │ │ │ ├── lib.rs │ │ │ ├── multicast.rs │ │ │ └── unicast.rs │ ├── zenoh-link-unixpipe │ │ ├── Cargo.toml │ │ ├── README.md │ │ └── src │ │ │ ├── lib.rs │ │ │ └── unix │ │ │ ├── mod.rs │ │ │ └── unicast.rs │ ├── zenoh-link-unixsock_stream │ │ ├── Cargo.toml │ │ ├── README.md │ │ └── src │ │ │ ├── lib.rs │ │ │ └── unicast.rs │ ├── zenoh-link-vsock │ │ ├── Cargo.toml │ │ ├── README.md │ │ └── src │ │ │ ├── lib.rs │ │ │ └── unicast.rs │ └── zenoh-link-ws │ │ ├── Cargo.toml │ │ ├── README.md │ │ └── src │ │ ├── lib.rs │ │ └── unicast.rs └── zenoh-transport │ ├── Cargo.toml │ ├── README.md │ ├── src │ ├── common │ │ ├── batch.rs │ │ ├── defragmentation.rs │ │ ├── mod.rs │ │ ├── pipeline.rs │ │ ├── priority.rs │ │ ├── seq_num.rs │ │ └── stats.rs │ ├── lib.rs │ ├── manager.rs │ ├── multicast │ │ ├── establishment.rs │ │ ├── link.rs │ │ ├── manager.rs │ │ ├── mod.rs │ │ ├── rx.rs │ │ ├── transport.rs │ │ └── tx.rs │ ├── shm.rs │ └── unicast │ │ ├── authentication.rs │ │ ├── establishment │ │ ├── accept.rs │ │ ├── cookie.rs │ │ ├── ext │ │ │ ├── auth │ │ │ │ ├── mod.rs │ │ │ │ ├── pubkey.rs │ │ │ │ └── usrpwd.rs │ │ │ ├── compression.rs │ │ │ ├── lowlatency.rs │ │ │ ├── mod.rs │ │ │ ├── multilink.rs │ │ │ ├── patch.rs │ │ │ ├── qos.rs │ │ │ └── shm.rs │ │ ├── mod.rs │ │ └── open.rs │ │ ├── link.rs │ │ ├── lowlatency │ │ ├── link.rs │ │ ├── mod.rs │ │ ├── rx.rs │ │ ├── transport.rs │ │ └── tx.rs │ │ ├── manager.rs │ │ ├── mod.rs │ │ ├── test_helpers.rs │ │ ├── transport_unicast_inner.rs │ │ └── universal │ │ ├── link.rs │ │ ├── mod.rs │ │ ├── reliability.rs │ │ ├── rx.rs │ │ ├── transport.rs │ │ └── tx.rs │ └── tests │ ├── endpoints.rs │ ├── multicast_compression.rs │ ├── multicast_transport.rs │ ├── transport_whitelist.rs │ ├── unicast_authenticator.rs │ ├── unicast_bind.rs │ ├── unicast_compression.rs │ ├── unicast_concurrent.rs │ ├── unicast_fragmentation.rs │ ├── unicast_intermittent.rs │ ├── unicast_multilink.rs │ ├── unicast_openclose.rs │ ├── unicast_priorities.rs │ ├── unicast_shm.rs │ ├── unicast_simultaneous.rs │ ├── unicast_time.rs │ └── unicast_transport.rs ├── plugins ├── zenoh-backend-example │ ├── Cargo.toml │ └── src │ │ └── lib.rs ├── zenoh-backend-traits │ ├── Cargo.toml │ ├── README.md │ └── src │ │ ├── config.rs │ │ ├── config.test.rs │ │ └── lib.rs ├── zenoh-plugin-example │ ├── Cargo.toml │ ├── README.md │ └── src │ │ └── lib.rs ├── zenoh-plugin-rest │ ├── Cargo.toml │ ├── README.md │ ├── build.rs │ ├── config.json5 │ ├── config_schema.json5 │ ├── examples │ │ └── z_serve_sse.rs │ └── src │ │ ├── config.rs │ │ └── lib.rs ├── zenoh-plugin-storage-manager │ ├── Cargo.toml │ ├── README.md │ ├── build.rs │ ├── config.json5 │ ├── config_schema.json5 │ ├── src │ │ ├── lib.rs │ │ ├── memory_backend │ │ │ └── mod.rs │ │ ├── replication │ │ │ ├── classification.rs │ │ │ ├── configuration.rs │ │ │ ├── core.rs │ │ │ ├── core │ │ │ │ ├── aligner_query.rs │ │ │ │ └── aligner_reply.rs │ │ │ ├── digest.rs │ │ │ ├── log.rs │ │ │ ├── mod.rs │ │ │ ├── service.rs │ │ │ └── tests │ │ │ │ ├── classification.test.rs │ │ │ │ ├── configuration.test.rs │ │ │ │ ├── digest.test.rs │ │ │ │ └── log.test.rs │ │ └── storages_mgt │ │ │ ├── mod.rs │ │ │ └── service.rs │ └── tests │ │ ├── operations.rs │ │ └── wildcard.rs └── zenoh-plugin-trait │ ├── Cargo.toml │ ├── README.md │ └── src │ ├── compatibility.rs │ ├── lib.rs │ ├── manager.rs │ ├── manager │ ├── dynamic_plugin.rs │ └── static_plugin.rs │ ├── plugin.rs │ └── vtable.rs ├── rust-toolchain.toml ├── rustfmt.toml ├── zenoh-dragon.png ├── zenoh-ext ├── Cargo.toml ├── README.md ├── examples │ ├── Cargo.toml │ ├── examples │ │ ├── README.md │ │ ├── z_advanced_pub.rs │ │ ├── z_advanced_sub.rs │ │ ├── z_member.rs │ │ └── z_view_size.rs │ └── src │ │ └── lib.rs ├── src │ ├── advanced_cache.rs │ ├── advanced_publisher.rs │ ├── advanced_subscriber.rs │ ├── group.rs │ ├── lib.rs │ ├── publication_cache.rs │ ├── publisher_ext.rs │ ├── querying_subscriber.rs │ ├── serialization.rs │ ├── session_ext.rs │ └── subscriber_ext.rs └── tests │ ├── advanced.rs │ └── liveliness.rs ├── zenoh ├── Cargo.toml ├── build.rs ├── src │ ├── api │ │ ├── admin.rs │ │ ├── builders │ │ │ ├── close.rs │ │ │ ├── info.rs │ │ │ ├── matching_listener.rs │ │ │ ├── mod.rs │ │ │ ├── publisher.rs │ │ │ ├── querier.rs │ │ │ ├── query.rs │ │ │ ├── queryable.rs │ │ │ ├── reply.rs │ │ │ ├── sample.rs │ │ │ ├── scouting.rs │ │ │ ├── session.rs │ │ │ └── subscriber.rs │ │ ├── bytes.rs │ │ ├── config.rs │ │ ├── encoding.rs │ │ ├── handlers │ │ │ ├── callback.rs │ │ │ ├── fifo.rs │ │ │ ├── mod.rs │ │ │ └── ring.rs │ │ ├── info.rs │ │ ├── key_expr.rs │ │ ├── liveliness.rs │ │ ├── loader.rs │ │ ├── matching.rs │ │ ├── mod.rs │ │ ├── plugins.rs │ │ ├── publisher.rs │ │ ├── querier.rs │ │ ├── query.rs │ │ ├── queryable.rs │ │ ├── sample.rs │ │ ├── scouting.rs │ │ ├── selector.rs │ │ ├── session.rs │ │ └── subscriber.rs │ ├── lib.rs │ ├── net │ │ ├── codec │ │ │ ├── linkstate.rs │ │ │ └── mod.rs │ │ ├── common.rs │ │ ├── mod.rs │ │ ├── primitives │ │ │ ├── demux.rs │ │ │ ├── mod.rs │ │ │ └── mux.rs │ │ ├── protocol │ │ │ ├── linkstate.rs │ │ │ ├── mod.rs │ │ │ └── network.rs │ │ ├── routing │ │ │ ├── dispatcher │ │ │ │ ├── face.rs │ │ │ │ ├── interests.rs │ │ │ │ ├── mod.rs │ │ │ │ ├── pubsub.rs │ │ │ │ ├── queries.rs │ │ │ │ ├── resource.rs │ │ │ │ ├── tables.rs │ │ │ │ └── token.rs │ │ │ ├── hat │ │ │ │ ├── client │ │ │ │ │ ├── interests.rs │ │ │ │ │ ├── mod.rs │ │ │ │ │ ├── pubsub.rs │ │ │ │ │ ├── queries.rs │ │ │ │ │ └── token.rs │ │ │ │ ├── linkstate_peer │ │ │ │ │ ├── interests.rs │ │ │ │ │ ├── mod.rs │ │ │ │ │ ├── pubsub.rs │ │ │ │ │ ├── queries.rs │ │ │ │ │ └── token.rs │ │ │ │ ├── mod.rs │ │ │ │ ├── p2p_peer │ │ │ │ │ ├── gossip.rs │ │ │ │ │ ├── interests.rs │ │ │ │ │ ├── mod.rs │ │ │ │ │ ├── pubsub.rs │ │ │ │ │ ├── queries.rs │ │ │ │ │ └── token.rs │ │ │ │ └── router │ │ │ │ │ ├── interests.rs │ │ │ │ │ ├── mod.rs │ │ │ │ │ ├── pubsub.rs │ │ │ │ │ ├── queries.rs │ │ │ │ │ └── token.rs │ │ │ ├── interceptor │ │ │ │ ├── access_control.rs │ │ │ │ ├── authorization.rs │ │ │ │ ├── downsampling.rs │ │ │ │ ├── low_pass.rs │ │ │ │ ├── mod.rs │ │ │ │ └── qos_overwrite.rs │ │ │ ├── mod.rs │ │ │ ├── namespace.rs │ │ │ └── router.rs │ │ ├── runtime │ │ │ ├── adminspace.rs │ │ │ ├── mod.rs │ │ │ └── orchestrator.rs │ │ └── tests │ │ │ ├── mod.rs │ │ │ └── tables.rs │ ├── prelude.rs │ └── tests │ │ ├── interceptor_cache.rs │ │ ├── link_weights.rs │ │ └── mod.rs └── tests │ ├── acl.rs │ ├── atexit.rs │ ├── attachments.rs │ ├── authentication.rs │ ├── bytes.rs │ ├── connection_retry.rs │ ├── events.rs │ ├── formatters.rs │ ├── handler.rs │ ├── interceptors.rs │ ├── keyexpr.rs │ ├── liveliness.rs │ ├── low_pass.rs │ ├── matching.rs │ ├── namespace.rs │ ├── open_time.rs │ ├── qos.rs │ ├── qos_overwrite.rs │ ├── routing.rs │ ├── session.rs │ ├── shm.rs │ ├── tcp_buffers.rs │ └── unicity.rs └── zenohd ├── .deb ├── postinst └── postrm ├── .rpm └── zenoh-router.spec ├── .service ├── zenohd.json5 └── zenohd.service ├── Cargo.toml ├── README.md ├── build.rs └── src └── main.rs /.cargo/config.toml: -------------------------------------------------------------------------------- 1 | [target.x86_64-unknown-linux-musl] 2 | rustflags = "-Ctarget-feature=-crt-static" 3 | 4 | [target.aarch64-unknown-linux-musl] 5 | rustflags = "-Ctarget-feature=-crt-static" 6 | -------------------------------------------------------------------------------- /.codecov.yml: -------------------------------------------------------------------------------- 1 | --- 2 | codecov: 3 | branch: main 4 | coverage: 5 | status: 6 | project: 7 | default: 8 | informational: true 9 | patch: 10 | default: 11 | informational: true 12 | -------------------------------------------------------------------------------- /.config/nextest.toml: -------------------------------------------------------------------------------- 1 | # By default, retry a few times until pass the test within the specified timeout 2 | [profile.default] 3 | retries = 2 4 | slow-timeout = { period = "60s", terminate-after = 2 } 5 | 6 | [profile.default.junit] 7 | path = "junit.xml" 8 | 9 | # Run the following tests exclusively with longer timeout 10 | [[profile.default.overrides]] 11 | filter = """ 12 | test(=zenoh_session_unicast) | 13 | test(=zenoh_session_multicast) | 14 | test(=zenoh_unicity_p2p) | 15 | test(=zenoh_unicity_brokered) | 16 | test(=transport_tcp_intermittent) | 17 | test(=transport_tcp_intermittent_for_lowlatency_transport) | 18 | test(=three_node_combination) | 19 | test(=watchdog_alloc_concurrent) | 20 | test(=header_check_memory_concurrent) | 21 | test(=header_link_concurrent) | 22 | test(=header_link_failure_concurrent) 23 | """ 24 | threads-required = 'num-cpus' 25 | slow-timeout = { period = "60s", terminate-after = 6 } 26 | -------------------------------------------------------------------------------- /.dockerignore: -------------------------------------------------------------------------------- 1 | target 2 | .github -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.yml: -------------------------------------------------------------------------------- 1 | name: Bug 2 | description: | 3 | Report a bug. 4 | labels: ["bug"] 5 | body: 6 | - type: textarea 7 | id: summary 8 | attributes: 9 | label: "Describe the bug" 10 | description: | 11 | A clear and concise description of the expected behaviour and what the bug is. 12 | placeholder: | 13 | E.g. zenoh peers can not automatically establish a connection. 14 | validations: 15 | required: true 16 | - type: textarea 17 | id: reproduce 18 | attributes: 19 | label: To reproduce 20 | description: "Steps to reproduce the behavior:" 21 | placeholder: | 22 | 1. Start a subscriber "..." 23 | 2. Start a publisher "...." 24 | 3. See error 25 | validations: 26 | required: true 27 | - type: textarea 28 | id: system 29 | attributes: 30 | label: System info 31 | description: "Please complete the following information:" 32 | placeholder: | 33 | - Platform: [e.g. Ubuntu 20.04 64-bit] 34 | - CPU [e.g. AMD Ryzen 3800X] 35 | - Zenoh version/commit [e.g. 6f172ea985d42d20d423a192a2d0d46bb0ce0d11] 36 | validations: 37 | required: true 38 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: Ask a question 4 | url: https://github.com/eclipse-zenoh/roadmap/discussions/categories/zenoh 5 | about: Open to the Zenoh community. Share your feedback with the Zenoh team. 6 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/new_feature.yml: -------------------------------------------------------------------------------- 1 | name: New feature 2 | description: | 3 | Suggest a new feature. 4 | labels: ["new feature"] 5 | body: 6 | - type: markdown 7 | attributes: 8 | value: | 9 | **Guidelines for a good issue** 10 | 11 | *Is your feature request related to a problem?* 12 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 13 | 14 | *Describe the solution you'd like* 15 | A clear and concise description of what you want to happen. 16 | 17 | *Describe alternatives you've considered* 18 | A clear and concise description of any alternative solutions or features you've considered. 19 | 20 | *Additional context* 21 | Add any other context about the feature request here. 22 | - type: textarea 23 | id: feature 24 | attributes: 25 | label: "Describe the feature" 26 | validations: 27 | required: true 28 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/release.yml: -------------------------------------------------------------------------------- 1 | name: Add an issue to the next release 2 | description: | 3 | Add an issue as part of next release. 4 | This will be added to the current release project. 5 | You must be a contributor to use this template. 6 | labels: ["release"] 7 | body: 8 | - type: markdown 9 | attributes: 10 | value: | 11 | **Guidelines for a good issue** 12 | 13 | *Is your release item related to a problem?* 14 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 15 | 16 | *Describe the solution you'd like* 17 | A clear and concise description of what you want to happen. 18 | 19 | *Describe alternatives you've considered* 20 | A clear and concise description of any alternative solutions or features you've considered. 21 | 22 | *Additional context* 23 | Add any other context about the release item request here. 24 | - type: textarea 25 | id: item 26 | attributes: 27 | label: "Describe the release item" 28 | validations: 29 | required: true 30 | -------------------------------------------------------------------------------- /.github/release.yml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2023 ZettaScale Technology 3 | # 4 | # This program and the accompanying materials are made available under the 5 | # terms of the Eclipse Public License 2.0 which is available at 6 | # http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | # which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | # 9 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | # 11 | # Contributors: 12 | # ZettaScale Zenoh Team, 13 | # 14 | 15 | changelog: 16 | categories: 17 | - title: Breaking changes 💥 18 | labels: 19 | - breaking-change 20 | - title: New features 🎉 21 | labels: 22 | - enhancement 23 | - new feature 24 | exclude: 25 | labels: 26 | - internal 27 | - title: Bug fixes 🐞 28 | labels: 29 | - bug 30 | exclude: 31 | labels: 32 | - internal 33 | - title: Documentation 📝 34 | labels: 35 | - documentation 36 | exclude: 37 | labels: 38 | - internal 39 | - title: Dependencies 👷 40 | labels: 41 | - dependencies 42 | exclude: 43 | labels: 44 | - internal 45 | - title: Other changes 46 | labels: 47 | - "*" 48 | exclude: 49 | labels: 50 | - internal -------------------------------------------------------------------------------- /.github/workflows/check-labels.yml: -------------------------------------------------------------------------------- 1 | name: Check required labels 2 | 3 | on: 4 | pull_request_target: 5 | types: [opened, synchronize, reopened, labeled] 6 | branches: ["**"] 7 | 8 | jobs: 9 | check-labels: 10 | name: Check PR labels 11 | uses: eclipse-zenoh/ci/.github/workflows/check-labels.yml@main 12 | secrets: 13 | github-token: ${{ secrets.GITHUB_TOKEN }} 14 | permissions: 15 | pull-requests: write 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Generated by Cargo 2 | # will have compiled files and executables 3 | **/target 4 | 5 | # Ignore all Cargo.lock but one at top-level, since it's committed in git. 6 | */**/Cargo.lock 7 | 8 | # These are backup files generated by rustfmt 9 | **/*.rs.bk 10 | 11 | # CLion project directory 12 | .idea 13 | 14 | # Emacs temps 15 | *~ 16 | 17 | # MacOS Related 18 | .DS_Store 19 | 20 | .vscode 21 | 22 | cargo-timing*.html 23 | 24 | ci/valgrind-check/*.log 25 | 26 | # Code coverage reports 27 | *.profraw -------------------------------------------------------------------------------- /.markdownlint.yaml: -------------------------------------------------------------------------------- 1 | { 2 | "MD013": false, # Line length limitation 3 | "MD033": false, # Enable Inline HTML 4 | "MD041": false, # Allow first line heading 5 | "MD045": false, # Allow Images have no alternate text 6 | } -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2024 ZettaScale Technology 3 | # 4 | # This program and the accompanying materials are made available under the 5 | # terms of the Eclipse Public License 2.0 which is available at 6 | # http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | # which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | # 9 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | # 11 | # Contributors: 12 | # ZettaScale Zenoh Team, 13 | # 14 | repos: 15 | - repo: local 16 | hooks: 17 | - id: fmt 18 | name: fmt 19 | entry: bash -c 'rustfmt --config "unstable_features=true,imports_granularity=Crate,group_imports=StdExternalCrate,skip_children=true" $(git ls-files '*.rs')' 20 | language: system 21 | types: [rust] 22 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | All changes for each release are tracked via [GitHub Releases](https://github.com/eclipse-zenoh/zenoh/releases). -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to Eclipse zenoh 2 | 3 | Thanks for your interest in this project. 4 | 5 | ## Project description 6 | 7 | Eclipse zenoh provides is a stack designed to 8 | 1. minimize network overhead, 9 | 2. support extremely constrained devices, 10 | 3. supports devices with low duty-cycle by allowing the negotiation of data exchange modes and schedules, 11 | 4. provide a rich set of abstraction for distributing, querying and storing data along the entire system, and 12 | 5. provide extremely low latency and high throughput. 13 | 14 | * https://projects.eclipse.org/projects/iot.zenoh 15 | 16 | ## Developer resources 17 | 18 | Information regarding source code management, builds, coding standards, and 19 | more. 20 | 21 | * https://projects.eclipse.org/projects/iot.zenoh/developer 22 | 23 | The project maintains the following source code repositories 24 | 25 | * https://github.com/eclipse-zenoh 26 | 27 | ## Eclipse Contributor Agreement 28 | 29 | Before your contribution can be accepted by the project team contributors must 30 | electronically sign the Eclipse Contributor Agreement (ECA). 31 | 32 | * http://www.eclipse.org/legal/ECA.php 33 | 34 | Commits that are provided by non-committers must have a Signed-off-by field in 35 | the footer indicating that the author is aware of the terms by which the 36 | contribution has been provided to the project. The non-committer must 37 | additionally have an Eclipse Foundation account and must have a signed Eclipse 38 | Contributor Agreement (ECA) on file. 39 | 40 | For more information, please see the Eclipse Committer Handbook: 41 | https://www.eclipse.org/projects/handbook/#resources-commit 42 | 43 | ## Contact 44 | 45 | Contact the project developers via the project's "dev" list. 46 | 47 | * https://accounts.eclipse.org/mailing-list/zenoh-dev 48 | 49 | Or via the Discord server. 50 | 51 | * https://discord.gg/vSDSpqnbkm 52 | -------------------------------------------------------------------------------- /CONTRIBUTORS.md: -------------------------------------------------------------------------------- 1 | # Contributors to Eclipse zenoh 2 | 3 | These are the contributors to Eclipse zenoh (the initial contributors and the contributors listed in the Git log). 4 | 5 | 6 | | GitHub username | Name | 7 | | --------------- | -----------------------------| 8 | | kydos | Angelo Corsaro (ZettaScale) | 9 | | JEnoch | Julien Enoch (ZettaScale) | 10 | | OlivierHecart | Olivier Hécart (ZettaScale) | 11 | | gabrik | Gabriele Baldoni (ZettaScale) | 12 | | Mallets | Luca Cominardi (ZettaScale) | 13 | | IvanPaez | Ivan Paez (ZettaScale) | 14 | -------------------------------------------------------------------------------- /Cross.toml: -------------------------------------------------------------------------------- 1 | [target.x86_64-unknown-linux-musl] 2 | image = "jenoch/rust-cross:x86_64-unknown-linux-musl" 3 | 4 | [target.arm-unknown-linux-gnueabi] 5 | image = "jenoch/rust-cross:arm-unknown-linux-gnueabi" 6 | 7 | [target.arm-unknown-linux-gnueabihf] 8 | image = "jenoch/rust-cross:arm-unknown-linux-gnueabihf" 9 | 10 | [target.armv7-unknown-linux-gnueabihf] 11 | image = "jenoch/rust-cross:armv7-unknown-linux-gnueabihf" 12 | 13 | [target.aarch64-unknown-linux-gnu] 14 | image = "jenoch/rust-cross:aarch64-unknown-linux-gnu" 15 | 16 | [target.aarch64-unknown-linux-musl] 17 | image = "jenoch/rust-cross:aarch64-unknown-linux-musl" 18 | 19 | -------------------------------------------------------------------------------- /NOTICE.md: -------------------------------------------------------------------------------- 1 | # Notices for Eclipse zenoh 2 | 3 | This content is produced and maintained by the Eclipse zenoh project. 4 | 5 | * Project home: https://projects.eclipse.org/projects/iot.zenoh 6 | 7 | ## Trademarks 8 | 9 | Eclipse zenoh is trademark of the Eclipse Foundation. 10 | Eclipse, and the Eclipse Logo are registered trademarks of the Eclipse Foundation. 11 | 12 | ## Copyright 13 | 14 | All content is the property of the respective authors or their employers. 15 | For more information regarding authorship of content, please consult the 16 | listed source code repository logs. 17 | 18 | ## Declared Project Licenses 19 | 20 | This program and the accompanying materials are made available under the 21 | terms of the Eclipse Public License 2.0 which is available at 22 | http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 23 | which is available at https://www.apache.org/licenses/LICENSE-2.0. 24 | 25 | SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 26 | 27 | ## Source Code 28 | 29 | The project maintains the following source code repositories: 30 | 31 | * https://github.com/eclipse-zenoh/zenoh.git 32 | * https://github.com/eclipse-zenoh/zenoh-c.git 33 | * https://github.com/eclipse-zenoh/zenoh-java.git 34 | * https://github.com/eclipse-zenoh/zenoh-go.git 35 | * https://github.com/eclipse-zenoh/zenoh-python.git 36 | 37 | ## Third-party Content 38 | 39 | *To be completed...* 40 | 41 | -------------------------------------------------------------------------------- /_typos.toml: -------------------------------------------------------------------------------- 1 | [files] 2 | extend-exclude = [ 3 | # Ignore files containing hexa. 4 | "io/zenoh-transport/tests/*.rs", 5 | "zenoh/tests/open_time.rs", 6 | "zenoh/tests/authentication.rs", 7 | ] 8 | 9 | 10 | [default.extend-words] 11 | mis = "mis" # mismatch 12 | thr = "thr" # throughput 13 | -------------------------------------------------------------------------------- /ci/nostd-check/Cargo.toml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2023 ZettaScale Technology 3 | # 4 | # This program and the accompanying materials are made available under the 5 | # terms of the Eclipse Public License 2.0 which is available at 6 | # http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | # which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | # 9 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | # 11 | # Contributors: 12 | # ZettaScale Zenoh Team, 13 | # 14 | [package] 15 | name = "nostd-check" 16 | version = "0.1.0" 17 | repository = "https://github.com/eclipse-zenoh/zenoh" 18 | homepage = "http://zenoh.io" 19 | authors = ["Davide Della Giustina "] 20 | edition = "2021" 21 | license = "EPL-2.0 OR Apache-2.0" 22 | categories = ["network-programming"] 23 | description = "Internal crate for zenoh." 24 | 25 | [dependencies] 26 | getrandom = { version = "0.2.8", features = ["custom"] } 27 | linked_list_allocator = "0.10.5" 28 | zenoh-buffers = { path = "../../commons/zenoh-buffers/", default-features = false } 29 | zenoh-codec = { path = "../../commons/zenoh-codec/", default-features = false } 30 | zenoh-protocol = { path = "../../commons/zenoh-protocol/", default-features = false } 31 | 32 | 33 | [[bin]] 34 | name = "nostd_check" 35 | path = "src/bin/nostd_check.rs" 36 | 37 | [package.metadata.cargo-machete] 38 | ignored = ["zenoh-buffers", "zenoh-codec", "zenoh-protocol"] -------------------------------------------------------------------------------- /ci/nostd-check/rust-toolchain.toml: -------------------------------------------------------------------------------- 1 | ../../rust-toolchain.toml -------------------------------------------------------------------------------- /ci/nostd-check/src/bin/nostd_check.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | 15 | #![no_std] 16 | 17 | use core::panic::PanicInfo; 18 | 19 | use getrandom::{register_custom_getrandom, Error}; 20 | use linked_list_allocator::LockedHeap; 21 | #[allow(unused_imports)] 22 | use {zenoh_buffers, zenoh_codec, zenoh_protocol}; 23 | 24 | #[panic_handler] 25 | fn dummy_panic_handler(_: &PanicInfo) -> ! { 26 | loop {} 27 | } 28 | 29 | #[global_allocator] 30 | static ALLOCATOR: LockedHeap = LockedHeap::empty(); 31 | 32 | fn dummy_get_rand(_: &mut [u8]) -> Result<(), Error> { 33 | Ok(()) 34 | } 35 | 36 | fn main() { 37 | register_custom_getrandom!(dummy_get_rand); 38 | } 39 | -------------------------------------------------------------------------------- /ci/valgrind-check/Cargo.toml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2024 ZettaScale Technology 3 | # 4 | # This program and the accompanying materials are made available under the 5 | # terms of the Eclipse Public License 2.0 which is available at 6 | # http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | # which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | # 9 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | # 11 | # Contributors: 12 | # ZettaScale Zenoh Team, 13 | # 14 | [package] 15 | name = "valgrind-check" 16 | version = "0.1.0" 17 | repository = "https://github.com/eclipse-zenoh/zenoh" 18 | homepage = "http://zenoh.io" 19 | license = "EPL-2.0 OR Apache-2.0" 20 | edition = "2021" 21 | categories = ["network-programming"] 22 | description = "Internal crate for zenoh." 23 | 24 | [dependencies] 25 | tokio = { version = "1.35.1", features = ["rt-multi-thread", "time", "io-std"] } 26 | zenoh = { path = "../../zenoh/" } 27 | zenoh-runtime = { path = "../../commons/zenoh-runtime/" } 28 | zenoh-util = { path = "../../commons/zenoh-util/", features = ["test"] } 29 | 30 | [[bin]] 31 | name = "pub_sub" 32 | path = "src/pub_sub/bin/z_pub_sub.rs" 33 | 34 | [[bin]] 35 | name = "queryable_get" 36 | path = "src/queryable_get/bin/z_queryable_get.rs" 37 | 38 | [package.metadata.cargo-machete] 39 | ignored = ["base64ct", "zerofrom", "litemap"] 40 | -------------------------------------------------------------------------------- /ci/valgrind-check/run.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) 4 | 5 | function check_leaks { 6 | echo "Checking $1 for memory leaks" 7 | valgrind --leak-check=full --num-callers=50 --log-file="$SCRIPT_DIR/$1_leaks.log" $SCRIPT_DIR/target/debug/$1 8 | num_leaks=$(grep 'ERROR SUMMARY: [0-9]+' -Eo "$SCRIPT_DIR/$1_leaks.log" | grep '[0-9]+' -Eo) 9 | echo "Detected $num_leaks memory leaks" 10 | if (( num_leaks == 0 )) 11 | then 12 | return 0 13 | else 14 | cat $SCRIPT_DIR/$1_leaks.log 15 | return -1 16 | fi 17 | } 18 | 19 | cargo build --manifest-path=$SCRIPT_DIR/Cargo.toml 20 | check_leaks "queryable_get" 21 | check_leaks "pub_sub" -------------------------------------------------------------------------------- /ci/valgrind-check/src/pub_sub/bin/z_pub_sub.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | use std::time::Duration; 15 | 16 | use zenoh::{config::Config, key_expr::KeyExpr}; 17 | 18 | #[tokio::main] 19 | async fn main() { 20 | let _z = zenoh_runtime::ZRuntimePoolGuard; 21 | zenoh_util::init_log_test(); 22 | 23 | let pub_key_expr = KeyExpr::try_from("test/valgrind/data").unwrap(); 24 | let sub_key_expr = KeyExpr::try_from("test/valgrind/**").unwrap(); 25 | 26 | println!("Declaring Publisher on '{pub_key_expr}'..."); 27 | let pub_session = zenoh::open(Config::default()).await.unwrap(); 28 | let publisher = pub_session.declare_publisher(&pub_key_expr).await.unwrap(); 29 | 30 | println!("Declaring Subscriber on '{sub_key_expr}'..."); 31 | let sub_session = zenoh::open(Config::default()).await.unwrap(); 32 | let _subscriber = sub_session 33 | .declare_subscriber(&sub_key_expr) 34 | .callback(|sample| { 35 | println!( 36 | ">> [Subscriber] Received {} ('{}': '{}')", 37 | sample.kind(), 38 | sample.key_expr().as_str(), 39 | sample 40 | .payload() 41 | .try_to_string() 42 | .unwrap_or_else(|e| e.to_string().into()) 43 | ); 44 | }) 45 | .await 46 | .unwrap(); 47 | 48 | for idx in 0..5 { 49 | tokio::time::sleep(Duration::from_secs(1)).await; 50 | let buf = format!("[{idx:4}] data"); 51 | println!("Putting Data ('{}': '{}')...", &pub_key_expr, buf); 52 | publisher.put(buf).await.unwrap(); 53 | } 54 | 55 | tokio::time::sleep(Duration::from_secs(1)).await; 56 | } 57 | -------------------------------------------------------------------------------- /clippy.toml: -------------------------------------------------------------------------------- 1 | # NOTE: Resources are hashed using their `.suffix` field without using any interior mutable fields. 2 | # See https://github.com/eclipse-zenoh/zenoh/blob/b55c781220d7ea9f7f117570990f6e4e063e58fe/zenoh/src/net/routing/dispatcher/resource.rs#L193 3 | # A corresponding comment is present in the `Hash` implementation of `Resource` as a reminder that this configuration is set. 4 | ignore-interior-mutability = [ 5 | "zenoh::net::routing::dispatcher::resource::Resource", 6 | ] 7 | -------------------------------------------------------------------------------- /commons/zenoh-buffers/Cargo.toml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2023 ZettaScale Technology 3 | # 4 | # This program and the accompanying materials are made available under the 5 | # terms of the Eclipse Public License 2.0 which is available at 6 | # http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | # which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | # 9 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | # 11 | # Contributors: 12 | # ZettaScale Zenoh Team, 13 | # 14 | [package] 15 | rust-version = { workspace = true } 16 | name = "zenoh-buffers" 17 | version = { workspace = true } 18 | repository = { workspace = true } 19 | homepage = { workspace = true } 20 | authors = { workspace = true } 21 | edition = { workspace = true } 22 | license = { workspace = true } 23 | categories = { workspace = true } 24 | description = "Internal crate for zenoh." 25 | 26 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 27 | [features] 28 | default = ["std"] 29 | shared-memory = [] 30 | std = [] 31 | test = ["rand"] 32 | 33 | [dependencies] 34 | rand = { workspace = true, optional = true } 35 | zenoh-collections = { workspace = true, default-features = false } 36 | -------------------------------------------------------------------------------- /commons/zenoh-buffers/README.md: -------------------------------------------------------------------------------- 1 | # ⚠️ WARNING ⚠️ 2 | 3 | This crate is intended for Zenoh's internal use. 4 | It is not guaranteed that the API will remain unchanged in any version, including patch updates. 5 | It is highly recommended to depend solely on the zenoh and zenoh-ext crates and to utilize their public APIs. 6 | 7 | - [Click here for Zenoh's main repository](https://github.com/eclipse-zenoh/zenoh) 8 | - [Click here for Zenoh's documentation](https://zenoh.io) 9 | -------------------------------------------------------------------------------- /commons/zenoh-codec/Cargo.toml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2023 ZettaScale Technology 3 | # 4 | # This program and the accompanying materials are made available under the 5 | # terms of the Eclipse Public License 2.0 which is available at 6 | # http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | # which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | # 9 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | # 11 | # Contributors: 12 | # ZettaScale Zenoh Team, 13 | # 14 | [package] 15 | rust-version = { workspace = true } 16 | name = "zenoh-codec" 17 | version = { workspace = true } 18 | repository = { workspace = true } 19 | homepage = { workspace = true } 20 | authors = [ 21 | "kydos ", 22 | "Luca Cominardi ", 23 | "Pierre Avital ", 24 | ] 25 | edition = { workspace = true } 26 | license = { workspace = true } 27 | categories = { workspace = true } 28 | description = "Internal crate for zenoh." 29 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 30 | 31 | [features] 32 | default = ["std"] 33 | std = [ 34 | "tracing", 35 | "uhlc/std", 36 | "zenoh-protocol/std", 37 | "zenoh-buffers/std" 38 | ] 39 | shared-memory = [ 40 | "std", 41 | "zenoh-shm", 42 | "zenoh-protocol/shared-memory", 43 | "zenoh-buffers/shared-memory" 44 | ] 45 | 46 | [dependencies] 47 | tracing = {workspace = true, optional = true } 48 | uhlc = { workspace = true } 49 | zenoh-buffers = { workspace = true, default-features = false } 50 | zenoh-protocol = { workspace = true } 51 | zenoh-shm = { workspace = true, optional = true } 52 | 53 | # INFO: May cause problems when testing no_std stuff. Check this tool: https://docs.rs/crate/cargo-no-dev-deps/0.1.0 54 | [dev-dependencies] 55 | criterion = { workspace = true } 56 | 57 | rand = { workspace = true, features = ["default"] } 58 | zenoh-protocol = { workspace = true, features = ["test"] } 59 | zenoh-util = {workspace = true } 60 | 61 | [[bench]] 62 | name = "codec" 63 | harness = false 64 | -------------------------------------------------------------------------------- /commons/zenoh-codec/README.md: -------------------------------------------------------------------------------- 1 | # ⚠️ WARNING ⚠️ 2 | 3 | This crate is intended for Zenoh's internal use. 4 | It is not guaranteed that the API will remain unchanged in any version, including patch updates. 5 | It is highly recommended to depend solely on the zenoh and zenoh-ext crates and to utilize their public APIs. 6 | 7 | - [Click here for Zenoh's main repository](https://github.com/eclipse-zenoh/zenoh) 8 | - [Click here for Zenoh's documentation](https://zenoh.io) 9 | -------------------------------------------------------------------------------- /commons/zenoh-codec/src/common/mod.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | pub mod extension; 15 | -------------------------------------------------------------------------------- /commons/zenoh-codec/src/core/timestamp.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | use core::convert::TryFrom; 15 | 16 | use zenoh_buffers::{ 17 | reader::{DidntRead, Reader}, 18 | writer::{DidntWrite, Writer}, 19 | }; 20 | use zenoh_protocol::core::{Timestamp, ZenohIdProto}; 21 | 22 | use crate::{LCodec, RCodec, WCodec, Zenoh080}; 23 | 24 | impl LCodec<&Timestamp> for Zenoh080 { 25 | fn w_len(self, x: &Timestamp) -> usize { 26 | let id = x.get_id(); 27 | self.w_len(x.get_time().as_u64()) + self.w_len(&id.to_le_bytes()[..id.size()]) 28 | } 29 | } 30 | 31 | impl WCodec<&Timestamp, &mut W> for Zenoh080 32 | where 33 | W: Writer, 34 | { 35 | type Output = Result<(), DidntWrite>; 36 | 37 | fn write(self, writer: &mut W, x: &Timestamp) -> Self::Output { 38 | self.write(&mut *writer, x.get_time().as_u64())?; 39 | let id = x.get_id(); 40 | self.write(&mut *writer, &id.to_le_bytes()[..id.size()])?; 41 | Ok(()) 42 | } 43 | } 44 | 45 | impl RCodec for Zenoh080 46 | where 47 | R: Reader, 48 | { 49 | type Error = DidntRead; 50 | 51 | fn read(self, reader: &mut R) -> Result { 52 | let time: u64 = self.read(&mut *reader)?; 53 | let size: usize = self.read(&mut *reader)?; 54 | if size > (uhlc::ID::MAX_SIZE) { 55 | return Err(DidntRead); 56 | } 57 | let mut id = [0_u8; ZenohIdProto::MAX_SIZE]; 58 | reader.read_exact(&mut id[..size])?; 59 | 60 | let time = uhlc::NTP64(time); 61 | let id = uhlc::ID::try_from(&id[..size]).map_err(|_| DidntRead)?; 62 | Ok(Timestamp::new(time, id)) 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /commons/zenoh-codec/src/scouting/mod.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | mod hello; 15 | mod scout; 16 | 17 | use zenoh_buffers::{ 18 | reader::{DidntRead, Reader}, 19 | writer::{DidntWrite, Writer}, 20 | }; 21 | use zenoh_protocol::{ 22 | common::imsg, 23 | scouting::{id, ScoutingBody, ScoutingMessage}, 24 | }; 25 | 26 | use crate::{RCodec, WCodec, Zenoh080, Zenoh080Header}; 27 | 28 | impl WCodec<&ScoutingMessage, &mut W> for Zenoh080 29 | where 30 | W: Writer, 31 | { 32 | type Output = Result<(), DidntWrite>; 33 | 34 | fn write(self, writer: &mut W, x: &ScoutingMessage) -> Self::Output { 35 | let ScoutingMessage { body, .. } = x; 36 | 37 | match body { 38 | ScoutingBody::Scout(s) => self.write(&mut *writer, s), 39 | ScoutingBody::Hello(h) => self.write(&mut *writer, h), 40 | } 41 | } 42 | } 43 | 44 | impl RCodec for Zenoh080 45 | where 46 | R: Reader, 47 | { 48 | type Error = DidntRead; 49 | 50 | fn read(self, reader: &mut R) -> Result { 51 | let header: u8 = self.read(&mut *reader)?; 52 | let codec = Zenoh080Header::new(header); 53 | 54 | let body = match imsg::mid(codec.header) { 55 | id::SCOUT => ScoutingBody::Scout(codec.read(&mut *reader)?), 56 | id::HELLO => ScoutingBody::Hello(codec.read(&mut *reader)?), 57 | _ => return Err(DidntRead), 58 | }; 59 | Ok(body.into()) 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /commons/zenoh-codec/src/transport/keepalive.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | use zenoh_buffers::{ 15 | reader::{DidntRead, Reader}, 16 | writer::{DidntWrite, Writer}, 17 | }; 18 | use zenoh_protocol::{ 19 | common::imsg, 20 | transport::{ 21 | id, 22 | keepalive::{flag, KeepAlive}, 23 | }, 24 | }; 25 | 26 | use crate::{common::extension, RCodec, WCodec, Zenoh080, Zenoh080Header}; 27 | 28 | impl WCodec<&KeepAlive, &mut W> for Zenoh080 29 | where 30 | W: Writer, 31 | { 32 | type Output = Result<(), DidntWrite>; 33 | 34 | fn write(self, writer: &mut W, x: &KeepAlive) -> Self::Output { 35 | let KeepAlive = x; 36 | 37 | // Header 38 | let header = id::KEEP_ALIVE; 39 | self.write(&mut *writer, header)?; 40 | Ok(()) 41 | } 42 | } 43 | 44 | impl RCodec for Zenoh080 45 | where 46 | R: Reader, 47 | { 48 | type Error = DidntRead; 49 | 50 | fn read(self, reader: &mut R) -> Result { 51 | let header: u8 = self.read(&mut *reader)?; 52 | let codec = Zenoh080Header::new(header); 53 | codec.read(reader) 54 | } 55 | } 56 | 57 | impl RCodec for Zenoh080Header 58 | where 59 | R: Reader, 60 | { 61 | type Error = DidntRead; 62 | 63 | fn read(self, reader: &mut R) -> Result { 64 | if imsg::mid(self.header) != id::KEEP_ALIVE { 65 | return Err(DidntRead); 66 | } 67 | 68 | // Extensions 69 | let has_ext = imsg::has_flag(self.header, flag::Z); 70 | if has_ext { 71 | extension::skip_all(reader, "Unknown KeepAlive ext")?; 72 | } 73 | 74 | Ok(KeepAlive) 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /commons/zenoh-collections/Cargo.toml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2023 ZettaScale Technology 3 | # 4 | # This program and the accompanying materials are made available under the 5 | # terms of the Eclipse Public License 2.0 which is available at 6 | # http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | # which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | # 9 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | # 11 | # Contributors: 12 | # ZettaScale Zenoh Team, 13 | # 14 | [package] 15 | rust-version = { workspace = true } 16 | name = "zenoh-collections" 17 | version = { workspace = true } 18 | repository = { workspace = true } 19 | homepage = { workspace = true } 20 | authors = [ 21 | "kydos ", 22 | "Luca Cominardi ", 23 | "Pierre Avital ", 24 | ] 25 | edition = { workspace = true } 26 | license = { workspace = true } 27 | categories = { workspace = true } 28 | description = "Internal crate for zenoh." 29 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 30 | 31 | [features] 32 | default = ["std"] 33 | std = ["ahash/default"] 34 | test = [] 35 | 36 | [dependencies] 37 | ahash = { workspace = true } 38 | -------------------------------------------------------------------------------- /commons/zenoh-collections/README.md: -------------------------------------------------------------------------------- 1 | # ⚠️ WARNING ⚠️ 2 | 3 | This crate is intended for Zenoh's internal use. 4 | It is not guaranteed that the API will remain unchanged in any version, including patch updates. 5 | It is highly recommended to depend solely on the zenoh and zenoh-ext crates and to utilize their public APIs. 6 | 7 | - [Click here for Zenoh's main repository](https://github.com/eclipse-zenoh/zenoh) 8 | - [Click here for Zenoh's documentation](https://zenoh.io) 9 | -------------------------------------------------------------------------------- /commons/zenoh-collections/src/lib.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | 15 | //! ⚠️ WARNING ⚠️ 16 | //! 17 | //! This crate is intended for Zenoh's internal use. 18 | //! 19 | //! [Click here for Zenoh's documentation](https://docs.rs/zenoh/latest/zenoh) 20 | #![cfg_attr(not(feature = "std"), no_std)] 21 | extern crate alloc; 22 | 23 | pub mod single_or_vec; 24 | pub use single_or_vec::SingleOrVec; 25 | 26 | #[cfg(feature = "std")] 27 | pub mod single_or_box_hashset; 28 | #[cfg(feature = "std")] 29 | pub use single_or_box_hashset::SingleOrBoxHashSet; 30 | 31 | #[cfg(feature = "std")] 32 | pub mod ring_buffer; 33 | #[cfg(feature = "std")] 34 | pub use ring_buffer::*; 35 | 36 | #[cfg(feature = "std")] 37 | pub mod stack_buffer; 38 | #[cfg(feature = "std")] 39 | pub use stack_buffer::*; 40 | -------------------------------------------------------------------------------- /commons/zenoh-collections/src/stack_buffer.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | use std::collections::VecDeque; 15 | 16 | pub struct StackBuffer { 17 | buffer: VecDeque, 18 | } 19 | 20 | impl StackBuffer { 21 | #[must_use] 22 | pub fn new(capacity: usize) -> StackBuffer { 23 | let buffer = VecDeque::::with_capacity(capacity); 24 | StackBuffer { buffer } 25 | } 26 | 27 | #[inline] 28 | pub fn push(&mut self, elem: T) -> Option { 29 | if self.len() < self.capacity() { 30 | self.buffer.push_front(elem); 31 | None 32 | } else { 33 | Some(elem) 34 | } 35 | } 36 | 37 | #[inline] 38 | pub fn pop(&mut self) -> Option { 39 | self.buffer.pop_front() 40 | } 41 | 42 | #[allow(dead_code)] 43 | #[inline] 44 | #[must_use] 45 | pub fn is_empty(&self) -> bool { 46 | self.buffer.is_empty() 47 | } 48 | 49 | #[inline] 50 | #[must_use] 51 | pub fn is_full(&self) -> bool { 52 | self.len() == self.capacity() 53 | } 54 | 55 | #[inline] 56 | #[must_use] 57 | pub fn len(&self) -> usize { 58 | self.buffer.len() 59 | } 60 | 61 | #[inline] 62 | #[must_use] 63 | pub fn capacity(&self) -> usize { 64 | self.buffer.capacity() 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /commons/zenoh-config/Cargo.toml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2023 ZettaScale Technology 3 | # 4 | # This program and the accompanying materials are made available under the 5 | # terms of the Eclipse Public License 2.0 which is available at 6 | # http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | # which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | # 9 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | # 11 | # Contributors: 12 | # ZettaScale Zenoh Team, 13 | # 14 | [package] 15 | rust-version = { workspace = true } 16 | name = "zenoh-config" 17 | version = { workspace = true } 18 | repository = { workspace = true } 19 | homepage = { workspace = true } 20 | authors = { workspace = true } 21 | edition = { workspace = true } 22 | license = { workspace = true } 23 | categories = { workspace = true } 24 | description = "Internal crate for zenoh." 25 | 26 | [features] 27 | internal = [] 28 | transport_tcp = [] 29 | unstable = [] 30 | 31 | [dependencies] 32 | tracing = { workspace = true } 33 | json5 = { workspace = true } 34 | num_cpus = { workspace = true } 35 | serde = { workspace = true, features = ["default"] } 36 | serde_json = { workspace = true } 37 | serde_with = { workspace = true } 38 | serde_yaml = { workspace = true } 39 | validated_struct = { workspace = true, features = ["json5", "json_get"] } 40 | nonempty-collections = {workspace = true } 41 | zenoh-core = { workspace = true } 42 | zenoh-keyexpr = { workspace = true } 43 | zenoh-protocol = { workspace = true } 44 | zenoh-result = { workspace = true } 45 | zenoh-util = { workspace = true } 46 | zenoh-macros = { workspace = true } 47 | secrecy = { workspace = true } 48 | uhlc = { workspace = true } 49 | 50 | [package.metadata.cargo-machete] 51 | ignored = ["tracing"] 52 | -------------------------------------------------------------------------------- /commons/zenoh-config/README.md: -------------------------------------------------------------------------------- 1 | # ⚠️ WARNING ⚠️ 2 | 3 | This crate is intended for Zenoh's internal use. 4 | It is not guaranteed that the API will remain unchanged in any version, including patch updates. 5 | It is highly recommended to depend solely on the zenoh and zenoh-ext crates and to utilize their public APIs. 6 | 7 | - [Click here for Zenoh's main repository](https://github.com/eclipse-zenoh/zenoh) 8 | - [Click here for Zenoh's documentation](https://zenoh.io) 9 | -------------------------------------------------------------------------------- /commons/zenoh-core/Cargo.toml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2023 ZettaScale Technology 3 | # 4 | # This program and the accompanying materials are made available under the 5 | # terms of the Eclipse Public License 2.0 which is available at 6 | # http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | # which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | # 9 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | # 11 | # Contributors: 12 | # ZettaScale Zenoh Team, 13 | # 14 | [package] 15 | rust-version = { workspace = true } 16 | name = "zenoh-core" 17 | version = { workspace = true } 18 | repository = { workspace = true } 19 | homepage = { workspace = true } 20 | authors = [ 21 | "kydos ", 22 | "Luca Cominardi ", 23 | "Pierre Avital ", 24 | ] 25 | edition = { workspace = true } 26 | license = { workspace = true } 27 | categories = { workspace = true } 28 | description = "Internal crate for zenoh." 29 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 30 | [features] 31 | std = [] 32 | default = ["std"] 33 | tracing-instrument = ["zenoh-runtime/tracing-instrument"] 34 | 35 | [dependencies] 36 | tokio = { workspace = true, features = ["rt"] } 37 | lazy_static = { workspace = true } 38 | zenoh-result = { workspace = true } 39 | zenoh-runtime = { workspace = true } 40 | -------------------------------------------------------------------------------- /commons/zenoh-core/README.md: -------------------------------------------------------------------------------- 1 | # ⚠️ WARNING ⚠️ 2 | 3 | This crate is intended for Zenoh's internal use. 4 | It is not guaranteed that the API will remain unchanged in any version, including patch updates. 5 | It is highly recommended to depend solely on the zenoh and zenoh-ext crates and to utilize their public APIs. 6 | 7 | - [Click here for Zenoh's main repository](https://github.com/eclipse-zenoh/zenoh) 8 | - [Click here for Zenoh's documentation](https://zenoh.io) 9 | -------------------------------------------------------------------------------- /commons/zenoh-crypto/Cargo.toml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2023 ZettaScale Technology 3 | # 4 | # This program and the accompanying materials are made available under the 5 | # terms of the Eclipse Public License 2.0 which is available at 6 | # http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | # which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | # 9 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | # 11 | # Contributors: 12 | # ZettaScale Zenoh Team, 13 | # 14 | [package] 15 | rust-version = { workspace = true } 16 | name = "zenoh-crypto" 17 | version = { workspace = true } 18 | repository = { workspace = true } 19 | homepage = { workspace = true } 20 | authors = [ 21 | "kydos ", 22 | "Luca Cominardi ", 23 | "Pierre Avital ", 24 | ] 25 | edition = { workspace = true } 26 | license = { workspace = true } 27 | categories = { workspace = true } 28 | description = "Internal crate for zenoh." 29 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 30 | 31 | [dependencies] 32 | aes = { workspace = true } 33 | hmac = { workspace = true } 34 | rand = { workspace = true, features = ["default"] } 35 | rand_chacha = { workspace = true } 36 | sha3 = { workspace = true } 37 | zenoh-result = { workspace = true, features = ["default"] } 38 | -------------------------------------------------------------------------------- /commons/zenoh-crypto/README.md: -------------------------------------------------------------------------------- 1 | # ⚠️ WARNING ⚠️ 2 | 3 | This crate is intended for Zenoh's internal use. 4 | It is not guaranteed that the API will remain unchanged in any version, including patch updates. 5 | It is highly recommended to depend solely on the zenoh and zenoh-ext crates and to utilize their public APIs. 6 | 7 | - [Click here for Zenoh's main repository](https://github.com/eclipse-zenoh/zenoh) 8 | - [Click here for Zenoh's documentation](https://zenoh.io) 9 | -------------------------------------------------------------------------------- /commons/zenoh-crypto/src/hmac.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | use hmac::{Hmac, Mac}; 15 | use sha3::{Digest, Sha3_256}; 16 | use zenoh_result::ZResult; 17 | 18 | pub fn sign(key: &[u8], data: &[u8]) -> ZResult> { 19 | let mut hmac = Hmac::::new_from_slice(key)?; 20 | hmac.update(data); 21 | Ok(hmac.finalize().into_bytes().as_slice().to_vec()) 22 | } 23 | 24 | pub fn digest(data: &[u8]) -> Vec { 25 | Sha3_256::digest(data).as_slice().to_vec() 26 | } 27 | -------------------------------------------------------------------------------- /commons/zenoh-crypto/src/lib.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | 15 | //! ⚠️ WARNING ⚠️ 16 | //! 17 | //! This crate is intended for Zenoh's internal use. 18 | //! 19 | //! [Click here for Zenoh's documentation](https://docs.rs/zenoh/latest/zenoh) 20 | mod cipher; 21 | pub mod hmac; 22 | mod prng; 23 | 24 | pub use cipher::*; 25 | pub use prng::*; 26 | -------------------------------------------------------------------------------- /commons/zenoh-crypto/src/prng.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | use rand_chacha::ChaCha20Rng; 15 | 16 | pub type PseudoRng = ChaCha20Rng; 17 | -------------------------------------------------------------------------------- /commons/zenoh-keyexpr/README.md: -------------------------------------------------------------------------------- 1 | # ⚠️ WARNING ⚠️ 2 | 3 | This crate is intended for Zenoh's internal use. 4 | It is not guaranteed that the API will remain unchanged in any version, including patch updates. 5 | It is highly recommended to depend solely on the zenoh and zenoh-ext crates and to utilize their public APIs. 6 | 7 | - [Click here for Zenoh's main repository](https://github.com/eclipse-zenoh/zenoh) 8 | - [Click here for Zenoh's documentation](https://zenoh.io) 9 | -------------------------------------------------------------------------------- /commons/zenoh-keyexpr/src/key_expr/intersect/ltr_chunk.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | // use crate::key_expr::SINGLE_WILD; 15 | 16 | // use super::{restriction::NoBigWilds, Intersector}; 17 | 18 | // pub struct LTRChunkIntersector; 19 | // impl Intersector, NoBigWilds<&[u8]>> for LTRChunkIntersector { 20 | // fn intersect(&self, mut left: NoBigWilds<&[u8]>, mut right: NoBigWilds<&[u8]>) -> bool { 21 | // loop { 22 | // match (left.0, right.0) { 23 | // ([], []) | (b"*", _) | (_, b"*") => return true, 24 | // ([SINGLE_WILD, new_left @ ..], [_, new_right @ ..]) => { 25 | // if self.intersect(NoBigWilds(new_left), right) { 26 | // return true; 27 | // } 28 | // right = NoBigWilds(new_right) 29 | // } 30 | // ([_, new_left @ ..], [SINGLE_WILD, new_right @ ..]) => { 31 | // if self.intersect(left, NoBigWilds(new_right)) { 32 | // return true; 33 | // } 34 | // left = NoBigWilds(new_left) 35 | // } 36 | // ([a, b @ ..], [c, d @ ..]) if a == c => { 37 | // left = NoBigWilds(b); 38 | // right = NoBigWilds(d) 39 | // } 40 | // _ => return false, 41 | // } 42 | // } 43 | // } 44 | // } 45 | -------------------------------------------------------------------------------- /commons/zenoh-keyexpr/src/key_expr/mod.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | 15 | //! This module implements the Key Expression Language, as explained in details in [`keyexpr`]'s documentation. 16 | 17 | pub(crate) const DELIMITER: u8 = b'/'; 18 | pub(crate) const SINGLE_WILD: u8 = b'*'; 19 | pub(crate) const DOUBLE_WILD: &[u8] = b"**"; 20 | pub(crate) const STAR_DSL: &[u8] = b"$*"; 21 | pub(crate) const FORBIDDEN_CHARS: [u8; 3] = [b'#', b'?', b'$']; 22 | 23 | pub(crate) mod owned; 24 | pub use owned::{OwnedKeyExpr, OwnedNonWildKeyExpr}; 25 | 26 | pub(crate) mod borrowed; 27 | pub use borrowed::*; 28 | 29 | /// Used to implement and expose the tools to implement canonization of Key Expressions for string-like types. 30 | /// The average user doesn't need to bother with it. 31 | pub mod canon; 32 | /// Used to implement and expose the tools to implement algorithms to detect Key Expression inclusivity. 33 | /// The average user doesn't need to bother with it. 34 | pub mod include; 35 | /// Used to implement and expose the tools to implement algorithms to detect Key Expression intersection. 36 | /// The average user doesn't need to bother with it. 37 | pub mod intersect; 38 | pub(crate) mod utils; 39 | 40 | /// Exposes a random Key Expression generator to help with testing. 41 | #[cfg(feature = "std")] 42 | pub mod fuzzer; 43 | 44 | pub mod format; 45 | 46 | #[cfg(test)] 47 | mod tests; 48 | -------------------------------------------------------------------------------- /commons/zenoh-keyexpr/src/keyexpr_tree/iters/mod.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | 15 | mod tree_iter; 16 | pub use tree_iter::{TreeIter, TreeIterMut}; 17 | mod intersection; 18 | pub use intersection::{Intersection, IntersectionMut}; 19 | mod inclusion; 20 | pub use inclusion::{Inclusion, InclusionMut}; 21 | mod includer; 22 | pub use includer::{Includer, IncluderMut}; 23 | -------------------------------------------------------------------------------- /commons/zenoh-macros/Cargo.toml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2023 ZettaScale Technology 3 | # 4 | # This program and the accompanying materials are made available under the 5 | # terms of the Eclipse Public License 2.0 which is available at 6 | # http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | # which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | # 9 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | # 11 | # Contributors: 12 | # ZettaScale Zenoh Team, 13 | # 14 | [package] 15 | rust-version = { workspace = true } 16 | name = "zenoh-macros" 17 | version = { workspace = true } 18 | repository = { workspace = true } 19 | homepage = { workspace = true } 20 | authors = { workspace = true } 21 | edition = { workspace = true } 22 | license = { workspace = true } 23 | categories = ["development-tools::procedural-macro-helpers"] 24 | description = "Internal crate for zenoh." 25 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 26 | 27 | [dependencies] 28 | proc-macro2 = { workspace = true } 29 | quote = { workspace = true } 30 | syn = { workspace = true, features = ["full"] } 31 | zenoh-keyexpr = { workspace = true, features = ["std"] } 32 | 33 | [lib] 34 | proc-macro = true 35 | -------------------------------------------------------------------------------- /commons/zenoh-macros/README.md: -------------------------------------------------------------------------------- 1 | # ⚠️ WARNING ⚠️ 2 | 3 | This crate is intended for Zenoh's internal use. 4 | It is not guaranteed that the API will remain unchanged in any version, including patch updates. 5 | It is highly recommended to depend solely on the zenoh and zenoh-ext crates and to utilize their public APIs. 6 | 7 | - [Click here for Zenoh's main repository](https://github.com/eclipse-zenoh/zenoh) 8 | - [Click here for Zenoh's documentation](https://zenoh.io) 9 | -------------------------------------------------------------------------------- /commons/zenoh-macros/build.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | use std::{env, ffi::OsString, fs::OpenOptions, io::Write, process::Command}; 15 | 16 | fn main() { 17 | let rustc = env::var_os("RUSTC").unwrap_or_else(|| OsString::from("rustc")); 18 | let output = Command::new(rustc) 19 | .arg("-v") 20 | .arg("-V") 21 | .output() 22 | .expect("Couldn't get rustc version"); 23 | let version_rs = std::path::PathBuf::from(env::var_os("OUT_DIR").unwrap()).join("version.rs"); 24 | let mut version_rs = OpenOptions::new() 25 | .create(true) 26 | .truncate(true) 27 | .write(true) 28 | .open(version_rs) 29 | .unwrap(); 30 | version_rs.write_all(&output.stdout).unwrap(); 31 | } 32 | -------------------------------------------------------------------------------- /commons/zenoh-protocol/Cargo.toml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2023 ZettaScale Technology 3 | # 4 | # This program and the accompanying materials are made available under the 5 | # terms of the Eclipse Public License 2.0 which is available at 6 | # http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | # which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | # 9 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | # 11 | # Contributors: 12 | # ZettaScale Zenoh Team, 13 | # 14 | [package] 15 | rust-version = { workspace = true } 16 | name = "zenoh-protocol" 17 | version = { workspace = true } 18 | repository = { workspace = true } 19 | homepage = { workspace = true } 20 | authors = { workspace = true } 21 | edition = { workspace = true } 22 | license = { workspace = true } 23 | categories = { workspace = true } 24 | description = "Internal crate for zenoh." 25 | 26 | [features] 27 | default = ["std"] 28 | internal = [] 29 | std = [ 30 | "rand?/std", 31 | "rand?/std_rng", 32 | "serde/std", 33 | "uhlc/std", 34 | "zenoh-keyexpr/std", 35 | "zenoh-result/std", 36 | "zenoh-buffers/std", 37 | ] 38 | shared-memory = ["std", "zenoh-buffers/shared-memory"] 39 | test = ["rand", "zenoh-buffers/test"] 40 | 41 | [dependencies] 42 | const_format = { workspace = true } 43 | rand = { workspace = true, features = ["alloc", "getrandom"], optional = true } 44 | serde = { workspace = true, features = ["alloc"] } 45 | uhlc = { workspace = true, default-features = false } 46 | zenoh-buffers = { workspace = true, default-features = false } 47 | zenoh-keyexpr = { workspace = true } 48 | zenoh-result = { workspace = true } 49 | 50 | # NOTE: May cause problems when testing no_std stuff. Check this tool: https://docs.rs/crate/cargo-no-dev-deps/0.1.0 51 | [dev-dependencies] 52 | lazy_static = { workspace = true } 53 | rand = { workspace = true, features = ["default"] } 54 | -------------------------------------------------------------------------------- /commons/zenoh-protocol/README.md: -------------------------------------------------------------------------------- 1 | # ⚠️ WARNING ⚠️ 2 | 3 | This crate is intended for Zenoh's internal use. 4 | It is not guaranteed that the API will remain unchanged in any version, including patch updates. 5 | It is highly recommended to depend solely on the zenoh and zenoh-ext crates and to utilize their public APIs. 6 | 7 | - [Click here for Zenoh's main repository](https://github.com/eclipse-zenoh/zenoh) 8 | - [Click here for Zenoh's documentation](https://zenoh.io) 9 | -------------------------------------------------------------------------------- /commons/zenoh-protocol/src/common/mod.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | pub mod extension; 15 | pub use extension::*; 16 | 17 | /*************************************/ 18 | /* IDS */ 19 | /*************************************/ 20 | // Inner Message IDs 21 | pub mod imsg { 22 | // Header mask 23 | pub const HEADER_BITS: u8 = 5; 24 | pub const HEADER_MASK: u8 = !(0xff << HEADER_BITS); 25 | 26 | pub const fn mid(header: u8) -> u8 { 27 | header & HEADER_MASK 28 | } 29 | 30 | pub const fn flags(header: u8) -> u8 { 31 | header & !HEADER_MASK 32 | } 33 | 34 | pub const fn has_flag(byte: u8, flag: u8) -> bool { 35 | byte & flag != 0 36 | } 37 | 38 | pub const fn unset_flag(mut byte: u8, flag: u8) -> u8 { 39 | byte &= !flag; 40 | byte 41 | } 42 | 43 | pub const fn set_flag(mut byte: u8, flag: u8) -> u8 { 44 | byte = unset_flag(byte, flag); 45 | byte |= flag; 46 | byte 47 | } 48 | 49 | pub const fn set_bitfield(mut byte: u8, value: u8, mask: u8) -> u8 { 50 | byte = unset_flag(byte, mask); 51 | byte |= value; 52 | byte 53 | } 54 | 55 | pub const fn has_option(options: u64, flag: u64) -> bool { 56 | options & flag != 0 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /commons/zenoh-protocol/src/scouting/mod.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | pub mod hello; 15 | pub mod scout; 16 | 17 | pub use hello::HelloProto; 18 | pub use scout::Scout; 19 | 20 | pub mod id { 21 | // Scouting Messages 22 | pub const SCOUT: u8 = 0x01; 23 | pub const HELLO: u8 = 0x02; 24 | } 25 | 26 | // Zenoh messages at scouting level 27 | #[derive(Debug, Clone, PartialEq, Eq)] 28 | pub enum ScoutingBody { 29 | Scout(Scout), 30 | Hello(HelloProto), 31 | } 32 | 33 | #[derive(Debug, Clone, PartialEq, Eq)] 34 | pub struct ScoutingMessage { 35 | pub body: ScoutingBody, 36 | } 37 | 38 | impl ScoutingMessage { 39 | #[cfg(feature = "test")] 40 | pub fn rand() -> Self { 41 | use rand::Rng; 42 | 43 | let mut rng = rand::thread_rng(); 44 | 45 | match rng.gen_range(0..2) { 46 | 0 => ScoutingBody::Scout(Scout::rand()), 47 | 1 => ScoutingBody::Hello(HelloProto::rand()), 48 | _ => unreachable!(), 49 | } 50 | .into() 51 | } 52 | } 53 | 54 | impl From for ScoutingMessage { 55 | fn from(body: ScoutingBody) -> Self { 56 | Self { body } 57 | } 58 | } 59 | 60 | impl From for ScoutingMessage { 61 | fn from(scout: Scout) -> Self { 62 | ScoutingBody::Scout(scout).into() 63 | } 64 | } 65 | 66 | impl From for ScoutingMessage { 67 | fn from(hello: HelloProto) -> Self { 68 | ScoutingBody::Hello(hello).into() 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /commons/zenoh-result/Cargo.toml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2023 ZettaScale Technology 3 | # 4 | # This program and the accompanying materials are made available under the 5 | # terms of the Eclipse Public License 2.0 which is available at 6 | # http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | # which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | # 9 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | # 11 | # Contributors: 12 | # ZettaScale Zenoh Team, 13 | # 14 | [package] 15 | rust-version = { workspace = true } 16 | name = "zenoh-result" 17 | version = { workspace = true } 18 | repository = { workspace = true } 19 | homepage = { workspace = true } 20 | authors = { workspace = true } 21 | edition = { workspace = true } 22 | license = { workspace = true } 23 | categories = { workspace = true } 24 | description = "Internal crate for zenoh." 25 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 26 | 27 | [features] 28 | default = ["std"] 29 | std = ["anyhow/std"] 30 | 31 | [dependencies] 32 | anyhow = { workspace = true } 33 | -------------------------------------------------------------------------------- /commons/zenoh-result/README.md: -------------------------------------------------------------------------------- 1 | # ⚠️ WARNING ⚠️ 2 | 3 | This crate is intended for Zenoh's internal use. 4 | It is not guaranteed that the API will remain unchanged in any version, including patch updates. 5 | It is highly recommended to depend solely on the zenoh and zenoh-ext crates and to utilize their public APIs. 6 | 7 | - [Click here for Zenoh's main repository](https://github.com/eclipse-zenoh/zenoh) 8 | - [Click here for Zenoh's documentation](https://zenoh.io) 9 | -------------------------------------------------------------------------------- /commons/zenoh-runtime/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "zenoh-runtime" 3 | rust-version = { workspace = true } 4 | version = { workspace = true } 5 | repository = { workspace = true } 6 | homepage = { workspace = true } 7 | authors = { workspace = true } 8 | edition = { workspace = true } 9 | license = { workspace = true } 10 | categories = { workspace = true } 11 | description = { workspace = true } 12 | 13 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 14 | 15 | [features] 16 | tracing-instrument = [] 17 | 18 | [dependencies] 19 | tracing = { workspace = true } 20 | ron = { workspace = true } 21 | serde = { workspace = true } 22 | lazy_static = { workspace = true } 23 | tokio = { workspace = true, features = ["fs", "io-util", "macros", "net", "rt-multi-thread", "sync", "time"] } 24 | zenoh-result = { workspace = true, features = ["std"] } 25 | zenoh-macros = { workspace = true } 26 | 27 | [package.metadata.cargo-machete] 28 | ignored = ["ron"] -------------------------------------------------------------------------------- /commons/zenoh-runtime/README.md: -------------------------------------------------------------------------------- 1 | # ⚠️ WARNING ⚠️ 2 | 3 | This crate is intended for Zenoh's internal use. 4 | It is not guaranteed that the API will remain unchanged in any version, including patch updates. 5 | It is highly recommended to depend solely on the zenoh and zenoh-ext crates and to utilize their public APIs. 6 | 7 | - [Click here for Zenoh's main repository](https://github.com/eclipse-zenoh/zenoh) 8 | - [Click here for Zenoh's documentation](https://zenoh.io) 9 | -------------------------------------------------------------------------------- /commons/zenoh-shm/Cargo.toml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2023 ZettaScale Technology 3 | # 4 | # This program and the accompanying materials are made available under the 5 | # terms of the Eclipse Public License 2.0 which is available at 6 | # http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | # which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | # 9 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | # 11 | # Contributors: 12 | # ZettaScale Zenoh Team, 13 | # 14 | [package] 15 | rust-version = { workspace = true } 16 | name = "zenoh-shm" 17 | version = { workspace = true } 18 | repository = { workspace = true } 19 | homepage = { workspace = true } 20 | authors = [ 21 | "kydos ", 22 | "Luca Cominardi ", 23 | "Pierre Avital ", 24 | ] 25 | edition = { workspace = true } 26 | license = { workspace = true } 27 | categories = { workspace = true } 28 | description = "Internal crate for zenoh." 29 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 30 | 31 | [features] 32 | test = ["num_cpus"] 33 | 34 | [dependencies] 35 | async-trait = { workspace = true } 36 | tracing = { workspace = true } 37 | tokio = { workspace = true } 38 | zenoh-result = { workspace = true } 39 | zenoh-core = { workspace = true } 40 | zenoh-macros = { workspace = true } 41 | zenoh-buffers = { workspace = true } 42 | rand = { workspace = true, features = ["std", "std_rng"] } 43 | static_init = { workspace = true } 44 | num-traits = { workspace = true } 45 | num_cpus = { workspace = true, optional = true } 46 | thread-priority = { workspace = true } 47 | stabby = { workspace = true } 48 | crossbeam-queue = { workspace = true } 49 | 50 | [target.'cfg(unix)'.dependencies] 51 | advisory-lock = { workspace = true } 52 | nix = { workspace = true, features = ["fs", "mman"] } 53 | 54 | [target.'cfg(windows)'.dependencies] 55 | win-sys = { workspace = true } 56 | winapi = { workspace = true } 57 | 58 | [dev-dependencies] 59 | libc = { workspace = true } 60 | 61 | [build-dependencies] 62 | cfg_aliases = "0.2.1" -------------------------------------------------------------------------------- /commons/zenoh-shm/README.md: -------------------------------------------------------------------------------- 1 | # ⚠️ WARNING ⚠️ 2 | 3 | This crate is intended for Zenoh's internal use. 4 | It is not guaranteed that the API will remain unchanged in any version, including patch updates. 5 | It is highly recommended to depend solely on the zenoh and zenoh-ext crates and to utilize their public APIs. 6 | 7 | - [Click here for Zenoh's main repository](https://github.com/eclipse-zenoh/zenoh) 8 | - [Click here for Zenoh's documentation](https://zenoh.io) 9 | -------------------------------------------------------------------------------- /commons/zenoh-shm/build.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2025 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | 15 | use cfg_aliases::cfg_aliases; 16 | 17 | fn main() { 18 | // these aliases should at least be included in the same aliases of Nix crate: 19 | // ___________________ 20 | // | | 21 | // | Nix aliases | 22 | // | ___________ | 23 | // | | Our | | 24 | // | | aliases | | 25 | // | |_________| | 26 | // |_________________| 27 | cfg_aliases! { 28 | dragonfly: { target_os = "dragonfly" }, 29 | ios: { target_os = "ios" }, 30 | freebsd: { target_os = "freebsd" }, 31 | macos: { target_os = "macos" }, 32 | netbsd: { target_os = "netbsd" }, 33 | openbsd: { target_os = "openbsd" }, 34 | watchos: { target_os = "watchos" }, 35 | tvos: { target_os = "tvos" }, 36 | visionos: { target_os = "visionos" }, 37 | 38 | apple_targets: { any(ios, macos, watchos, tvos, visionos) }, 39 | bsd: { any(freebsd, dragonfly, netbsd, openbsd, apple_targets) }, 40 | 41 | // we use this alias to detect platforms that 42 | // don't support advisory file locking on tmpfs 43 | shm_external_lockfile: { any(bsd, target_os = "redox") }, 44 | } 45 | 46 | println!("cargo:rustc-check-cfg=cfg(apple_targets)"); 47 | println!("cargo:rustc-check-cfg=cfg(bsd)"); 48 | println!("cargo:rustc-check-cfg=cfg(shm_external_lockfile)"); 49 | } 50 | -------------------------------------------------------------------------------- /commons/zenoh-shm/src/api/buffer/mod.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | 15 | pub mod traits; 16 | pub mod zshm; 17 | pub mod zshmmut; 18 | -------------------------------------------------------------------------------- /commons/zenoh-shm/src/api/buffer/traits.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | 15 | use std::ops::{Deref, DerefMut}; 16 | 17 | #[zenoh_macros::unstable_doc] 18 | pub trait ShmBuf: Deref + AsRef<[u8]> { 19 | #[zenoh_macros::unstable_doc] 20 | fn is_valid(&self) -> bool; 21 | } 22 | 23 | #[zenoh_macros::unstable_doc] 24 | pub trait ShmBufMut: ShmBuf + DerefMut + AsMut<[u8]> {} 25 | -------------------------------------------------------------------------------- /commons/zenoh-shm/src/api/cleanup.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2024 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | 15 | use crate::posix_shm::cleanup::cleanup_orphaned_segments; 16 | 17 | /// Linux: Trigger cleanup for orphaned SHM segments 18 | /// If process that created named SHM segment crashes or exits by a signal, the segment persists in the system 19 | /// disregarding if it is used by other Zenoh processes or not. This is the detail of POSIX specification for 20 | /// shared memory that is hard to bypass. To deal with this we developed a cleanup routine that enumerates all 21 | /// segments and tries to find processes that are using it. If no such process found, segment will be removed. 22 | /// There is no ideal signal to trigger this cleanup, so by default, zenoh triggers it in the following moments: 23 | /// - first POSIX SHM segment creation 24 | /// - process exit via exit() call or return from maint function 25 | /// It is OK to additionally trigger this function at any time, but be aware that this can be costly. 26 | /// 27 | /// For non-linux platforms this function currently does nothing 28 | #[zenoh_macros::unstable_doc] 29 | pub fn cleanup_orphaned_shm_segments() { 30 | cleanup_orphaned_segments(); 31 | } 32 | -------------------------------------------------------------------------------- /commons/zenoh-shm/src/api/client/mod.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | 15 | pub mod shm_client; 16 | pub mod shm_segment; 17 | -------------------------------------------------------------------------------- /commons/zenoh-shm/src/api/client/shm_client.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | 15 | use std::{fmt::Debug, sync::Arc}; 16 | 17 | use zenoh_result::ZResult; 18 | 19 | use super::shm_segment::ShmSegment; 20 | use crate::api::common::types::SegmentID; 21 | 22 | /// ShmClient - client factory implementation for particular shared memory protocol 23 | #[zenoh_macros::unstable_doc] 24 | pub trait ShmClient: Debug + Send + Sync { 25 | /// Attach to particular shared memory segment 26 | #[zenoh_macros::unstable_doc] 27 | fn attach(&self, segment: SegmentID) -> ZResult>; 28 | } 29 | -------------------------------------------------------------------------------- /commons/zenoh-shm/src/api/client/shm_segment.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | 15 | use std::{fmt::Debug, sync::atomic::AtomicPtr}; 16 | 17 | use zenoh_result::ZResult; 18 | 19 | use crate::api::common::types::ChunkID; 20 | 21 | /// ShmSegment - RAII interface to interact with particular shared memory segment 22 | #[zenoh_macros::unstable_doc] 23 | pub trait ShmSegment: Debug + Send + Sync { 24 | /// Obtain the actual region of memory identified by it's id 25 | #[zenoh_macros::unstable_doc] 26 | fn map(&self, chunk: ChunkID) -> ZResult>; 27 | } 28 | -------------------------------------------------------------------------------- /commons/zenoh-shm/src/api/common/mod.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | 15 | pub mod types; 16 | -------------------------------------------------------------------------------- /commons/zenoh-shm/src/api/common/types.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | 15 | /// Unique protocol identifier. 16 | /// Here is a contract: it is up to user to make sure that incompatible ShmClient 17 | /// and ShmProviderBackend implementations will never use the same ProtocolID 18 | #[zenoh_macros::unstable_doc] 19 | pub type ProtocolID = u32; 20 | 21 | /// Unique segment identifier 22 | #[zenoh_macros::unstable_doc] 23 | pub type SegmentID = u32; 24 | 25 | /// Chunk id within it's segment 26 | #[zenoh_macros::unstable_doc] 27 | pub type ChunkID = u32; 28 | -------------------------------------------------------------------------------- /commons/zenoh-shm/src/api/mod.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | 15 | pub mod buffer; 16 | pub mod cleanup; 17 | pub mod client; 18 | pub mod client_storage; 19 | pub mod common; 20 | pub mod protocol_implementations; 21 | pub mod provider; 22 | -------------------------------------------------------------------------------- /commons/zenoh-shm/src/api/protocol_implementations/mod.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | 15 | pub mod posix; 16 | -------------------------------------------------------------------------------- /commons/zenoh-shm/src/api/protocol_implementations/posix/mod.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | 15 | pub mod posix_shm_client; 16 | pub mod posix_shm_provider_backend; 17 | pub mod protocol_id; 18 | 19 | pub(crate) mod posix_shm_segment; 20 | -------------------------------------------------------------------------------- /commons/zenoh-shm/src/api/protocol_implementations/posix/posix_shm_client.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | 15 | use std::sync::Arc; 16 | 17 | use zenoh_result::ZResult; 18 | 19 | use super::posix_shm_segment::PosixShmSegment; 20 | use crate::api::{ 21 | client::{shm_client::ShmClient, shm_segment::ShmSegment}, 22 | common::types::SegmentID, 23 | }; 24 | 25 | /// Client factory implementation for particular shared memory protocol 26 | #[zenoh_macros::unstable_doc] 27 | #[derive(Debug)] 28 | pub struct PosixShmClient; 29 | 30 | impl ShmClient for PosixShmClient { 31 | /// Attach to particular shared memory segment 32 | #[zenoh_macros::unstable_doc] 33 | fn attach(&self, segment: SegmentID) -> ZResult> { 34 | Ok(Arc::new(PosixShmSegment::open(segment)?)) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /commons/zenoh-shm/src/api/protocol_implementations/posix/posix_shm_segment.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | 15 | use std::{num::NonZeroUsize, sync::atomic::AtomicPtr}; 16 | 17 | use zenoh_result::ZResult; 18 | 19 | use crate::{ 20 | api::{ 21 | client::shm_segment::ShmSegment, 22 | common::types::{ChunkID, SegmentID}, 23 | }, 24 | posix_shm::array::ArrayInSHM, 25 | }; 26 | 27 | #[derive(Debug)] 28 | pub(crate) struct PosixShmSegment { 29 | pub(crate) segment: ArrayInSHM, 30 | } 31 | 32 | impl PosixShmSegment { 33 | pub(crate) fn create(alloc_size: NonZeroUsize) -> ZResult { 34 | let segment = ArrayInSHM::create(alloc_size)?; 35 | Ok(Self { segment }) 36 | } 37 | 38 | pub(crate) fn open(id: SegmentID) -> ZResult { 39 | let segment = ArrayInSHM::open(id)?; 40 | Ok(Self { segment }) 41 | } 42 | } 43 | 44 | impl ShmSegment for PosixShmSegment { 45 | fn map(&self, chunk: ChunkID) -> ZResult> { 46 | unsafe { Ok(AtomicPtr::new(self.segment.elem_mut(chunk))) } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /commons/zenoh-shm/src/api/protocol_implementations/posix/protocol_id.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | 15 | use crate::api::common::types::ProtocolID; 16 | 17 | /// Protocol identifier to use when creating ShmProvider 18 | #[zenoh_macros::unstable_doc] 19 | pub const POSIX_PROTOCOL_ID: ProtocolID = 0; 20 | -------------------------------------------------------------------------------- /commons/zenoh-shm/src/api/provider/chunk.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | 15 | use std::{num::NonZeroUsize, sync::atomic::AtomicPtr}; 16 | 17 | use crate::api::common::types::{ChunkID, SegmentID}; 18 | 19 | /// Uniquely identifies the particular chunk within particular segment 20 | #[zenoh_macros::unstable_doc] 21 | #[derive(Clone, Debug, PartialEq, Eq)] 22 | #[stabby::stabby] 23 | pub struct ChunkDescriptor { 24 | pub segment: SegmentID, 25 | pub chunk: ChunkID, 26 | pub len: NonZeroUsize, 27 | } 28 | 29 | impl ChunkDescriptor { 30 | /// Create a new Chunk Descriptor 31 | #[zenoh_macros::unstable_doc] 32 | pub fn new(segment: SegmentID, chunk: ChunkID, len: NonZeroUsize) -> Self { 33 | Self { 34 | segment, 35 | chunk, 36 | len, 37 | } 38 | } 39 | } 40 | 41 | /// A recently-allocated chunk. 42 | #[zenoh_macros::unstable_doc] 43 | pub struct AllocatedChunk { 44 | pub descriptor: ChunkDescriptor, 45 | pub data: AtomicPtr, 46 | } 47 | 48 | impl AllocatedChunk { 49 | /// Create a new Allocated Chunk 50 | #[zenoh_macros::unstable_doc] 51 | pub fn new(descriptor: ChunkDescriptor, data: AtomicPtr) -> Self { 52 | Self { descriptor, data } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /commons/zenoh-shm/src/api/provider/mod.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | 15 | pub mod chunk; 16 | pub mod shm_provider; 17 | pub mod shm_provider_backend; 18 | pub mod types; 19 | -------------------------------------------------------------------------------- /commons/zenoh-shm/src/api/provider/shm_provider_backend.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | use super::{ 15 | chunk::ChunkDescriptor, 16 | types::{ChunkAllocResult, MemoryLayout, ZLayoutError}, 17 | }; 18 | 19 | /// The provider backend trait 20 | /// Implement this interface to create a Zenoh-compatible shared memory provider 21 | #[zenoh_macros::unstable_doc] 22 | pub trait ShmProviderBackend { 23 | /// Allocate the chunk of desired size. 24 | /// If successful, the result's chunk size will be >= len 25 | #[zenoh_macros::unstable_doc] 26 | fn alloc(&self, layout: &MemoryLayout) -> ChunkAllocResult; 27 | 28 | /// Deallocate the chunk. 29 | /// It is guaranteed that chunk's descriptor will correspond to the one returned from alloc(...) 30 | #[zenoh_macros::unstable_doc] 31 | fn free(&self, chunk: &ChunkDescriptor); 32 | 33 | /// Defragment the memory. 34 | /// Should return the size of largest defragmented chunk 35 | #[zenoh_macros::unstable_doc] 36 | fn defragment(&self) -> usize; 37 | 38 | /// Bytes available for use 39 | #[zenoh_macros::unstable_doc] 40 | fn available(&self) -> usize; 41 | 42 | /// Check and calculate suitable layout for layout. 43 | /// Depending on the implementation, backend may relayout allocations for bigger layouts. 44 | /// This method is used to: 45 | /// - validate, if the provided layout can be used with this backend 46 | /// - adopt the layout for backend capabilities 47 | #[zenoh_macros::unstable_doc] 48 | fn layout_for(&self, layout: MemoryLayout) -> Result; 49 | } 50 | -------------------------------------------------------------------------------- /commons/zenoh-shm/src/header/chunk_header.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | 15 | use std::{ 16 | num::NonZeroUsize, 17 | sync::atomic::{AtomicBool, AtomicU32, AtomicUsize, Ordering}, 18 | }; 19 | 20 | use crate::api::provider::chunk::ChunkDescriptor; 21 | 22 | // Chunk header 23 | #[stabby::stabby] 24 | #[derive(Debug)] 25 | pub struct ChunkHeaderType { 26 | /* 27 | TODO: We don't really need 32 bits here, but access to 16-bit felds with 1 byte alignment is less performant on most of the platforms. 28 | We need to bench and select reasonable integer sizes here once we have an implementation to bench 29 | */ 30 | pub refcount: AtomicU32, 31 | pub watchdog_invalidated: AtomicBool, 32 | pub generation: AtomicU32, 33 | 34 | /// Protocol identifier for particular SHM implementation 35 | pub protocol: AtomicU32, 36 | 37 | /// The data chunk descriptor 38 | segment: AtomicU32, 39 | chunk: AtomicU32, 40 | len: AtomicUsize, 41 | } 42 | 43 | impl ChunkHeaderType { 44 | pub fn set_data_descriptor(&self, descriptor: &ChunkDescriptor) { 45 | self.segment.store(descriptor.segment, Ordering::Relaxed); 46 | self.chunk.store(descriptor.chunk, Ordering::Relaxed); 47 | self.len.store(descriptor.len.into(), Ordering::Relaxed); 48 | } 49 | 50 | pub fn data_descriptor(&self) -> ChunkDescriptor { 51 | ChunkDescriptor::new( 52 | self.segment.load(Ordering::Relaxed), 53 | self.chunk.load(Ordering::Relaxed), 54 | // SAFETY: this is safe because Write access to self.len is available only from set_data_descriptor 55 | unsafe { NonZeroUsize::new_unchecked(self.len.load(Ordering::Relaxed)) }, 56 | ) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /commons/zenoh-shm/src/header/mod.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | 15 | pub(crate) mod chunk_header; 16 | -------------------------------------------------------------------------------- /commons/zenoh-shm/src/init.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2024 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | 15 | use crate::{ 16 | api::client_storage::GLOBAL_CLIENT_STORAGE, 17 | cleanup::CLEANUP, 18 | metadata::{storage::GLOBAL_METADATA_STORAGE, subscription::GLOBAL_METADATA_SUBSCRIPTION}, 19 | watchdog::{confirmator::GLOBAL_CONFIRMATOR, validator::GLOBAL_VALIDATOR}, 20 | }; 21 | 22 | pub fn init() { 23 | CLEANUP.init(); 24 | GLOBAL_CLIENT_STORAGE.init(); 25 | GLOBAL_METADATA_STORAGE.init(); 26 | GLOBAL_METADATA_SUBSCRIPTION.init(); 27 | GLOBAL_CONFIRMATOR.init(); 28 | GLOBAL_VALIDATOR.init(); 29 | } 30 | -------------------------------------------------------------------------------- /commons/zenoh-shm/src/metadata/allocated_descriptor.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2025 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | 15 | use std::ops::Deref; 16 | 17 | use super::{descriptor::OwnedMetadataDescriptor, storage::GLOBAL_METADATA_STORAGE}; 18 | use crate::watchdog::validator::GLOBAL_VALIDATOR; 19 | 20 | #[derive(Debug)] 21 | pub struct AllocatedMetadataDescriptor { 22 | descriptor: OwnedMetadataDescriptor, 23 | } 24 | 25 | impl AllocatedMetadataDescriptor { 26 | pub fn new(descriptor: OwnedMetadataDescriptor) -> Self { 27 | //initialize header fields 28 | let header = descriptor.header(); 29 | header 30 | .refcount 31 | .store(1, std::sync::atomic::Ordering::SeqCst); 32 | header 33 | .watchdog_invalidated 34 | .store(false, std::sync::atomic::Ordering::SeqCst); 35 | 36 | // reset watchdog on allocation 37 | descriptor.validate(); 38 | 39 | Self { descriptor } 40 | } 41 | } 42 | 43 | impl Drop for AllocatedMetadataDescriptor { 44 | fn drop(&mut self) { 45 | GLOBAL_VALIDATOR.read().remove(self.descriptor.clone()); 46 | GLOBAL_METADATA_STORAGE 47 | .read() 48 | .reclaim(self.descriptor.clone()); 49 | } 50 | } 51 | 52 | impl Deref for AllocatedMetadataDescriptor { 53 | type Target = OwnedMetadataDescriptor; 54 | 55 | fn deref(&self) -> &Self::Target { 56 | &self.descriptor 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /commons/zenoh-shm/src/metadata/mod.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2025 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | 15 | pub mod descriptor; 16 | 17 | tested_crate_module!(storage); 18 | tested_crate_module!(subscription); 19 | 20 | pub(crate) mod allocated_descriptor; 21 | 22 | mod segment; 23 | -------------------------------------------------------------------------------- /commons/zenoh-shm/src/posix_shm/cleanup.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | 15 | pub(crate) use platform::cleanup_orphaned_segments; 16 | 17 | #[cfg(not(target_os = "linux"))] 18 | mod platform { 19 | pub(crate) fn cleanup_orphaned_segments() {} 20 | } 21 | 22 | #[cfg(target_os = "linux")] 23 | mod platform { 24 | use std::fs; 25 | 26 | use zenoh_result::ZResult; 27 | 28 | use crate::shm; 29 | 30 | pub(crate) fn cleanup_orphaned_segments() { 31 | if let Err(e) = cleanup_orphaned_segments_inner() { 32 | tracing::error!("Error performing orphaned SHM segments cleanup: {e}") 33 | } 34 | } 35 | 36 | fn cleanup_orphaned_segments_inner() -> ZResult<()> { 37 | #[cfg(shm_external_lockfile)] 38 | let shm_files = fs::read_dir(std::env::temp_dir())?; 39 | #[cfg(not(shm_external_lockfile))] 40 | let shm_files = fs::read_dir("/dev/shm")?; 41 | 42 | for segment_file in shm_files.filter_map(Result::ok).filter(|f| { 43 | if let Some(ext) = f.path().extension() { 44 | return ext == "zenoh"; 45 | } 46 | false 47 | }) { 48 | if let Some(Some(id_str)) = segment_file 49 | .path() 50 | .file_stem() 51 | .map(|os_str| os_str.to_str()) 52 | { 53 | if let Ok(id) = id_str.parse::() { 54 | shm::Segment::ensure_not_persistent(id); 55 | } 56 | } 57 | } 58 | 59 | Ok(()) 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /commons/zenoh-shm/src/posix_shm/mod.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | 15 | pub mod array; 16 | pub mod struct_in_shm; 17 | tested_crate_module!(segment); 18 | pub(crate) mod cleanup; 19 | -------------------------------------------------------------------------------- /commons/zenoh-shm/src/version.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2024 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | 15 | pub const SHM_VERSION: u64 = 1; 16 | -------------------------------------------------------------------------------- /commons/zenoh-shm/src/watchdog/mod.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | 15 | tested_crate_module!(periodic_task); 16 | tested_crate_module!(validator); 17 | tested_crate_module!(confirmator); 18 | -------------------------------------------------------------------------------- /commons/zenoh-sync/Cargo.toml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2023 ZettaScale Technology 3 | # 4 | # This program and the accompanying materials are made available under the 5 | # terms of the Eclipse Public License 2.0 which is available at 6 | # http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | # which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | # 9 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | # 11 | # Contributors: 12 | # ZettaScale Zenoh Team, 13 | # 14 | [package] 15 | rust-version = { workspace = true } 16 | name = "zenoh-sync" 17 | version = { workspace = true } 18 | repository = { workspace = true } 19 | homepage = { workspace = true } 20 | authors = [ 21 | "kydos ", 22 | "Luca Cominardi ", 23 | "Pierre Avital ", 24 | ] 25 | edition = { workspace = true } 26 | license = { workspace = true } 27 | categories = { workspace = true } 28 | description = "Internal crate for zenoh." 29 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 30 | 31 | [dependencies] 32 | arc-swap = { workspace = true } 33 | event-listener = { workspace = true } 34 | futures = { workspace = true } 35 | tokio = { workspace = true, features = ["sync"] } 36 | zenoh-buffers = { workspace = true } 37 | zenoh-collections = { workspace = true, features = ["default"] } 38 | zenoh-core = { workspace = true } 39 | 40 | [dev-dependencies] 41 | tokio = { workspace = true, features = ["macros", "sync", "rt-multi-thread", "time"] } 42 | zenoh-result = { workspace = true } 43 | -------------------------------------------------------------------------------- /commons/zenoh-sync/README.md: -------------------------------------------------------------------------------- 1 | # ⚠️ WARNING ⚠️ 2 | 3 | This crate is intended for Zenoh's internal use. 4 | It is not guaranteed that the API will remain unchanged in any version, including patch updates. 5 | It is highly recommended to depend solely on the zenoh and zenoh-ext crates and to utilize their public APIs. 6 | 7 | - [Click here for Zenoh's main repository](https://github.com/eclipse-zenoh/zenoh) 8 | - [Click here for Zenoh's documentation](https://zenoh.io) 9 | -------------------------------------------------------------------------------- /commons/zenoh-sync/src/condition.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | use std::{pin::Pin, sync::MutexGuard}; 15 | 16 | use event_listener::{Event, EventListener}; 17 | use tokio::sync::MutexGuard as AsyncMutexGuard; 18 | 19 | pub type ConditionWaiter = Pin>; 20 | /// This is a Condition Variable similar to that provided by POSIX. 21 | /// As for POSIX condition variables, this assumes that a mutex is 22 | /// properly used to coordinate behaviour. In other terms there should 23 | /// not be race condition on [notify_one](Condition::notify_one) or 24 | /// [notify_all](Condition::notify_all). 25 | /// 26 | #[derive(Default)] 27 | pub struct Condition { 28 | event: Event, 29 | } 30 | 31 | impl Condition { 32 | /// Creates a new condition variable with a given capacity. 33 | /// The capacity indicates the maximum number of tasks that 34 | /// may be waiting on the condition. 35 | pub fn new() -> Condition { 36 | Condition::default() 37 | } 38 | 39 | /// Waits for the condition to be notified 40 | #[inline] 41 | pub async fn wait(&self, guard: AsyncMutexGuard<'_, T>) { 42 | let listener = self.event.listen(); 43 | drop(guard); 44 | listener.await; 45 | } 46 | 47 | #[inline] 48 | pub fn waiter(&self, guard: MutexGuard<'_, T>) -> ConditionWaiter { 49 | let listener = self.event.listen(); 50 | drop(guard); 51 | Box::pin(listener) 52 | } 53 | 54 | /// Notifies one pending listener 55 | #[inline] 56 | pub fn notify_one(&self) { 57 | self.event.notify_additional_relaxed(1); 58 | } 59 | 60 | /// Notifies all pending listeners 61 | #[inline] 62 | pub fn notify_all(&self) { 63 | self.event.notify_additional_relaxed(usize::MAX); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /commons/zenoh-sync/src/lib.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | 15 | //! ⚠️ WARNING ⚠️ 16 | //! 17 | //! This module is intended for Zenoh's internal use. 18 | //! 19 | //! [Click here for Zenoh's documentation](https://docs.rs/zenoh/latest/zenoh) 20 | use std::{ 21 | future::Future, 22 | pin::Pin, 23 | task::{Context, Poll}, 24 | }; 25 | 26 | use futures::FutureExt; 27 | 28 | pub mod event; 29 | pub use event::*; 30 | 31 | pub mod fifo_queue; 32 | pub use fifo_queue::*; 33 | 34 | pub mod lifo_queue; 35 | pub use lifo_queue::*; 36 | 37 | pub mod object_pool; 38 | pub use object_pool::*; 39 | 40 | pub mod mvar; 41 | pub use mvar::*; 42 | 43 | pub mod condition; 44 | pub use condition::*; 45 | 46 | pub mod signal; 47 | pub use signal::*; 48 | 49 | pub mod cache; 50 | pub use cache::*; 51 | 52 | pub fn get_mut_unchecked(arc: &mut std::sync::Arc) -> &mut T { 53 | unsafe { &mut (*(std::sync::Arc::as_ptr(arc) as *mut T)) } 54 | } 55 | 56 | /// An alias for `Pin + Send>>`. 57 | #[must_use = "futures do nothing unless you `.await` or poll them"] 58 | pub struct PinBoxFuture(Pin + Send>>); 59 | 60 | impl Future for PinBoxFuture { 61 | type Output = T; 62 | 63 | #[inline] 64 | fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { 65 | self.0.poll_unpin(cx) 66 | } 67 | } 68 | 69 | #[inline] 70 | pub fn pinbox(fut: impl Future + Send + 'static) -> PinBoxFuture { 71 | PinBoxFuture(Box::pin(fut)) 72 | } 73 | -------------------------------------------------------------------------------- /commons/zenoh-task/Cargo.toml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2024 ZettaScale Technology 3 | # 4 | # This program and the accompanying materials are made available under the 5 | # terms of the Eclipse Public License 2.0 which is available at 6 | # http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | # which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | # 9 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | # 11 | # Contributors: 12 | # ZettaScale Zenoh Team, 13 | # 14 | [package] 15 | rust-version = { workspace = true } 16 | name = "zenoh-task" 17 | version = { workspace = true } 18 | repository = { workspace = true } 19 | homepage = { workspace = true } 20 | authors = {workspace = true } 21 | edition = { workspace = true } 22 | license = { workspace = true } 23 | categories = { workspace = true } 24 | description = "Internal crate for zenoh." 25 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 26 | 27 | [features] 28 | tracing-instrument = ["zenoh-runtime/tracing-instrument"] 29 | 30 | [dependencies] 31 | tokio = { workspace = true, features = ["default", "sync"] } 32 | futures = { workspace = true } 33 | tracing = {workspace = true} 34 | zenoh-core = { workspace = true } 35 | zenoh-runtime = { workspace = true } 36 | tokio-util = { workspace = true, features = ["rt"] } -------------------------------------------------------------------------------- /commons/zenoh-task/README.md: -------------------------------------------------------------------------------- 1 | # ⚠️ WARNING ⚠️ 2 | 3 | This crate is intended for Zenoh's internal use. 4 | It is not guaranteed that the API will remain unchanged in any version, including patch updates. 5 | It is highly recommended to depend solely on the zenoh and zenoh-ext crates and to utilize their public APIs. 6 | 7 | - [Click here for Zenoh's main repository](https://github.com/eclipse-zenoh/zenoh) 8 | - [Click here for Zenoh's documentation](https://zenoh.io) 9 | -------------------------------------------------------------------------------- /commons/zenoh-util/Cargo.toml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2023 ZettaScale Technology 3 | # 4 | # This program and the accompanying materials are made available under the 5 | # terms of the Eclipse Public License 2.0 which is available at 6 | # http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | # which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | # 9 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | # 11 | # Contributors: 12 | # ZettaScale Zenoh Team, 13 | # 14 | [package] 15 | rust-version = { workspace = true } 16 | name = "zenoh-util" 17 | version = { workspace = true } 18 | repository = { workspace = true } 19 | homepage = { workspace = true } 20 | authors = [ 21 | "kydos ", 22 | "Luca Cominardi ", 23 | "Pierre Avital ", 24 | ] 25 | edition = { workspace = true } 26 | license = { workspace = true } 27 | categories = { workspace = true } 28 | description = "Internal crate for zenoh." 29 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 30 | 31 | [badges] 32 | maintenance = { status = "actively-developed" } 33 | 34 | [features] 35 | test = [] 36 | 37 | [dependencies] 38 | tokio = { workspace = true, features = ["time", "net"] } 39 | async-trait = { workspace = true } 40 | flume = { workspace = true } 41 | home = { workspace = true } 42 | humantime = { workspace = true } 43 | lazy_static = { workspace = true } 44 | libloading = { workspace = true } 45 | tracing = { workspace = true } 46 | tracing-subscriber = { workspace = true } 47 | shellexpand = { workspace = true } 48 | zenoh-core = { workspace = true } 49 | zenoh-result = { workspace = true, features = ["default"] } 50 | const_format = { workspace = true } 51 | serde = { workspace = true, features = ["default"] } 52 | serde_json = { workspace = true } 53 | 54 | [target.'cfg(windows)'.dependencies] 55 | winapi = { workspace = true } 56 | 57 | [target.'cfg(unix)'.dependencies] 58 | libc = { workspace = true } 59 | pnet_datalink = { workspace = true } 60 | 61 | [dev-dependencies] 62 | -------------------------------------------------------------------------------- /commons/zenoh-util/README.md: -------------------------------------------------------------------------------- 1 | # ⚠️ WARNING ⚠️ 2 | 3 | This crate is intended for Zenoh's internal use. 4 | It is not guaranteed that the API will remain unchanged in any version, including patch updates. 5 | It is highly recommended to depend solely on the zenoh and zenoh-ext crates and to utilize their public APIs. 6 | 7 | - [Click here for Zenoh's main repository](https://github.com/eclipse-zenoh/zenoh) 8 | - [Click here for Zenoh's documentation](https://zenoh.io) 9 | -------------------------------------------------------------------------------- /commons/zenoh-util/src/ffi/mod.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | 15 | #[cfg(windows)] 16 | pub mod win; 17 | 18 | /// # Safety 19 | /// Dereferences raw pointer argument 20 | pub unsafe fn pwstr_to_string(ptr: *mut u16) -> String { 21 | use std::slice::from_raw_parts; 22 | let len = (0_usize..) 23 | .find(|&n| *ptr.add(n) == 0) 24 | .expect("Couldn't find null terminator"); 25 | let array: &[u16] = from_raw_parts(ptr, len); 26 | String::from_utf16_lossy(array) 27 | } 28 | 29 | /// # Safety 30 | /// Dereferences raw pointer argument 31 | pub unsafe fn pstr_to_string(ptr: *mut i8) -> String { 32 | use std::slice::from_raw_parts; 33 | let len = (0_usize..) 34 | .find(|&n| *ptr.add(n) == 0) 35 | .expect("Couldn't find null terminator"); 36 | let array: &[u8] = from_raw_parts(ptr as *const u8, len); 37 | String::from_utf8_lossy(array).to_string() 38 | } 39 | -------------------------------------------------------------------------------- /commons/zenoh-util/tests/zresult.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | use zenoh_result::{zerror, ZResult}; 15 | 16 | #[test] 17 | fn error_simple() { 18 | let err: ZResult<()> = Err(zerror!("TEST").into()); 19 | if let Err(e) = err { 20 | let s = e.to_string(); 21 | println!("{e}"); 22 | println!("{e:?}"); 23 | assert!(s.contains("TEST")); 24 | assert!(s.contains(file!())); 25 | // assert!(e.source().is_none()); 26 | } else { 27 | panic!(); 28 | } 29 | } 30 | 31 | #[test] 32 | fn error_with_source() { 33 | let err1: ZResult<()> = Err(zerror!("ERR1").into()); 34 | if let Err(e) = err1 { 35 | let e = zerror!(e => "ERR2"); 36 | let s = e.to_string(); 37 | println!("{e}"); 38 | println!("{e:?}"); 39 | 40 | assert!(s.contains(file!())); 41 | // assert!(e.source().is_some()); 42 | assert!(s.contains("ERR1")); 43 | assert!(s.contains("ERR2")); 44 | } else { 45 | panic!(); 46 | } 47 | 48 | let ioerr = std::io::Error::other("IOERR"); 49 | let e = zerror!( ioerr =>"ERR2"); 50 | let s = e.to_string(); 51 | println!("{e}"); 52 | println!("{e:?}"); 53 | 54 | assert!(s.contains(file!())); 55 | // assert!(e.source().is_some()); 56 | assert!(s.contains("IOERR")); 57 | assert!(s.contains("ERR2")); 58 | } 59 | -------------------------------------------------------------------------------- /deny.toml: -------------------------------------------------------------------------------- 1 | # NOTE: Before allowing a new license, make sure it is approved by the Eclipse Foundation. 2 | # A list of approved third party licenses is available at: https://www.eclipse.org/legal/licenses.php. 3 | [licenses] 4 | allow = [ 5 | "MIT", 6 | "Apache-2.0", 7 | "EPL-2.0", 8 | "ISC", 9 | "Unicode-DFS-2016", 10 | "Unicode-3.0", 11 | "Zlib", 12 | "BSD-2-Clause", 13 | "BSD-3-Clause", 14 | "CC0-1.0", 15 | "MPL-2.0", 16 | "OpenSSL", 17 | "BSL-1.0" 18 | ] 19 | 20 | # This was copied from https://github.com/EmbarkStudios/cargo-deny/blob/main/deny.toml#L64 21 | [[licenses.clarify]] 22 | crate = "ring" 23 | expression = "ISC AND MIT AND OpenSSL" 24 | license-files = [{ path = "LICENSE", hash = 0xbd0eed23 }] 25 | [licenses.private] 26 | ignore = true 27 | -------------------------------------------------------------------------------- /examples/build.rs: -------------------------------------------------------------------------------- 1 | use std::{env, fs::File, io::Write, path::Path}; 2 | 3 | use which::which; 4 | 5 | fn main() -> std::io::Result<()> { 6 | // If protoc is not installed, we cheat because building protoc from source 7 | // with protobuf-src is way too long 8 | if which("protoc").is_err() { 9 | const PROTO: &str = r#"#[derive(Clone, PartialEq, ::prost::Message)] pub struct Entity { #[prost(uint32, tag = "1")] pub id: u32, #[prost(string, tag = "2")] pub name: ::prost::alloc::string::String,}"#; 10 | let out_path = Path::new(&env::var("OUT_DIR").unwrap()).join("example.rs"); 11 | File::create(out_path)?.write_all(PROTO.as_bytes())?; 12 | return Ok(()); 13 | } 14 | prost_build::compile_protos(&["examples/example.proto"], &["examples/"])?; 15 | Ok(()) 16 | } 17 | -------------------------------------------------------------------------------- /examples/examples/example.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package example; 4 | 5 | message Entity { 6 | uint32 id = 1; 7 | string name = 2; 8 | } 9 | -------------------------------------------------------------------------------- /examples/examples/z_delete.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | use clap::Parser; 15 | use zenoh::{key_expr::KeyExpr, Config}; 16 | use zenoh_examples::CommonArgs; 17 | 18 | #[tokio::main] 19 | async fn main() { 20 | // initiate logging 21 | zenoh::init_log_from_env_or("error"); 22 | 23 | let (config, key_expr) = parse_args(); 24 | 25 | println!("Opening session..."); 26 | let session = zenoh::open(config).await.unwrap(); 27 | 28 | println!("Deleting resources matching '{key_expr}'..."); 29 | session.delete(&key_expr).await.unwrap(); 30 | 31 | session.close().await.unwrap(); 32 | } 33 | 34 | #[derive(clap::Parser, Clone, PartialEq, Eq, Hash, Debug)] 35 | struct Args { 36 | #[arg(short, long, default_value = "demo/example/zenoh-rs-put")] 37 | /// The key expression to write to. 38 | key: KeyExpr<'static>, 39 | #[command(flatten)] 40 | common: CommonArgs, 41 | } 42 | 43 | fn parse_args() -> (Config, KeyExpr<'static>) { 44 | let args = Args::parse(); 45 | (args.common.into(), args.key) 46 | } 47 | -------------------------------------------------------------------------------- /examples/examples/z_formats.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | 15 | use zenoh::key_expr::{ 16 | format::{kedefine, keformat}, 17 | keyexpr, 18 | }; 19 | kedefine!( 20 | pub file_format: "user_id/${user_id:*}/file/${file:*/**}", 21 | pub(crate) settings_format: "user_id/${user_id:*}/settings/${setting:**}" 22 | ); 23 | 24 | fn main() { 25 | // Formatting 26 | let mut formatter = file_format::formatter(); 27 | let file = "hi/there"; 28 | let ke = keformat!(formatter, user_id = 42, file).unwrap(); 29 | println!("{formatter:?} => {ke}"); 30 | // Parsing 31 | let settings_ke = keyexpr::new("user_id/30/settings/dark_mode").unwrap(); 32 | let parsed = settings_format::parse(settings_ke).unwrap(); 33 | assert_eq!(parsed.user_id(), keyexpr::new("30").unwrap()); 34 | assert_eq!(parsed.setting(), keyexpr::new("dark_mode").ok()); 35 | } 36 | -------------------------------------------------------------------------------- /examples/examples/z_forward.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | use clap::Parser; 15 | use zenoh::{key_expr::KeyExpr, Config}; 16 | use zenoh_examples::CommonArgs; 17 | use zenoh_ext::SubscriberForward; 18 | 19 | #[tokio::main] 20 | async fn main() { 21 | // Initiate logging 22 | zenoh::init_log_from_env_or("error"); 23 | 24 | let (config, key_expr, forward) = parse_args(); 25 | 26 | println!("Opening session..."); 27 | let session = zenoh::open(config).await.unwrap(); 28 | 29 | println!("Declaring Subscriber on '{key_expr}'..."); 30 | let mut subscriber = session.declare_subscriber(&key_expr).await.unwrap(); 31 | println!("Declaring Publisher on '{forward}'..."); 32 | let publisher = session.declare_publisher(&forward).await.unwrap(); 33 | println!("Forwarding data from '{key_expr}' to '{forward}'..."); 34 | subscriber.forward(publisher).await.unwrap(); 35 | } 36 | 37 | #[derive(clap::Parser, Clone, PartialEq, Eq, Hash, Debug)] 38 | struct Args { 39 | #[arg(short, long, default_value = "demo/example/**")] 40 | /// The key expression to subscribe to. 41 | key: KeyExpr<'static>, 42 | #[arg(short, long, default_value = "demo/forward")] 43 | /// The key expression to forward to. 44 | forward: KeyExpr<'static>, 45 | #[command(flatten)] 46 | common: CommonArgs, 47 | } 48 | 49 | fn parse_args() -> (Config, KeyExpr<'static>, KeyExpr<'static>) { 50 | let args = Args::parse(); 51 | (args.common.into(), args.key, args.forward) 52 | } 53 | -------------------------------------------------------------------------------- /examples/examples/z_info.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | use clap::Parser; 15 | use zenoh::session::ZenohId; 16 | use zenoh_examples::CommonArgs; 17 | 18 | #[tokio::main] 19 | async fn main() { 20 | // initiate logging 21 | zenoh::init_log_from_env_or("error"); 22 | 23 | let config = parse_args(); 24 | 25 | println!("Opening session..."); 26 | let session = zenoh::open(config).await.unwrap(); 27 | 28 | let info = session.info(); 29 | println!("zid: {}", info.zid().await); 30 | println!( 31 | "routers zid: {:?}", 32 | info.routers_zid().await.collect::>() 33 | ); 34 | println!( 35 | "peers zid: {:?}", 36 | info.peers_zid().await.collect::>() 37 | ); 38 | } 39 | 40 | #[derive(clap::Parser, Clone, PartialEq, Eq, Hash, Debug)] 41 | struct Args { 42 | #[command(flatten)] 43 | common: CommonArgs, 44 | } 45 | 46 | fn parse_args() -> zenoh::Config { 47 | let args = Args::parse(); 48 | args.common.into() 49 | } 50 | -------------------------------------------------------------------------------- /examples/examples/z_liveliness.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | use clap::Parser; 15 | use zenoh::{key_expr::KeyExpr, Config}; 16 | use zenoh_examples::CommonArgs; 17 | 18 | #[tokio::main] 19 | async fn main() { 20 | // Initiate logging 21 | zenoh::init_log_from_env_or("error"); 22 | 23 | let (config, key_expr) = parse_args(); 24 | 25 | println!("Opening session..."); 26 | let session = zenoh::open(config).await.unwrap(); 27 | 28 | println!("Declaring LivelinessToken on '{}'...", &key_expr); 29 | let token = session.liveliness().declare_token(&key_expr).await.unwrap(); 30 | 31 | println!("Press CTRL-C to undeclare LivelinessToken and quit..."); 32 | std::thread::park(); 33 | 34 | // LivelinessTokens are automatically closed when dropped 35 | // Use the code below to manually undeclare it if needed 36 | token.undeclare().await.unwrap(); 37 | } 38 | 39 | #[derive(clap::Parser, Clone, PartialEq, Eq, Hash, Debug)] 40 | struct Args { 41 | #[arg(short, long, default_value = "group1/zenoh-rs")] 42 | /// The key expression of the liveliness token. 43 | key: KeyExpr<'static>, 44 | #[command(flatten)] 45 | common: CommonArgs, 46 | } 47 | 48 | fn parse_args() -> (Config, KeyExpr<'static>) { 49 | let args = Args::parse(); 50 | (args.common.into(), args.key) 51 | } 52 | -------------------------------------------------------------------------------- /examples/examples/z_pong.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | use clap::Parser; 15 | use zenoh::{key_expr::keyexpr, qos::CongestionControl, Config, Wait}; 16 | use zenoh_examples::CommonArgs; 17 | 18 | fn main() { 19 | // initiate logging 20 | zenoh::init_log_from_env_or("error"); 21 | 22 | let (config, express) = parse_args(); 23 | 24 | let session = zenoh::open(config).wait().unwrap(); 25 | 26 | // The key expression to read the data from 27 | let key_expr_ping = keyexpr::new("test/ping").unwrap(); 28 | 29 | // The key expression to echo the data back 30 | let key_expr_pong = keyexpr::new("test/pong").unwrap(); 31 | 32 | let publisher = session 33 | .declare_publisher(key_expr_pong) 34 | .congestion_control(CongestionControl::Block) 35 | .express(express) 36 | .wait() 37 | .unwrap(); 38 | 39 | session 40 | .declare_subscriber(key_expr_ping) 41 | .callback(move |sample| publisher.put(sample.payload().clone()).wait().unwrap()) 42 | .background() 43 | .wait() 44 | .unwrap(); 45 | std::thread::park(); 46 | } 47 | 48 | #[derive(clap::Parser, Clone, PartialEq, Eq, Hash, Debug)] 49 | struct Args { 50 | /// express for sending data 51 | #[arg(long, default_value = "false")] 52 | no_express: bool, 53 | #[command(flatten)] 54 | common: CommonArgs, 55 | } 56 | 57 | fn parse_args() -> (Config, bool) { 58 | let args = Args::parse(); 59 | (args.common.into(), !args.no_express) 60 | } 61 | -------------------------------------------------------------------------------- /examples/examples/z_posix_shm_provider.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | use zenoh::{ 15 | shm::{ 16 | AllocAlignment, MemoryLayout, PosixShmProviderBackend, ShmProviderBuilder, 17 | POSIX_PROTOCOL_ID, 18 | }, 19 | Wait, 20 | }; 21 | 22 | fn main() { 23 | // Construct an SHM backend 24 | let backend = { 25 | // NOTE: code in this block is a specific PosixShmProviderBackend API. 26 | 27 | // Total amount of shared memory to allocate 28 | let size = 4096; 29 | 30 | // An alignment for POSIX SHM provider 31 | // Due to internal optimization, all allocations will be aligned corresponding to this alignment, 32 | // so the provider will be able to satisfy allocation layouts with alignment <= provider_alignment 33 | let provider_alignment = AllocAlignment::default(); 34 | 35 | // A layout for POSIX Provider's memory 36 | let provider_layout = MemoryLayout::new(size, provider_alignment).unwrap(); 37 | 38 | // Build a provider backend 39 | PosixShmProviderBackend::builder() 40 | .with_layout(provider_layout) 41 | .wait() 42 | .unwrap() 43 | }; 44 | 45 | // Construct an SHM provider for particular backend and POSIX_PROTOCOL_ID 46 | let _shm_provider = ShmProviderBuilder::builder() 47 | .protocol_id::() 48 | .backend(backend) 49 | .wait(); 50 | } 51 | -------------------------------------------------------------------------------- /examples/examples/z_put.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | use clap::Parser; 15 | use zenoh::{key_expr::KeyExpr, Config}; 16 | use zenoh_examples::CommonArgs; 17 | 18 | #[tokio::main] 19 | async fn main() { 20 | // initiate logging 21 | zenoh::init_log_from_env_or("error"); 22 | 23 | let (config, key_expr, payload) = parse_args(); 24 | 25 | println!("Opening session..."); 26 | let session = zenoh::open(config).await.unwrap(); 27 | 28 | println!("Putting Data ('{key_expr}': '{payload}')..."); 29 | // Refer to z_bytes.rs to see how to serialize different types of message 30 | session.put(&key_expr, payload).await.unwrap(); 31 | } 32 | 33 | #[derive(clap::Parser, Clone, PartialEq, Eq, Hash, Debug)] 34 | struct Args { 35 | #[arg(short, long, default_value = "demo/example/zenoh-rs-put")] 36 | /// The key expression to write to. 37 | key: KeyExpr<'static>, 38 | #[arg(short, long, default_value = "Put from Rust!")] 39 | /// The payload to write. 40 | payload: String, 41 | #[command(flatten)] 42 | common: CommonArgs, 43 | } 44 | 45 | fn parse_args() -> (Config, KeyExpr<'static>, String) { 46 | let args = Args::parse(); 47 | (args.common.into(), args.key, args.payload) 48 | } 49 | -------------------------------------------------------------------------------- /examples/examples/z_put_float.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | use clap::Parser; 15 | use zenoh::{key_expr::KeyExpr, Config}; 16 | use zenoh_examples::CommonArgs; 17 | use zenoh_ext::z_serialize; 18 | 19 | #[tokio::main] 20 | async fn main() { 21 | // initiate logging 22 | zenoh::init_log_from_env_or("error"); 23 | 24 | let (config, key_expr, payload) = parse_args(); 25 | 26 | println!("Opening session..."); 27 | let session = zenoh::open(config).await.unwrap(); 28 | 29 | println!("Putting Float ('{key_expr}': '{payload}')..."); 30 | // you must have imported `zenoh_ext::ZBytesExt` to use `ZBytes::serialize` 31 | session.put(&key_expr, z_serialize(&payload)).await.unwrap(); 32 | 33 | session.close().await.unwrap(); 34 | } 35 | 36 | #[derive(clap::Parser, Clone, PartialEq, Debug)] 37 | struct Args { 38 | #[arg(short, long, default_value = "demo/example/zenoh-rs-put")] 39 | /// The key expression to write to. 40 | key: KeyExpr<'static>, 41 | #[arg(short, long, default_value_t = std::f64::consts::PI)] 42 | /// The payload to write. 43 | payload: f64, 44 | #[command(flatten)] 45 | common: CommonArgs, 46 | } 47 | 48 | fn parse_args() -> (Config, KeyExpr<'static>, f64) { 49 | let args = Args::parse(); 50 | (args.common.into(), args.key, args.payload) 51 | } 52 | -------------------------------------------------------------------------------- /examples/examples/z_scout.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | use zenoh::{config::WhatAmI, scout, Config}; 15 | 16 | #[tokio::main] 17 | async fn main() { 18 | // initiate logging 19 | zenoh::init_log_from_env_or("error"); 20 | 21 | println!("Scouting..."); 22 | let receiver = scout(WhatAmI::Peer | WhatAmI::Router, Config::default()) 23 | .await 24 | .unwrap(); 25 | 26 | let _ = tokio::time::timeout(std::time::Duration::from_secs(1), async { 27 | while let Ok(hello) = receiver.recv_async().await { 28 | println!("{hello}"); 29 | } 30 | }) 31 | .await; 32 | 33 | // stop scouting 34 | receiver.stop(); 35 | } 36 | -------------------------------------------------------------------------------- /io/zenoh-link-commons/Cargo.toml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2023 ZettaScale Technology 3 | # 4 | # This program and the accompanying materials are made available under the 5 | # terms of the Eclipse Public License 2.0 which is available at 6 | # http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | # which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | # 9 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | # 11 | # Contributors: 12 | # ZettaScale Zenoh Team, 13 | # 14 | [package] 15 | authors = { workspace = true } 16 | categories = { workspace = true } 17 | description = "Internal crate for zenoh." 18 | edition = { workspace = true } 19 | homepage = { workspace = true } 20 | license = { workspace = true } 21 | name = "zenoh-link-commons" 22 | repository = { workspace = true } 23 | rust-version = { workspace = true } 24 | version = { workspace = true } 25 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 26 | 27 | [features] 28 | compression = [] 29 | tls = ["dep:rustls", "dep:rustls-webpki"] 30 | 31 | [dependencies] 32 | async-trait = { workspace = true } 33 | flume = { workspace = true } 34 | futures = { workspace = true } 35 | rustls = { workspace = true, optional = true } 36 | rustls-webpki = { workspace = true, optional = true } 37 | serde = { workspace = true, features = ["default"] } 38 | socket2 = { workspace = true } 39 | time = { workspace = true } 40 | tokio = { workspace = true, features = [ 41 | "fs", 42 | "io-util", 43 | "net", 44 | "sync", 45 | "time", 46 | ] } 47 | tokio-util = { workspace = true, features = ["rt"] } 48 | tracing = { workspace = true } 49 | zenoh-buffers = { workspace = true } 50 | zenoh-codec = { workspace = true } 51 | zenoh-core = { workspace = true } 52 | zenoh-protocol = { workspace = true } 53 | zenoh-result = { workspace = true } 54 | zenoh-runtime = { workspace = true } 55 | zenoh-util = { workspace = true } 56 | 57 | [package.metadata.cargo-machete] 58 | ignored = ["rustls-webpki"] -------------------------------------------------------------------------------- /io/zenoh-link-commons/README.md: -------------------------------------------------------------------------------- 1 | # ⚠️ WARNING ⚠️ 2 | 3 | This crate is intended for Zenoh's internal use. 4 | It is not guaranteed that the API will remain unchanged in any version, including patch updates. 5 | It is highly recommended to depend solely on the zenoh and zenoh-ext crates and to utilize their public APIs. 6 | 7 | - [Click here for Zenoh's main repository](https://github.com/eclipse-zenoh/zenoh) 8 | - [Click here for Zenoh's documentation](https://zenoh.io) 9 | -------------------------------------------------------------------------------- /io/zenoh-link/Cargo.toml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2023 ZettaScale Technology 3 | # 4 | # This program and the accompanying materials are made available under the 5 | # terms of the Eclipse Public License 2.0 which is available at 6 | # http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | # which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | # 9 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | # 11 | # Contributors: 12 | # ZettaScale Zenoh Team, 13 | # 14 | [package] 15 | rust-version = { workspace = true } 16 | name = "zenoh-link" 17 | version = { workspace = true } 18 | repository = { workspace = true } 19 | homepage = { workspace = true } 20 | authors = { workspace = true } 21 | edition = { workspace = true } 22 | license = { workspace = true } 23 | categories = { workspace = true } 24 | description = "Internal crate for zenoh." 25 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 26 | 27 | [features] 28 | transport_quic = ["zenoh-link-quic"] 29 | transport_tcp = ["zenoh-link-tcp", "zenoh-config/transport_tcp"] 30 | transport_tls = ["zenoh-link-tls"] 31 | transport_udp = ["zenoh-link-udp"] 32 | transport_unixsock-stream = ["zenoh-link-unixsock_stream"] 33 | transport_ws = ["zenoh-link-ws"] 34 | transport_serial = ["zenoh-link-serial"] 35 | transport_unixpipe = ["zenoh-link-unixpipe", "zenoh-link-unixpipe/transport_unixpipe"] 36 | transport_vsock = ["zenoh-link-vsock"] 37 | 38 | [dependencies] 39 | zenoh-config = { workspace = true } 40 | zenoh-link-commons = { workspace = true } 41 | zenoh-link-quic = { workspace = true, optional = true } 42 | zenoh-link-serial = { workspace = true, optional = true } 43 | zenoh-link-tcp = { workspace = true, optional = true } 44 | zenoh-link-tls = { workspace = true, optional = true } 45 | zenoh-link-udp = { workspace = true, optional = true } 46 | zenoh-link-unixsock_stream = { workspace = true, optional = true } 47 | zenoh-link-ws = { workspace = true, optional = true } 48 | zenoh-link-unixpipe = { workspace = true, optional = true } 49 | zenoh-link-vsock = { workspace = true, optional = true } 50 | zenoh-protocol = { workspace = true } 51 | zenoh-result = { workspace = true } 52 | -------------------------------------------------------------------------------- /io/zenoh-link/README.md: -------------------------------------------------------------------------------- 1 | # ⚠️ WARNING ⚠️ 2 | 3 | This crate is intended for Zenoh's internal use. 4 | It is not guaranteed that the API will remain unchanged in any version, including patch updates. 5 | It is highly recommended to depend solely on the zenoh and zenoh-ext crates and to utilize their public APIs. 6 | 7 | - [Click here for Zenoh's main repository](https://github.com/eclipse-zenoh/zenoh) 8 | - [Click here for Zenoh's documentation](https://zenoh.io) 9 | -------------------------------------------------------------------------------- /io/zenoh-links/README.md: -------------------------------------------------------------------------------- 1 | # ⚠️ WARNING ⚠️ 2 | 3 | This crate is intended for Zenoh's internal use. 4 | It is not guaranteed that the API will remain unchanged in any version, including patch updates. 5 | It is highly recommended to depend solely on the zenoh and zenoh-ext crates and to utilize their public APIs. 6 | 7 | - [Click here for Zenoh's main repository](https://github.com/eclipse-zenoh/zenoh) 8 | - [Click here for Zenoh's documentation](https://zenoh.io) 9 | -------------------------------------------------------------------------------- /io/zenoh-links/zenoh-link-quic/Cargo.toml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2023 ZettaScale Technology 3 | # 4 | # This program and the accompanying materials are made available under the 5 | # terms of the Eclipse Public License 2.0 which is available at 6 | # http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | # which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | # 9 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | # 11 | # Contributors: 12 | # ZettaScale Zenoh Team, 13 | # 14 | [package] 15 | authors = { workspace = true } 16 | categories = { workspace = true } 17 | description = "Internal crate for zenoh." 18 | edition = { workspace = true } 19 | homepage = { workspace = true } 20 | license = { workspace = true } 21 | name = "zenoh-link-quic" 22 | repository = { workspace = true } 23 | rust-version = { workspace = true } 24 | version = { workspace = true } 25 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 26 | 27 | [dependencies] 28 | async-trait = { workspace = true } 29 | base64 = { workspace = true } 30 | quinn = { workspace = true } 31 | rustls = { workspace = true } 32 | rustls-pemfile = { workspace = true } 33 | rustls-pki-types = { workspace = true } 34 | rustls-webpki = { workspace = true } 35 | secrecy = { workspace = true } 36 | time = { workspace = true } 37 | tokio = { workspace = true, features = [ 38 | "fs", 39 | "io-util", 40 | "net", 41 | "sync", 42 | "time", 43 | ] } 44 | # tokio-rustls = { workspace = true } 45 | tokio-util = { workspace = true, features = ["rt"] } 46 | tracing = { workspace = true } 47 | webpki-roots = { workspace = true } 48 | x509-parser = { workspace = true } 49 | zenoh-config = { workspace = true } 50 | zenoh-core = { workspace = true } 51 | zenoh-link-commons = { workspace = true, features = ["tls"] } 52 | zenoh-protocol = { workspace = true } 53 | zenoh-result = { workspace = true } 54 | zenoh-util = { workspace = true } 55 | 56 | [package.metadata.cargo-machete] 57 | ignored = ["rustls-webpki"] -------------------------------------------------------------------------------- /io/zenoh-links/zenoh-link-quic/README.md: -------------------------------------------------------------------------------- 1 | # ⚠️ WARNING ⚠️ 2 | 3 | This crate is intended for Zenoh's internal use. 4 | It is not guaranteed that the API will remain unchanged in any version, including patch updates. 5 | It is highly recommended to depend solely on the zenoh and zenoh-ext crates and to utilize their public APIs. 6 | 7 | - [Click here for Zenoh's main repository](https://github.com/eclipse-zenoh/zenoh) 8 | - [Click here for Zenoh's documentation](https://zenoh.io) 9 | -------------------------------------------------------------------------------- /io/zenoh-links/zenoh-link-serial/Cargo.toml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2023 ZettaScale Technology 3 | # 4 | # This program and the accompanying materials are made available under the 5 | # terms of the Eclipse Public License 2.0 which is available at 6 | # http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | # which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | # 9 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | # 11 | # Contributors: 12 | # ZettaScale Zenoh Team, 13 | # 14 | [package] 15 | rust-version = { workspace = true } 16 | name = "zenoh-link-serial" 17 | version = { workspace = true } 18 | repository = { workspace = true } 19 | homepage = { workspace = true } 20 | authors = [ 21 | "kydos ", 22 | "Julien Enoch ", 23 | "Olivier Hécart ", 24 | "Luca Cominardi ", 25 | "Pierre Avital ", 26 | "Gabriele Baldoni " 27 | ] 28 | edition = { workspace = true } 29 | license = { workspace = true } 30 | categories = { workspace = true } 31 | description = "Internal crate for zenoh." 32 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 33 | 34 | [dependencies] 35 | async-trait = { workspace = true } 36 | tracing = {workspace = true} 37 | tokio = { workspace = true, features = ["io-std", "macros", "net", "rt-multi-thread", "time"] } 38 | tokio-util = { workspace = true, features = ["rt"] } 39 | uuid = { workspace = true, default-features = true } 40 | z-serial = { workspace = true } 41 | zenoh-core = { workspace = true } 42 | zenoh-link-commons = { workspace = true } 43 | zenoh-protocol = { workspace = true } 44 | zenoh-result = { workspace = true } 45 | zenoh-runtime = { workspace = true } 46 | -------------------------------------------------------------------------------- /io/zenoh-links/zenoh-link-serial/README.md: -------------------------------------------------------------------------------- 1 | # ⚠️ WARNING ⚠️ 2 | 3 | This crate is intended for Zenoh's internal use. 4 | It is not guaranteed that the API will remain unchanged in any version, including patch updates. 5 | It is highly recommended to depend solely on the zenoh and zenoh-ext crates and to utilize their public APIs. 6 | 7 | - [Click here for Zenoh's main repository](https://github.com/eclipse-zenoh/zenoh) 8 | - [Click here for Zenoh's documentation](https://zenoh.io) 9 | -------------------------------------------------------------------------------- /io/zenoh-links/zenoh-link-tcp/Cargo.toml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2023 ZettaScale Technology 3 | # 4 | # This program and the accompanying materials are made available under the 5 | # terms of the Eclipse Public License 2.0 which is available at 6 | # http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | # which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | # 9 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | # 11 | # Contributors: 12 | # ZettaScale Zenoh Team, 13 | # 14 | [package] 15 | rust-version = { workspace = true } 16 | name = "zenoh-link-tcp" 17 | version = { workspace = true } 18 | repository = { workspace = true } 19 | homepage = { workspace = true } 20 | authors = { workspace = true } 21 | edition = { workspace = true } 22 | license = { workspace = true } 23 | categories = { workspace = true } 24 | description = "Internal crate for zenoh." 25 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 26 | 27 | [dependencies] 28 | async-trait = { workspace = true } 29 | socket2 = { workspace = true } 30 | tokio = { workspace = true, features = ["net", "io-util", "rt", "time"] } 31 | tokio-util = { workspace = true, features = ["rt"] } 32 | tracing = {workspace = true} 33 | zenoh-config = { workspace = true } 34 | zenoh-core = { workspace = true } 35 | zenoh-link-commons = { workspace = true } 36 | zenoh-protocol = { workspace = true } 37 | zenoh-result = { workspace = true } 38 | -------------------------------------------------------------------------------- /io/zenoh-links/zenoh-link-tcp/README.md: -------------------------------------------------------------------------------- 1 | # ⚠️ WARNING ⚠️ 2 | 3 | This crate is intended for Zenoh's internal use. 4 | It is not guaranteed that the API will remain unchanged in any version, including patch updates. 5 | It is highly recommended to depend solely on the zenoh and zenoh-ext crates and to utilize their public APIs. 6 | 7 | - [Click here for Zenoh's main repository](https://github.com/eclipse-zenoh/zenoh) 8 | - [Click here for Zenoh's documentation](https://zenoh.io) 9 | -------------------------------------------------------------------------------- /io/zenoh-links/zenoh-link-tls/Cargo.toml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2023 ZettaScale Technology 3 | # 4 | # This program and the accompanying materials are made available under the 5 | # terms of the Eclipse Public License 2.0 which is available at 6 | # http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | # which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | # 9 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | # 11 | # Contributors: 12 | # ZettaScale Zenoh Team, 13 | # 14 | [package] 15 | authors = { workspace = true } 16 | categories = { workspace = true } 17 | description = "Internal crate for zenoh." 18 | edition = { workspace = true } 19 | homepage = { workspace = true } 20 | license = { workspace = true } 21 | name = "zenoh-link-tls" 22 | repository = { workspace = true } 23 | rust-version = { workspace = true } 24 | version = { workspace = true } 25 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 26 | 27 | [dependencies] 28 | async-trait = { workspace = true } 29 | base64 = { workspace = true } 30 | rustls = { workspace = true } 31 | rustls-pemfile = { workspace = true } 32 | rustls-pki-types = { workspace = true } 33 | rustls-webpki = { workspace = true } 34 | secrecy = { workspace = true } 35 | socket2 = { workspace = true } 36 | tokio = { workspace = true, features = ["fs", "io-util", "net", "sync"] } 37 | tokio-rustls = { workspace = true } 38 | tokio-util = { workspace = true, features = ["rt"] } 39 | time = { workspace = true } 40 | tracing = { workspace = true } 41 | x509-parser = { workspace = true } 42 | webpki-roots = { workspace = true } 43 | tls-listener = { workspace = true } 44 | zenoh-config = { workspace = true } 45 | zenoh-core = { workspace = true } 46 | zenoh-link-commons = { workspace = true, features = ["tls"] } 47 | zenoh-protocol = { workspace = true } 48 | zenoh-result = { workspace = true } 49 | zenoh-runtime = { workspace = true } 50 | 51 | [package.metadata.cargo-machete] 52 | ignored = ["rustls-webpki"] -------------------------------------------------------------------------------- /io/zenoh-links/zenoh-link-tls/README.md: -------------------------------------------------------------------------------- 1 | # ⚠️ WARNING ⚠️ 2 | 3 | This crate is intended for Zenoh's internal use. 4 | It is not guaranteed that the API will remain unchanged in any version, including patch updates. 5 | It is highly recommended to depend solely on the zenoh and zenoh-ext crates and to utilize their public APIs. 6 | 7 | - [Click here for Zenoh's main repository](https://github.com/eclipse-zenoh/zenoh) 8 | - [Click here for Zenoh's documentation](https://zenoh.io) 9 | -------------------------------------------------------------------------------- /io/zenoh-links/zenoh-link-udp/Cargo.toml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2023 ZettaScale Technology 3 | # 4 | # This program and the accompanying materials are made available under the 5 | # terms of the Eclipse Public License 2.0 which is available at 6 | # http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | # which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | # 9 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | # 11 | # Contributors: 12 | # ZettaScale Zenoh Team, 13 | # 14 | [package] 15 | rust-version = { workspace = true } 16 | name = "zenoh-link-udp" 17 | version = { workspace = true } 18 | repository = { workspace = true } 19 | homepage = { workspace = true } 20 | authors = { workspace = true } 21 | edition = { workspace = true } 22 | license = { workspace = true } 23 | categories = { workspace = true } 24 | description = "Internal crate for zenoh." 25 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 26 | 27 | [dependencies] 28 | tokio = { workspace = true, features = ["net", "io-util", "rt", "time"] } 29 | tokio-util = { workspace = true, features = ["rt"] } 30 | async-trait = { workspace = true } 31 | tracing = {workspace = true} 32 | socket2 = { workspace = true } 33 | zenoh-buffers = { workspace = true } 34 | zenoh-core = { workspace = true } 35 | zenoh-link-commons = { workspace = true } 36 | zenoh-protocol = { workspace = true } 37 | zenoh-result = { workspace = true } 38 | zenoh-sync = { workspace = true } 39 | zenoh-util = { workspace = true } 40 | -------------------------------------------------------------------------------- /io/zenoh-links/zenoh-link-udp/README.md: -------------------------------------------------------------------------------- 1 | # ⚠️ WARNING ⚠️ 2 | 3 | This crate is intended for Zenoh's internal use. 4 | It is not guaranteed that the API will remain unchanged in any version, including patch updates. 5 | It is highly recommended to depend solely on the zenoh and zenoh-ext crates and to utilize their public APIs. 6 | 7 | - [Click here for Zenoh's main repository](https://github.com/eclipse-zenoh/zenoh) 8 | - [Click here for Zenoh's documentation](https://zenoh.io) 9 | -------------------------------------------------------------------------------- /io/zenoh-links/zenoh-link-unixpipe/Cargo.toml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2023 ZettaScale Technology 3 | # 4 | # This program and the accompanying materials are made available under the 5 | # terms of the Eclipse Public License 2.0 which is available at 6 | # http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | # which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | # 9 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | # 11 | # Contributors: 12 | # ZettaScale Zenoh Team, 13 | # 14 | [package] 15 | rust-version = { workspace = true } 16 | name = "zenoh-link-unixpipe" 17 | version = { workspace = true } 18 | repository = { workspace = true } 19 | homepage = { workspace = true } 20 | authors = { workspace = true } 21 | edition = { workspace = true } 22 | license = { workspace = true } 23 | categories = { workspace = true } 24 | description = "Internal crate for zenoh." 25 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 26 | 27 | [features] 28 | transport_unixpipe = [] 29 | 30 | [dependencies] 31 | async-trait = { workspace = true } 32 | tracing = {workspace = true} 33 | rand = { workspace = true, features = ["default"] } 34 | zenoh-core = { workspace = true } 35 | zenoh-config = { workspace = true } 36 | zenoh-link-commons = { workspace = true } 37 | zenoh-protocol = { workspace = true } 38 | zenoh-result = { workspace = true } 39 | zenoh-runtime = { workspace = true } 40 | tokio = { workspace = true, features = ["sync", "fs", "io-util", "macros"] } 41 | tokio-util = { workspace = true, features = ["rt"] } 42 | 43 | [target.'cfg(unix)'.dependencies] 44 | unix-named-pipe = "0.2.0" 45 | nix = { workspace = true } 46 | filepath = "0.1.2" 47 | 48 | [target.'cfg(all(not(target_os="macos"), unix))'.dependencies] 49 | advisory-lock = { workspace = true } 50 | -------------------------------------------------------------------------------- /io/zenoh-links/zenoh-link-unixpipe/README.md: -------------------------------------------------------------------------------- 1 | # ⚠️ WARNING ⚠️ 2 | 3 | This crate is intended for Zenoh's internal use. 4 | It is not guaranteed that the API will remain unchanged in any version, including patch updates. 5 | It is highly recommended to depend solely on the zenoh and zenoh-ext crates and to utilize their public APIs. 6 | 7 | - [Click here for Zenoh's main repository](https://github.com/eclipse-zenoh/zenoh) 8 | - [Click here for Zenoh's documentation](https://zenoh.io) 9 | -------------------------------------------------------------------------------- /io/zenoh-links/zenoh-link-unixpipe/src/lib.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | 15 | //! ⚠️ WARNING ⚠️ 16 | //! 17 | //! This crate is intended for Zenoh's internal use. 18 | //! 19 | //! [Click here for Zenoh's documentation](https://docs.rs/zenoh/latest/zenoh) 20 | 21 | #[cfg(unix)] 22 | mod unix; 23 | #[cfg(unix)] 24 | pub use unix::*; 25 | -------------------------------------------------------------------------------- /io/zenoh-links/zenoh-link-unixsock_stream/Cargo.toml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2023 ZettaScale Technology 3 | # 4 | # This program and the accompanying materials are made available under the 5 | # terms of the Eclipse Public License 2.0 which is available at 6 | # http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | # which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | # 9 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | # 11 | # Contributors: 12 | # ZettaScale Zenoh Team, 13 | # 14 | [package] 15 | rust-version = { workspace = true } 16 | name = "zenoh-link-unixsock_stream" 17 | version = { workspace = true } 18 | repository = { workspace = true } 19 | homepage = { workspace = true } 20 | authors = [ 21 | "kydos ", 22 | "Julien Enoch ", 23 | "Olivier Hécart ", 24 | "Luca Cominardi ", 25 | "Pierre Avital ", 26 | "Gabriele Baldoni " 27 | ] 28 | edition = { workspace = true } 29 | license = { workspace = true } 30 | categories = { workspace = true } 31 | description = "Internal crate for zenoh." 32 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 33 | 34 | [dependencies] 35 | async-trait = { workspace = true } 36 | tracing = {workspace = true} 37 | nix = { workspace = true } 38 | tokio = { workspace = true, features = ["io-std", "macros", "net", "rt-multi-thread", "time"] } 39 | tokio-util = { workspace = true, features = ["rt"] } 40 | uuid = { workspace = true, features = ["default"] } 41 | zenoh-core = { workspace = true } 42 | zenoh-link-commons = { workspace = true } 43 | zenoh-protocol = { workspace = true } 44 | zenoh-result = { workspace = true } 45 | zenoh-runtime = { workspace = true } 46 | -------------------------------------------------------------------------------- /io/zenoh-links/zenoh-link-unixsock_stream/README.md: -------------------------------------------------------------------------------- 1 | # ⚠️ WARNING ⚠️ 2 | 3 | This crate is intended for Zenoh's internal use. 4 | It is not guaranteed that the API will remain unchanged in any version, including patch updates. 5 | It is highly recommended to depend solely on the zenoh and zenoh-ext crates and to utilize their public APIs. 6 | 7 | - [Click here for Zenoh's main repository](https://github.com/eclipse-zenoh/zenoh) 8 | - [Click here for Zenoh's documentation](https://zenoh.io) 9 | -------------------------------------------------------------------------------- /io/zenoh-links/zenoh-link-vsock/Cargo.toml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2024 ZettaScale Technology 3 | # 4 | # This program and the accompanying materials are made available under the 5 | # terms of the Eclipse Public License 2.0 which is available at 6 | # http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | # which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | # 9 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | # 11 | # Contributors: 12 | # ZettaScale Zenoh Team, 13 | # 14 | [package] 15 | rust-version = { workspace = true } 16 | name = "zenoh-link-vsock" 17 | version = { workspace = true } 18 | repository = { workspace = true } 19 | homepage = { workspace = true } 20 | authors = { workspace = true } 21 | edition = { workspace = true } 22 | license = { workspace = true } 23 | categories = { workspace = true } 24 | description = "Internal crate for zenoh." 25 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 26 | 27 | [dependencies] 28 | async-trait = { workspace = true } 29 | tokio = { workspace = true, features = ["net", "io-util", "rt", "time"] } 30 | tokio-util = { workspace = true, features = ["rt"] } 31 | tracing = {workspace = true} 32 | libc = { workspace = true } 33 | zenoh-core = { workspace = true } 34 | zenoh-link-commons = { workspace = true } 35 | zenoh-protocol = { workspace = true } 36 | zenoh-result = { workspace = true } 37 | zenoh-runtime = { workspace = true } 38 | 39 | # Workspaces does not support platform dependent dependencies, and 40 | # tokio-vsock not compiled on other platforms, so we put it there 41 | [target.'cfg(target_os = "linux")'.dependencies] 42 | tokio-vsock = "0.5.0" 43 | -------------------------------------------------------------------------------- /io/zenoh-links/zenoh-link-vsock/README.md: -------------------------------------------------------------------------------- 1 | # ⚠️ WARNING ⚠️ 2 | 3 | This crate is intended for Zenoh's internal use. 4 | It is not guaranteed that the API will remain unchanged in any version, including patch updates. 5 | It is highly recommended to depend solely on the zenoh and zenoh-ext crates and to utilize their public APIs. 6 | 7 | - [Click here for Zenoh's main repository](https://github.com/eclipse-zenoh/zenoh) 8 | - [Click here for Zenoh's documentation](https://zenoh.io) 9 | -------------------------------------------------------------------------------- /io/zenoh-links/zenoh-link-ws/Cargo.toml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2023 ZettaScale Technology 3 | # 4 | # This program and the accompanying materials are made available under the 5 | # terms of the Eclipse Public License 2.0 which is available at 6 | # http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | # which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | # 9 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | # 11 | # Contributors: 12 | # ZettaScale Zenoh Team, 13 | # 14 | [package] 15 | rust-version = { workspace = true } 16 | name = "zenoh-link-ws" 17 | version = { workspace = true } 18 | repository = { workspace = true } 19 | homepage = { workspace = true } 20 | authors = [ 21 | "kydos ", 22 | "Julien Enoch ", 23 | "Olivier Hécart ", 24 | "Luca Cominardi ", 25 | "Pierre Avital ", 26 | "Gabriele Baldoni " 27 | ] 28 | edition = { workspace = true } 29 | license = { workspace = true } 30 | categories = { workspace = true } 31 | description = "Internal crate for zenoh." 32 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 33 | 34 | [dependencies] 35 | async-trait = { workspace = true } 36 | futures-util = { workspace = true, features = ["sink", "std"] } 37 | tracing = {workspace = true} 38 | tokio = { workspace = true, features = ["io-std", "macros", "net", "rt-multi-thread", "time"] } 39 | tokio-util = { workspace = true, features = ["rt"] } 40 | tokio-tungstenite = { workspace = true } 41 | url = { workspace = true } 42 | zenoh-core = { workspace = true } 43 | zenoh-link-commons = { workspace = true } 44 | zenoh-protocol = { workspace = true } 45 | zenoh-result = { workspace = true } 46 | zenoh-util = { workspace = true } 47 | zenoh-runtime = { workspace = true } 48 | -------------------------------------------------------------------------------- /io/zenoh-links/zenoh-link-ws/README.md: -------------------------------------------------------------------------------- 1 | # ⚠️ WARNING ⚠️ 2 | 3 | This crate is intended for Zenoh's internal use. 4 | It is not guaranteed that the API will remain unchanged in any version, including patch updates. 5 | It is highly recommended to depend solely on the zenoh and zenoh-ext crates and to utilize their public APIs. 6 | 7 | - [Click here for Zenoh's main repository](https://github.com/eclipse-zenoh/zenoh) 8 | - [Click here for Zenoh's documentation](https://zenoh.io) 9 | -------------------------------------------------------------------------------- /io/zenoh-transport/README.md: -------------------------------------------------------------------------------- 1 | # ⚠️ WARNING ⚠️ 2 | 3 | This crate is intended for Zenoh's internal use. 4 | It is not guaranteed that the API will remain unchanged in any version, including patch updates. 5 | It is highly recommended to depend solely on the zenoh and zenoh-ext crates and to utilize their public APIs. 6 | 7 | - [Click here for Zenoh's main repository](https://github.com/eclipse-zenoh/zenoh) 8 | - [Click here for Zenoh's documentation](https://zenoh.io) 9 | -------------------------------------------------------------------------------- /io/zenoh-transport/src/common/mod.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | pub mod batch; 15 | pub(crate) mod defragmentation; 16 | pub(crate) mod pipeline; 17 | pub(crate) mod priority; 18 | pub(crate) mod seq_num; 19 | #[cfg(feature = "stats")] 20 | pub mod stats; 21 | -------------------------------------------------------------------------------- /io/zenoh-transport/src/unicast/authentication.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2024 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | use zenoh_link::LinkAuthId; 15 | 16 | #[cfg(feature = "auth_usrpwd")] 17 | use super::establishment::ext::auth::UsrPwdId; 18 | 19 | #[derive(Clone, Default, Debug, PartialEq, Eq)] 20 | pub struct TransportAuthId { 21 | username: Option, 22 | link_auth_ids: Vec, 23 | } 24 | 25 | impl TransportAuthId { 26 | #[cfg(feature = "auth_usrpwd")] 27 | pub(crate) fn set_username(&mut self, user_pwd_id: &UsrPwdId) { 28 | self.username = if let Some(username) = &user_pwd_id.0 { 29 | // Convert username from Vec to String 30 | match std::str::from_utf8(username) { 31 | Ok(name) => Some(name.to_owned()), 32 | Err(e) => { 33 | tracing::error!("Error in extracting username {}", e); 34 | None 35 | } 36 | } 37 | } else { 38 | None 39 | } 40 | } 41 | 42 | pub(crate) fn push_link_auth_id(&mut self, link_auth_id: LinkAuthId) { 43 | self.link_auth_ids.push(link_auth_id); 44 | } 45 | 46 | pub fn username(&self) -> Option<&String> { 47 | self.username.as_ref() 48 | } 49 | 50 | pub fn link_auth_ids(&self) -> &Vec { 51 | &self.link_auth_ids 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /io/zenoh-transport/src/unicast/establishment/ext/mod.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2022 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | #[cfg(feature = "transport_auth")] 15 | pub mod auth; 16 | #[cfg(feature = "transport_compression")] 17 | pub(crate) mod compression; 18 | pub(crate) mod lowlatency; 19 | #[cfg(feature = "transport_multilink")] 20 | pub(crate) mod multilink; 21 | pub(crate) mod patch; 22 | pub(crate) mod qos; 23 | #[cfg(feature = "shared-memory")] 24 | pub(crate) mod shm; 25 | -------------------------------------------------------------------------------- /io/zenoh-transport/src/unicast/lowlatency/mod.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | pub(crate) mod transport; 15 | 16 | mod link; 17 | mod rx; 18 | mod tx; 19 | -------------------------------------------------------------------------------- /io/zenoh-transport/src/unicast/lowlatency/tx.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | use zenoh_protocol::{ 15 | network::{NetworkMessageExt, NetworkMessageMut}, 16 | transport::{TransportBodyLowLatencyRef, TransportMessageLowLatencyRef}, 17 | }; 18 | #[cfg(feature = "shared-memory")] 19 | use zenoh_result::bail; 20 | use zenoh_result::ZResult; 21 | 22 | use super::transport::TransportUnicastLowlatency; 23 | #[cfg(feature = "shared-memory")] 24 | use crate::shm::map_zmsg_to_partner; 25 | 26 | impl TransportUnicastLowlatency { 27 | #[allow(unused_mut)] // When feature "shared-memory" is not enabled 28 | #[allow(clippy::let_and_return)] // When feature "stats" is not enabled 29 | #[inline(always)] 30 | pub(crate) fn internal_schedule(&self, mut msg: NetworkMessageMut) -> ZResult<()> { 31 | #[cfg(feature = "shared-memory")] 32 | { 33 | if let Err(e) = map_zmsg_to_partner(&mut msg, &self.config.shm) { 34 | bail!("Failed SHM conversion: {}", e); 35 | } 36 | } 37 | 38 | let msg = TransportMessageLowLatencyRef { 39 | body: TransportBodyLowLatencyRef::Network(msg.as_ref()), 40 | }; 41 | let res = self.send(msg); 42 | 43 | #[cfg(feature = "stats")] 44 | if res.is_ok() { 45 | self.stats.inc_tx_n_msgs(1); 46 | } else { 47 | self.stats.inc_tx_n_dropped(1); 48 | } 49 | 50 | res 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /io/zenoh-transport/src/unicast/test_helpers.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | use zenoh_core::zcondfeat; 15 | 16 | use crate::{unicast::TransportManagerBuilderUnicast, TransportManager}; 17 | 18 | pub fn make_transport_manager_builder( 19 | #[cfg(feature = "transport_multilink")] max_links: usize, 20 | #[cfg(feature = "shared-memory")] with_shm: bool, 21 | lowlatency_transport: bool, 22 | ) -> TransportManagerBuilderUnicast { 23 | let transport = make_basic_transport_manager_builder( 24 | #[cfg(feature = "shared-memory")] 25 | with_shm, 26 | lowlatency_transport, 27 | ); 28 | 29 | zcondfeat!( 30 | "transport_multilink", 31 | { 32 | println!("...with max links: {}...", max_links); 33 | transport.max_links(max_links) 34 | }, 35 | transport 36 | ) 37 | } 38 | 39 | pub fn make_basic_transport_manager_builder( 40 | #[cfg(feature = "shared-memory")] with_shm: bool, 41 | lowlatency_transport: bool, 42 | ) -> TransportManagerBuilderUnicast { 43 | println!("Create transport manager builder..."); 44 | let config = zcondfeat!( 45 | "shared-memory", 46 | { 47 | println!("...with SHM..."); 48 | TransportManager::config_unicast().shm(with_shm) 49 | }, 50 | TransportManager::config_unicast() 51 | ); 52 | if lowlatency_transport { 53 | println!("...with LowLatency transport..."); 54 | } 55 | match lowlatency_transport { 56 | true => config.lowlatency(true).qos(false), 57 | false => config, 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /io/zenoh-transport/src/unicast/universal/mod.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | pub(crate) mod transport; 15 | 16 | mod link; 17 | mod rx; 18 | mod tx; 19 | -------------------------------------------------------------------------------- /plugins/zenoh-backend-example/Cargo.toml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2023 ZettaScale Technology 3 | # 4 | # This program and the accompanying materials are made available under the 5 | # terms of the Eclipse Public License 2.0 which is available at 6 | # http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | # which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | # 9 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | # 11 | # Contributors: 12 | # ZettaScale Zenoh Team, 13 | # 14 | [package] 15 | rust-version = { workspace = true } 16 | name = "zenoh-backend-example" 17 | version = { workspace = true } 18 | authors = { workspace = true } 19 | edition = { workspace = true } 20 | publish = false 21 | 22 | [features] 23 | default = ["dynamic_plugin", "zenoh/default"] 24 | dynamic_plugin = [] 25 | 26 | [lib] 27 | name = "zenoh_backend_example" 28 | # This crate type will make `cargo` output a dynamic library instead of a rust static library 29 | crate-type = ["cdylib"] 30 | 31 | [dependencies] 32 | async-trait = { workspace = true } 33 | git-version = { workspace = true } 34 | serde_json = { workspace = true } 35 | tokio = { workspace = true } 36 | zenoh = { workspace = true, default-features = false } 37 | zenoh-plugin-trait = { workspace = true, default-features = false } 38 | zenoh_backend_traits = { workspace = true, default-features = false } 39 | 40 | [package.metadata.cargo-machete] 41 | ignored = ["git-version"] 42 | -------------------------------------------------------------------------------- /plugins/zenoh-backend-traits/Cargo.toml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2023 ZettaScale Technology 3 | # 4 | # This program and the accompanying materials are made available under the 5 | # terms of the Eclipse Public License 2.0 which is available at 6 | # http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | # which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | # 9 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | # 11 | # Contributors: 12 | # ZettaScale Zenoh Team, 13 | # 14 | [package] 15 | rust-version = { workspace = true } 16 | name = "zenoh_backend_traits" 17 | version = { workspace = true } 18 | repository = { workspace = true } 19 | homepage = { workspace = true } 20 | authors = { workspace = true } 21 | edition = { workspace = true } 22 | license = { workspace = true } 23 | categories = { workspace = true } 24 | description = "Zenoh: traits to be implemented by backends libraries" 25 | 26 | [badges] 27 | maintenance = { status = "actively-developed" } 28 | 29 | [features] 30 | default = ["zenoh/default"] 31 | 32 | [dependencies] 33 | async-trait = { workspace = true } 34 | derive_more = { workspace = true } 35 | serde_json = { workspace = true } 36 | zenoh = { workspace = true, default-features = false, features = ["unstable", "internal"] } 37 | zenoh-result = { workspace = true } 38 | zenoh-util = { workspace = true } 39 | schemars = { workspace = true } 40 | zenoh-plugin-trait = { workspace = true } 41 | const_format = { workspace = true } 42 | either = { workspace = true } 43 | -------------------------------------------------------------------------------- /plugins/zenoh-backend-traits/README.md: -------------------------------------------------------------------------------- 1 | # ⚠️ WARNING ⚠️ 2 | 3 | This crate is intended for Zenoh's internal use. 4 | It is not guaranteed that the API will remain unchanged in any version, including patch updates. 5 | It is highly recommended to depend solely on the zenoh and zenoh-ext crates and to utilize their public APIs. 6 | 7 | - [Click here for Zenoh's main repository](https://github.com/eclipse-zenoh/zenoh) 8 | - [Click here for Zenoh's documentation](https://zenoh.io) 9 | -------------------------------------------------------------------------------- /plugins/zenoh-plugin-example/Cargo.toml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2023 ZettaScale Technology 3 | # 4 | # This program and the accompanying materials are made available under the 5 | # terms of the Eclipse Public License 2.0 which is available at 6 | # http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | # which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | # 9 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | # 11 | # Contributors: 12 | # ZettaScale Zenoh Team, 13 | # 14 | [package] 15 | rust-version = { workspace = true } 16 | name = "zenoh-plugin-example" 17 | version = { workspace = true } 18 | authors = { workspace = true } 19 | edition = { workspace = true } 20 | publish = false 21 | 22 | [features] 23 | default = ["dynamic_plugin"] 24 | dynamic_plugin = [] 25 | 26 | [lib] 27 | # When auto-detecting the "example" plugin, `zenohd` will look for a dynamic library named "zenoh_plugin_example" 28 | # `zenohd` will expect the file to be named according to OS conventions: 29 | # - libzenoh_plugin_example.so on linux 30 | # - libzenoh_plugin_example.dylib on macOS 31 | # - zenoh_plugin_example.dll on Windows 32 | name = "zenoh_plugin_example" 33 | # This crate type will make `cargo` output a dynamic library instead of a rust static library 34 | crate-type = ["cdylib"] 35 | 36 | [dependencies] 37 | zenoh-util = { workspace = true } 38 | futures = { workspace = true } 39 | lazy_static = { workspace = true } 40 | git-version = { workspace = true } 41 | tracing = { workspace = true } 42 | tokio = { workspace = true } 43 | serde_json = { workspace = true } 44 | zenoh = { workspace = true, features = [ 45 | "default", 46 | "plugins", 47 | "internal", 48 | "unstable", 49 | ] } 50 | zenoh-plugin-trait = { workspace = true } 51 | 52 | [package.metadata.cargo-machete] 53 | ignored = ["git-version"] -------------------------------------------------------------------------------- /plugins/zenoh-plugin-example/README.md: -------------------------------------------------------------------------------- 1 | # ⚠️ WARNING ⚠️ 2 | 3 | This crate is intended for Zenoh's internal use. 4 | It is not guaranteed that the API will remain unchanged in any version, including patch updates. 5 | It is highly recommended to depend solely on the zenoh and zenoh-ext crates and to utilize their public APIs. 6 | 7 | - [Click here for Zenoh's main repository](https://github.com/eclipse-zenoh/zenoh) 8 | - [Click here for Zenoh's documentation](https://zenoh.io) 9 | -------------------------------------------------------------------------------- /plugins/zenoh-plugin-rest/README.md: -------------------------------------------------------------------------------- 1 | # ⚠️ WARNING ⚠️ 2 | 3 | This crate is intended for Zenoh's internal use. 4 | It is not guaranteed that the API will remain unchanged in any version, including patch updates. 5 | It is highly recommended to depend solely on the zenoh and zenoh-ext crates and to utilize their public APIs. 6 | 7 | - [Click here for Zenoh's main repository](https://github.com/eclipse-zenoh/zenoh) 8 | - [Click here for Zenoh's documentation](https://zenoh.io) 9 | -------------------------------------------------------------------------------- /plugins/zenoh-plugin-rest/build.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | use schemars::schema_for; 15 | 16 | use crate::config::Config; 17 | 18 | #[path = "src/config.rs"] 19 | mod config; 20 | 21 | fn main() { 22 | // Add rustc version to zenohd 23 | let version_meta = rustc_version::version_meta().unwrap(); 24 | println!( 25 | "cargo:rustc-env=RUSTC_VERSION={}", 26 | version_meta.short_version_string 27 | ); 28 | 29 | let schema = serde_json::to_value(schema_for!(Config)).unwrap(); 30 | let validator = jsonschema::validator_for(&schema).unwrap(); 31 | let config = std::fs::read_to_string("config.json5").unwrap(); 32 | let config: serde_json::Value = serde_json::from_str(&config).unwrap(); 33 | if let Err(es) = validator.validate(&config) { 34 | let es = es.map(|e| e.to_string()).collect::>().join("\n"); 35 | panic!("config.json5 schema validation error: {}", es); 36 | }; 37 | } 38 | -------------------------------------------------------------------------------- /plugins/zenoh-plugin-rest/config.json5: -------------------------------------------------------------------------------- 1 | { 2 | "http_port": "8080" 3 | } -------------------------------------------------------------------------------- /plugins/zenoh-plugin-rest/config_schema.json5: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "Config", 4 | "type": "object", 5 | "required": [ 6 | "http_port" 7 | ], 8 | "properties": { 9 | "__config__": { 10 | "type": [ 11 | "string", 12 | "null" 13 | ] 14 | }, 15 | "__path__": { 16 | "default": null, 17 | "type": [ 18 | "array", 19 | "null" 20 | ], 21 | "items": { 22 | "type": "string" 23 | } 24 | }, 25 | "__required__": { 26 | "type": [ 27 | "boolean", 28 | "null" 29 | ] 30 | }, 31 | "http_port": { 32 | "type": "string" 33 | } 34 | }, 35 | "additionalProperties": false 36 | } -------------------------------------------------------------------------------- /plugins/zenoh-plugin-storage-manager/README.md: -------------------------------------------------------------------------------- 1 | # ⚠️ WARNING ⚠️ 2 | 3 | This crate is intended for Zenoh's internal use. 4 | It is not guaranteed that the API will remain unchanged in any version, including patch updates. 5 | It is highly recommended to depend solely on the zenoh and zenoh-ext crates and to utilize their public APIs. 6 | 7 | - [Click here for Zenoh's main repository](https://github.com/eclipse-zenoh/zenoh) 8 | - [Click here for Zenoh's documentation](https://zenoh.io) 9 | -------------------------------------------------------------------------------- /plugins/zenoh-plugin-storage-manager/build.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | use schemars::schema_for; 15 | use zenoh_backend_traits::config::PluginConfig; 16 | 17 | fn main() { 18 | // Add rustc version to zenohd 19 | let version_meta = rustc_version::version_meta().unwrap(); 20 | println!( 21 | "cargo:rustc-env=RUSTC_VERSION={}", 22 | version_meta.short_version_string 23 | ); 24 | 25 | let schema = serde_json::to_value(schema_for!(PluginConfig)).unwrap(); 26 | let validator = jsonschema::validator_for(&schema).unwrap(); 27 | let config = std::fs::read_to_string("config.json5").unwrap(); 28 | let config: serde_json::Value = serde_json::from_str(&config).unwrap(); 29 | if let Err(es) = validator.validate(&config) { 30 | let es = es.map(|e| e.to_string()).collect::>().join("\n"); 31 | panic!("config.json5 schema validation error: {}", es); 32 | }; 33 | } 34 | -------------------------------------------------------------------------------- /plugins/zenoh-plugin-storage-manager/config.json5: -------------------------------------------------------------------------------- 1 | { 2 | "volumes": { 3 | "example": { 4 | "__path__": ["target/debug/libzenoh_backend_example.so","target/debug/libzenoh_backend_example.dylib"], 5 | "__config__": "../../plugins/example-storage-plugin/config.json5" 6 | } 7 | }, 8 | "storages": { 9 | "memory": { 10 | "volume": "memory", 11 | "key_expr": "demo/memory/**" 12 | }, 13 | "example": { 14 | "volume": "example", 15 | "key_expr": "demo/example/**" 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /plugins/zenoh-plugin-storage-manager/config_schema.json5: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "PluginConfig", 4 | "type": "object", 5 | "required": [ 6 | "storages", 7 | "volumes" 8 | ], 9 | "properties": { 10 | "backend_search_dirs": { 11 | "type": [ 12 | "array", 13 | "null" 14 | ], 15 | "items": { 16 | "type": "string" 17 | } 18 | }, 19 | "required": { 20 | "type": [ 21 | "boolean", 22 | "null" 23 | ] 24 | }, 25 | "storages": { 26 | "type": "object", 27 | "additionalProperties": true 28 | }, 29 | "volumes": { 30 | "type": "object", 31 | "additionalProperties": true 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /plugins/zenoh-plugin-storage-manager/src/replication/mod.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2024 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | 15 | //! This module exposes the [ReplicationService] structure needed by the storage manager to 16 | //! replicate the content of storage across a Zenoh network. 17 | //! 18 | //! This structure, and thus the replication, only works for storage that have the [History::Latest] 19 | //! capability. 20 | //! 21 | //! From a high-level, the replication works by generating a concise view of the state of the 22 | //! storage at regular time intervals. To do so, the time is divided in 'intervals' (themselves 23 | //! divided into 'sub-intervals') and each publication mapped to one such group. Then a fingerprint 24 | //! of each group is computed and these fingerprints are sent over the network to other storage for 25 | //! comparison. 26 | //! 27 | //! [History::Latest]: zenoh_backend_traits::History::Latest 28 | 29 | mod classification; 30 | mod configuration; 31 | mod core; 32 | mod digest; 33 | mod log; 34 | mod service; 35 | 36 | pub(crate) use log::{Action, Event, LogLatest, LogLatestKey}; 37 | pub(crate) use service::ReplicationService; 38 | -------------------------------------------------------------------------------- /plugins/zenoh-plugin-trait/Cargo.toml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2023 ZettaScale Technology 3 | # 4 | # This program and the accompanying materials are made available under the 5 | # terms of the Eclipse Public License 2.0 which is available at 6 | # http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | # which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | # 9 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | # 11 | # Contributors: 12 | # ZettaScale Zenoh Team, 13 | # 14 | [package] 15 | rust-version = { workspace = true } 16 | name = "zenoh-plugin-trait" 17 | version = { workspace = true } 18 | repository = { workspace = true } 19 | homepage = { workspace = true } 20 | authors = { workspace = true } 21 | edition = { workspace = true } 22 | license = { workspace = true } 23 | categories = { workspace = true } 24 | description = { workspace = true } 25 | 26 | [lib] 27 | name = "zenoh_plugin_trait" 28 | 29 | [dependencies] 30 | libloading = { workspace = true } 31 | tracing = { workspace = true } 32 | serde = { workspace = true } 33 | git-version = { workspace = true } 34 | zenoh-macros = { workspace = true } 35 | zenoh-result = { workspace = true } 36 | zenoh-util = { workspace = true } 37 | zenoh-config = { workspace = true } 38 | zenoh-keyexpr = { workspace = true, features = ["internal", "unstable"] } 39 | -------------------------------------------------------------------------------- /plugins/zenoh-plugin-trait/README.md: -------------------------------------------------------------------------------- 1 | # ⚠️ WARNING ⚠️ 2 | 3 | This crate is intended for Zenoh's internal use. 4 | It is not guaranteed that the API will remain unchanged in any version, including patch updates. 5 | It is highly recommended to depend solely on the zenoh and zenoh-ext crates and to utilize their public APIs. 6 | 7 | - [Click here for Zenoh's main repository](https://github.com/eclipse-zenoh/zenoh) 8 | - [Click here for Zenoh's documentation](https://zenoh.io) 9 | -------------------------------------------------------------------------------- /rust-toolchain.toml: -------------------------------------------------------------------------------- 1 | [toolchain] 2 | channel = "1.85.0" 3 | -------------------------------------------------------------------------------- /rustfmt.toml: -------------------------------------------------------------------------------- 1 | edition = "2021" 2 | use_try_shorthand = true 3 | use_field_init_shorthand = true 4 | 5 | # Unstable features below 6 | # unstable_features = true 7 | # version = "Two" 8 | # comment_width = 100 # default is 80 9 | # error_on_line_overflow = true 10 | # format_code_in_doc_comments = true 11 | # format_macro_bodies = true 12 | # format_macro_matchers = true 13 | # format_strings = true 14 | # imports_granularity = "Crate" 15 | # group_imports = "StdExternalCrate" 16 | # normalize_doc_attributes = true 17 | # wrap_comments = true 18 | -------------------------------------------------------------------------------- /zenoh-dragon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZettaScaleLabs/zenoh/b33ddc35210faf949ecb8f68c5fcff520d8b1d2e/zenoh-dragon.png -------------------------------------------------------------------------------- /zenoh-ext/Cargo.toml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2023 ZettaScale Technology 3 | # 4 | # This program and the accompanying materials are made available under the 5 | # terms of the Eclipse Public License 2.0 which is available at 6 | # http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | # which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | # 9 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | # 11 | # Contributors: 12 | # ZettaScale Zenoh Team, 13 | # 14 | [package] 15 | rust-version = { workspace = true } 16 | name = "zenoh-ext" 17 | version = { workspace = true } 18 | repository = { workspace = true } 19 | homepage = { workspace = true } 20 | authors = ["kydos ", "Julien Enoch "] 21 | edition = { workspace = true } 22 | license = { workspace = true } 23 | categories = { workspace = true } 24 | description = "Zenoh: extensions to the client API." 25 | 26 | [badges] 27 | maintenance = { status = "actively-developed" } 28 | 29 | [features] 30 | default = ["zenoh/default"] 31 | internal = [] 32 | unstable = ["zenoh/unstable", "zenoh/internal"] 33 | 34 | [dependencies] 35 | tokio = { workspace = true, features = [ 36 | "rt", 37 | "sync", 38 | "time", 39 | "macros", 40 | "io-std", 41 | ] } 42 | async-trait = { workspace = true } 43 | bincode = { workspace = true } 44 | zenoh-util = { workspace = true } 45 | flume = { workspace = true } 46 | futures = { workspace = true } 47 | tracing = { workspace = true } 48 | serde = { workspace = true, features = ["default"] } 49 | leb128 = { workspace = true } 50 | uhlc = { workspace = true } 51 | zenoh = { workspace = true, default-features = false } 52 | zenoh-macros = { workspace = true } 53 | 54 | [dev-dependencies] 55 | zenoh-config = { workspace = true } 56 | rand = { workspace = true } 57 | 58 | [package.metadata.docs.rs] 59 | features = ["unstable"] 60 | -------------------------------------------------------------------------------- /zenoh-ext/README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | [![CI](https://github.com/eclipse-zenoh/zenoh/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/eclipse-zenoh/zenoh/actions?query=workflow%3ACI+branch%3Amain++) 4 | [![Discussion](https://img.shields.io/badge/discussion-on%20github-blue)](https://github.com/eclipse-zenoh/roadmap/discussions) 5 | [![Discord](https://img.shields.io/badge/chat-on%20discord-blue)](https://discord.gg/2GJ958VuHs) 6 | [![License](https://img.shields.io/badge/License-EPL%202.0-blue)](https://choosealicense.com/licenses/epl-2.0/) 7 | [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) 8 | 9 | # Eclipse Zenoh Extensions 10 | 11 | This crate provides some useful extensions on top of [`zenoh`](https://crates.io/crates/zenoh) crate. 12 | 13 | For more information, see its documentation: 14 | and some examples of usage in 15 | -------------------------------------------------------------------------------- /zenoh-ext/examples/Cargo.toml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2023 ZettaScale Technology 3 | # 4 | # This program and the accompanying materials are made available under the 5 | # terms of the Eclipse Public License 2.0 which is available at 6 | # http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | # which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | # 9 | # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | # 11 | # Contributors: 12 | # ZettaScale Zenoh Team, 13 | # 14 | [package] 15 | rust-version = { workspace = true } 16 | name = "zenoh-ext-examples" 17 | version = { workspace = true } 18 | repository = { workspace = true } 19 | homepage = { workspace = true } 20 | authors = ["kydos ", "Julien Enoch "] 21 | edition = { workspace = true } 22 | license = { workspace = true } 23 | categories = { workspace = true } 24 | description = "Internal crate for zenoh" 25 | publish = false 26 | 27 | [badges] 28 | maintenance = { status = "actively-developed" } 29 | 30 | [features] 31 | default = ["zenoh/default", "zenoh-ext/default", "zenoh-examples/default"] 32 | unstable = [] 33 | 34 | [dependencies] 35 | clap = { workspace = true, features = ["derive"] } 36 | futures = { workspace = true } 37 | tokio = { workspace = true, features = [ 38 | "rt", 39 | "sync", 40 | "time", 41 | "macros", 42 | "io-std", 43 | ] } 44 | zenoh = { workspace = true, default-features = false } 45 | zenoh-ext = { workspace = true, default-features = false, features = ["unstable"]} 46 | zenoh-examples = { workspace = true, default-features = false } 47 | 48 | [dev-dependencies] 49 | zenoh-config = { workspace = true } 50 | 51 | [[example]] 52 | name = "z_advanced_pub" 53 | path = "examples/z_advanced_pub.rs" 54 | 55 | [[example]] 56 | name = "z_advanced_sub" 57 | path = "examples/z_advanced_sub.rs" 58 | 59 | [[example]] 60 | name = "z_member" 61 | path = "examples/z_member.rs" 62 | 63 | [[example]] 64 | name = "z_view_size" 65 | path = "examples/z_view_size.rs" 66 | 67 | [package.metadata.docs.rs] 68 | features = ["unstable"] 69 | -------------------------------------------------------------------------------- /zenoh-ext/examples/examples/README.md: -------------------------------------------------------------------------------- 1 | # Zenoh Rust extra examples 2 | 3 | ## Start instructions 4 | 5 | When zenoh is built in release mode: 6 | 7 | ```bash 8 | ./target/release/example/ 9 | ``` 10 | 11 | Each example accepts the `-h` or `--help` option that provides a description of its arguments and their default values. 12 | 13 | If you run the tests against the zenoh router running in a Docker container, you need to add the 14 | `-e tcp/localhost:7447` option to your examples. That's because Docker doesn't support UDP multicast 15 | transport, and therefore the zenoh scouting and discrovery mechanism cannot work with. 16 | 17 | ## Examples description 18 | 19 | ### z_advanced_pub 20 | 21 | Declares an AdvancedPublisher with a given key expression. 22 | All the publications are locally cached (with a configurable history size - i.e. max number of cached data per resource, default 1). The cache can be queried by an AdvancedSubscriber for hsitory 23 | or retransmission. 24 | 25 | Typical usage: 26 | 27 | ```bash 28 | z_advanced_pub 29 | ``` 30 | 31 | or 32 | 33 | ```bash 34 | z_advanced_pub --history 10 35 | ``` 36 | 37 | ### z_advanced_sub 38 | 39 | Declares an AdvancedSubscriber with a given key expression. 40 | The AdvancedSubscriber can query for AdvancedPublisher history at startup 41 | and on late joiner publisher detection. The AdvancedSubscriber can detect 42 | sample loss and ask for retransmission. 43 | 44 | Typical usage: 45 | 46 | ```bash 47 | z_advanced_sub 48 | ``` 49 | 50 | ### z_member 51 | 52 | Group Management example: join a group and display the received group events (Join, Leave, LeaseExpired), as well as an updated group view. 53 | 54 | Typical usage: 55 | 56 | ```bash 57 | z_member 58 | ``` 59 | 60 | (start/stop several in parallel) 61 | 62 | ### z_view_size 63 | 64 | Group Management example: join a group and wait for the group view to reach a configurable size (default: 3 members). 65 | 66 | Typical usage: 67 | 68 | ```bash 69 | z_view_size 70 | ``` 71 | 72 | (start/stop several in parallel) 73 | -------------------------------------------------------------------------------- /zenoh-ext/examples/examples/z_member.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | use std::{sync::Arc, time::Duration}; 15 | 16 | use futures::StreamExt; 17 | use zenoh::Config; 18 | use zenoh_ext::group::*; 19 | 20 | #[tokio::main] 21 | async fn main() { 22 | zenoh::init_log_from_env_or("error"); 23 | let z = Arc::new(zenoh::open(Config::default()).await.unwrap()); 24 | let member = Member::new(z.zid().to_string()) 25 | .unwrap() 26 | .lease(Duration::from_secs(3)); 27 | 28 | let group = Group::join(z.clone(), "zgroup", member).await.unwrap(); 29 | let rx = group.subscribe().await; 30 | let mut stream = rx.stream(); 31 | while let Some(evt) = stream.next().await { 32 | println!(">>> {:?}", &evt); 33 | println!(">> Group View <<"); 34 | let v = group.view().await; 35 | println!( 36 | "{}", 37 | v.iter() 38 | .fold(String::from("\n"), |a, b| format!("\t{a} \n\t{b:?}")), 39 | ); 40 | println!(">>>>>>> Eventual Leader <<<<<<<<<"); 41 | let m = group.leader().await; 42 | println!("Leader mid = {m:?}"); 43 | println!(">>>>>>><<<<<<<<<"); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /zenoh-ext/examples/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! Examples on using Zenoh. 2 | //! See the code in ../examples/ 3 | //! Check ../README.md for usage. 4 | //! 5 | pub use zenoh_examples::CommonArgs; 6 | -------------------------------------------------------------------------------- /zenoh/build.rs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 ZettaScale Technology 2 | // 3 | // This program and the accompanying materials are made available under the 4 | // terms of the Eclipse Public License 2.0 which is available at 5 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 6 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 7 | // 8 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 9 | // 10 | // Contributors: 11 | // ZettaScale Zenoh Team, 12 | // 13 | fn main() { 14 | // Add rustc version to zenohd 15 | let version_meta = rustc_version::version_meta().unwrap(); 16 | println!( 17 | "cargo:rustc-env=RUSTC_VERSION={}", 18 | version_meta.short_version_string 19 | ); 20 | 21 | let version = rustc_version::version().unwrap(); 22 | if version >= rustc_version::Version::parse("1.85.0").unwrap() 23 | && version <= rustc_version::Version::parse("1.85.1").unwrap() 24 | { 25 | // https://github.com/rust-lang/rust/issues/138696 26 | println!("cargo:rustc-cfg=nolocal_thread_not_available"); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /zenoh/src/api/builders/mod.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2024 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | 15 | pub(crate) mod close; 16 | pub(crate) mod info; 17 | pub(crate) mod matching_listener; 18 | pub(crate) mod publisher; 19 | #[cfg(feature = "unstable")] 20 | pub(crate) mod querier; 21 | pub(crate) mod query; 22 | pub(crate) mod queryable; 23 | pub(crate) mod reply; 24 | pub(crate) mod sample; 25 | pub(crate) mod scouting; 26 | pub(crate) mod session; 27 | pub(crate) mod subscriber; 28 | -------------------------------------------------------------------------------- /zenoh/src/api/handlers/mod.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | 15 | //! Callback handler trait. 16 | mod callback; 17 | mod fifo; 18 | mod ring; 19 | 20 | pub use callback::*; 21 | pub use fifo::*; 22 | pub use ring::*; 23 | 24 | use crate::api::session::API_DATA_RECEPTION_CHANNEL_SIZE; 25 | 26 | /// A type that can be converted into a [`Callback`]-Handler pair. 27 | /// 28 | /// When Zenoh functions accept types that implement these, it intends to use the [`Callback`] as just that, 29 | /// while granting you access to the handler through the returned value via [`std::ops::Deref`] and [`std::ops::DerefMut`]. 30 | /// 31 | /// Any closure that accepts `T` can be converted into a pair of itself and `()`. 32 | pub trait IntoHandler { 33 | type Handler; 34 | 35 | fn into_handler(self) -> (Callback, Self::Handler); 36 | } 37 | 38 | /// The default handler in Zenoh is a FIFO queue. 39 | #[repr(transparent)] 40 | #[derive(Default)] 41 | pub struct DefaultHandler(FifoChannel); 42 | 43 | impl IntoHandler for DefaultHandler { 44 | type Handler = >::Handler; 45 | 46 | fn into_handler(self) -> (Callback, Self::Handler) { 47 | self.0.into_handler() 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /zenoh/src/api/mod.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2024 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | 15 | pub(crate) type Id = u32; 16 | 17 | pub(crate) mod admin; 18 | pub(crate) mod builders; 19 | pub(crate) mod bytes; 20 | pub(crate) mod config; 21 | pub(crate) mod encoding; 22 | pub(crate) mod handlers; 23 | pub(crate) mod info; 24 | pub(crate) mod key_expr; 25 | pub(crate) mod liveliness; 26 | #[cfg(feature = "plugins")] 27 | pub(crate) mod loader; 28 | #[cfg(feature = "unstable")] 29 | pub(crate) mod matching; 30 | #[cfg(feature = "plugins")] 31 | pub(crate) mod plugins; 32 | pub(crate) mod publisher; 33 | #[cfg(feature = "unstable")] 34 | pub(crate) mod querier; 35 | pub(crate) mod query; 36 | pub(crate) mod queryable; 37 | pub(crate) mod sample; 38 | pub(crate) mod scouting; 39 | pub(crate) mod selector; 40 | pub(crate) mod session; 41 | pub(crate) mod subscriber; 42 | -------------------------------------------------------------------------------- /zenoh/src/net/codec/mod.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | pub(crate) mod linkstate; 15 | 16 | #[derive(Clone, Copy)] 17 | pub struct Zenoh080Routing; 18 | 19 | impl Zenoh080Routing { 20 | pub const fn new() -> Self { 21 | Self 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /zenoh/src/net/mod.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | 15 | //! ⚠️ WARNING ⚠️ 16 | //! 17 | //! This module is intended for Zenoh's internal use. 18 | //! 19 | //! [Click here for Zenoh's documentation](https://docs.rs/zenoh/latest/zenoh) 20 | pub(crate) mod codec; 21 | mod common; 22 | pub(crate) mod primitives; 23 | pub(crate) mod protocol; 24 | pub(crate) mod routing; 25 | #[doc(hidden)] 26 | pub mod runtime; 27 | 28 | #[cfg(test)] 29 | pub(crate) mod tests; 30 | -------------------------------------------------------------------------------- /zenoh/src/net/protocol/mod.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | pub(crate) mod linkstate; 15 | pub(crate) mod network; 16 | 17 | pub(crate) const ROUTERS_NET_NAME: &str = "[Routers Network]"; 18 | pub(crate) const PEERS_NET_NAME: &str = "[Peers Network]"; 19 | -------------------------------------------------------------------------------- /zenoh/src/net/routing/dispatcher/mod.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | 15 | //! ⚠️ WARNING ⚠️ 16 | //! 17 | //! This module is intended for Zenoh's internal use. 18 | //! 19 | //! [Click here for Zenoh's documentation](https://docs.rs/zenoh/latest/zenoh) 20 | pub mod face; 21 | pub mod interests; 22 | pub mod pubsub; 23 | pub mod queries; 24 | pub mod resource; 25 | pub mod tables; 26 | pub mod token; 27 | -------------------------------------------------------------------------------- /zenoh/src/net/tests/mod.rs: -------------------------------------------------------------------------------- 1 | pub(crate) mod tables; 2 | -------------------------------------------------------------------------------- /zenoh/src/prelude.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2023 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | 15 | //! A "prelude" for crates using the `zenoh` crate. 16 | //! 17 | //! This prelude is similar to the standard library's prelude in that you'll 18 | //! almost always want to import its entire contents, but unlike the standard 19 | //! library's prelude you'll have to do so manually. 20 | //! 21 | //! Examples: 22 | //! 23 | //! ``` 24 | //! use zenoh::prelude::*; 25 | //! ``` 26 | 27 | pub use crate::Wait; 28 | -------------------------------------------------------------------------------- /zenoh/src/tests/mod.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2025 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | 15 | mod interceptor_cache; 16 | mod link_weights; 17 | -------------------------------------------------------------------------------- /zenoh/tests/formatters.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2024 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | #![cfg(feature = "unstable")] 15 | use zenoh::key_expr::format::{kedefine, keformat}; 16 | 17 | #[test] 18 | fn kedefine_reuse() { 19 | kedefine!( 20 | pub gkeys: "zenoh/${group:*}/${member:*}", 21 | ); 22 | let mut formatter = gkeys::formatter(); 23 | let k1 = keformat!(formatter, group = "foo", member = "bar").unwrap(); 24 | assert_eq!(dbg!(k1).as_str(), "zenoh/foo/bar"); 25 | 26 | formatter.set("member", "*").unwrap(); 27 | let k2 = formatter.build().unwrap(); 28 | assert_eq!(dbg!(k2).as_str(), "zenoh/foo/*"); 29 | 30 | dbg!(&mut formatter).group("foo").unwrap(); 31 | dbg!(&mut formatter).member("*").unwrap(); 32 | let k2 = dbg!(&mut formatter).build().unwrap(); 33 | assert_eq!(dbg!(k2).as_str(), "zenoh/foo/*"); 34 | 35 | let k3 = keformat!(formatter, group = "foo", member = "*").unwrap(); 36 | assert_eq!(dbg!(k3).as_str(), "zenoh/foo/*"); 37 | 38 | keformat!(formatter, group = "**", member = "**").unwrap_err(); 39 | } 40 | -------------------------------------------------------------------------------- /zenoh/tests/handler.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2024 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | use std::{thread, time::Duration}; 15 | 16 | use zenoh::{handlers::RingChannel, Config, Wait}; 17 | 18 | #[test] 19 | fn pubsub_with_ringbuffer() { 20 | let zenoh = zenoh::open(Config::default()).wait().unwrap(); 21 | let sub = zenoh 22 | .declare_subscriber("test/ringbuffer") 23 | .with(RingChannel::new(3)) 24 | .wait() 25 | .unwrap(); 26 | for i in 0..10 { 27 | zenoh 28 | .put("test/ringbuffer", format!("put{i}")) 29 | .wait() 30 | .unwrap(); 31 | } 32 | // Should only receive the last three samples ("put7", "put8", "put9") 33 | for i in 7..10 { 34 | assert_eq!( 35 | sub.recv().unwrap().payload().try_to_string().unwrap(), 36 | format!("put{i}") 37 | ); 38 | } 39 | // Wait for the subscriber to get the value 40 | thread::sleep(Duration::from_millis(1000)); 41 | } 42 | 43 | #[test] 44 | fn query_with_ringbuffer() { 45 | let zenoh = zenoh::open(Config::default()).wait().unwrap(); 46 | let queryable = zenoh 47 | .declare_queryable("test/ringbuffer_query") 48 | .with(RingChannel::new(1)) 49 | .wait() 50 | .unwrap(); 51 | 52 | let _reply1 = zenoh 53 | .get("test/ringbuffer_query") 54 | .payload("query1") 55 | .wait() 56 | .unwrap(); 57 | let _reply2 = zenoh 58 | .get("test/ringbuffer_query") 59 | .payload("query2") 60 | .wait() 61 | .unwrap(); 62 | 63 | let query = queryable.recv().unwrap(); 64 | // Only receive the latest query 65 | assert_eq!(query.payload().unwrap().try_to_string().unwrap(), "query2"); 66 | } 67 | -------------------------------------------------------------------------------- /zenoh/tests/keyexpr.rs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2025 ZettaScale Technology 3 | // 4 | // This program and the accompanying materials are made available under the 5 | // terms of the Eclipse Public License 2.0 which is available at 6 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 7 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 8 | // 9 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 10 | // 11 | // Contributors: 12 | // ZettaScale Zenoh Team, 13 | // 14 | #[cfg(feature = "internal")] 15 | use zenoh::key_expr::KeyExpr; 16 | 17 | #[test] 18 | #[cfg(feature = "internal")] 19 | fn keyexpr_test_dummy() { 20 | let dummy_expr = KeyExpr::dummy(); 21 | assert!(dummy_expr.is_dummy()); 22 | 23 | let non_dummy_expr = KeyExpr::try_from("dummy").unwrap(); 24 | assert!(!non_dummy_expr.is_dummy()); 25 | } 26 | -------------------------------------------------------------------------------- /zenohd/.deb/postinst: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # postinst script for Eclipse Zenoh 3 | # 4 | # see: dh_installdeb(1) 5 | 6 | set -e 7 | 8 | # summary of how this script can be called: 9 | # * `configure' 10 | # * `abort-upgrade' 11 | # * `abort-remove' `in-favour' 12 | # 13 | # * `abort-remove' 14 | # * `abort-deconfigure' `in-favour' 15 | # `removing' 16 | # 17 | # for details, see https://www.debian.org/doc/debian-policy/ or 18 | # the debian-policy package 19 | 20 | 21 | case "$1" in 22 | configure) 23 | if ! command -v systemctl > /dev/null 2>&1 24 | then 25 | echo "WARNING: 'systemctl' not found - cannot install zenohd as a service." 26 | exit 0 27 | fi 28 | id -u zenohd > /dev/null 2>&1 || useradd -r -s /bin/false zenohd 29 | mkdir -p /var/zenohd 30 | chown zenohd:zenohd /var/zenohd 31 | systemctl daemon-reload 32 | systemctl disable zenohd 33 | ;; 34 | 35 | abort-upgrade|abort-remove|abort-deconfigure) 36 | ;; 37 | 38 | *) 39 | echo "postinst called with unknown argument \`$1'" >&2 40 | exit 1 41 | ;; 42 | esac 43 | 44 | # dh_installdeb will replace this with shell code automatically 45 | # generated by other debhelper scripts. 46 | 47 | #DEBHELPER# 48 | 49 | exit 0 -------------------------------------------------------------------------------- /zenohd/.deb/postrm: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # postrm script for Eclipse Zenoh 3 | # see: dh_installdeb(1) 4 | 5 | set -e 6 | 7 | # summary of how this script can be called: 8 | # * `remove' 9 | # * `purge' 10 | # * `upgrade' 11 | # * `failed-upgrade' 12 | # * `abort-install' 13 | # * `abort-install' 14 | # * `abort-upgrade' 15 | # * `disappear' 16 | # 17 | # for details, see https://www.debian.org/doc/debian-policy/ or 18 | # the debian-policy package 19 | 20 | 21 | case "$1" in 22 | purge|remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear) 23 | userdel zenohd > /dev/null 2>&1 || true 24 | rm -rf /etc/zenohd /var/zenohd 25 | ;; 26 | 27 | *) 28 | echo "postrm called with unknown argument \`$1'" >&2 29 | exit 1 30 | ;; 31 | esac 32 | 33 | # dh_installdeb will replace this with shell code automatically 34 | # generated by other debhelper scripts. 35 | 36 | #DEBHELPER# 37 | 38 | exit 0 39 | 40 | -------------------------------------------------------------------------------- /zenohd/.rpm/zenoh-router.spec: -------------------------------------------------------------------------------- 1 | %define __spec_install_post %{nil} 2 | %define __os_install_post %{_dbpath}/brp-compress 3 | %define debug_package %{nil} 4 | 5 | Name: zenoh-router 6 | Summary: The zenoh router 7 | Version: @@VERSION@@ 8 | Release: @@RELEASE@@%{?dist} 9 | License: EPL-2.0 OR Apache-2.0 10 | Group: System Environment/Daemons 11 | Source0: %{name}-%{version}.tar.gz 12 | URL: http://zenoh.io 13 | 14 | BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root 15 | 16 | %description 17 | %{summary} 18 | 19 | %prep 20 | %setup -q 21 | 22 | %install 23 | rm -rf %{buildroot} 24 | mkdir -p %{buildroot} 25 | cp -a * %{buildroot} 26 | 27 | %clean 28 | rm -rf %{buildroot} 29 | 30 | %files 31 | %defattr(-,root,root,-) 32 | %{_bindir}/* 33 | -------------------------------------------------------------------------------- /zenohd/.service/zenohd.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description = Eclipse Zenoh Router 3 | Documentation=https://zenoh.io/docs/getting-started/key-concepts/ 4 | After=network-online.target 5 | Wants=network-online.target 6 | 7 | 8 | [Service] 9 | Type=simple 10 | Environment="RUST_LOG=info" "ZENOH_HOME=/var/zenohd" 11 | ExecStart = /usr/bin/zenohd -c /etc/zenohd/zenohd.json5 12 | KillMode=mixed 13 | KillSignal=SIGINT 14 | RestartKillSignal=SIGINT 15 | Restart=on-failure 16 | PermissionsStartOnly=true 17 | User=zenohd 18 | StandardOutput=syslog 19 | StandardError=syslog 20 | SyslogIdentifier=zenohd 21 | [Install] 22 | WantedBy=multi-user.target -------------------------------------------------------------------------------- /zenohd/README.md: -------------------------------------------------------------------------------- 1 | ../README.md -------------------------------------------------------------------------------- /zenohd/build.rs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 ZettaScale Technology 2 | // 3 | // This program and the accompanying materials are made available under the 4 | // terms of the Eclipse Public License 2.0 which is available at 5 | // http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 6 | // which is available at https://www.apache.org/licenses/LICENSE-2.0. 7 | // 8 | // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 9 | // 10 | // Contributors: 11 | // ZettaScale Zenoh Team, 12 | // 13 | fn main() { 14 | // Add rustc version to zenohd 15 | let version_meta = rustc_version::version_meta().unwrap(); 16 | println!( 17 | "cargo:rustc-env=RUSTC_VERSION={}", 18 | version_meta.short_version_string 19 | ); 20 | } 21 | --------------------------------------------------------------------------------