Skip to content

Commit 6a3ee70

Browse files
committed
Refactor DontFragmentAttr to DontFragment
And add an deprecated type alias.
1 parent d7ae6d1 commit 6a3ee70

2 files changed

Lines changed: 21 additions & 10 deletions

File tree

internal/proto/dontfrag.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,30 @@ import (
44
"github.com/pion/stun"
55
)
66

7-
// DontFragmentAttr represents DONT-FRAGMENT attribute.
8-
type DontFragmentAttr struct{}
7+
// DontFragmentAttr is a deprecated alias for DontFragment
8+
// Deprecated: Please use DontFragment
9+
type DontFragmentAttr = DontFragment
10+
11+
// DontFragment represents DONT-FRAGMENT attribute.
12+
//
13+
// This attribute is used by the client to request that the server set
14+
// the DF (Don't Fragment) bit in the IP header when relaying the
15+
// application data onward to the peer. This attribute has no value
16+
// part and thus the attribute length field is 0.
17+
//
18+
// RFC 5766 Section 14.8
19+
type DontFragment struct{}
920

1021
const dontFragmentSize = 0
1122

1223
// AddTo adds DONT-FRAGMENT attribute to message.
13-
func (DontFragmentAttr) AddTo(m *stun.Message) error {
24+
func (DontFragment) AddTo(m *stun.Message) error {
1425
m.Add(stun.AttrDontFragment, nil)
1526
return nil
1627
}
1728

1829
// GetFrom decodes DONT-FRAGMENT from message.
19-
func (d *DontFragmentAttr) GetFrom(m *stun.Message) error {
30+
func (d *DontFragment) GetFrom(m *stun.Message) error {
2031
v, err := m.Get(stun.AttrDontFragment)
2132
if err != nil {
2233
return err
@@ -28,7 +39,7 @@ func (d *DontFragmentAttr) GetFrom(m *stun.Message) error {
2839
}
2940

3041
// IsSet returns true if DONT-FRAGMENT attribute is set.
31-
func (DontFragmentAttr) IsSet(m *stun.Message) bool {
42+
func (DontFragment) IsSet(m *stun.Message) bool {
3243
_, err := m.Get(stun.AttrDontFragment)
3344
return err == nil
3445
}

internal/proto/dontfrag_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@ import (
77
)
88

99
func TestDontFragment(t *testing.T) {
10-
var DontFragment DontFragmentAttr
10+
var dontFrag DontFragment
1111

1212
t.Run("False", func(t *testing.T) {
1313
m := new(stun.Message)
1414
m.WriteHeader()
15-
if DontFragment.IsSet(m) {
15+
if dontFrag.IsSet(m) {
1616
t.Error("should not be set")
1717
}
1818
})
1919
t.Run("AddTo", func(t *testing.T) {
2020
m := new(stun.Message)
21-
if err := DontFragment.AddTo(m); err != nil {
21+
if err := dontFrag.AddTo(m); err != nil {
2222
t.Error(err)
2323
}
2424
m.WriteHeader()
@@ -27,11 +27,11 @@ func TestDontFragment(t *testing.T) {
2727
if _, err := decoded.Write(m.Raw); err != nil {
2828
t.Fatal("failed to decode message:", err)
2929
}
30-
if !DontFragment.IsSet(m) {
30+
if !dontFrag.IsSet(m) {
3131
t.Error("should be set")
3232
}
3333
if wasAllocs(func() {
34-
DontFragment.IsSet(m)
34+
dontFrag.IsSet(m)
3535
}) {
3636
t.Error("unexpected allocations")
3737
}

0 commit comments

Comments
 (0)