Skip to content

Commit

Permalink
feat(rust): improvements to portals commands arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianbenavides committed Nov 13, 2024
1 parent d859300 commit 14f951b
Show file tree
Hide file tree
Showing 52 changed files with 1,101 additions and 439 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ async fn start_node(ctx: Context, project_information_path: &str, token: OneTime
// 4. create a tcp outlet with the above policy
tcp.create_outlet(
"outlet",
HostnamePort::new("127.0.0.1", 5000),
HostnamePort::new("127.0.0.1", 5000)?,
TcpOutletOptions::new()
.with_incoming_access_control_impl(incoming_access_control)
.with_outgoing_access_control_impl(outgoing_access_control),
Expand Down
2 changes: 1 addition & 1 deletion implementations/rust/ockam/ockam/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub use relay_service::{RelayService, RelayServiceOptions};
/// Transport
pub mod transport {
pub use ockam_transport_core::{
parse_socket_addr, HostnamePort, StaticHostnamePort, Transport,
parse_socket_addr, HostnamePort, SchemeHostnamePort, StaticHostnamePort, Transport,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl KafkaInletController {
}

let inlet_bind_address =
HostnamePort::new(inner.bind_hostname.clone(), inner.current_port);
HostnamePort::new(inner.bind_hostname.clone(), inner.current_port)?;

let node_manager = self.node_manager.upgrade().ok_or_else(|| {
Error::new(Origin::Node, Kind::Internal, "node manager was shut down")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ async fn producer__flow_with_mock_kafka__content_encryption_and_decryption(
.tcp
.create_outlet(
"kafka_consumer_outlet",
HostnamePort::new("127.0.0.1", consumer_mock_kafka.port),
HostnamePort::new("127.0.0.1", consumer_mock_kafka.port)?,
TcpOutletOptions::new(),
)
.await?;
Expand All @@ -181,7 +181,7 @@ async fn producer__flow_with_mock_kafka__content_encryption_and_decryption(
.tcp
.create_outlet(
"kafka_producer_outlet",
HostnamePort::new("127.0.0.1", producer_mock_kafka.port),
HostnamePort::new("127.0.0.1", producer_mock_kafka.port)?,
TcpOutletOptions::new(),
)
.await?;
Expand Down Expand Up @@ -217,7 +217,7 @@ async fn producer__flow_with_mock_kafka__content_encryption_and_decryption(
.tcp
.create_outlet(
"kafka_consumer_outlet",
HostnamePort::new("127.0.0.1", consumer_mock_kafka.port),
HostnamePort::new("127.0.0.1", consumer_mock_kafka.port)?,
TcpOutletOptions::new(),
)
.await?;
Expand Down
6 changes: 5 additions & 1 deletion implementations/rust/ockam/ockam_api/src/nodes/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,10 @@ mod tests {
}

fn outlet_info(worker_addr: Address) -> OutletInfo {
OutletInfo::new(HostnamePort::new("127.0.0.1", 0), Some(&worker_addr), true)
OutletInfo::new(
HostnamePort::new("127.0.0.1", 0).unwrap(),
Some(&worker_addr),
true,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ impl NodeManager {

// the port could be zero, to simplify the following code we
// resolve the address to a full socket address
let socket_addr =
ockam_node::compat::asynchronous::resolve_peer(listen_addr.to_string()).await?;
let socket_addr = ockam_node::compat::asynchronous::resolve_peer(&listen_addr).await?;
let listen_addr = if listen_addr.port() == 0 {
get_free_address_for(&socket_addr.ip().to_string())
.map_err(|err| ockam_core::Error::new(Origin::Transport, Kind::Invalid, err))?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl RendezvousHealthcheck {
udp_socket_address: SocketAddr,
) -> Result<Self> {
let peer = if udp_socket_address.ip().is_unspecified() {
HostnamePort::new("localhost", udp_socket_address.port()).to_string()
HostnamePort::new("localhost", udp_socket_address.port())?.to_string()
} else {
udp_socket_address.to_string()
};
Expand Down
2 changes: 1 addition & 1 deletion implementations/rust/ockam/ockam_api/tests/latency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ pub fn measure_buffer_latency_two_nodes_portal() {
.node_manager
.create_inlet(
&first_node.context,
HostnamePort::new("127.0.0.1", 0),
HostnamePort::new("127.0.0.1", 0)?,
route![],
route![],
second_node_listen_address
Expand Down
10 changes: 5 additions & 5 deletions implementations/rust/ockam/ockam_api/tests/portals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async fn inlet_outlet_local_successful(context: &mut Context) -> ockam::Result<(
.node_manager
.create_inlet(
context,
HostnamePort::new("127.0.0.1", 0),
HostnamePort::new("127.0.0.1", 0)?,
route![],
route![],
MultiAddr::from_str("/secure/api/service/outlet")?,
Expand Down Expand Up @@ -122,7 +122,7 @@ fn portal_node_goes_down_reconnect() {
.node_manager
.create_inlet(
&first_node.context,
HostnamePort::new("127.0.0.1", 0),
HostnamePort::new("127.0.0.1", 0)?,
route![],
route![],
second_node_listen_address
Expand Down Expand Up @@ -280,7 +280,7 @@ fn portal_low_bandwidth_connection_keep_working_for_60s() {
.node_manager
.create_inlet(
&first_node.context,
HostnamePort::new("127.0.0.1", 0),
HostnamePort::new("127.0.0.1", 0)?,
route![],
route![],
InternetAddress::from(passthrough_server_handle.chosen_addr)
Expand Down Expand Up @@ -394,7 +394,7 @@ fn portal_heavy_load_exchanged() {
.node_manager
.create_inlet(
&first_node.context,
HostnamePort::new("127.0.0.1", 0),
HostnamePort::new("127.0.0.1", 0)?,
route![],
route![],
second_node_listen_address
Expand Down Expand Up @@ -547,7 +547,7 @@ fn test_portal_payload_transfer(outgoing_disruption: Disruption, incoming_disrup
.node_manager
.create_inlet(
&first_node.context,
HostnamePort::new("127.0.0.1", 0),
HostnamePort::new("127.0.0.1", 0)?,
route![],
route![],
InternetAddress::from(passthrough_server_handle.chosen_addr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use ockam::transport::HostnamePort;
use ockam::Address;
use ockam_api::address::extract_address_value;
use ockam_api::nodes::models::portal::OutletAccessControl;
use std::str::FromStr;
use std::sync::Arc;
use tracing::{debug, info};

Expand All @@ -21,9 +22,12 @@ impl AppState {
} else {
format!("{DEFAULT_HOST}:{to}")
};
let socket_addr = resolve_peer(addr).await.into_diagnostic().wrap_err(
"Invalid address. The expected formats are 'host:port', 'ip:port' or 'port'",
)?;
let socket_addr = resolve_peer(&HostnamePort::from_str(&addr)?)
.await
.into_diagnostic()
.wrap_err(
"Invalid address. The expected formats are 'host:port', 'ip:port' or 'port'",
)?;
let worker_addr: Address = extract_address_value(&from)
.wrap_err("Invalid service address")?
.into();
Expand Down
Loading

0 comments on commit 14f951b

Please sign in to comment.