mirror of
https://github.com/gortc/stun.git
synced 2025-09-26 20:41:36 +08:00
all: backport pion/stun fixes (#64)
all: backport pion/stun fixes Co-authored-by: null <moises.marangon@gmail.com>
This commit is contained in:
@@ -14,7 +14,8 @@ Complies to [gortc principles](https://gortc.io/#principles) as core package.
|
||||
|
||||
See [example](https://godoc.org/github.com/gortc/stun#example-Message) and [stun server](https://github.com/gortc/stund) for simple usage.
|
||||
Also see [gortc/turn](https://github.com/gortc/turn) for TURN [[RFC5766](https://tools.ietf.org/html/rfc5766)] implementation and
|
||||
[gortcd](https://github.com/gortc/gortcd) for TURN and STUN server.
|
||||
[gortcd](https://github.com/gortc/gortcd) for TURN and STUN server. This repo was merged to [pion/stun](https://github.com/pion/stun)
|
||||
at version `v1.19.0`.
|
||||
|
||||
# Example
|
||||
You can get your current IP address from any STUN server by sending
|
||||
|
@@ -187,10 +187,10 @@ type ClientAgent interface {
|
||||
|
||||
// Client simulates "connection" to STUN server.
|
||||
type Client struct {
|
||||
rto int64 // time.Duration
|
||||
a ClientAgent
|
||||
c Connection
|
||||
close chan struct{}
|
||||
rto int64 // time.Duration
|
||||
rtoRate time.Duration
|
||||
maxAttempts int32
|
||||
closed bool
|
||||
|
19
message.go
19
message.go
@@ -104,17 +104,16 @@ func (m *Message) Reset() {
|
||||
m.Attributes = m.Attributes[:0]
|
||||
}
|
||||
|
||||
// grow ensures that internal buffer will fit v more bytes and
|
||||
// increases it capacity if necessary.
|
||||
func (m *Message) grow(v int) {
|
||||
// Not performing any optimizations here
|
||||
// (e.g. preallocate len(buf) * 2 to reduce allocations)
|
||||
// because they are already done by []byte implementation.
|
||||
n := len(m.Raw) + v
|
||||
for cap(m.Raw) < n {
|
||||
m.Raw = append(m.Raw, 0)
|
||||
// grow ensures that internal buffer has n length.
|
||||
func (m *Message) grow(n int) {
|
||||
if len(m.Raw) >= n {
|
||||
return
|
||||
}
|
||||
m.Raw = m.Raw[:n]
|
||||
if cap(m.Raw) >= n {
|
||||
m.Raw = m.Raw[:n]
|
||||
return
|
||||
}
|
||||
m.Raw = append(m.Raw, make([]byte, n-len(m.Raw))...)
|
||||
}
|
||||
|
||||
// Add appends new attribute to message. Not goroutine-safe.
|
||||
|
@@ -472,7 +472,7 @@ func TestMessage_Equal(t *testing.T) {
|
||||
func TestMessageGrow(t *testing.T) {
|
||||
m := New()
|
||||
m.grow(512)
|
||||
if len(m.Raw) < 532 {
|
||||
if len(m.Raw) < 512 {
|
||||
t.Error("Bad length", len(m.Raw))
|
||||
}
|
||||
}
|
||||
@@ -480,10 +480,10 @@ func TestMessageGrow(t *testing.T) {
|
||||
func TestMessageGrowSmaller(t *testing.T) {
|
||||
m := New()
|
||||
m.grow(2)
|
||||
if cap(m.Raw) < 22 {
|
||||
if cap(m.Raw) < 20 {
|
||||
t.Error("Bad capacity", cap(m.Raw))
|
||||
}
|
||||
if len(m.Raw) < 22 {
|
||||
if len(m.Raw) < 20 {
|
||||
t.Error("Bad length", len(m.Raw))
|
||||
}
|
||||
}
|
||||
|
@@ -124,6 +124,6 @@ func (v *TextAttribute) GetFromAs(m *Message, t AttrType) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*v = append((*v)[:0], a...)
|
||||
*v = a
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user