diff --git a/agent.go b/agent.go new file mode 100644 index 0000000..cb42de8 --- /dev/null +++ b/agent.go @@ -0,0 +1,9 @@ +package ice + +type Role byte + +// Possible ICE Agent roles. +const ( + Controlling Role = iota + Controlled +) diff --git a/icecontrol.go b/icecontrol.go index ffa285f..5d4b824 100644 --- a/icecontrol.go +++ b/icecontrol.go @@ -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) } diff --git a/icecontrol_test.go b/icecontrol_test.go index ef79fce..c6ea46f 100644 --- a/icecontrol_test.go +++ b/icecontrol_test.go @@ -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") } @@ -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) } @@ -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") } @@ -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") } @@ -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) } @@ -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") }