Publish Epiphany providers to Odin over RUDP
This commit is contained in:
parent
b879569fc8
commit
be55c27d6c
6 changed files with 381 additions and 4 deletions
|
|
@ -1,6 +1,7 @@
|
|||
use anyhow::Context;
|
||||
use anyhow::Result;
|
||||
use chrono::Utc;
|
||||
use cultmesh_rs::CultMeshRudpDocumentPublishOptions;
|
||||
use epiphany_core::EPIPHANY_CULTMESH_DAEMON_RESTART_POLICY_SCHEMA_VERSION;
|
||||
use epiphany_core::EPIPHANY_CULTMESH_DAEMON_SERVICE_LIFECYCLE_RECEIPT_SCHEMA_VERSION;
|
||||
use epiphany_core::EPIPHANY_CULTMESH_GLOBAL_VERSE_ID;
|
||||
|
|
@ -52,6 +53,7 @@ use epiphany_core::epiphany_cultmesh_daemon_tool_invocation_receipt_for_intent;
|
|||
use epiphany_core::epiphany_cultmesh_eve_connection_intent_from_advertisement;
|
||||
use epiphany_core::epiphany_cultmesh_eve_connection_receipt_for_intent;
|
||||
use epiphany_core::epiphany_cultmesh_imagination_consensus_receipt_for_feedback;
|
||||
use epiphany_core::epiphany_gamecult_eve_provider_advertisements;
|
||||
use epiphany_core::epiphany_service_execution_audit_report;
|
||||
use epiphany_core::load_agent_state_soa_entry;
|
||||
use epiphany_core::load_epiphany_cultmesh_cluster_topology;
|
||||
|
|
@ -117,6 +119,7 @@ use sha2::Sha256;
|
|||
use std::collections::BTreeMap;
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::net::SocketAddr;
|
||||
use std::path::PathBuf;
|
||||
|
||||
const WRAPPER_OVERVIEW_COMMAND: &str = "tools/epiphany_local_run.ps1 -Mode swarm-overview";
|
||||
|
|
@ -219,6 +222,70 @@ fn run_cli() -> Result<()> {
|
|||
}))?
|
||||
);
|
||||
}
|
||||
"provider-advertisements" | "provider-advertisement" => {
|
||||
let advertisements =
|
||||
epiphany_gamecult_eve_provider_advertisements(Utc::now().to_rfc3339());
|
||||
println!(
|
||||
"{}",
|
||||
serde_json::to_string_pretty(&json!({
|
||||
"schemaVersion": "epiphany.odin_provider_advertisement_preview.v0",
|
||||
"status": "ok",
|
||||
"schemaId": epiphany_core::GAMECULT_EVE_PROVIDER_ADVERTISEMENT_SCHEMA_VERSION,
|
||||
"count": advertisements.len(),
|
||||
"providerIds": advertisements.iter().map(|(id, _)| id.clone()).collect::<Vec<_>>(),
|
||||
"providers": advertisements.iter().map(|(_, entry)| entry.value.clone()).collect::<Vec<_>>(),
|
||||
"privateStateExposed": false,
|
||||
}))?
|
||||
);
|
||||
}
|
||||
"publish-odin" | "odin-startup-respect" => {
|
||||
let target = args
|
||||
.odin_cultmesh_rudp
|
||||
.context("publish-odin requires --odin-cultmesh-rudp <host:port>")?;
|
||||
let observed_at = Utc::now().to_rfc3339();
|
||||
seed_epiphany_local_verse_context(
|
||||
&args.store,
|
||||
args.runtime_id.clone(),
|
||||
observed_at.clone(),
|
||||
)?;
|
||||
let mut node = open_epiphany_cultmesh_node(&args.store, args.runtime_id.clone())?;
|
||||
let advertisements = epiphany_gamecult_eve_provider_advertisements(observed_at);
|
||||
let mut provider_ids = Vec::new();
|
||||
for (provider_id, advertisement) in &advertisements {
|
||||
node.put(provider_id.clone(), advertisement)?;
|
||||
node.publish_document_to_rudp_catalog(
|
||||
provider_id.clone(),
|
||||
advertisement,
|
||||
CultMeshRudpDocumentPublishOptions {
|
||||
target,
|
||||
runtime_id: args.runtime_id.clone(),
|
||||
source_role: Some("epiphany.provider".to_string()),
|
||||
tags: vec![
|
||||
"startup-respect".to_string(),
|
||||
"odin-verse-discovery".to_string(),
|
||||
],
|
||||
..CultMeshRudpDocumentPublishOptions::default()
|
||||
},
|
||||
)?;
|
||||
provider_ids.push(provider_id.clone());
|
||||
}
|
||||
node.flush()?;
|
||||
println!(
|
||||
"{}",
|
||||
serde_json::to_string_pretty(&json!({
|
||||
"schemaVersion": "epiphany.odin_startup_respect_receipt.v0",
|
||||
"status": "ok",
|
||||
"store": args.store,
|
||||
"runtimeId": args.runtime_id,
|
||||
"odinCultMeshRudp": target.to_string(),
|
||||
"schemaId": epiphany_core::GAMECULT_EVE_PROVIDER_ADVERTISEMENT_SCHEMA_VERSION,
|
||||
"publishedCount": provider_ids.len(),
|
||||
"providerIds": provider_ids,
|
||||
"tags": ["startup-respect", "odin-verse-discovery"],
|
||||
"privateStateExposed": false,
|
||||
}))?
|
||||
);
|
||||
}
|
||||
"query" => {
|
||||
let context = query_epiphany_local_verse_context(&args.store, args.runtime_id.clone())?;
|
||||
println!("{}", serde_json::to_string_pretty(&context)?);
|
||||
|
|
@ -3972,7 +4039,7 @@ fn run_cli() -> Result<()> {
|
|||
);
|
||||
}
|
||||
other => anyhow::bail!(
|
||||
"unknown command {other:?}; use seed, query, tools, tool-directory, invoke-tool, restart-policy-directory, swarm-brake, swarm-status, cluster-topology, eve-surfaces, daemon-status, agent-state, agent-state-report, poke-daemon, poke-down-daemons, bifrost-publication, bifrost-public-proof, bifrost-artifact-acceptance, bifrost-metrics, bifrost-ledger, collaboration-feedback, connect-eve, or smoke"
|
||||
"unknown command {other:?}; use seed, query, provider-advertisements, publish-odin, tools, tool-directory, invoke-tool, restart-policy-directory, swarm-brake, swarm-status, cluster-topology, eve-surfaces, daemon-status, agent-state, agent-state-report, poke-daemon, poke-down-daemons, bifrost-publication, bifrost-public-proof, bifrost-artifact-acceptance, bifrost-metrics, bifrost-ledger, collaboration-feedback, connect-eve, or smoke"
|
||||
),
|
||||
}
|
||||
Ok(())
|
||||
|
|
@ -10781,6 +10848,7 @@ struct Args {
|
|||
requested_action: Option<String>,
|
||||
affected_clusters: Option<Vec<String>>,
|
||||
protected_surfaces: Option<Vec<String>>,
|
||||
odin_cultmesh_rudp: Option<SocketAddr>,
|
||||
}
|
||||
|
||||
impl Args {
|
||||
|
|
@ -10845,6 +10913,7 @@ impl Args {
|
|||
let mut requested_action = None;
|
||||
let mut affected_clusters = Vec::new();
|
||||
let mut protected_surfaces = Vec::new();
|
||||
let mut odin_cultmesh_rudp = None;
|
||||
|
||||
while let Some(arg) = values.next() {
|
||||
match arg.as_str() {
|
||||
|
|
@ -10905,6 +10974,16 @@ impl Args {
|
|||
values.next().context("missing --protected-surface value")?,
|
||||
);
|
||||
}
|
||||
"--odin-cultmesh-rudp" => {
|
||||
let value = values
|
||||
.next()
|
||||
.context("missing --odin-cultmesh-rudp value")?;
|
||||
odin_cultmesh_rudp = Some(
|
||||
value
|
||||
.parse::<SocketAddr>()
|
||||
.with_context(|| format!("invalid --odin-cultmesh-rudp {value:?}"))?,
|
||||
);
|
||||
}
|
||||
"--reason" => {
|
||||
reason = Some(values.next().context("missing --reason value")?);
|
||||
}
|
||||
|
|
@ -11181,6 +11260,7 @@ impl Args {
|
|||
requested_action,
|
||||
affected_clusters: some_if_not_empty(affected_clusters),
|
||||
protected_surfaces: some_if_not_empty(protected_surfaces),
|
||||
odin_cultmesh_rudp,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ use cultmesh_rs::CultMeshNodeOptions;
|
|||
use cultmesh_rs::cultmesh_documents;
|
||||
use serde::Serialize;
|
||||
use serde_json::Value;
|
||||
use serde_json::json;
|
||||
use std::path::Path;
|
||||
|
||||
pub const EPIPHANY_CULTMESH_STATUS_TYPE: &str = "epiphany.cultmesh.status";
|
||||
|
|
@ -111,6 +112,9 @@ pub const EPIPHANY_CULTMESH_CLUSTER_TOPOLOGY_SCHEMA_VERSION: &str =
|
|||
pub const EPIPHANY_CULTMESH_ODIN_ADVERTISEMENT_TYPE: &str = "epiphany.cultmesh.odin_advertisement";
|
||||
pub const EPIPHANY_CULTMESH_ODIN_ADVERTISEMENT_SCHEMA_VERSION: &str =
|
||||
"epiphany.cultmesh.odin_advertisement.v0";
|
||||
pub const GAMECULT_EVE_PROVIDER_ADVERTISEMENT_TYPE: &str = "gamecult.eve.provider_advertisement";
|
||||
pub const GAMECULT_EVE_PROVIDER_ADVERTISEMENT_SCHEMA_VERSION: &str =
|
||||
"gamecult.eve.provider_advertisement.v1";
|
||||
pub const EPIPHANY_CULTMESH_EVE_CONNECTION_INTENT_TYPE: &str =
|
||||
"epiphany.cultmesh.eve_connection_intent";
|
||||
pub const EPIPHANY_CULTMESH_EVE_CONNECTION_INTENT_SCHEMA_VERSION: &str =
|
||||
|
|
@ -1133,6 +1137,16 @@ pub struct EpiphanyCultMeshOdinAdvertisementEntry {
|
|||
pub notes: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DatabaseEntry)]
|
||||
#[cultcache(
|
||||
type = "gamecult.eve.provider_advertisement",
|
||||
schema = "gamecult.eve.provider_advertisement.v1"
|
||||
)]
|
||||
pub struct GameCultEveProviderAdvertisementCompatEntry {
|
||||
#[cultcache(key = 0)]
|
||||
pub value: Value,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, DatabaseEntry)]
|
||||
#[cultcache(
|
||||
type = "epiphany.cultmesh.eve_connection_intent",
|
||||
|
|
@ -2544,6 +2558,7 @@ cultmesh_documents!(EpiphanyCultMeshDocuments {
|
|||
EpiphanyCultMeshGlobalRoomPolicyEntry => EPIPHANY_CULTMESH_GLOBAL_ROOM_POLICY_SCHEMA_VERSION,
|
||||
EpiphanyCultMeshClusterTopologyEntry => EPIPHANY_CULTMESH_CLUSTER_TOPOLOGY_SCHEMA_VERSION,
|
||||
EpiphanyCultMeshOdinAdvertisementEntry => EPIPHANY_CULTMESH_ODIN_ADVERTISEMENT_SCHEMA_VERSION,
|
||||
GameCultEveProviderAdvertisementCompatEntry => GAMECULT_EVE_PROVIDER_ADVERTISEMENT_SCHEMA_VERSION,
|
||||
EpiphanyCultMeshEveConnectionIntentEntry => EPIPHANY_CULTMESH_EVE_CONNECTION_INTENT_SCHEMA_VERSION,
|
||||
EpiphanyCultMeshEveConnectionReceiptEntry => EPIPHANY_CULTMESH_EVE_CONNECTION_RECEIPT_SCHEMA_VERSION,
|
||||
EpiphanyCultMeshEveSurfaceStateEntry => EPIPHANY_CULTMESH_EVE_SURFACE_STATE_SCHEMA_VERSION,
|
||||
|
|
@ -6484,6 +6499,73 @@ pub fn epiphany_cultmesh_odin_advertisements() -> Vec<EpiphanyCultMeshOdinAdvert
|
|||
.collect()
|
||||
}
|
||||
|
||||
pub fn epiphany_gamecult_eve_provider_advertisements(
|
||||
updated_at: impl Into<String>,
|
||||
) -> Vec<(String, GameCultEveProviderAdvertisementCompatEntry)> {
|
||||
let updated_at = updated_at.into();
|
||||
epiphany_cultmesh_odin_advertisements()
|
||||
.into_iter()
|
||||
.map(|advertisement| {
|
||||
let provider_id = format!("epiphany.{}", advertisement.cluster_id);
|
||||
let provider = GameCultEveProviderAdvertisementCompatEntry {
|
||||
value: json!({
|
||||
"schema": GAMECULT_EVE_PROVIDER_ADVERTISEMENT_SCHEMA_VERSION,
|
||||
"providerId": provider_id,
|
||||
"serviceId": "epiphany.agent",
|
||||
"verseId": advertisement.advertised_verse_id,
|
||||
"title": format!("Epiphany {}", advertisement.body_kind),
|
||||
"description": advertisement.public_summary,
|
||||
"canonicalService": "gamecult.epiphany",
|
||||
"locatedService": format!("gamecult.epiphany.{}", advertisement.body_kind),
|
||||
"cultMeshAddress": advertisement.eve_surface_id,
|
||||
"status": "active",
|
||||
"mode": "daemon-live",
|
||||
"updatedAt": updated_at,
|
||||
"bodyDomain": advertisement.body_domain,
|
||||
"bodyKind": advertisement.body_kind,
|
||||
"clusterId": advertisement.cluster_id,
|
||||
"daemonSurfaceId": advertisement.daemon_surface_id,
|
||||
"surfaceId": advertisement.eve_surface_id,
|
||||
"privateStateExposed": advertisement.private_state_exposed,
|
||||
"capabilities": [
|
||||
"epiphany-agent-state",
|
||||
"cultmesh-local-verse",
|
||||
"eve-surface-target",
|
||||
"repo-work-coordination",
|
||||
"operator-safe-discovery"
|
||||
],
|
||||
"endpoints": [
|
||||
{
|
||||
"transport": "cultmesh-local-verse",
|
||||
"address": ".epiphany-run/cultmesh/local-verse.ccmp"
|
||||
}
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
"transport": "repo-cli",
|
||||
"address": "cargo run --manifest-path epiphany-core/Cargo.toml --bin epiphany-verse-query -- eve-surfaces",
|
||||
"role": "eve-surface-directory"
|
||||
},
|
||||
{
|
||||
"transport": "repo-cli",
|
||||
"address": "cargo run --manifest-path epiphany-core/Cargo.toml --bin epiphany-verse-query -- publish-odin --odin-cultmesh-rudp <host:port>",
|
||||
"role": "provider-advertisement"
|
||||
}
|
||||
],
|
||||
"schemaCatalog": advertisement.advertised_document_types.iter().map(|schema_id| {
|
||||
json!({
|
||||
"schemaId": schema_id,
|
||||
"authority": "Epiphany"
|
||||
})
|
||||
}).collect::<Vec<_>>(),
|
||||
"notes": advertisement.notes,
|
||||
}),
|
||||
};
|
||||
(provider_id, provider)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn write_epiphany_cultmesh_odin_advertisements(
|
||||
store_path: impl AsRef<Path>,
|
||||
runtime_id: impl Into<String>,
|
||||
|
|
|
|||
|
|
@ -312,6 +312,9 @@ pub use cultmesh_integration::EpiphanyLocalVerseContractSummary;
|
|||
pub use cultmesh_integration::EpiphanyLocalVerseWorkLoopSummary;
|
||||
pub use cultmesh_integration::EpiphanyServiceExecutionAuditCheck;
|
||||
pub use cultmesh_integration::EpiphanyServiceExecutionAuditReport;
|
||||
pub use cultmesh_integration::GAMECULT_EVE_PROVIDER_ADVERTISEMENT_SCHEMA_VERSION;
|
||||
pub use cultmesh_integration::GAMECULT_EVE_PROVIDER_ADVERTISEMENT_TYPE;
|
||||
pub use cultmesh_integration::GameCultEveProviderAdvertisementCompatEntry;
|
||||
pub use cultmesh_integration::default_epiphany_cultmesh_operator_status;
|
||||
pub use cultmesh_integration::default_epiphany_cultmesh_swarm_brake;
|
||||
pub use cultmesh_integration::epiphany_cluster_service_execution_audit_report;
|
||||
|
|
@ -347,6 +350,7 @@ pub use cultmesh_integration::epiphany_cultmesh_role_review_event_from_summary_j
|
|||
pub use cultmesh_integration::epiphany_cultmesh_soul_contracts;
|
||||
pub use cultmesh_integration::epiphany_cultmesh_substrate_gate_contracts;
|
||||
pub use cultmesh_integration::epiphany_cultmesh_verse_policies;
|
||||
pub use cultmesh_integration::epiphany_gamecult_eve_provider_advertisements;
|
||||
pub use cultmesh_integration::epiphany_local_verse_work_loop_summary;
|
||||
pub use cultmesh_integration::epiphany_service_execution_audit_report;
|
||||
pub use cultmesh_integration::load_epiphany_cultmesh_cluster_topology;
|
||||
|
|
|
|||
|
|
@ -1894,6 +1894,7 @@ pub fn runtime_hello_frame(store_path: impl AsRef<Path>) -> Result<Vec<u8>> {
|
|||
"cultnet.schema_catalog_request.v0".to_string(),
|
||||
"cultnet.schema_catalog_response.v0".to_string(),
|
||||
]),
|
||||
transport_profiles: None,
|
||||
supports_schema_catalog: Some(true),
|
||||
};
|
||||
let payload = encode_cultnet_message_to_vec(&message, CultNetWireContract::CultNetSchemaV0)?;
|
||||
|
|
|
|||
214
vendor/cultmesh-rs/src/lib.rs
vendored
214
vendor/cultmesh-rs/src/lib.rs
vendored
|
|
@ -4,8 +4,21 @@ use cultcache_rs::CultSoaTable;
|
|||
use cultcache_rs::DatabaseEntry;
|
||||
use cultcache_rs::SingleFileMessagePackBackingStore;
|
||||
use cultcache_rs::SoaDocument;
|
||||
use cultnet_rs::CultNetDocumentPutOptions;
|
||||
use cultnet_rs::CultNetDocumentRegistry;
|
||||
use cultnet_rs::CultNetRudpSocketTransportConnection;
|
||||
use cultnet_rs::CultNetRudpSocketTransportOptions;
|
||||
use cultnet_rs::CultNetWireContract;
|
||||
use cultnet_rs::encode_cultnet_message_to_vec;
|
||||
use serde::Serialize;
|
||||
use std::net::SocketAddr;
|
||||
use std::net::UdpSocket;
|
||||
use std::path::Path;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
use std::time::Instant;
|
||||
|
||||
pub const CULTMESH_RUDP_DOCUMENT_CATALOG_CONNECTION_ID: u32 = 0x0d1d_0002;
|
||||
|
||||
pub trait CultMeshDocumentSet: Clone + Send + Sync + 'static {
|
||||
fn register_cache(&self, cache: &mut CultCache) -> Result<()>;
|
||||
|
|
@ -35,7 +48,8 @@ macro_rules! cultmesh_documents {
|
|||
) -> ::anyhow::Result<()> {
|
||||
$(
|
||||
registry.register(
|
||||
cultnet_rs::CultNetDocumentBinding::for_entry::<$entry>(
|
||||
cultnet_rs::CultNetDocumentBinding::for_entry_with_schema_id::<$entry>(
|
||||
$schema_version.to_string(),
|
||||
$schema_version.to_string(),
|
||||
),
|
||||
);
|
||||
|
|
@ -52,6 +66,47 @@ pub struct CultMeshNodeOptions {
|
|||
pub pull_on_start: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct CultMeshRudpDocumentPublishOptions {
|
||||
pub target: SocketAddr,
|
||||
pub runtime_id: String,
|
||||
pub connection_id: u32,
|
||||
pub connect_timeout: Duration,
|
||||
pub flush_timeout: Duration,
|
||||
pub poll_interval: Duration,
|
||||
pub resend_delay_ms: u64,
|
||||
pub source_agent_id: Option<String>,
|
||||
pub source_role: Option<String>,
|
||||
pub tags: Vec<String>,
|
||||
}
|
||||
|
||||
impl CultMeshRudpDocumentPublishOptions {
|
||||
pub fn odin(target: SocketAddr, runtime_id: impl Into<String>) -> Self {
|
||||
Self {
|
||||
target,
|
||||
runtime_id: runtime_id.into(),
|
||||
..Self::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for CultMeshRudpDocumentPublishOptions {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
target: SocketAddr::from(([127, 0, 0, 1], 17871)),
|
||||
runtime_id: "cultmesh-rudp-document-publisher".to_string(),
|
||||
connection_id: CULTMESH_RUDP_DOCUMENT_CATALOG_CONNECTION_ID,
|
||||
connect_timeout: Duration::from_secs(1),
|
||||
flush_timeout: Duration::from_millis(150),
|
||||
poll_interval: Duration::from_millis(5),
|
||||
resend_delay_ms: 100,
|
||||
source_agent_id: None,
|
||||
source_role: None,
|
||||
tags: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for CultMeshNodeOptions {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
|
|
@ -107,6 +162,91 @@ impl CultMeshNode {
|
|||
pub fn flush(&mut self) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn publish_document_to_rudp_catalog<T>(
|
||||
&self,
|
||||
key: impl Into<String>,
|
||||
value: &T,
|
||||
options: CultMeshRudpDocumentPublishOptions,
|
||||
) -> Result<()>
|
||||
where
|
||||
T: DatabaseEntry + Serialize,
|
||||
{
|
||||
let key = key.into();
|
||||
let message = self.documents.create_raw_document_put_message(
|
||||
format!("{}:{}:{}", options.runtime_id, T::TYPE, key),
|
||||
key,
|
||||
value,
|
||||
CultNetDocumentPutOptions {
|
||||
source_runtime_id: Some(options.runtime_id.clone()),
|
||||
source_agent_id: options.source_agent_id.clone(),
|
||||
source_role: options.source_role.clone(),
|
||||
tags: if options.tags.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(options.tags.clone())
|
||||
},
|
||||
..CultNetDocumentPutOptions::default()
|
||||
},
|
||||
)?;
|
||||
publish_cultnet_message_to_rudp_catalog(&message, options)
|
||||
}
|
||||
}
|
||||
|
||||
fn publish_cultnet_message_to_rudp_catalog(
|
||||
message: &cultnet_rs::CultNetMessage,
|
||||
options: CultMeshRudpDocumentPublishOptions,
|
||||
) -> Result<()> {
|
||||
if options.runtime_id.trim().is_empty() {
|
||||
anyhow::bail!("runtime_id must be non-empty");
|
||||
}
|
||||
let bind_addr = if options.target.is_ipv4() {
|
||||
SocketAddr::from(([0, 0, 0, 0], 0))
|
||||
} else {
|
||||
SocketAddr::from(([0, 0, 0, 0, 0, 0, 0, 0], 0))
|
||||
};
|
||||
let socket = UdpSocket::bind(bind_addr)?;
|
||||
socket.set_read_timeout(Some(options.poll_interval))?;
|
||||
let mut client = CultNetRudpSocketTransportConnection::new(
|
||||
CultNetRudpSocketTransportOptions {
|
||||
runtime_id: options.runtime_id.clone(),
|
||||
socket,
|
||||
mode: cultnet_rs::CultNetRudpSocketMode::Client,
|
||||
remote_addr: Some(options.target),
|
||||
connection_id: options.connection_id,
|
||||
initial_sequence: 1,
|
||||
resend_delay_ms: options.resend_delay_ms,
|
||||
transport_id: Some("cultmesh-rudp-document-publisher".to_string()),
|
||||
max_payload_bytes: None,
|
||||
max_fragment_bytes: Some(1200),
|
||||
max_pending_reliable_packets: Some(64),
|
||||
media_reliable_expire_after_ms: None,
|
||||
},
|
||||
)?;
|
||||
client.connect(Vec::new())?;
|
||||
let connect_deadline = Instant::now() + options.connect_timeout;
|
||||
while !client.connected() && Instant::now() < connect_deadline {
|
||||
let _ = client.receive_once()?;
|
||||
client.poll_resends()?;
|
||||
thread::sleep(options.poll_interval);
|
||||
}
|
||||
if !client.connected() {
|
||||
anyhow::bail!(
|
||||
"Timed out connecting CultMesh RUDP document publisher {} to {}",
|
||||
options.runtime_id,
|
||||
options.target
|
||||
);
|
||||
}
|
||||
|
||||
let payload = encode_cultnet_message_to_vec(message, CultNetWireContract::CultNetSchemaV0)?;
|
||||
client.send("schema", payload)?;
|
||||
let flush_deadline = Instant::now() + options.flush_timeout;
|
||||
while Instant::now() < flush_deadline {
|
||||
let _ = client.receive_once()?;
|
||||
client.poll_resends()?;
|
||||
thread::sleep(options.poll_interval);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default)]
|
||||
|
|
@ -178,6 +318,10 @@ mod tests {
|
|||
use super::*;
|
||||
use pretty_assertions::assert_eq;
|
||||
use std::collections::BTreeMap;
|
||||
use std::net::UdpSocket;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
use std::time::Instant;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, cultcache_rs::DatabaseEntry)]
|
||||
#[cultcache(type = "cultmesh.test.note", schema = "CultMeshTestNote")]
|
||||
|
|
@ -237,12 +381,78 @@ mod tests {
|
|||
assert!(
|
||||
reloaded
|
||||
.documents()
|
||||
.binding_by_schema_id(Note::TYPE)
|
||||
.binding_by_schema_id("cultmesh.test.note.v0")
|
||||
.is_some()
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn node_publishes_registered_document_to_rudp_catalog() -> Result<()> {
|
||||
let temp = tempfile::tempdir()?;
|
||||
let store_path = temp.path().join("cultmesh.ccmp");
|
||||
let note = Note {
|
||||
body: "respect odin once".to_string(),
|
||||
owner: "self".to_string(),
|
||||
};
|
||||
let node = CultMesh::create_node(
|
||||
&store_path,
|
||||
TestDocuments,
|
||||
CultMeshNodeOptions {
|
||||
runtime_id: "epiphany-test".to_string(),
|
||||
..CultMeshNodeOptions::default()
|
||||
},
|
||||
)?;
|
||||
|
||||
let socket = UdpSocket::bind("127.0.0.1:0")?;
|
||||
socket.set_read_timeout(Some(Duration::from_millis(10)))?;
|
||||
let target = socket.local_addr()?;
|
||||
let (sender, receiver) = std::sync::mpsc::channel();
|
||||
let server = thread::spawn(move || -> Result<()> {
|
||||
let mut server = cultnet_rs::CultNetRudpSocketTransportConnection::new(
|
||||
cultnet_rs::CultNetRudpSocketTransportOptions::server(
|
||||
"odin-test-catalog",
|
||||
socket,
|
||||
CULTMESH_RUDP_DOCUMENT_CATALOG_CONNECTION_ID,
|
||||
),
|
||||
)?;
|
||||
let deadline = Instant::now() + Duration::from_secs(2);
|
||||
while Instant::now() < deadline {
|
||||
if let Some(frame) = server.receive_once()? {
|
||||
let message = cultnet_rs::decode_cultnet_message_from_slice(
|
||||
&frame.payload,
|
||||
cultnet_rs::CultNetWireContract::CultNetSchemaV0,
|
||||
)?;
|
||||
if let cultnet_rs::CultNetMessage::DocumentPutRaw { document, .. } = message {
|
||||
sender
|
||||
.send((
|
||||
document.schema_id,
|
||||
document.record_key,
|
||||
document.source_runtime_id,
|
||||
))
|
||||
.ok();
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
server.poll_resends()?;
|
||||
}
|
||||
anyhow::bail!("timed out waiting for RUDP document put")
|
||||
});
|
||||
|
||||
node.publish_document_to_rudp_catalog(
|
||||
"note",
|
||||
¬e,
|
||||
CultMeshRudpDocumentPublishOptions::odin(target, "epiphany-test"),
|
||||
)?;
|
||||
let received = receiver.recv_timeout(Duration::from_secs(2))?;
|
||||
server.join().expect("server thread should not panic")?;
|
||||
|
||||
assert_eq!(received.0, "cultmesh.test.note.v0");
|
||||
assert_eq!(received.1, "note");
|
||||
assert_eq!(received.2.as_deref(), Some("epiphany-test"));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn node_projects_soa_tables_for_registered_documents() -> Result<()> {
|
||||
let temp = tempfile::tempdir()?;
|
||||
|
|
|
|||
2
vendor/cultnet-rs
vendored
2
vendor/cultnet-rs
vendored
|
|
@ -1 +1 @@
|
|||
Subproject commit 77580f8eee1def465eb8d74c3c86c9c7dcd75d2d
|
||||
Subproject commit bcad85eabdcb23b0c76633ca0b6a1d324dfc3d66
|
||||
Reference in a new issue