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

46 lines
1.2 KiB
Go
Raw Normal View History

2022-03-10 09:44:48 +00:00
package proto
2024-01-03 21:57:33 +00:00
import (
"github.com/pion/stun"
)
2022-03-10 09:44:48 +00:00
2024-01-03 21:57:33 +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-01-03 21:57:33 +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-01-03 21:57:33 +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
}
if err = stun.CheckSize(stun.AttrDontFragment, len(v), dontFragmentSize); err != nil {
return err
}
return nil
}
2022-03-10 09:44:48 +00:00
// IsSet returns true if DONT-FRAGMENT attribute is set.
2024-01-03 21:57:33 +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
}