status-go/vendor/github.com/pion/turn/v2/internal/proto/dontfrag.go

46 lines
1.2 KiB
Go
Raw Normal View History

2024-06-05 20:10:03 +00:00
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT
2022-03-10 09:44:48 +00:00
package proto
2024-05-15 23:15:00 +00:00
import (
"github.com/pion/stun"
)
2022-03-10 09:44:48 +00:00
2024-05-15 23:15:00 +00:00
// DontFragmentAttr is a deprecated alias for DontFragment
// Deprecated: Please use DontFragment
type DontFragmentAttr = DontFragment
// DontFragment represents DONT-FRAGMENT attribute.
//
// This attribute is used by the client to request that the server set
// the DF (Don't Fragment) bit in the IP header when relaying the
// application data onward to the peer. This attribute has no value
// part and thus the attribute length field is 0.
//
// RFC 5766 Section 14.8
type DontFragment struct{}
const dontFragmentSize = 0
2022-03-10 09:44:48 +00:00
// AddTo adds DONT-FRAGMENT attribute to message.
2024-05-15 23:15:00 +00:00
func (DontFragment) AddTo(m *stun.Message) error {
2022-03-10 09:44:48 +00:00
m.Add(stun.AttrDontFragment, nil)
return nil
}
2024-05-15 23:15:00 +00:00
// GetFrom decodes DONT-FRAGMENT from message.
func (d *DontFragment) GetFrom(m *stun.Message) error {
v, err := m.Get(stun.AttrDontFragment)
if err != nil {
return err
}
2024-06-05 20:10:03 +00:00
return stun.CheckSize(stun.AttrDontFragment, len(v), dontFragmentSize)
2024-05-15 23:15:00 +00:00
}
2022-03-10 09:44:48 +00:00
// IsSet returns true if DONT-FRAGMENT attribute is set.
2024-05-15 23:15:00 +00:00
func (DontFragment) IsSet(m *stun.Message) bool {
2022-03-10 09:44:48 +00:00
_, err := m.Get(stun.AttrDontFragment)
return err == nil
}