-
-
Notifications
You must be signed in to change notification settings - Fork 562
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rust): provide async implementations of blocking entity and vaul…
…t functions
- Loading branch information
Showing
71 changed files
with
2,102 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use ockam::{route, Context, Entity, Result, SecureChannels, TrustEveryonePolicy, Vault}; | ||
|
||
#[ockam::node] | ||
async fn main(mut ctx: Context) -> Result<()> { | ||
// Create a Vault to safely store secret keys for Alice and Bob. | ||
let vault = Vault::async_create(&ctx).await?; | ||
|
||
// Create an Entity to represent Bob. | ||
let mut bob = Entity::async_create(&ctx, &vault).await?; | ||
|
||
// Create a secure channel listener for Bob that will wait for requests to | ||
// initiate an Authenticated Key Exchange. | ||
bob.async_create_secure_channel_listener("bob", TrustEveryonePolicy).await?; | ||
|
||
// Create an entity to represent Alice. | ||
let mut alice = Entity::async_create(&ctx, &vault).await?; | ||
|
||
// As Alice, connect to Bob's secure channel listener and perform an | ||
// Authenticated Key Exchange to establish an encrypted secure channel with Bob. | ||
let channel = alice.async_create_secure_channel("bob", TrustEveryonePolicy).await?; | ||
|
||
// Send a message, ** THROUGH ** the secure channel, | ||
// to the "app" worker on the other side. | ||
// | ||
// This message will automatically get encrypted when it enters the channel | ||
// and decrypted just before it exits the channel. | ||
ctx.send(route![channel, "app"], "Hello Ockam!".to_string()).await?; | ||
|
||
// Wait to receive a message for the "app" worker and print it. | ||
let message = ctx.receive::<String>().await?; | ||
println!("App Received: {}", message); // should print "Hello Ockam!" | ||
|
||
// Stop all workers, stop the node, cleanup and return. | ||
ctx.stop().await | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.