From 190c0033476000a30c3e8f68a024dea1f7068ac1 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Wed, 29 May 2024 00:15:42 +0000 Subject: [PATCH] update docs on release to ockam ref ockam_v0.124.0 --- portals/kafka/warpstream/README.md | 2 +- reference/libraries/rust/credentials.md | 18 ++++++++--- reference/libraries/rust/routing.md | 34 ++++++++++++++++----- reference/libraries/rust/secure-channels.md | 3 +- reference/protocols/routing.md | 34 ++++++++++++++++----- reference/protocols/secure-channels.md | 3 +- 6 files changed, 73 insertions(+), 21 deletions(-) diff --git a/portals/kafka/warpstream/README.md b/portals/kafka/warpstream/README.md index 8d7b8d94..60e00ef7 100644 --- a/portals/kafka/warpstream/README.md +++ b/portals/kafka/warpstream/README.md @@ -24,4 +24,4 @@ To learn how end-to-end trust is established, please read: “[Warpstream CloudSend end-to-end encrypted messages through Warpstream Cloud. \ No newline at end of file +
Warpstream CloudSend end-to-end encrypted messages through Warpstream Cloud.
diff --git a/reference/libraries/rust/credentials.md b/reference/libraries/rust/credentials.md index 9abb5b22..1aab50de 100644 --- a/reference/libraries/rust/credentials.md +++ b/reference/libraries/rust/credentials.md @@ -259,10 +259,20 @@ async fn main(ctx: Context) -> Result<()> { DefaultAddress::ECHO_SERVICE, &sc_listener_options.spawner_flow_control_id(), ); - let allow_production_incoming = - IncomingAbac::create_name_value(node.identities_attributes(), issuer.clone(), "cluster", "production"); - let allow_production_outgoing = - OutgoingAbac::create_name_value(&ctx, node.identities_attributes(), issuer, "cluster", "production").await?; + let allow_production_incoming = IncomingAbac::create_name_value( + node.identities_attributes(), + Some(issuer.clone()), + "cluster", + "production", + ); + let allow_production_outgoing = OutgoingAbac::create_name_value( + &ctx, + node.identities_attributes(), + Some(issuer), + "cluster", + "production", + ) + .await?; node.start_worker_with_access_control( DefaultAddress::ECHO_SERVICE, Echoer, diff --git a/reference/libraries/rust/routing.md b/reference/libraries/rust/routing.md index ca36ec1e..d1ccb347 100644 --- a/reference/libraries/rust/routing.md +++ b/reference/libraries/rust/routing.md @@ -346,9 +346,23 @@ Add the following code to this file: ```rust // src/relay.rs -use ockam::{Address, Any, Context, Result, Routed, Worker}; +use ockam::{Any, Context, Result, Route, Routed, Worker}; -pub struct Relay(pub Address); +pub struct Relay { + route: Route, +} + +impl Relay { + pub fn new(route: impl Into) -> Self { + let route = route.into(); + + if route.is_empty() { + panic!("Relay can't forward messages to an empty route"); + } + + Self { route } + } +} #[ockam::worker] impl Worker for Relay { @@ -360,20 +374,26 @@ impl Worker for Relay { async fn handle_message(&mut self, ctx: &mut Context, msg: Routed) -> Result<()> { println!("Address: {}, Received: {:?}", ctx.address(), msg); + let next_on_route = self.route.next()?.clone(); + // Some type conversion let mut local_message = msg.into_local_message(); - local_message = local_message.replace_front_onward_route(&self.0)?; // Prepend predefined address to the ownward_route + local_message = local_message.pop_front_onward_route()?; + local_message = local_message.prepend_front_onward_route(&self.route); // Prepend predefined route to the onward_route let prev_hop = local_message.return_route_ref().next()?.clone(); - if let Some(info) = ctx.flow_controls().find_flow_control_with_producer_address(&self.0) { + if let Some(info) = ctx + .flow_controls() + .find_flow_control_with_producer_address(&next_on_route) + { ctx.flow_controls() .add_consumer(prev_hop.clone(), info.flow_control_id()); } if let Some(info) = ctx.flow_controls().find_flow_control_with_producer_address(&prev_hop) { - ctx.flow_controls().add_consumer(self.0.clone(), info.flow_control_id()); + ctx.flow_controls().add_consumer(next_on_route, info.flow_control_id()); } // Send the message on its onward_route @@ -462,8 +482,8 @@ async fn main(ctx: Context) -> Result<()> { // Create a TCP connection to the responder node. let connection_to_responder = tcp.connect("127.0.0.1:4000", TcpConnectionOptions::new()).await?; - // Create a Relay worker - node.start_worker("forward_to_responder", Relay(connection_to_responder.into())) + // Create and start a Relay worker + node.start_worker("forward_to_responder", Relay::new(connection_to_responder)) .await?; // Create a TCP listener and wait for incoming connections. diff --git a/reference/libraries/rust/secure-channels.md b/reference/libraries/rust/secure-channels.md index a5973879..4f3b2c94 100644 --- a/reference/libraries/rust/secure-channels.md +++ b/reference/libraries/rust/secure-channels.md @@ -88,6 +88,7 @@ Add the following code to this file: use hello_ockam::Relay; use ockam::{node, Context, Result, TcpConnectionOptions, TcpListenerOptions, TcpTransportExtension}; +use ockam_core::route; #[ockam::node] async fn main(ctx: Context) -> Result<()> { @@ -101,7 +102,7 @@ async fn main(ctx: Context) -> Result<()> { let connection_to_bob = tcp.connect("127.0.0.1:4000", TcpConnectionOptions::new()).await?; // Start a Relay to forward messages to Bob using the TCP connection. - node.start_worker("forward_to_bob", Relay(connection_to_bob.into())) + node.start_worker("forward_to_bob", Relay::new(route![connection_to_bob])) .await?; // Create a TCP listener and wait for incoming connections. diff --git a/reference/protocols/routing.md b/reference/protocols/routing.md index 13d7cb0d..4ffe5844 100644 --- a/reference/protocols/routing.md +++ b/reference/protocols/routing.md @@ -316,9 +316,23 @@ We'll create a worker, called `Relay`, that takes every incoming message and for {% code lineNumbers="true" fullWidth="true" %} ```rust // src/relay.rs -use ockam::{Address, Any, Context, Result, Routed, Worker}; +use ockam::{Any, Context, Result, Route, Routed, Worker}; -pub struct Relay(pub Address); +pub struct Relay { + route: Route, +} + +impl Relay { + pub fn new(route: impl Into) -> Self { + let route = route.into(); + + if route.is_empty() { + panic!("Relay can't forward messages to an empty route"); + } + + Self { route } + } +} #[ockam::worker] impl Worker for Relay { @@ -330,20 +344,26 @@ impl Worker for Relay { async fn handle_message(&mut self, ctx: &mut Context, msg: Routed) -> Result<()> { println!("Address: {}, Received: {:?}", ctx.address(), msg); + let next_on_route = self.route.next()?.clone(); + // Some type conversion let mut local_message = msg.into_local_message(); - local_message = local_message.replace_front_onward_route(&self.0)?; // Prepend predefined address to the ownward_route + local_message = local_message.pop_front_onward_route()?; + local_message = local_message.prepend_front_onward_route(&self.route); // Prepend predefined route to the onward_route let prev_hop = local_message.return_route_ref().next()?.clone(); - if let Some(info) = ctx.flow_controls().find_flow_control_with_producer_address(&self.0) { + if let Some(info) = ctx + .flow_controls() + .find_flow_control_with_producer_address(&next_on_route) + { ctx.flow_controls() .add_consumer(prev_hop.clone(), info.flow_control_id()); } if let Some(info) = ctx.flow_controls().find_flow_control_with_producer_address(&prev_hop) { - ctx.flow_controls().add_consumer(self.0.clone(), info.flow_control_id()); + ctx.flow_controls().add_consumer(next_on_route, info.flow_control_id()); } // Send the message on its onward_route @@ -376,8 +396,8 @@ async fn main(ctx: Context) -> Result<()> { // Create a TCP connection to the responder node. let connection_to_responder = tcp.connect("127.0.0.1:4000", TcpConnectionOptions::new()).await?; - // Create a Relay worker - node.start_worker("forward_to_responder", Relay(connection_to_responder.into())) + // Create and start a Relay worker + node.start_worker("forward_to_responder", Relay::new(connection_to_responder)) .await?; // Create a TCP listener and wait for incoming connections. diff --git a/reference/protocols/secure-channels.md b/reference/protocols/secure-channels.md index 92c06bc2..2b1d74e7 100644 --- a/reference/protocols/secure-channels.md +++ b/reference/protocols/secure-channels.md @@ -103,6 +103,7 @@ async fn main(ctx: Context) -> Result<()> { use hello_ockam::Relay; use ockam::{node, Context, Result, TcpConnectionOptions, TcpListenerOptions, TcpTransportExtension}; +use ockam_core::route; #[ockam::node] async fn main(ctx: Context) -> Result<()> { @@ -116,7 +117,7 @@ async fn main(ctx: Context) -> Result<()> { let connection_to_bob = tcp.connect("127.0.0.1:4000", TcpConnectionOptions::new()).await?; // Start a Relay to forward messages to Bob using the TCP connection. - node.start_worker("forward_to_bob", Relay(connection_to_bob.into())) + node.start_worker("forward_to_bob", Relay::new(route![connection_to_bob])) .await?; // Create a TCP listener and wait for incoming connections.