Skip to content

Commit

Permalink
refactor(rust): rename forwarder to relay
Browse files Browse the repository at this point in the history
where possible.
We will need to migrate the service and path names at some stage
  • Loading branch information
etorreborre committed Oct 3, 2023
1 parent 0d12c1c commit 1a49eba
Show file tree
Hide file tree
Showing 48 changed files with 386 additions and 422 deletions.
12 changes: 5 additions & 7 deletions examples/rust/file_transfer/examples/receiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use file_transfer::FileData;
use ockam::identity::SecureChannelListenerOptions;
use ockam::remote::RemoteForwarderOptions;
use ockam::remote::RemoteRelayOptions;
use ockam::{
errcode::{Kind, Origin},
node, Context, Error, Result, Routed, TcpConnectionOptions, Worker,
Expand Down Expand Up @@ -102,17 +102,15 @@ async fn main(ctx: Context) -> Result<()> {
//
// To allow Sender and others to initiate an end-to-end secure channel with this program
// we connect with 1.node.ockam.network:4000 as a TCP client and ask the forwarding
// service on that node to create a forwarder for us.
// service on that node to create a relay for us.
//
// All messages that arrive at that forwarding address will be sent to this program
// using the TCP connection we created as a client.
let node_in_hub = tcp.connect("1.node.ockam.network:4000", tcp_options).await?;
let forwarder = node
.create_forwarder(node_in_hub, RemoteForwarderOptions::new())
.await?;
println!("\n[✓] RemoteForwarder was created on the node at: 1.node.ockam.network:4000");
let relay = node.create_relay(node_in_hub, RemoteRelayOptions::new()).await?;
println!("\n[✓] RemoteRelay was created on the node at: 1.node.ockam.network:4000");
println!("Forwarding address for Receiver is:");
println!("{}", forwarder.remote_address());
println!("{}", relay.remote_address());

// Start a worker, of type FileReception, at address "receiver".
node.start_worker("receiver", FileReception::default()).await?;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// This node creates a tcp connection to a node at 127.0.0.1:4000
// Starts a forwarder worker to forward messages to 127.0.0.1:4000
// Starts a relay worker to forward messages to 127.0.0.1:4000
// Starts a tcp listener at 127.0.0.1:3000
// It then runs forever waiting to route messages.

use hello_ockam::Forwarder;
use hello_ockam::Relay;
use ockam::{node, Context, Result, TcpConnectionOptions, TcpListenerOptions, TcpTransportExtension};

#[ockam::node]
Expand All @@ -17,14 +17,14 @@ 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 Forwarder worker
node.start_worker("forward_to_responder", Forwarder(connection_to_responder.into()))
// Create a Relay worker
node.start_worker("forward_to_responder", Relay(connection_to_responder.into()))
.await?;

// Create a TCP listener and wait for incoming connections.
let listener = tcp.listen("127.0.0.1:3000", TcpListenerOptions::new()).await?;

// Allow access to the Forwarder via TCP connections from the TCP listener
// Allow access to the Relay via TCP connections from the TCP listener
node.flow_controls()
.add_consumer("forward_to_responder", listener.flow_control_id());

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// This node creates a tcp connection to a node at 127.0.0.1:4000
// Starts a forwarder worker to forward messages to 127.0.0.1:4000
// Starts a relay worker to forward messages to 127.0.0.1:4000
// Starts a tcp listener at 127.0.0.1:3000
// It then runs forever waiting to route messages.

use hello_ockam::Forwarder;
use hello_ockam::Relay;
use ockam::{node, Context, Result, TcpConnectionOptions, TcpListenerOptions, TcpTransportExtension};

#[ockam::node]
Expand All @@ -17,8 +17,8 @@ async fn main(ctx: Context) -> Result<()> {
// Create a TCP connection to Bob.
let connection_to_bob = tcp.connect("127.0.0.1:4000", TcpConnectionOptions::new()).await?;

// Start a Forwarder to forward messages to Bob using the TCP connection.
node.start_worker("forward_to_bob", Forwarder(connection_to_bob.into()))
// Start a Relay to forward messages to Bob using the TCP connection.
node.start_worker("forward_to_bob", Relay(connection_to_bob.into()))
.await?;

// Create a TCP listener and wait for incoming connections.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use ockam::identity::{
AuthorityService, RemoteCredentialsRetriever, RemoteCredentialsRetrieverInfo, SecureChannelListenerOptions,
SecureChannelOptions, TrustContext, TrustMultiIdentifiersPolicy,
};
use ockam::remote::RemoteForwarderOptions;
use ockam::remote::RemoteRelayOptions;
use ockam::{node, route, Context, Result, TcpOutletOptions};
use ockam_api::authenticator::enrollment_tokens::TokenAcceptor;
use ockam_api::nodes::NodeManager;
Expand All @@ -16,14 +16,14 @@ use std::sync::Arc;

/// This node supports a "control" server on which several "edge" devices can connect
///
/// The connections go through the Ockam Orchestrator, via a Forwarder, and a secure channel
/// The connections go through the Ockam Orchestrator, via a Relay, and a secure channel
/// can be established to forward messages to an outlet going to a local Python webserver.
///
///
/// This example shows how to:
///
/// - retrieve credentials from an authority
/// - create a Forwarder on the Ockam Orchestrator
/// - create a Relay on the Ockam Orchestrator
/// - create a TCP outlet with some access control checking the authenticated attributes of the caller
///
/// The node needs to be started with:
Expand Down Expand Up @@ -118,7 +118,7 @@ async fn start_node(ctx: Context, project_information_path: &str, token: OneTime
)
.await?;

// 5. create a forwarder on the Ockam orchestrator
// 5. create a relay on the Ockam orchestrator

let tcp_project_route = multiaddr_to_route(&project.route(), &tcp).await.unwrap(); // FIXME: Handle error
let project_options =
Expand All @@ -140,11 +140,11 @@ async fn start_node(ctx: Context, project_information_path: &str, token: OneTime
)
.await?;

// finally create a forwarder using the secure channel to the project
let forwarder = node
.create_static_forwarder(secure_channel_address, "control_plane1", RemoteForwarderOptions::new())
// finally create a relay using the secure channel to the project
let relay = node
.create_static_relay(secure_channel_address, "control_plane1", RemoteRelayOptions::new())
.await?;
println!("forwarder is {forwarder:?}");
println!("relay is {relay:?}");

// 6. create a secure channel listener which will allow the edge node to
// start a secure channel when it is ready
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use ockam_transport_tcp::{TcpInletOptions, TcpTransportExtension};
/// This node supports an "edge" server which can connect to a "control" node
/// in order to connect its TCP inlet to the "control" node TCP outlet
///
/// The connections go through the Ockam Orchestrator, via the control node Forwarder.
/// The connections go through the Ockam Orchestrator, via the control node Relay.
///
/// This example shows how to:
///
Expand Down Expand Up @@ -131,7 +131,7 @@ async fn start_node(ctx: Context, project_information_path: &str, token: OneTime
)
.await?;

// 4.3 then create a secure channel to the control node (via its forwarder)
// 4.3 then create a secure channel to the control node (via its relay)
let secure_channel_listener_route = route![secure_channel_address, "forward_to_control_plane1", "untrusted"];
let secure_channel_to_control = node
.create_secure_channel(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
/// | +-------------------------------------+
/// | | |
/// | | | create secure channel to control
/// | | | via the forwarder
/// | | | via the relay
/// v v |
/// +--------------+ +-------------------------------+-------+
/// | Authority | | | |
Expand All @@ -67,10 +67,10 @@
/// - we create initially some secure channels to the Authority in order to retrieve credential
/// based on a one-time token generated with `ockam project ticket --attribute component=<name of node>`
///
/// - then the control node creates a forwarder on the Orchestrator in order to accept TCP traffic without
/// - then the control node creates a relay on the Orchestrator in order to accept TCP traffic without
/// having to open a port to the internet. It also starts a channel listener ("untrusted", accept all incoming requests for now)
///
/// - on its side the edge node starts a secure channel via forwarder (named "forward_to_control_plane1"), to the "untrusted" listener
/// - on its side the edge node starts a secure channel via relay (named "forward_to_control_plane1"), to the "untrusted" listener
/// with the secure channel address it creates an Inlet which will direct TCP traffic via the secure channel to get to the
/// control node and then to the "outlet" worker to reach the Python webserver
///
Expand Down
12 changes: 5 additions & 7 deletions examples/rust/get_started/examples/bob.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use ockam::identity::SecureChannelListenerOptions;
use ockam::remote::RemoteForwarderOptions;
use ockam::remote::RemoteRelayOptions;
use ockam::{node, Routed, TcpConnectionOptions, Worker};
use ockam::{Context, Result};
use ockam_transport_tcp::TcpTransportExtension;
Expand Down Expand Up @@ -48,19 +48,17 @@ async fn main(ctx: Context) -> Result<()> {
//
// To allow Alice and others to initiate an end-to-end secure channel with this program
// we connect with 1.node.ockam.network:4000 as a TCP client and ask the forwarding
// service on that node to create a forwarder for us.
// service on that node to create a relay for us.
//
// All messages that arrive at that forwarding address will be sent to this program
// using the TCP connection we created as a client.
let node_in_hub = tcp
.connect("1.node.ockam.network:4000", TcpConnectionOptions::new())
.await?;
let forwarder = node
.create_forwarder(node_in_hub, RemoteForwarderOptions::new())
.await?;
println!("\n[✓] RemoteForwarder was created on the node at: 1.node.ockam.network:4000");
let relay = node.create_relay(node_in_hub, RemoteRelayOptions::new()).await?;
println!("\n[✓] RemoteRelay was created on the node at: 1.node.ockam.network:4000");
println!("Forwarding address for Bob is:");
println!("{}", forwarder.remote_address());
println!("{}", relay.remote_address());

// We won't call ctx.stop() here, this program will run until you stop it with Ctrl-C
Ok(())
Expand Down
4 changes: 2 additions & 2 deletions examples/rust/get_started/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ mod echoer;

pub use echoer::*;

mod forwarder;
mod hop;
mod relay;

pub use forwarder::*;
pub use hop::*;
pub use relay::*;

mod logger;
mod project;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use ockam::{Address, Any, Context, LocalMessage, Result, Routed, Worker};

pub struct Forwarder(pub Address);
pub struct Relay(pub Address);

#[ockam::worker]
impl Worker for Forwarder {
impl Worker for Relay {
type Context = Context;
type Message = Any;

Expand Down
2 changes: 1 addition & 1 deletion examples/rust/tcp_inlet_and_outlet/examples/04-inlet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async fn main(ctx: Context) -> Result<()> {
// TCP Transport Outlet.
//
// For this example, we know that the Outlet node is listening for Ockam Routing Messages
// through a Remote Forwarder at "1.node.ockam.network:4000" and its forwarder address
// through a Remote Relay at "1.node.ockam.network:4000" and its forwarder address
// points to secure channel listener.
let e = node.create_identity().await?;

Expand Down
12 changes: 5 additions & 7 deletions examples/rust/tcp_inlet_and_outlet/examples/04-outlet.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use ockam::identity::SecureChannelListenerOptions;
use ockam::remote::RemoteForwarderOptions;
use ockam::remote::RemoteRelayOptions;
use ockam::{node, Context, Result, TcpConnectionOptions, TcpOutletOptions};
use ockam_transport_tcp::TcpTransportExtension;

Expand Down Expand Up @@ -45,17 +45,15 @@ async fn main(ctx: Context) -> Result<()> {

// To allow Inlet Node and others to initiate an end-to-end secure channel with this program
// we connect with 1.node.ockam.network:4000 as a TCP client and ask the forwarding
// service on that node to create a forwarder for us.
// service on that node to create a relay for us.
//
// All messages that arrive at that forwarding address will be sent to this program
// using the TCP connection we created as a client.
let node_in_hub = tcp.connect("1.node.ockam.network:4000", tcp_options).await?;
let forwarder = node
.create_forwarder(node_in_hub, RemoteForwarderOptions::new())
.await?;
println!("\n[✓] RemoteForwarder was created on the node at: 1.node.ockam.network:4000");
let relay = node.create_relay(node_in_hub, RemoteRelayOptions::new()).await?;
println!("\n[✓] RemoteRelay was created on the node at: 1.node.ockam.network:4000");
println!("Forwarding address in Hub is:");
println!("{}", forwarder.remote_address());
println!("{}", relay.remote_address());

// We won't call ctx.stop() here,
// so this program will keep running until you interrupt it with Ctrl-C.
Expand Down
2 changes: 1 addition & 1 deletion examples/rust/tcp_inlet_and_outlet/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ fn run_04_inlet_outlet_seperate_processes_secure_channel_via_ockam_hub() -> Resu
let port = rand::thread_rng().gen_range(10000..65535);
// Spawn outlet, wait for it to start up, grab dynamic forwarding address
let outlet = CmdBuilder::new("cargo run --example 04-outlet ockam.io:80").spawn()?;
outlet.match_stdout(r"(?i)RemoteForwarder was created on the node")?;
outlet.match_stdout(r"(?i)RemoteRelay was created on the node")?;
let fwd_address = outlet.match_stdout(r"(?m)^FWD_(\w+)$")?.swap_remove(0).unwrap();
println!("Forwarding address: {fwd_address}");

Expand Down

This file was deleted.

4 changes: 2 additions & 2 deletions implementations/rust/ockam/ockam/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ pub use ockam_node::{

mod delay;
mod error;
mod forwarding_service;
mod metadata;
mod monotonic;
mod relay_service;
mod system;
mod unique;

pub use error::OckamError;
pub use forwarding_service::{ForwardingService, ForwardingServiceOptions};
pub use metadata::OckamMessage;
pub use relay_service::{RelayService, RelayServiceOptions};
pub use system::{SystemBuilder, SystemHandler, WorkerSystem};
pub use unique::unique_with_prefix;

Expand Down
22 changes: 11 additions & 11 deletions implementations/rust/ockam/ockam/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use ockam_identity::{PurposeKeys, Vault, VaultStorage};
use ockam_node::{Context, HasContext, MessageReceiveOptions, MessageSendReceiveOptions};
use ockam_vault::KeyId;

use crate::remote::{RemoteForwarder, RemoteForwarderInfo, RemoteForwarderOptions};
use crate::remote::{RemoteRelay, RemoteRelayInfo, RemoteRelayOptions};
use crate::stream::Stream;
use crate::OckamError;

Expand Down Expand Up @@ -81,23 +81,23 @@ impl Node {
Stream::new(self.get_context()).await
}

/// Create a new forwarder
pub async fn create_forwarder(
/// Create a new relay
pub async fn create_relay(
&self,
orchestrator_route: impl Into<Route>,
options: RemoteForwarderOptions,
) -> Result<RemoteForwarderInfo> {
RemoteForwarder::create(self.get_context(), orchestrator_route, options).await
options: RemoteRelayOptions,
) -> Result<RemoteRelayInfo> {
RemoteRelay::create(self.get_context(), orchestrator_route, options).await
}

/// Create a new static forwarder
pub async fn create_static_forwarder(
/// Create a new static relay
pub async fn create_static_relay(
&self,
orchestrator_route: impl Into<Route>,
alias: impl Into<String>,
options: RemoteForwarderOptions,
) -> Result<RemoteForwarderInfo> {
RemoteForwarder::create_static(self.get_context(), orchestrator_route, alias, options).await
options: RemoteRelayOptions,
) -> Result<RemoteRelayInfo> {
RemoteRelay::create_static(self.get_context(), orchestrator_route, alias, options).await
}

/// Create an Identity
Expand Down
7 changes: 7 additions & 0 deletions implementations/rust/ockam/ockam/src/relay_service/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
mod options;
mod relay;
#[allow(clippy::module_inception)]
mod relay_service;

pub use options::*;
pub use relay_service::*;
Loading

0 comments on commit 1a49eba

Please sign in to comment.