mirror of
https://github.com/logos-blockchain/logos-blockchain-testing.git
synced 2026-04-01 00:33:40 +00:00
58 lines
1.8 KiB
Rust
58 lines
1.8 KiB
Rust
use cfgsync_adapter::{
|
|
DynCfgsyncError, MaterializationResult, MaterializedArtifacts, RegistrationSnapshot,
|
|
RegistrationSnapshotMaterializer,
|
|
};
|
|
use cfgsync_artifacts::{ArtifactFile, ArtifactSet};
|
|
use cfgsync_core::NodeRegistration;
|
|
use cfgsync_runtime::{OutputMap, fetch_and_write, serve};
|
|
use tempfile::tempdir;
|
|
use tokio::time::{Duration, sleep};
|
|
|
|
struct ExampleMaterializer;
|
|
|
|
impl RegistrationSnapshotMaterializer for ExampleMaterializer {
|
|
fn materialize_snapshot(
|
|
&self,
|
|
registrations: &RegistrationSnapshot,
|
|
) -> Result<MaterializationResult, DynCfgsyncError> {
|
|
if registrations.is_empty() {
|
|
return Ok(MaterializationResult::NotReady);
|
|
}
|
|
|
|
let nodes = registrations.iter().map(|registration| {
|
|
(
|
|
registration.identifier.clone(),
|
|
ArtifactSet::new(vec![ArtifactFile::new(
|
|
"/config.yaml",
|
|
format!("id: {}\n", registration.identifier),
|
|
)]),
|
|
)
|
|
});
|
|
|
|
Ok(MaterializationResult::ready(
|
|
MaterializedArtifacts::from_nodes(nodes),
|
|
))
|
|
}
|
|
}
|
|
|
|
#[tokio::main]
|
|
async fn main() -> anyhow::Result<()> {
|
|
let port = 4400;
|
|
let server = tokio::spawn(async move { serve(port, ExampleMaterializer).await });
|
|
|
|
// Give the server a moment to bind before the client registers.
|
|
sleep(Duration::from_millis(100)).await;
|
|
|
|
let tempdir = tempdir()?;
|
|
let config_path = tempdir.path().join("config.yaml");
|
|
let outputs = OutputMap::new().route("/config.yaml", &config_path);
|
|
let registration = NodeRegistration::new("node-1", "127.0.0.1".parse()?);
|
|
|
|
fetch_and_write(®istration, "http://127.0.0.1:4400", &outputs).await?;
|
|
|
|
println!("{}", std::fs::read_to_string(&config_path)?);
|
|
|
|
server.abort();
|
|
Ok(())
|
|
}
|