mirror of
https://gitlab.com/veilid/veilid.git
synced 2025-09-19 20:44:44 -04:00
add private route example
This commit is contained in:
parent
e5e3fd03c1
commit
d742171aa7
29 changed files with 588 additions and 122 deletions
1
veilid-core/examples/basic/.gitignore
vendored
1
veilid-core/examples/basic/.gitignore
vendored
|
@ -1 +0,0 @@
|
|||
.veilid
|
|
@ -1,20 +1,24 @@
|
|||
[package]
|
||||
name = "veilid-core-examples-basic"
|
||||
version = "0.1.0"
|
||||
# ---
|
||||
description = "Example demonstrating a basic Veilid application"
|
||||
resolver = "2"
|
||||
repository.workspace = true
|
||||
authors.workspace = true
|
||||
license.workspace = true
|
||||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
autobins = false
|
||||
publish = false
|
||||
|
||||
[[bin]]
|
||||
name = "basic"
|
||||
[[example]]
|
||||
name = "basic-example"
|
||||
path = "./src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
tokio = { version = "^1.43.0" }
|
||||
veilid-core = { version = "0.4.7", path = "../../../veilid-core" }
|
||||
veilid-core = { path = "../../../veilid-core" }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
|
11
veilid-core/examples/basic/README.md
Normal file
11
veilid-core/examples/basic/README.md
Normal file
|
@ -0,0 +1,11 @@
|
|||
# Basic Example
|
||||
|
||||
Demonstration of simple Veilid application that just starts a node
|
||||
|
||||
## Running this example
|
||||
|
||||
Run this:
|
||||
|
||||
```
|
||||
# cargo run --example basic-example
|
||||
```
|
|
@ -4,6 +4,7 @@ use veilid_core::{VeilidConfig, VeilidConfigProtectedStore, VeilidConfigTableSto
|
|||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
// Create a basic update callback to display Veilid's update events
|
||||
let update_callback = Arc::new(move |update: VeilidUpdate| {
|
||||
match update {
|
||||
AppMessage(msg) => {
|
||||
|
@ -23,6 +24,12 @@ async fn main() {
|
|||
};
|
||||
});
|
||||
|
||||
// Set up a config for this application
|
||||
let exe_dir = std::env::current_exe()
|
||||
.map(|x| x.parent().map(|p| p.to_owned()))
|
||||
.ok()
|
||||
.flatten()
|
||||
.unwrap_or(".".into());
|
||||
let config = VeilidConfig {
|
||||
program_name: "Example Veilid".into(),
|
||||
namespace: "veilid-example".into(),
|
||||
|
@ -31,16 +38,23 @@ async fn main() {
|
|||
// IMPORTANT: don't do this in production
|
||||
// This avoids prompting for a password and is insecure
|
||||
always_use_insecure_storage: true,
|
||||
directory: "./.veilid/protected_store".into(),
|
||||
directory: exe_dir
|
||||
.join(".veilid/protected_store")
|
||||
.to_string_lossy()
|
||||
.to_string(),
|
||||
..Default::default()
|
||||
},
|
||||
table_store: VeilidConfigTableStore {
|
||||
directory: "./.veilid/table_store".into(),
|
||||
directory: exe_dir
|
||||
.join(".veilid/table_store")
|
||||
.to_string_lossy()
|
||||
.to_string(),
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
// Startup Veilid node
|
||||
let veilid = veilid_core::api_startup_config(update_callback, config)
|
||||
.await
|
||||
.unwrap();
|
||||
|
@ -48,7 +62,10 @@ async fn main() {
|
|||
"Node ID: {}",
|
||||
veilid.config().unwrap().get().network.routing_table.node_id
|
||||
);
|
||||
|
||||
// Attach to the network
|
||||
veilid.attach().await.unwrap();
|
||||
|
||||
// Until CTRL+C is pressed, keep running
|
||||
tokio::signal::ctrl_c().await.unwrap();
|
||||
veilid.shutdown().await;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue