Skip to content

Commit

Permalink
agent: add Role type
Browse files Browse the repository at this point in the history
  • Loading branch information
ernado committed Oct 6, 2018
1 parent 81ad7ca commit 9ea721a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
9 changes: 9 additions & 0 deletions agent.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package ice

type Role byte

// Possible ICE Agent roles.
const (
Controlling Role = iota
Controlled
)
16 changes: 8 additions & 8 deletions icecontrol.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,28 @@ func (a *tieBreaker) GetFromAs(m *stun.Message, t stun.AttrType) error {
return nil
}

// Controlled represents ICE-CONTROLLED attribute.
type Controlled uint64
// AttrControlled represents ICE-CONTROLLED attribute.
type AttrControlled uint64

// AddTo adds ICE-CONTROLLED to message.
func (c Controlled) AddTo(m *stun.Message) error {
func (c AttrControlled) AddTo(m *stun.Message) error {
return tieBreaker(c).AddToAs(m, stun.AttrICEControlled)
}

// GetFrom decodes ICE-CONTROLLED from message.
func (c *Controlled) GetFrom(m *stun.Message) error {
func (c *AttrControlled) GetFrom(m *stun.Message) error {
return (*tieBreaker)(c).GetFromAs(m, stun.AttrICEControlled)
}

// Controlling represents ICE-CONTROLLING attribute.
type Controlling uint64
// AttrControlling represents ICE-CONTROLLING attribute.
type AttrControlling uint64

// AddTo adds ICE-CONTROLLING to message.
func (c Controlling) AddTo(m *stun.Message) error {
func (c AttrControlling) AddTo(m *stun.Message) error {
return tieBreaker(c).AddToAs(m, stun.AttrICEControlling)
}

// GetFrom decodes ICE-CONTROLLING from message.
func (c *Controlling) GetFrom(m *stun.Message) error {
func (c *AttrControlling) GetFrom(m *stun.Message) error {
return (*tieBreaker)(c).GetFromAs(m, stun.AttrICEControlling)
}
12 changes: 6 additions & 6 deletions icecontrol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

func TestControlled_GetFrom(t *testing.T) {
m := new(stun.Message)
var c Controlled
var c AttrControlled
if err := c.GetFrom(m); err != stun.ErrAttributeNotFound {
t.Error("unexpected error")
}
Expand All @@ -19,7 +19,7 @@ func TestControlled_GetFrom(t *testing.T) {
if _, err := m1.Write(m.Raw); err != nil {
t.Error(err)
}
var c1 Controlled
var c1 AttrControlled
if err := c1.GetFrom(m1); err != nil {
t.Error(err)
}
Expand All @@ -29,7 +29,7 @@ func TestControlled_GetFrom(t *testing.T) {
t.Run("IncorrectSize", func(t *testing.T) {
m3 := new(stun.Message)
m3.Add(stun.AttrICEControlled, make([]byte, 100))
var c2 Controlled
var c2 AttrControlled
if err := c2.GetFrom(m3); !stun.IsAttrSizeInvalid(err) {
t.Error("should error")
}
Expand All @@ -38,7 +38,7 @@ func TestControlled_GetFrom(t *testing.T) {

func TestControlling_GetFrom(t *testing.T) {
m := new(stun.Message)
var c Controlling
var c AttrControlling
if err := c.GetFrom(m); err != stun.ErrAttributeNotFound {
t.Error("unexpected error")
}
Expand All @@ -49,7 +49,7 @@ func TestControlling_GetFrom(t *testing.T) {
if _, err := m1.Write(m.Raw); err != nil {
t.Error(err)
}
var c1 Controlling
var c1 AttrControlling
if err := c1.GetFrom(m1); err != nil {
t.Error(err)
}
Expand All @@ -59,7 +59,7 @@ func TestControlling_GetFrom(t *testing.T) {
t.Run("IncorrectSize", func(t *testing.T) {
m3 := new(stun.Message)
m3.Add(stun.AttrICEControlling, make([]byte, 100))
var c2 Controlling
var c2 AttrControlling
if err := c2.GetFrom(m3); !stun.IsAttrSizeInvalid(err) {
t.Error("should error")
}
Expand Down

0 comments on commit 9ea721a

Please sign in to comment.