AdmissionPolicy
The host's say on who gets into its room, and on how long each newcomer may come back without being asked again.
A device that knocks for the first time — or that has been away too long to be let straight back in — is a newcomer, and only the app knows whether to let it in. kuilt asks this policy, and the answer is either AdmissionDecision.Admit, with the GrantTerms of the pass the newcomer gets, or AdmissionDecision.Reject with a RejectCode the joiner sees.
The policy sees only newcomers. A device the host is still holding a seat for, or one coming back inside the pass it was given, is let back in by the room without asking: the room checks the device's key against the seats it holds and the pass against its own key first. So a policy cannot refuse a returning device; revoking its key in HostAdmission.revocations makes it a newcomer again, and then the policy decides.
Revoking is not a ban, so do not refuse on it: a revocation cannot be undone, and a policy that refuses every revoked key keeps that device out for good. Refuse on the app's own blocked set, which it can undo, and keep that set across restarts as you keep the revocations: a forgotten block lets a revoked device back in as a newcomer. To keep a device out from its next return, block it and revoke it: blocking alone leaves a held seat or a pass it holds working, and revoking alone only sends it back to this policy. Neither removes a device that is in the room now.
Every host entry point takes one inside a HostAdmission: RoomFactory.host, an AdoptRole.Host adopt, and ElectionLobby.start. A newcomer is a device whose proven key holds no seat in the room: a first visit, or a second tab of a device already in the room, which gets a membership of its own and so is asked about like any other.
decide suspends so a policy can look something up, but it must answer within the host's admit timeout. A policy still deciding when the newcomer's challenge runs out is cancelled and the newcomer hears nothing, so its own admit deadline ends the attempt; a later Hello is asked about afresh. A policy that throws refuses the newcomer with RejectCode.AdmissionPolicyFailed, which is retryable, and the room keeps running. It may run concurrently with itself, for two joiners at once.
Samples
// RejectCode is open. The joiner does not know this code, so it arrives as
// RejectCode.Unknown("not-welcome", retryable = false), and a reconnecting device stops knocking.
val notWelcome = object : RejectCode {
override val id: String = "not-welcome"
override val retryable: Boolean = false
}
// The room checks returning passes against this list. Kept in the store, since a friend's pass
// never expires: an in-memory list forgets on restart, and the voided passes work again.
val revocations = RevocationList.open(store)
val policy = AdmissionPolicy { request ->
// `key` is the device key the joiner proved it holds. `displayName` is only its say-so.
when {
// The app's blocked set, never the revocations: a revocation cannot be taken back, so
// refusing every revoked key here would ban it for good.
request.key in blocked.value -> AdmissionDecision.Reject(notWelcome)
request.key in friends -> AdmissionDecision.Admit(GrantTerms(Duration.INFINITE, GrantReach.AnyRoomOfIssuer))
else -> AdmissionDecision.Admit(GrantTerms(readmitFor = 1.hours))
}
}
return HostAdmission(policy, revocations)Functions
Whether the newcomer described by request gets in, and on what terms.