Add Kotlin authority lease ergonomics
This commit is contained in:
parent
4431d7bc93
commit
c1521c3ba0
3 changed files with 129 additions and 0 deletions
|
|
@ -212,6 +212,10 @@ Current progress:
|
|||
connect, accept, single-packet sends, or fragmented sends enqueue anything;
|
||||
TCP-framed profiles do not publish the field because they do not own the RUDP
|
||||
pending-reliable queue.
|
||||
- Kotlin now mirrors the C#/TypeScript/Python local authority lease gate:
|
||||
peer cards may advertise `authorityLeaseId`, but `CultMeshAuthorityLeaseCatalog`
|
||||
owns role/shard/time authorization so discovery contact cannot impersonate
|
||||
trust.
|
||||
- The remaining parity work is to deepen Python's server-side use of its port
|
||||
and move each runtime's existing TCP/LiteNetLib/WebSocket bodies behind those
|
||||
ports, then broaden RUDP interop into reconnect policy and the wider
|
||||
|
|
|
|||
|
|
@ -212,6 +212,36 @@ val peerResponse = peers.createResponse(
|
|||
instances, so catalog discovery can ride the same MessagePack schema-v0 lane as
|
||||
RUDP schema traffic.
|
||||
|
||||
Peer cards are contact hints, not trust. Kotlin now mirrors the C#/TS/Python
|
||||
lease gate so local clients can keep discovery and authority separate:
|
||||
|
||||
```kotlin
|
||||
val peer = CultMeshPeerCard(
|
||||
peerId = "kotlin-peer",
|
||||
verseId = "public",
|
||||
endpoints = listOf("rudp://127.0.0.1:4100"),
|
||||
roles = listOf("shard-primary"),
|
||||
shardIds = listOf("players"),
|
||||
authorityLeaseId = "lease:kotlin-peer",
|
||||
)
|
||||
|
||||
val leases = createAuthorityLeaseCatalog()
|
||||
leases.upsert(
|
||||
CultMeshAuthorityLease(
|
||||
leaseId = "lease:kotlin-peer",
|
||||
verseId = "public",
|
||||
peerId = "kotlin-peer",
|
||||
roles = listOf("shard-primary"),
|
||||
shardIds = listOf("players"),
|
||||
issuerRuntimeId = "odin",
|
||||
validFrom = Instant.parse("2026-06-15T00:00:00Z"),
|
||||
expiresAt = Instant.parse("2026-06-15T01:00:00Z"),
|
||||
),
|
||||
)
|
||||
|
||||
check(leases.isAuthorized(peer, "shard-primary", "players"))
|
||||
```
|
||||
|
||||
`EveMediaObservationDocument` carries byte-backed device streams such as camera
|
||||
luma frames and microphone PCM blocks. The document is observation transport,
|
||||
not synchronization authority: the device owns capture and local timestamps,
|
||||
|
|
|
|||
|
|
@ -715,6 +715,64 @@ data class CultMeshPeerCard(
|
|||
}
|
||||
}
|
||||
|
||||
data class CultMeshAuthorityLease(
|
||||
val leaseId: String,
|
||||
val verseId: String,
|
||||
val peerId: String,
|
||||
val roles: List<String>,
|
||||
val validFrom: Instant,
|
||||
val expiresAt: Instant,
|
||||
val shardIds: List<String> = emptyList(),
|
||||
val issuerRuntimeId: String,
|
||||
val signature: String? = null,
|
||||
) {
|
||||
init {
|
||||
requireNonBlank(leaseId, "leaseId")
|
||||
requireNonBlank(verseId, "verseId")
|
||||
requireNonBlank(peerId, "peerId")
|
||||
requireNonBlank(issuerRuntimeId, "issuerRuntimeId")
|
||||
if (!expiresAt.isAfter(validFrom)) throw IOException("CultMesh authority lease expiry must be after validFrom")
|
||||
}
|
||||
|
||||
fun isValidAt(at: Instant): Boolean = !at.isBefore(validFrom) && at.isBefore(expiresAt)
|
||||
|
||||
fun covers(peer: CultMeshPeerCard, role: String, shardId: String? = null, at: Instant = Instant.now()): Boolean {
|
||||
requireNonBlank(role, "role")
|
||||
return isValidAt(at) &&
|
||||
verseId == peer.verseId &&
|
||||
peerId == peer.peerId &&
|
||||
leaseId == peer.authorityLeaseId &&
|
||||
role in roles &&
|
||||
peer.hasRole(role) &&
|
||||
(shardId.isNullOrBlank() || shardIds.isEmpty() || shardId in shardIds)
|
||||
}
|
||||
}
|
||||
|
||||
class CultMeshAuthorityLeaseCatalog {
|
||||
private val knownLeases = linkedMapOf<String, CultMeshAuthorityLease>()
|
||||
|
||||
val leases: List<CultMeshAuthorityLease>
|
||||
get() = knownLeases.toSortedMap().values.toList()
|
||||
|
||||
fun upsert(lease: CultMeshAuthorityLease) {
|
||||
knownLeases[lease.leaseId] = lease
|
||||
}
|
||||
|
||||
fun get(leaseId: String): CultMeshAuthorityLease? {
|
||||
requireNonBlank(leaseId, "leaseId")
|
||||
return knownLeases[leaseId]
|
||||
}
|
||||
|
||||
fun isAuthorized(peer: CultMeshPeerCard, role: String, shardId: String? = null, at: Instant = Instant.now()): Boolean {
|
||||
requireNonBlank(role, "role")
|
||||
val leaseId = peer.authorityLeaseId ?: return false
|
||||
val lease = knownLeases[leaseId] ?: return false
|
||||
return lease.covers(peer, role, shardId, at)
|
||||
}
|
||||
}
|
||||
|
||||
fun createAuthorityLeaseCatalog(): CultMeshAuthorityLeaseCatalog = CultMeshAuthorityLeaseCatalog()
|
||||
|
||||
class CultMeshVerseCatalog {
|
||||
private val knownVerses = linkedMapOf<String, CultMeshVerseDescriptor>()
|
||||
private val subscribers = mutableListOf<(CultMeshVerseDescriptor) -> Unit>()
|
||||
|
|
@ -1981,6 +2039,7 @@ fun main(args: Array<String>) {
|
|||
cultNetSchemaMessagesUseMessagePackMaps()
|
||||
cultNetSchemaCatalogsRoundTripDescriptors()
|
||||
cultMeshCatalogsRoundTripDiscoveryMessages()
|
||||
cultMeshAuthorityLeasesGatePeerTrust()
|
||||
cultNetShardCatalogsAndLogsRoundTrip()
|
||||
rudpPacketCodecUsesDeterministicReliableOrderedFixture()
|
||||
rudpSessionPingsAndDetectsReceiveTimeout()
|
||||
|
|
@ -2266,6 +2325,42 @@ private fun cultMeshCatalogsRoundTripDiscoveryMessages() {
|
|||
check(appliedPeerCatalog.get("peer-a")?.hasRole("schema") == true)
|
||||
}
|
||||
|
||||
private fun cultMeshAuthorityLeasesGatePeerTrust() {
|
||||
val peer = CultMeshPeerCard(
|
||||
peerId = "peer-authority",
|
||||
verseId = "public",
|
||||
endpoints = listOf("rudp://127.0.0.1:4100"),
|
||||
roles = listOf("shard-primary", "schema"),
|
||||
shardIds = listOf("players"),
|
||||
authorityLeaseId = "lease:peer-authority",
|
||||
)
|
||||
val leases = createAuthorityLeaseCatalog()
|
||||
val validFrom = Instant.parse("2026-06-15T00:00:00Z")
|
||||
val expiresAt = Instant.parse("2026-06-15T01:00:00Z")
|
||||
val duringLease = Instant.parse("2026-06-15T00:30:00Z")
|
||||
|
||||
check(!leases.isAuthorized(peer, "shard-primary", "players", duringLease))
|
||||
leases.upsert(
|
||||
CultMeshAuthorityLease(
|
||||
leaseId = "lease:peer-authority",
|
||||
verseId = "public",
|
||||
peerId = "peer-authority",
|
||||
roles = listOf("shard-primary"),
|
||||
shardIds = listOf("players"),
|
||||
issuerRuntimeId = "kotlin-authority",
|
||||
validFrom = validFrom,
|
||||
expiresAt = expiresAt,
|
||||
),
|
||||
)
|
||||
|
||||
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(!leases.isAuthorized(peer, "schema", "players", duringLease))
|
||||
check(!leases.isAuthorized(peer, "shard-primary", "inventory", duringLease))
|
||||
check(!leases.isAuthorized(peer, "shard-primary", "players", expiresAt))
|
||||
}
|
||||
|
||||
private fun cultNetShardCatalogsAndLogsRoundTrip() {
|
||||
val notes = stringDocument("kotlin.note", "kotlin.note.v1")
|
||||
val cache = CultCache()
|
||||
|
|
|
|||
Loading…
Reference in a new issue