Add Rust authorized RUDP peer sugar
This commit is contained in:
parent
6510419439
commit
2998f96e73
5 changed files with 133 additions and 11 deletions
|
|
@ -387,7 +387,8 @@ Current progress:
|
|||
- Rust now has a small `CultMesh` facade for its substrate role: peer cards,
|
||||
sorted peer catalogs, authority lease catalogs, schema registry factories,
|
||||
shard catalog factories, `rudp://host:port` endpoint parsing, and RUDP
|
||||
client/server construction from endpoint or peer-card contact hints. The
|
||||
client/server construction from endpoint, peer-card contact hints, or the
|
||||
first peer authorized by the authority lease catalog for a Verse role. The
|
||||
facade delegates to the existing Rust schema registry, shard catalog, and RUDP
|
||||
socket transport owners; discovery contact remains separate from trust, which
|
||||
is still gated by the authority lease catalog.
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ CultMesh.
|
|||
| C# | Reference implementation and production game/server substrate | CultCache typed documents and SoA, CultNet schema-v0, LiteNetLib production path with adapter profile, shared transport profiles, shared RUDP socket transport, RUDP reconnect policy/controller and reconnect-loop helper, LiteNetLib client reconnect-controller adoption, schema-client transport port for service request/response clients, CultMesh node/session/catalog/stream/simulation/RUDP surfaces, authorized peer lookup | No need to abandon LiteNetLib before the CultNet adapter fully owns production service adoption |
|
||||
| Python | Package runtime, local daemon endpoint, raw interop peer, typed state participant | CultCache/CultNet/CultMesh package surface, branded CultMesh node/schema/shard/Verse/peer/authority/stream/RUDP ergonomics, authorized peer lookup, shard catalogs/logs, schema-transport factory for raw client request/subscription flows, local TCP CultMesh server, session/prediction/simulation fact helpers, RUDP codec/session/socket transport, RUDP reconnect policy/controller and reconnect-loop helper, schema-v0 MessagePack over RUDP evidence, benchmark evidence against C# cache paths | Universal C# throughput, full C# daemon/server stack, and RUDP as the only public service pipe |
|
||||
| TypeScript | Node/browser-adjacent projection and interop runtime | CultCache parity tests, CultNet schema-v0 peer, advertised schema/shard catalog wire contracts plus request/sync helpers, transport profiles, TCP-framed transport port and peer helper, shared RUDP socket transport, RUDP reconnect policy/controller, RUDP reconnect-loop helper, branded CultMesh node/schema/shard/Verse/peer/authority/stream/RUDP ergonomics, authorized peer lookup | Full C# game session/server stack |
|
||||
| Rust | Low-level cache/transport/runtime substrate | CultCache/CultNet interop lane, schema and shard catalog helpers, transport profiles, TCP-framed port, shared RUDP codec/session/socket transport, RUDP reconnect policy/controller and reconnect-loop helper, schema-v0 MessagePack over RUDP evidence, small CultMesh facade for schema registry, shard catalog, peer cards, authority leases, RUDP endpoint parsing, and peer-card RUDP client construction | Full CultMesh game-session/server facade, stream catalog, or production game-session server |
|
||||
| Rust | Low-level cache/transport/runtime substrate | CultCache/CultNet interop lane, schema and shard catalog helpers, transport profiles, TCP-framed port, shared RUDP codec/session/socket transport, RUDP reconnect policy/controller and reconnect-loop helper, schema-v0 MessagePack over RUDP evidence, small CultMesh facade for schema registry, shard catalog, peer cards, authority leases, authorized peer lookup, RUDP endpoint parsing, and peer-card/authorized-peer RUDP client construction | Full CultMesh game-session/server facade, stream catalog, or production game-session server |
|
||||
| Kotlin | JVM/Android client substrate | Typed MessagePack cache, built-in schema catalog advertisement, schema/shard catalogs with shared schema-message transport fetch/sync helpers, authority leases, authorized peer lookup, stream catalog, branded `CultMesh` facade, WebSocket transport profile/connection helper, RUDP client/server sugar, RUDP reconnect policy/controller and reconnect-loop helper, schema-v0 MessagePack over RUDP evidence | C# SoA store, full C# server daemon, or Unity hot-loop memory layout |
|
||||
|
||||
## Evidence Gates
|
||||
|
|
|
|||
|
|
@ -124,8 +124,9 @@ contact and authority ergonomics:
|
|||
|
||||
```rust
|
||||
use cultnet_rs::{
|
||||
CultMesh, CultMeshPeerCard, CultMeshRudpSocketOptions, CultNetSchemaKind,
|
||||
CultMesh, CultMeshAuthorityLease, CultMeshPeerCard, CultMeshRudpSocketOptions, CultNetSchemaKind,
|
||||
};
|
||||
use chrono::{Duration, Utc};
|
||||
|
||||
let schemas = CultMesh::create_builtin_schema_registry()?;
|
||||
let shared_contracts = schemas.list(&cultnet_rs::CultNetSchemaCatalogOptions {
|
||||
|
|
@ -146,12 +147,33 @@ let peer = CultMeshPeerCard::new(
|
|||
"local",
|
||||
[format!("rudp://127.0.0.1:{port}")],
|
||||
)
|
||||
.with_roles(["schema"]);
|
||||
.with_roles(["schema"])
|
||||
.with_authority_lease_id("lease:rust-server");
|
||||
|
||||
let mut client = CultMesh::create_rudp_client_for_peer(
|
||||
let now = Utc::now();
|
||||
let mut peers = CultMesh::create_peer_catalog();
|
||||
let mut leases = CultMesh::create_authority_lease_catalog();
|
||||
peers.upsert(peer.clone())?;
|
||||
leases.upsert(CultMeshAuthorityLease {
|
||||
lease_id: "lease:rust-server".to_string(),
|
||||
verse_id: "local".to_string(),
|
||||
peer_id: "rust-server".to_string(),
|
||||
roles: vec!["schema".to_string()],
|
||||
shard_ids: Vec::new(),
|
||||
issuer_runtime_id: None,
|
||||
valid_from: now - Duration::minutes(1),
|
||||
expires_at: now + Duration::minutes(1),
|
||||
})?;
|
||||
|
||||
let mut client = CultMesh::create_rudp_client_for_authorized_peer(
|
||||
"rust-client",
|
||||
0x1020_3040,
|
||||
&peer,
|
||||
&peers,
|
||||
&leases,
|
||||
"local",
|
||||
"schema",
|
||||
None,
|
||||
now,
|
||||
CultMeshRudpSocketOptions::default(),
|
||||
)?;
|
||||
client.connect(b"join".to_vec())?;
|
||||
|
|
@ -184,5 +206,6 @@ if decision.is_some() {
|
|||
|
||||
`CultMesh::parse_rudp_endpoint(...)` handles advertised `rudp://host:port`
|
||||
contact hints, and `CultMeshAuthorityLeaseCatalog` keeps trust separate from
|
||||
discovery. A peer card can say where to dial; a lease decides whether that peer
|
||||
is allowed to own a role or shard.
|
||||
discovery. A peer card can say where to dial; `peers.first_authorized(...)` and
|
||||
`CultMesh::create_rudp_client_for_authorized_peer(...)` only use that contact
|
||||
hint after a lease says the peer may own the requested role or shard.
|
||||
|
|
|
|||
|
|
@ -104,6 +104,33 @@ impl CultMeshPeerCatalog {
|
|||
.cloned()
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn find_authorized(
|
||||
&self,
|
||||
verse_id: &str,
|
||||
role: &str,
|
||||
leases: &CultMeshAuthorityLeaseCatalog,
|
||||
shard_id: Option<&str>,
|
||||
at: DateTime<Utc>,
|
||||
) -> Vec<CultMeshPeerCard> {
|
||||
self.find(verse_id, Some(role))
|
||||
.into_iter()
|
||||
.filter(|peer| leases.is_authorized(peer, role, shard_id, at))
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn first_authorized(
|
||||
&self,
|
||||
verse_id: &str,
|
||||
role: &str,
|
||||
leases: &CultMeshAuthorityLeaseCatalog,
|
||||
shard_id: Option<&str>,
|
||||
at: DateTime<Utc>,
|
||||
) -> Option<CultMeshPeerCard> {
|
||||
self.find_authorized(verse_id, role, leases, shard_id, at)
|
||||
.into_iter()
|
||||
.next()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
|
|
@ -327,6 +354,25 @@ impl CultMesh {
|
|||
let endpoint = peer.rudp_endpoint()?;
|
||||
Self::create_rudp_client(runtime_id, connection_id, &endpoint, options)
|
||||
}
|
||||
|
||||
pub fn create_rudp_client_for_authorized_peer(
|
||||
runtime_id: impl Into<String>,
|
||||
connection_id: u32,
|
||||
peers: &CultMeshPeerCatalog,
|
||||
leases: &CultMeshAuthorityLeaseCatalog,
|
||||
verse_id: &str,
|
||||
role: &str,
|
||||
shard_id: Option<&str>,
|
||||
at: DateTime<Utc>,
|
||||
options: CultMeshRudpSocketOptions,
|
||||
) -> Result<CultNetRudpSocketTransportConnection> {
|
||||
let peer = peers
|
||||
.first_authorized(verse_id, role, leases, shard_id, at)
|
||||
.ok_or_else(|| {
|
||||
anyhow!("No authorized RUDP peer for role {role} in Verse {verse_id}")
|
||||
})?;
|
||||
Self::create_rudp_client_for_peer(runtime_id, connection_id, &peer, options)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn cultnet_rudp_endpoint(endpoint: &str) -> Result<CultNetRudpEndpoint> {
|
||||
|
|
|
|||
|
|
@ -1164,15 +1164,47 @@ fn cultmesh_facade_creates_rudp_client_from_peer_endpoint() -> Result<()> {
|
|||
);
|
||||
|
||||
let peer = CultMeshPeerCard::new("rust-cultmesh-server", "local", [endpoint.uri()])
|
||||
.with_roles(["schema"]);
|
||||
.with_roles(["schema"])
|
||||
.with_authority_lease_id("lease:rust-cultmesh-server");
|
||||
let mut peers = CultMesh::create_peer_catalog();
|
||||
peers.upsert(peer.clone())?;
|
||||
assert_eq!(peers.find("local", Some("schema")), vec![peer.clone()]);
|
||||
let now = Utc::now();
|
||||
let mut leases = CultMesh::create_authority_lease_catalog();
|
||||
assert!(
|
||||
CultMesh::create_rudp_client_for_authorized_peer(
|
||||
"rust-cultmesh-client",
|
||||
connection_id,
|
||||
&peers,
|
||||
&leases,
|
||||
"local",
|
||||
"schema",
|
||||
None,
|
||||
now,
|
||||
options.clone(),
|
||||
)
|
||||
.is_err()
|
||||
);
|
||||
leases.upsert(CultMeshAuthorityLease {
|
||||
lease_id: "lease:rust-cultmesh-server".to_string(),
|
||||
verse_id: "local".to_string(),
|
||||
peer_id: "rust-cultmesh-server".to_string(),
|
||||
roles: vec!["schema".to_string()],
|
||||
shard_ids: Vec::new(),
|
||||
issuer_runtime_id: Some("odin".to_string()),
|
||||
valid_from: now - Duration::minutes(1),
|
||||
expires_at: now + Duration::minutes(1),
|
||||
})?;
|
||||
|
||||
let mut client = CultMesh::create_rudp_client_for_peer(
|
||||
let mut client = CultMesh::create_rudp_client_for_authorized_peer(
|
||||
"rust-cultmesh-client",
|
||||
connection_id,
|
||||
&peer,
|
||||
&peers,
|
||||
&leases,
|
||||
"local",
|
||||
"schema",
|
||||
None,
|
||||
now,
|
||||
options,
|
||||
)?;
|
||||
client.connect(b"join".to_vec())?;
|
||||
|
|
@ -1252,8 +1284,15 @@ fn cultmesh_authority_leases_gate_peer_contact_hints() -> Result<()> {
|
|||
.with_roles(["shard-primary"])
|
||||
.with_authority_lease_id("lease:rust-peer");
|
||||
let mut leases = CultMesh::create_authority_lease_catalog();
|
||||
let mut peers = CultMesh::create_peer_catalog();
|
||||
peers.upsert(peer.clone())?;
|
||||
|
||||
assert!(!leases.is_authorized(&peer, "shard-primary", Some("players"), now));
|
||||
assert!(
|
||||
peers
|
||||
.find_authorized("public", "shard-primary", &leases, Some("players"), now)
|
||||
.is_empty()
|
||||
);
|
||||
leases.upsert(CultMeshAuthorityLease {
|
||||
lease_id: "lease:rust-peer".to_string(),
|
||||
verse_id: "public".to_string(),
|
||||
|
|
@ -1266,7 +1305,20 @@ fn cultmesh_authority_leases_gate_peer_contact_hints() -> Result<()> {
|
|||
})?;
|
||||
|
||||
assert!(leases.is_authorized(&peer, "shard-primary", Some("players"), now));
|
||||
assert_eq!(
|
||||
peers.find_authorized("public", "shard-primary", &leases, Some("players"), now),
|
||||
vec![peer.clone()]
|
||||
);
|
||||
assert_eq!(
|
||||
peers.first_authorized("public", "shard-primary", &leases, Some("players"), now),
|
||||
Some(peer.clone())
|
||||
);
|
||||
assert!(!leases.is_authorized(&peer, "schema", Some("players"), now));
|
||||
assert!(
|
||||
peers
|
||||
.first_authorized("public", "schema", &leases, Some("players"), now)
|
||||
.is_none()
|
||||
);
|
||||
assert!(!leases.is_authorized(&peer, "shard-primary", Some("inventory"), now));
|
||||
assert!(!leases.is_authorized(
|
||||
&peer,
|
||||
|
|
|
|||
Loading…
Reference in a new issue