Source File
lifetime.go
Belonging Package
github.com/pion/turn/v4/internal/proto
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>// SPDX-License-Identifier: MITpackage protoimport ()// DefaultLifetime in RFC 5766 is 10 minutes.//// RFC 5766 Section 2.2.const DefaultLifetime = time.Minute * 10// Lifetime represents LIFETIME attribute.//// The LIFETIME attribute represents the duration for which the server// will maintain an allocation in the absence of a refresh. The value// portion of this attribute is 4-bytes long and consists of a 32-bit// unsigned integral value representing the number of seconds remaining// until expiration.//// RFC 5766 Section 14.2.type Lifetime struct {time.Duration}// Seconds in uint32.const lifetimeSize = 4 // 4 bytes, 32 bits// AddTo adds LIFETIME to message.func ( Lifetime) ( *stun.Message) error {:= make([]byte, lifetimeSize)binary.BigEndian.PutUint32(, uint32(.Seconds())).Add(stun.AttrLifetime, )return nil}// GetFrom decodes LIFETIME from message.func ( *Lifetime) ( *stun.Message) error {, := .Get(stun.AttrLifetime)if != nil {return}if = stun.CheckSize(stun.AttrLifetime, len(), lifetimeSize); != nil {return}_ = [lifetimeSize-1] // Asserting length:= binary.BigEndian.Uint32().Duration = time.Second * time.Duration()return nil}
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |