| 1 | package hub |
| 2 | |
| 3 | import "context" |
| 4 | |
| 5 | // Authorize is the §2.5 last-row check on its own: a participation |
| 6 | // bound to this session, in this room, admitted. A member-kind |
| 7 | // participation re-derives standing first (§15.12), exactly as Relay |
| 8 | // does, through memberStandingGone; one whose standing is gone is ended |
| 9 | // here with lost{standing} and answered ErrNotYours. A guest never |
| 10 | // consults standing at all (ruling 14): memberStandingGone returns |
| 11 | // immediately for a non-member kind, without a StandingFor call. |
| 12 | // |
| 13 | // A nil return is not "nothing happened": memberStandingGone still |
| 14 | // records a kind that changed (setKindLocked), which — for an admitted |
| 15 | // member — broadcasts a fresh roster to the room, the same side effect |
| 16 | // Relay's own re-derivation has. What a nil return promises is only |
| 17 | // that no *participation* ended and nothing was relayed; it is not a |
| 18 | // pure read the way CanResume's probe is (that one never writes at |
| 19 | // all). GET /m/{sqid}/ice is its caller. |
| 20 | func (h *Hub) Authorize(ctx context.Context, sqid, session string, peer PeerID) error { |
| 21 | gone, err := h.memberStandingGone(ctx, sqid, session, peer, true) |
| 22 | if err != nil { |
| 23 | return err |
| 24 | } |
| 25 | if gone { |
| 26 | return ErrNotYours |
| 27 | } |
| 28 | h.mu.Lock() |
| 29 | defer h.mu.Unlock() |
| 30 | p, ok := h.findLocked(sqid, session, peer) |
| 31 | if !ok { |
| 32 | return ErrUnknownPeer |
| 33 | } |
| 34 | if !p.Admitted { |
| 35 | return ErrNotAdmitted |
| 36 | } |
| 37 | return nil |
| 38 | } |
| 39 | |
| 40 | // Recheck re-derives a participation's standing now and applies it, as |
| 41 | // the next mutating request would (§2.4, §15.12): a member whose |
| 42 | // standing is gone is ended with lost{standing} and the departure the |
| 43 | // room is owed, and a changed kind is recorded. It reports whether the |
| 44 | // participation ended. A guest is never touched (ruling 14). The app's |
| 45 | // held stream calls it when its own decision says a member has left, so |
| 46 | // the ending is the hub's, in the hub's words. |
| 47 | func (h *Hub) Recheck(ctx context.Context, sqid, session string, peer PeerID) (bool, error) { |
| 48 | return h.memberStandingGone(ctx, sqid, session, peer, true) |
| 49 | } |
| 50 | |