Add Kotlin authorized RUDP peer sugar

This commit is contained in:
Meta Vens 2026-06-16 16:45:21 +01:00
commit c399451880
4 changed files with 102 additions and 4 deletions

View file

@ -369,7 +369,10 @@ Current progress:
files exist. Transports do not own catalog truth.
- Kotlin authority lease catalogs now also expose watch callbacks, so JVM and
Android clients can react to lease changes without treating peer-card contact
hints as trust.
hints as trust. Kotlin peer catalogs also expose authorized-peer lookup
helpers, and the branded `CultMesh` facade can create a RUDP client from the
first peer authorized for a Verse role while still delegating the trust check
to the authority lease catalog.
- 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

View file

@ -34,7 +34,7 @@ CultMesh.
| 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, 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 | 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 |
| 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, 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 |
| 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

View file

@ -221,6 +221,27 @@ CultMesh.createRudpServer(
}
```
When peer discovery and authority leases are already local, callers can ask the
branded entrypoint to select an authorized RUDP peer for a Verse role:
```kotlin
val peers = CultMesh.createPeerCatalog()
val leases = CultMesh.createAuthorityLeaseCatalog()
val client = CultMesh.createRudpClientForAuthorizedPeer(
runtimeId = "kotlin-client",
connectionId = 0x10203040,
peers = peers,
leases = leases,
verseId = "local",
role = "schema",
)
```
The helper uses `CultMeshPeerCatalog.firstAuthorized(...)`, which delegates
trust to `CultMeshAuthorityLeaseCatalog.isAuthorized(...)`; peer endpoints
remain contact hints, not authority.
The sugar delegates to the same `CultNetRudpSocketTransportConnection` and
`cultnet.transport.rudp.v0` packet codec used by the cross-runtime interop
harness. `sendSchema`, `sendLatest`, and `sendRealtime` select the shared

View file

@ -379,6 +379,24 @@ object CultMesh {
return createRudpClient(runtimeId, connectionId, endpoint, bindHost, bindPort, tuning)
}
fun createRudpClientForAuthorizedPeer(
runtimeId: String,
connectionId: Long,
peers: CultMeshPeerCatalog,
leases: CultMeshAuthorityLeaseCatalog,
verseId: String,
role: String,
shardId: String? = null,
at: Instant = Instant.now(),
bindHost: String = "127.0.0.1",
bindPort: Int = 0,
tuning: CultNetRudpSocketTuning = CultNetRudpSocketTuning(),
): CultNetRudpSocketTransportConnection {
val peer = peers.firstAuthorized(verseId, role, leases, shardId, at)
?: throw IOException("No authorized RUDP peer for role $role in Verse $verseId")
return createRudpClientForPeer(runtimeId, connectionId, peer, bindHost, bindPort, tuning)
}
fun createRudpReconnectLoop(
reconnectPolicy: CultNetReconnectPolicy = createReconnectPolicy(),
connectPayload: ByteArray = ByteArray(0),
@ -1583,6 +1601,26 @@ class CultMeshPeerCatalog {
return peers.filter { peer -> peer.verseId == verseId && (role == null || peer.hasRole(role)) }
}
fun findAuthorized(
verseId: String,
role: String,
leases: CultMeshAuthorityLeaseCatalog,
shardId: String? = null,
at: Instant = Instant.now(),
): List<CultMeshPeerCard> {
requireNonBlank(verseId, "verseId")
requireNonBlank(role, "role")
return find(verseId, role).filter { peer -> leases.isAuthorized(peer, role, shardId, at) }
}
fun firstAuthorized(
verseId: String,
role: String,
leases: CultMeshAuthorityLeaseCatalog,
shardId: String? = null,
at: Instant = Instant.now(),
): CultMeshPeerCard? = findAuthorized(verseId, role, leases, shardId, at).firstOrNull()
fun createResponse(request: CultNetMessage): CultNetMessage {
require(request.schemaVersion == "cultmesh.peer_exchange_request.v0") {
"Expected cultmesh.peer_exchange_request.v0, received ${request.schemaVersion}"
@ -3388,8 +3426,11 @@ private fun cultMeshAuthorityLeasesGatePeerTrust() {
val duringLease = Instant.parse("2026-06-15T00:30:00Z")
var watchedLease: CultMeshAuthorityLease? = null
val unsubscribeLease = leases.watch { watchedLease = it }
val peers = CultMesh.createPeerCatalog()
peers.upsert(peer)
check(!leases.isAuthorized(peer, "shard-primary", "players", duringLease))
check(peers.findAuthorized("public", "shard-primary", leases, "players", duringLease).isEmpty())
leases.upsert(
CultMeshAuthorityLease(
leaseId = "lease:peer-authority",
@ -3410,6 +3451,9 @@ private fun cultMeshAuthorityLeasesGatePeerTrust() {
check(leases.get("lease:peer-authority")?.issuerRuntimeId == "kotlin-authority")
check(leases.leases.map { it.leaseId } == listOf("lease:peer-authority"))
check(leases.isAuthorized(peer, "shard-primary", "players", duringLease))
check(peers.findAuthorized("public", "shard-primary", leases, "players", duringLease).single().peerId == "peer-authority")
check(peers.firstAuthorized("public", "shard-primary", leases, "players", duringLease)?.peerId == "peer-authority")
check(peers.firstAuthorized("public", "schema", leases, "players", duringLease) == null)
check(!leases.isAuthorized(peer, "schema", "players", duringLease))
check(!leases.isAuthorized(peer, "shard-primary", "inventory", duringLease))
check(!leases.isAuthorized(peer, "shard-primary", "players", expiresAt))
@ -3911,11 +3955,41 @@ private fun rudpSocketTransportErgonomicFactoriesCarrySchemaFrames() {
verseId = "local",
endpoints = listOf(endpoint.uri),
roles = listOf("schema"),
authorityLeaseId = "lease:kotlin-rudp-sugar-peer",
)
CultMesh.createRudpClientForPeer(
val peers = CultMesh.createPeerCatalog()
val leases = CultMesh.createAuthorityLeaseCatalog()
peers.upsert(peer)
val unauthorized = runCatching {
CultMesh.createRudpClientForAuthorizedPeer(
runtimeId = "kotlin-rudp-sugar-client",
connectionId = connectionId,
peers = peers,
leases = leases,
verseId = "local",
role = "schema",
tuning = CultNetRudpSocketTuning(resendDelayMs = 25, maxFragmentBytes = 1024, maxPendingReliablePackets = 16),
)
}.exceptionOrNull()
check(unauthorized is IOException)
leases.upsert(
CultMeshAuthorityLease(
leaseId = "lease:kotlin-rudp-sugar-peer",
verseId = "local",
peerId = "kotlin-rudp-sugar-peer",
roles = listOf("schema"),
issuerRuntimeId = "kotlin-authority",
validFrom = Instant.now().minusSeconds(60),
expiresAt = Instant.now().plusSeconds(60),
),
)
CultMesh.createRudpClientForAuthorizedPeer(
runtimeId = "kotlin-rudp-sugar-client",
connectionId = connectionId,
peer = peer,
peers = peers,
leases = leases,
verseId = "local",
role = "schema",
tuning = CultNetRudpSocketTuning(resendDelayMs = 25, maxFragmentBytes = 1024, maxPendingReliablePackets = 16),
).use { client ->
client.connect("join")