summaryrefslogtreecommitdiff
path: root/vendor/github.com/pion/turn/v2/internal/proto/rsrvtoken.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/pion/turn/v2/internal/proto/rsrvtoken.go')
-rw-r--r--vendor/github.com/pion/turn/v2/internal/proto/rsrvtoken.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/vendor/github.com/pion/turn/v2/internal/proto/rsrvtoken.go b/vendor/github.com/pion/turn/v2/internal/proto/rsrvtoken.go
new file mode 100644
index 0000000..6e2ed4d
--- /dev/null
+++ b/vendor/github.com/pion/turn/v2/internal/proto/rsrvtoken.go
@@ -0,0 +1,39 @@
+package proto
+
+import "github.com/pion/stun"
+
+// ReservationToken represents RESERVATION-TOKEN attribute.
+//
+// The RESERVATION-TOKEN attribute contains a token that uniquely
+// identifies a relayed transport address being held in reserve by the
+// server. The server includes this attribute in a success response to
+// tell the client about the token, and the client includes this
+// attribute in a subsequent Allocate request to request the server use
+// that relayed transport address for the allocation.
+//
+// RFC 5766 Section 14.9
+type ReservationToken []byte
+
+const reservationTokenSize = 8 // 8 bytes
+
+// AddTo adds RESERVATION-TOKEN to message.
+func (t ReservationToken) AddTo(m *stun.Message) error {
+ if err := stun.CheckSize(stun.AttrReservationToken, len(t), reservationTokenSize); err != nil {
+ return err
+ }
+ m.Add(stun.AttrReservationToken, t)
+ return nil
+}
+
+// GetFrom decodes RESERVATION-TOKEN from message.
+func (t *ReservationToken) GetFrom(m *stun.Message) error {
+ v, err := m.Get(stun.AttrReservationToken)
+ if err != nil {
+ return err
+ }
+ if err = stun.CheckSize(stun.AttrReservationToken, len(v), reservationTokenSize); err != nil {
+ return err
+ }
+ *t = v
+ return nil
+}