| 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 | |