attachment.go RawHistoryFolder
1package protocol
2
3import (
4 "errors"
5
6 "github.com/bnema/vev/internal/domain"
7)
8
9var ErrInvalidAttachment = errors.New("invalid attachment transition")
10
11// SuspendAttachment requests a publication barrier on the current attachment.
12// RequestID is nonzero and unique among this connection's transitions. Until
13// its matching ACK arrives the client must not transfer foreground ownership.
14type SuspendAttachment struct{ RequestID uint64 }
15
16// AttachmentSuspended acknowledges that input, UI, rendering and geometry
17// authority have been revoked and pending publications drained. After this ACK
18// no pre-suspension output may become visible. Target is the retained lifecycle,
19// not authority to select any other session. The authenticated transport stays open.
20type AttachmentSuspended struct {
21 RequestID uint64
22 Target ExactSessionTarget
23}
24
25// ActivateAttachment reclaims only the exact target retained by this suspended
26// attachment, with the client's current geometry. It does not grant same-peer
27// navigation authority. Input remains gated until the matching full publication
28// and AttachmentActivated have both been received.
29type ActivateAttachment struct {
30 RequestID uint64
31 Target ExactSessionTarget
32 Size domain.Size
33 PixelWidth int
34 PixelHeight int
35}
36
37func (m ActivateAttachment) Geometry() domain.Geometry {
38 return domain.Geometry{Size: m.Size, PixelWidth: m.PixelWidth, PixelHeight: m.PixelHeight}.NormalizePixels()
39}
40
41// AttachmentActivated commits a successful activation after a full Output and
42// changed RoutePosition on a fresh epoch. Identity and the
43// epoch/state/view-publication fence must match that Output's context. The
44// receiver checks freshness against its previous
45// chain and correlation against the pending request; Validate checks only the
46// self-contained message. Failure must not emit this success ACK (the existing
47// error/close path permits eviction and reconnect).
48type AttachmentActivated struct {
49 RequestID uint64
50 Identity CommittedRouteIdentity
51 Epoch uint64
52 State uint64
53 ViewPublication uint64
54}
55
56func (m SuspendAttachment) Validate() error {
57 if m.RequestID == 0 {
58 return ErrInvalidAttachment
59 }
60 return nil
61}
62func (m AttachmentSuspended) Validate() error {
63 if m.RequestID == 0 || m.Target.Validate() != nil {
64 return ErrInvalidAttachment
65 }
66 return nil
67}
68func (m ActivateAttachment) Validate() error {
69 if m.RequestID == 0 || m.Target.Validate() != nil {
70 return ErrInvalidAttachment
71 }
72 if ValidateGeometry(domain.Geometry{Size: m.Size, PixelWidth: m.PixelWidth, PixelHeight: m.PixelHeight}) != nil {
73 return ErrInvalidAttachment
74 }
75 return nil
76}
77func (m AttachmentActivated) Validate() error {
78 if m.RequestID == 0 || m.Identity.Validate() != nil || m.Epoch == 0 || m.State == 0 || m.ViewPublication == 0 {
79 return ErrInvalidAttachment
80 }
81 return nil
82}
83
84func (SuspendAttachment) clientMessage() {}
85func (ActivateAttachment) clientMessage() {}
86func (AttachmentSuspended) serverMessage() {}
87func (AttachmentActivated) serverMessage() {}