Add Rust CultMesh peer RUDP facade
This commit is contained in:
parent
fa985255da
commit
290620a317
6 changed files with 506 additions and 1 deletions
|
|
@ -247,6 +247,12 @@ Current progress:
|
|||
client directly from a peer card contact hint. The facade delegates to the
|
||||
same owners as the top-level helpers instead of creating a second authority
|
||||
path.
|
||||
- Rust now has a small `CultMesh` facade for its substrate role: peer cards,
|
||||
sorted peer catalogs, authority lease catalogs, `rudp://host:port` endpoint
|
||||
parsing, and RUDP client/server construction from endpoint or peer-card
|
||||
contact hints. The facade delegates to the existing Rust RUDP socket
|
||||
transport; discovery contact remains separate from trust, which is still
|
||||
gated by the authority lease catalog.
|
||||
- The remaining parity work is to move the remaining TCP/LiteNetLib/WebSocket
|
||||
service bodies behind their shared transport ports, then broaden RUDP interop
|
||||
into automatic reconnect orchestration and the wider schema-message matrix.
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ CultMesh.
|
|||
| C# | Reference implementation and production game/server substrate | CultCache typed documents and SoA, CultNet schema-v0, LiteNetLib production path, shared transport profiles, shared RUDP socket transport, RUDP reconnect policy advertisement, CultMesh node/session/catalog/stream/simulation surfaces | 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, schema catalogs, shard catalogs/logs, local TCP CultMesh server, session/prediction/simulation fact helpers, authority leases, streams, RUDP codec/session/socket transport, RUDP reconnect policy advertisement, 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, transport profiles, TCP-framed transport port, shared RUDP socket transport, RUDP reconnect policy advertisement, local CultMesh node/catalog/authority/stream ergonomics | Full C# game session/server stack |
|
||||
| Rust | Low-level cache/transport/runtime substrate | CultCache/CultNet interop lane, transport profiles, TCP-framed port, shared RUDP codec/session/socket transport, RUDP reconnect policy advertisement, schema-v0 MessagePack over RUDP evidence | Full CultMesh ergonomic facade or production game-session server |
|
||||
| Rust | Low-level cache/transport/runtime substrate | CultCache/CultNet interop lane, transport profiles, TCP-framed port, shared RUDP codec/session/socket transport, RUDP reconnect policy advertisement, schema-v0 MessagePack over RUDP evidence, small CultMesh facade for 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 |
|
||||
| Kotlin | JVM/Android client substrate | Typed MessagePack cache, schema/shard catalogs, authority leases, stream catalog, branded `CultMesh` facade, RUDP client/server sugar, RUDP reconnect policy advertisement, schema-v0 MessagePack over RUDP evidence | C# SoA store, full C# server daemon, or Unity hot-loop memory layout |
|
||||
|
||||
## Evidence Gates
|
||||
|
|
|
|||
|
|
@ -77,3 +77,42 @@ and the receiving cache still decodes once to keep typed reads and validation
|
|||
honest. The win is narrower and realer: identical payload bytes stop getting
|
||||
decoded into generic sludge and then encoded right back into the same bytes for
|
||||
no reason.
|
||||
|
||||
## CultMesh Rust Facade
|
||||
|
||||
Rust is still the low-level substrate runtime, not a clone of the C# game
|
||||
server. It does now expose the small CultMesh entrypoint needed for practical
|
||||
contact and authority ergonomics:
|
||||
|
||||
```rust
|
||||
use cultnet_rs::{
|
||||
CultMesh, CultMeshPeerCard, CultMeshRudpSocketOptions,
|
||||
};
|
||||
|
||||
let mut server = CultMesh::create_rudp_server(
|
||||
"rust-server",
|
||||
0x1020_3040,
|
||||
CultMeshRudpSocketOptions::default(),
|
||||
)?;
|
||||
let port = server.profile.transports[0].port.unwrap();
|
||||
|
||||
let peer = CultMeshPeerCard::new(
|
||||
"rust-server",
|
||||
"local",
|
||||
[format!("rudp://127.0.0.1:{port}")],
|
||||
)
|
||||
.with_roles(["schema"]);
|
||||
|
||||
let mut client = CultMesh::create_rudp_client_for_peer(
|
||||
"rust-client",
|
||||
0x1020_3040,
|
||||
&peer,
|
||||
CultMeshRudpSocketOptions::default(),
|
||||
)?;
|
||||
client.connect(b"join".to_vec())?;
|
||||
```
|
||||
|
||||
`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.
|
||||
|
|
|
|||
373
packages/cultnet-rs/src/cultmesh.rs
Normal file
373
packages/cultnet-rs/src/cultmesh.rs
Normal file
|
|
@ -0,0 +1,373 @@
|
|||
use anyhow::Result;
|
||||
use anyhow::anyhow;
|
||||
use chrono::DateTime;
|
||||
use chrono::Utc;
|
||||
use std::collections::BTreeMap;
|
||||
use std::net::SocketAddr;
|
||||
use std::net::ToSocketAddrs;
|
||||
use std::net::UdpSocket;
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::CultNetRudpSocketMode;
|
||||
use crate::CultNetRudpSocketTransportConnection;
|
||||
use crate::CultNetRudpSocketTransportOptions;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct CultMeshPeerCard {
|
||||
pub peer_id: String,
|
||||
pub verse_id: String,
|
||||
pub endpoints: Vec<String>,
|
||||
pub roles: Vec<String>,
|
||||
pub shard_ids: Vec<String>,
|
||||
pub authority_lease_id: Option<String>,
|
||||
}
|
||||
|
||||
impl CultMeshPeerCard {
|
||||
pub fn new(
|
||||
peer_id: impl Into<String>,
|
||||
verse_id: impl Into<String>,
|
||||
endpoints: impl IntoIterator<Item = impl Into<String>>,
|
||||
) -> Self {
|
||||
Self {
|
||||
peer_id: peer_id.into(),
|
||||
verse_id: verse_id.into(),
|
||||
endpoints: endpoints.into_iter().map(Into::into).collect(),
|
||||
roles: Vec::new(),
|
||||
shard_ids: Vec::new(),
|
||||
authority_lease_id: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_roles(mut self, roles: impl IntoIterator<Item = impl Into<String>>) -> Self {
|
||||
self.roles = roles.into_iter().map(Into::into).collect();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_shard_ids(
|
||||
mut self,
|
||||
shard_ids: impl IntoIterator<Item = impl Into<String>>,
|
||||
) -> Self {
|
||||
self.shard_ids = shard_ids.into_iter().map(Into::into).collect();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_authority_lease_id(mut self, authority_lease_id: impl Into<String>) -> Self {
|
||||
self.authority_lease_id = Some(authority_lease_id.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn rudp_endpoint(&self) -> Result<CultNetRudpEndpoint> {
|
||||
let endpoint = self
|
||||
.endpoints
|
||||
.iter()
|
||||
.find(|endpoint| endpoint.to_ascii_lowercase().starts_with("rudp://"))
|
||||
.ok_or_else(|| anyhow!("Peer {} does not advertise a RUDP endpoint", self.peer_id))?;
|
||||
CultMesh::parse_rudp_endpoint(endpoint)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct CultMeshPeerCatalog {
|
||||
peers: BTreeMap<String, CultMeshPeerCard>,
|
||||
}
|
||||
|
||||
impl CultMeshPeerCatalog {
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
pub fn upsert(&mut self, peer: CultMeshPeerCard) -> Result<()> {
|
||||
require_non_empty(&peer.peer_id, "peer.peer_id")?;
|
||||
require_non_empty(&peer.verse_id, "peer.verse_id")?;
|
||||
self.peers.insert(peer.peer_id.clone(), peer);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn get(&self, peer_id: &str) -> Option<&CultMeshPeerCard> {
|
||||
self.peers.get(peer_id)
|
||||
}
|
||||
|
||||
pub fn peers(&self) -> Vec<CultMeshPeerCard> {
|
||||
self.peers.values().cloned().collect()
|
||||
}
|
||||
|
||||
pub fn find(&self, verse_id: &str, role: Option<&str>) -> Vec<CultMeshPeerCard> {
|
||||
self.peers
|
||||
.values()
|
||||
.filter(|peer| {
|
||||
peer.verse_id == verse_id
|
||||
&& role.is_none_or(|role| peer.roles.iter().any(|value| value == role))
|
||||
})
|
||||
.cloned()
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct CultMeshAuthorityLease {
|
||||
pub lease_id: String,
|
||||
pub verse_id: String,
|
||||
pub peer_id: String,
|
||||
pub roles: Vec<String>,
|
||||
pub shard_ids: Vec<String>,
|
||||
pub issuer_runtime_id: Option<String>,
|
||||
pub valid_from: DateTime<Utc>,
|
||||
pub expires_at: DateTime<Utc>,
|
||||
}
|
||||
|
||||
impl CultMeshAuthorityLease {
|
||||
pub fn covers(
|
||||
&self,
|
||||
peer: &CultMeshPeerCard,
|
||||
role: &str,
|
||||
shard_id: Option<&str>,
|
||||
at: DateTime<Utc>,
|
||||
) -> bool {
|
||||
at >= self.valid_from
|
||||
&& at < self.expires_at
|
||||
&& self.verse_id == peer.verse_id
|
||||
&& self.peer_id == peer.peer_id
|
||||
&& self.roles.iter().any(|value| value == role)
|
||||
&& peer.roles.iter().any(|value| value == role)
|
||||
&& shard_id.is_none_or(|shard_id| {
|
||||
self.shard_ids.is_empty() || self.shard_ids.iter().any(|value| value == shard_id)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct CultMeshAuthorityLeaseCatalog {
|
||||
leases: BTreeMap<String, CultMeshAuthorityLease>,
|
||||
}
|
||||
|
||||
impl CultMeshAuthorityLeaseCatalog {
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
pub fn upsert(&mut self, lease: CultMeshAuthorityLease) -> Result<()> {
|
||||
require_non_empty(&lease.lease_id, "lease.lease_id")?;
|
||||
require_non_empty(&lease.verse_id, "lease.verse_id")?;
|
||||
require_non_empty(&lease.peer_id, "lease.peer_id")?;
|
||||
if lease.expires_at <= lease.valid_from {
|
||||
return Err(anyhow!(
|
||||
"CultMesh authority lease expiry must be after valid_from"
|
||||
));
|
||||
}
|
||||
self.leases.insert(lease.lease_id.clone(), lease);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn get(&self, lease_id: &str) -> Option<&CultMeshAuthorityLease> {
|
||||
self.leases.get(lease_id)
|
||||
}
|
||||
|
||||
pub fn leases(&self) -> Vec<CultMeshAuthorityLease> {
|
||||
self.leases.values().cloned().collect()
|
||||
}
|
||||
|
||||
pub fn is_authorized(
|
||||
&self,
|
||||
peer: &CultMeshPeerCard,
|
||||
role: &str,
|
||||
shard_id: Option<&str>,
|
||||
at: DateTime<Utc>,
|
||||
) -> bool {
|
||||
let Some(lease_id) = peer.authority_lease_id.as_deref() else {
|
||||
return false;
|
||||
};
|
||||
self.leases
|
||||
.get(lease_id)
|
||||
.is_some_and(|lease| lease.covers(peer, role, shard_id, at))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct CultNetRudpEndpoint {
|
||||
pub host: String,
|
||||
pub port: u16,
|
||||
}
|
||||
|
||||
impl CultNetRudpEndpoint {
|
||||
pub fn uri(&self) -> String {
|
||||
if self.host.contains(':') && !self.host.starts_with('[') {
|
||||
format!("rudp://[{}]:{}", self.host, self.port)
|
||||
} else {
|
||||
format!("rudp://{}:{}", self.host, self.port)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn socket_addr(&self) -> Result<SocketAddr> {
|
||||
format!("{}:{}", socket_host(&self.host), self.port)
|
||||
.to_socket_addrs()
|
||||
.map_err(|error| anyhow!("Invalid RUDP socket endpoint {}: {error}", self.uri()))?
|
||||
.next()
|
||||
.ok_or_else(|| anyhow!("RUDP socket endpoint {} did not resolve", self.uri()))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct CultMeshRudpSocketOptions {
|
||||
pub bind_host: String,
|
||||
pub bind_port: u16,
|
||||
pub read_timeout: Option<Duration>,
|
||||
pub initial_sequence: u32,
|
||||
pub resend_delay_ms: u64,
|
||||
pub max_payload_bytes: Option<u32>,
|
||||
pub max_fragment_bytes: Option<u32>,
|
||||
pub max_pending_reliable_packets: Option<u32>,
|
||||
}
|
||||
|
||||
impl Default for CultMeshRudpSocketOptions {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
bind_host: "127.0.0.1".to_string(),
|
||||
bind_port: 0,
|
||||
read_timeout: Some(Duration::from_millis(20)),
|
||||
initial_sequence: 1,
|
||||
resend_delay_ms: 250,
|
||||
max_payload_bytes: None,
|
||||
max_fragment_bytes: None,
|
||||
max_pending_reliable_packets: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct CultMesh;
|
||||
|
||||
impl CultMesh {
|
||||
pub fn create_peer_catalog() -> CultMeshPeerCatalog {
|
||||
CultMeshPeerCatalog::new()
|
||||
}
|
||||
|
||||
pub fn create_authority_lease_catalog() -> CultMeshAuthorityLeaseCatalog {
|
||||
CultMeshAuthorityLeaseCatalog::new()
|
||||
}
|
||||
|
||||
pub fn parse_rudp_endpoint(endpoint: &str) -> Result<CultNetRudpEndpoint> {
|
||||
cultnet_rudp_endpoint(endpoint)
|
||||
}
|
||||
|
||||
pub fn create_rudp_server(
|
||||
runtime_id: impl Into<String>,
|
||||
connection_id: u32,
|
||||
options: CultMeshRudpSocketOptions,
|
||||
) -> Result<CultNetRudpSocketTransportConnection> {
|
||||
let socket = bind_rudp_socket(&options)?;
|
||||
CultNetRudpSocketTransportConnection::new(CultNetRudpSocketTransportOptions {
|
||||
runtime_id: runtime_id.into(),
|
||||
socket,
|
||||
mode: CultNetRudpSocketMode::Server,
|
||||
remote_addr: None,
|
||||
connection_id,
|
||||
initial_sequence: options.initial_sequence,
|
||||
resend_delay_ms: options.resend_delay_ms,
|
||||
transport_id: None,
|
||||
max_payload_bytes: options.max_payload_bytes,
|
||||
max_fragment_bytes: options.max_fragment_bytes,
|
||||
max_pending_reliable_packets: options.max_pending_reliable_packets,
|
||||
reconnect_policy: None,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn create_rudp_client(
|
||||
runtime_id: impl Into<String>,
|
||||
connection_id: u32,
|
||||
endpoint: &CultNetRudpEndpoint,
|
||||
options: CultMeshRudpSocketOptions,
|
||||
) -> Result<CultNetRudpSocketTransportConnection> {
|
||||
let socket = bind_rudp_socket(&options)?;
|
||||
CultNetRudpSocketTransportConnection::new(CultNetRudpSocketTransportOptions {
|
||||
runtime_id: runtime_id.into(),
|
||||
socket,
|
||||
mode: CultNetRudpSocketMode::Client,
|
||||
remote_addr: Some(endpoint.socket_addr()?),
|
||||
connection_id,
|
||||
initial_sequence: options.initial_sequence,
|
||||
resend_delay_ms: options.resend_delay_ms,
|
||||
transport_id: None,
|
||||
max_payload_bytes: options.max_payload_bytes,
|
||||
max_fragment_bytes: options.max_fragment_bytes,
|
||||
max_pending_reliable_packets: options.max_pending_reliable_packets,
|
||||
reconnect_policy: None,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn create_rudp_client_for_endpoint(
|
||||
runtime_id: impl Into<String>,
|
||||
connection_id: u32,
|
||||
endpoint: &str,
|
||||
options: CultMeshRudpSocketOptions,
|
||||
) -> Result<CultNetRudpSocketTransportConnection> {
|
||||
let endpoint = Self::parse_rudp_endpoint(endpoint)?;
|
||||
Self::create_rudp_client(runtime_id, connection_id, &endpoint, options)
|
||||
}
|
||||
|
||||
pub fn create_rudp_client_for_peer(
|
||||
runtime_id: impl Into<String>,
|
||||
connection_id: u32,
|
||||
peer: &CultMeshPeerCard,
|
||||
options: CultMeshRudpSocketOptions,
|
||||
) -> Result<CultNetRudpSocketTransportConnection> {
|
||||
let endpoint = peer.rudp_endpoint()?;
|
||||
Self::create_rudp_client(runtime_id, connection_id, &endpoint, options)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn cultnet_rudp_endpoint(endpoint: &str) -> Result<CultNetRudpEndpoint> {
|
||||
let scheme = "rudp://";
|
||||
if endpoint.len() < scheme.len() || !endpoint[..scheme.len()].eq_ignore_ascii_case(scheme) {
|
||||
return Err(anyhow!("RUDP endpoint must use the rudp scheme"));
|
||||
}
|
||||
let rest = &endpoint[scheme.len()..];
|
||||
let (host, port_text) = if let Some(rest) = rest.strip_prefix('[') {
|
||||
let (host, port_rest) = rest
|
||||
.split_once(']')
|
||||
.ok_or_else(|| anyhow!("RUDP IPv6 endpoint must close the host bracket"))?;
|
||||
let port_text = port_rest
|
||||
.strip_prefix(':')
|
||||
.ok_or_else(|| anyhow!("RUDP endpoint must include a valid port"))?;
|
||||
(host.to_string(), port_text)
|
||||
} else {
|
||||
let (host, port_text) = rest
|
||||
.rsplit_once(':')
|
||||
.ok_or_else(|| anyhow!("RUDP endpoint must include a host and port"))?;
|
||||
if host.contains(':') {
|
||||
return Err(anyhow!("RUDP IPv6 endpoint host must be bracketed"));
|
||||
}
|
||||
(host.to_string(), port_text)
|
||||
};
|
||||
require_non_empty(&host, "rudp host")?;
|
||||
let port = port_text
|
||||
.parse::<u16>()
|
||||
.map_err(|error| anyhow!("RUDP endpoint must include a valid port: {error}"))?;
|
||||
if port == 0 {
|
||||
return Err(anyhow!("RUDP endpoint port must be greater than zero"));
|
||||
}
|
||||
Ok(CultNetRudpEndpoint { host, port })
|
||||
}
|
||||
|
||||
fn bind_rudp_socket(options: &CultMeshRudpSocketOptions) -> Result<UdpSocket> {
|
||||
let socket = UdpSocket::bind(format!(
|
||||
"{}:{}",
|
||||
socket_host(&options.bind_host),
|
||||
options.bind_port
|
||||
))?;
|
||||
socket.set_read_timeout(options.read_timeout)?;
|
||||
Ok(socket)
|
||||
}
|
||||
|
||||
fn socket_host(host: &str) -> String {
|
||||
if host.contains(':') && !host.starts_with('[') {
|
||||
format!("[{host}]")
|
||||
} else {
|
||||
host.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
fn require_non_empty(value: &str, field: &str) -> Result<()> {
|
||||
if value.trim().is_empty() {
|
||||
return Err(anyhow!("CultMesh {field} must not be empty"));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
mod contracts;
|
||||
mod cultmesh;
|
||||
mod framing;
|
||||
mod replication;
|
||||
mod rudp;
|
||||
|
|
@ -7,6 +8,7 @@ mod security;
|
|||
mod transport;
|
||||
|
||||
pub use contracts::*;
|
||||
pub use cultmesh::*;
|
||||
pub use framing::*;
|
||||
pub use replication::*;
|
||||
pub use rudp::*;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,13 @@
|
|||
use anyhow::Result;
|
||||
use chrono::Duration;
|
||||
use chrono::Utc;
|
||||
use cultcache_rs::CultCache;
|
||||
use cultcache_rs::DatabaseEntry;
|
||||
use cultcache_rs::SingleFileMessagePackBackingStore;
|
||||
use cultnet_rs::CultMesh;
|
||||
use cultnet_rs::CultMeshAuthorityLease;
|
||||
use cultnet_rs::CultMeshPeerCard;
|
||||
use cultnet_rs::CultMeshRudpSocketOptions;
|
||||
use cultnet_rs::CultNetClientSecurityOptions;
|
||||
use cultnet_rs::CultNetDocumentBinding;
|
||||
use cultnet_rs::CultNetDocumentMutationContract;
|
||||
|
|
@ -950,6 +955,86 @@ fn rudp_socket_transport_carries_fragmented_reliable_ordered_schema_frames() ->
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cultmesh_facade_creates_rudp_client_from_peer_endpoint() -> Result<()> {
|
||||
let connection_id = 0x2030_4050;
|
||||
let options = CultMeshRudpSocketOptions {
|
||||
resend_delay_ms: 25,
|
||||
max_fragment_bytes: Some(8),
|
||||
max_pending_reliable_packets: Some(16),
|
||||
..CultMeshRudpSocketOptions::default()
|
||||
};
|
||||
let mut server =
|
||||
CultMesh::create_rudp_server("rust-cultmesh-server", connection_id, options.clone())?;
|
||||
let server_port = server.profile.transports[0]
|
||||
.port
|
||||
.expect("RUDP server profile advertises its local port");
|
||||
let endpoint = CultMesh::parse_rudp_endpoint(&format!("rudp://127.0.0.1:{server_port}"))?;
|
||||
assert_eq!(endpoint.host, "127.0.0.1");
|
||||
assert_eq!(endpoint.port, server_port);
|
||||
assert_eq!(
|
||||
CultMesh::parse_rudp_endpoint("RuDp://localhost:4100")?.host,
|
||||
"localhost"
|
||||
);
|
||||
assert_eq!(
|
||||
CultMesh::parse_rudp_endpoint("rudp://[::1]:4100")?.uri(),
|
||||
"rudp://[::1]:4100"
|
||||
);
|
||||
|
||||
let peer = CultMeshPeerCard::new("rust-cultmesh-server", "local", [endpoint.uri()])
|
||||
.with_roles(["schema"]);
|
||||
let mut peers = CultMesh::create_peer_catalog();
|
||||
peers.upsert(peer.clone())?;
|
||||
assert_eq!(peers.find("local", Some("schema")), vec![peer.clone()]);
|
||||
|
||||
let mut client = CultMesh::create_rudp_client_for_peer(
|
||||
"rust-cultmesh-client",
|
||||
connection_id,
|
||||
&peer,
|
||||
options,
|
||||
)?;
|
||||
client.connect(b"join".to_vec())?;
|
||||
pump_rudp_handshake(&mut client, &mut server)?;
|
||||
|
||||
client.send("schema", b"client-state".to_vec())?;
|
||||
let server_frame = receive_rudp_frame(&mut server)?;
|
||||
assert_eq!(server_frame.channel_id, "schema");
|
||||
assert_eq!(server_frame.payload, b"client-state");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cultmesh_authority_leases_gate_peer_contact_hints() -> Result<()> {
|
||||
let now = Utc::now();
|
||||
let peer = CultMeshPeerCard::new("rust-peer", "public", ["rudp://127.0.0.1:4100"])
|
||||
.with_roles(["shard-primary"])
|
||||
.with_authority_lease_id("lease:rust-peer");
|
||||
let mut leases = CultMesh::create_authority_lease_catalog();
|
||||
|
||||
assert!(!leases.is_authorized(&peer, "shard-primary", Some("players"), now));
|
||||
leases.upsert(CultMeshAuthorityLease {
|
||||
lease_id: "lease:rust-peer".to_string(),
|
||||
verse_id: "public".to_string(),
|
||||
peer_id: "rust-peer".to_string(),
|
||||
roles: vec!["shard-primary".to_string()],
|
||||
shard_ids: vec!["players".to_string()],
|
||||
issuer_runtime_id: Some("odin".to_string()),
|
||||
valid_from: now - Duration::minutes(1),
|
||||
expires_at: now + Duration::minutes(1),
|
||||
})?;
|
||||
|
||||
assert!(leases.is_authorized(&peer, "shard-primary", Some("players"), now));
|
||||
assert!(!leases.is_authorized(&peer, "schema", Some("players"), now));
|
||||
assert!(!leases.is_authorized(&peer, "shard-primary", Some("inventory"), now));
|
||||
assert!(!leases.is_authorized(
|
||||
&peer,
|
||||
"shard-primary",
|
||||
Some("players"),
|
||||
now + Duration::minutes(1)
|
||||
));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn legacy_gamecult_networking_contract_round_trips_login_union() -> Result<()> {
|
||||
let message = CultNetMessage::Login {
|
||||
|
|
|
|||
Loading…
Reference in a new issue