Skip to content

Commit

Permalink
chore(rust): use HashMap instead of sqlite in low latency exmple
Browse files Browse the repository at this point in the history
  • Loading branch information
SanjoDeundiak committed Dec 31, 2024
1 parent b6c1607 commit 263a963
Show file tree
Hide file tree
Showing 5 changed files with 347 additions and 36 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/rust/low_latency_portal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ rust-version = "1.70.0"

[dependencies]
ockam = { path = "../../../implementations/rust/ockam/ockam", features = ["aws-lc"] }
async-trait = "0.1"
serde = { version = "1.0.215", features = ["derive"] }
serde_json = "1.0"
hex = "0.4.3"
Expand Down
65 changes: 29 additions & 36 deletions examples/rust/low_latency_portal/examples/inlet-node.rs
Original file line number Diff line number Diff line change
@@ -1,76 +1,75 @@
use log::info;
use low_latency_portal::{parse, InletConfig};
use low_latency_portal::{parse, HashMapRepository, InletConfig};
use ockam::compat::str::FromStr;
use ockam::compat::sync::Arc;
use ockam::identity::models::ChangeHistory;
use ockam::identity::{Identifier, SecureChannelOptions, SecureChannels, TrustIdentifierPolicy, Vault};
use ockam::identity::{
Identifier, Identities, SecureChannelOptions, SecureChannelRegistry, SecureChannels, TrustIdentifierPolicy, Vault,
};
use ockam::tcp::{TcpConnectionOptions, TcpInletOptions, TcpTransport};
use ockam::vault::{EdDSACurve25519SecretKey, SigningSecret, SoftwareVaultForSigning};
use ockam::vault::{
EdDSACurve25519SecretKey, SigningSecret, SoftwareVaultForSecureChannels, SoftwareVaultForSigning,
SoftwareVaultForVerifyingSignatures,
};
use ockam::{route, Context, Result};
use std::str::FromStr;

#[ockam::node]
async fn main(ctx: Context) -> Result<()> {
let args: Vec<String> = std::env::args().collect();

info!("A");
let config = if let Some(config) = args.get(1) {
config.clone()
} else {
let config = std::fs::read("inlet.config.json").unwrap();
String::from_utf8(config).unwrap()
};

info!("B");
let config: InletConfig = parse(&config)?;
info!("C");

let outlet_identifier = Identifier::from_str(&config.outlet_identifier)?;
let inlet_identity_key = hex::decode(config.inlet_identity_key).unwrap();
let inlet_change_history = ChangeHistory::import_from_string(&config.inlet_change_history)?;

info!("D");
let hash_map_storage = Arc::new(HashMapRepository::default());

let tcp = TcpTransport::create(&ctx).await?;

info!("E");

let identity_vault = SoftwareVaultForSigning::create().await?; // FIXME: 16ms

info!("F");
let identity_vault = Arc::new(SoftwareVaultForSigning::new(hash_map_storage.clone()));
let secure_channel_vault = Arc::new(SoftwareVaultForSecureChannels::new(hash_map_storage.clone()));
let credential_vault = Arc::new(SoftwareVaultForSigning::new(hash_map_storage.clone()));
let verifying_vault = Arc::new(SoftwareVaultForVerifyingSignatures::new());

let relay_identity_key = EdDSACurve25519SecretKey::new(inlet_identity_key.try_into().unwrap());

info!("G");
let relay_identity_key = SigningSecret::EdDSACurve25519(relay_identity_key);

info!("H");

identity_vault.import_key(relay_identity_key).await?;

info!("J");

let mut vault = Vault::create().await?; // FIXME: 25ms
vault.identity_vault = identity_vault;

info!("K");

let secure_channels = SecureChannels::builder().await?.with_vault(vault).build(); // FIXME: 16 ms

info!("L");
let vault = Vault::new(identity_vault, secure_channel_vault, credential_vault, verifying_vault);

let identities = Identities::new(
vault,
hash_map_storage.clone(),
hash_map_storage.clone(),
hash_map_storage.clone(),
hash_map_storage.clone(),
);
let secure_channels = SecureChannels::new(
Arc::new(identities),
SecureChannelRegistry::new(),
hash_map_storage.clone(),
);

let inlet_identifier = secure_channels
.identities()
.identities_verification()
.import_from_change_history(None, inlet_change_history)
.await?;

info!("M");

let tcp_connection_to_relay = tcp
.connect(config.relay_address.to_string(), TcpConnectionOptions::new())
.await?;

info!("N");

let secure_channel_to_outlet = secure_channels
.create_secure_channel(
&ctx,
Expand All @@ -84,22 +83,16 @@ async fn main(ctx: Context) -> Result<()> {
)
.await?;

info!("O");

tcp.create_inlet(
config.inlet_address.to_string(),
route![secure_channel_to_outlet, "outlet"],
TcpInletOptions::new(),
)
.await?;

info!("P");

info!("Initialized successfully");

ctx.stop().await?;

info!("Q");

Ok(())
}
Loading

0 comments on commit 263a963

Please sign in to comment.