Skip to content

Commit

Permalink
Fix Public API Breakage
Browse files Browse the repository at this point in the history
stun.TransactionID can't be changed, reverting
for now.

Resolves pion/demo-conference#7
  • Loading branch information
Sean-Der committed Oct 1, 2020
1 parent 85839ae commit 1d24ef2
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 36 deletions.
2 changes: 1 addition & 1 deletion agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func BenchmarkAgent_Process(b *testing.B) {
}
}()
b.ReportAllocs()
m := MustBuild(TransactionID())
m := MustBuild(TransactionID)
for i := 0; i < b.N; i++ {
if err := a.Process(m); err != nil {
b.Fatal(err)
Expand Down
42 changes: 21 additions & 21 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func TestClosedOrPanic(t *testing.T) {
}

func TestClient_Start(t *testing.T) {
response := MustBuild(TransactionID(), BindingSuccess)
response := MustBuild(TransactionID, BindingSuccess)
response.Encode()
write := make(chan struct{}, 1)
read := make(chan struct{}, 1)
Expand Down Expand Up @@ -196,7 +196,7 @@ func TestClient_Start(t *testing.T) {
if err := c.Close(); err == nil {
t.Error("second close should fail")
}
if err := c.Do(MustBuild(TransactionID()), nil); err == nil {
if err := c.Do(MustBuild(TransactionID), nil); err == nil {
t.Error("Do after Close should fail")
}
}()
Expand Down Expand Up @@ -230,7 +230,7 @@ func TestClient_Start(t *testing.T) {
}

func TestClient_Do(t *testing.T) {
response := MustBuild(TransactionID(), BindingSuccess)
response := MustBuild(TransactionID, BindingSuccess)
response.Encode()
conn := &testConnection{
b: response.Raw,
Expand All @@ -249,7 +249,7 @@ func TestClient_Do(t *testing.T) {
if err := c.Close(); err == nil {
t.Error("second close should fail")
}
if err := c.Do(MustBuild(TransactionID()), nil); err == nil {
if err := c.Do(MustBuild(TransactionID), nil); err == nil {
t.Error("Do after Close should fail")
}
}()
Expand All @@ -263,7 +263,7 @@ func TestClient_Do(t *testing.T) {
}); err != nil {
t.Error(err)
}
m = MustBuild(TransactionID())
m = MustBuild(TransactionID)
if err := c.Do(m, nil); err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -335,7 +335,7 @@ func (a errorAgent) Stop([TransactionIDSize]byte) error {
}

func TestClientAgentError(t *testing.T) {
response := MustBuild(TransactionID(), BindingSuccess)
response := MustBuild(TransactionID, BindingSuccess)
response.Encode()
conn := &testConnection{
b: response.Raw,
Expand Down Expand Up @@ -384,7 +384,7 @@ func TestClientConnErr(t *testing.T) {
t.Error(err)
}
}()
m := MustBuild(TransactionID())
m := MustBuild(TransactionID)
if err := c.Do(m, nil); err == nil {
t.Error("error expected")
}
Expand Down Expand Up @@ -412,7 +412,7 @@ func TestClientConnErrStopErr(t *testing.T) {
t.Error(err)
}
}()
m := MustBuild(TransactionID())
m := MustBuild(TransactionID)
if err := c.Do(m, NoopHandler()); err == nil {
t.Error("error expected")
}
Expand Down Expand Up @@ -470,7 +470,7 @@ func TestDialError(t *testing.T) {
}

func TestClientCloseErr(t *testing.T) {
response := MustBuild(TransactionID(), BindingSuccess)
response := MustBuild(TransactionID, BindingSuccess)
response.Encode()
conn := &testConnection{
b: response.Raw,
Expand All @@ -494,7 +494,7 @@ func TestClientCloseErr(t *testing.T) {
}

func TestWithNoConnClose(t *testing.T) {
response := MustBuild(TransactionID(), BindingSuccess)
response := MustBuild(TransactionID, BindingSuccess)
response.Encode()
closeErr := errClientCloseError
conn := &testConnection{
Expand Down Expand Up @@ -548,7 +548,7 @@ func (a *gcWaitAgent) Start(id [TransactionIDSize]byte, deadline time.Time) erro
}

func TestClientGC(t *testing.T) {
response := MustBuild(TransactionID(), BindingSuccess)
response := MustBuild(TransactionID, BindingSuccess)
response.Encode()
conn := &testConnection{
b: response.Raw,
Expand Down Expand Up @@ -614,7 +614,7 @@ func TestClientFinalizer(t *testing.T) {
}
clientFinalizer(c)
clientFinalizer(c)
response := MustBuild(TransactionID(), BindingSuccess)
response := MustBuild(TransactionID, BindingSuccess)
response.Encode()
conn = &testConnection{
b: response.Raw,
Expand Down Expand Up @@ -738,7 +738,7 @@ func (n *manualAgent) Stop(id [TransactionIDSize]byte) error {
}

func TestClientRetransmission(t *testing.T) {
response := MustBuild(TransactionID(), BindingSuccess)
response := MustBuild(TransactionID, BindingSuccess)
response.Encode()
connL, connR := net.Pipe()
defer connL.Close()
Expand Down Expand Up @@ -801,7 +801,7 @@ func TestClientRetransmission(t *testing.T) {
}

func testClientDoConcurrent(t *testing.T, concurrency int) {
response := MustBuild(TransactionID(), BindingSuccess)
response := MustBuild(TransactionID, BindingSuccess)
response.Encode()
connL, connR := net.Pipe()
defer connL.Close()
Expand Down Expand Up @@ -847,7 +847,7 @@ func testClientDoConcurrent(t *testing.T, concurrency int) {
wg.Add(1)
go func() {
defer wg.Done()
if doErr := c.Do(MustBuild(TransactionID(), BindingRequest), func(event Event) {
if doErr := c.Do(MustBuild(TransactionID, BindingRequest), func(event Event) {
if event.Error != nil {
t.Error("failed")
}
Expand Down Expand Up @@ -989,7 +989,7 @@ func TestClientClosedStart(t *testing.T) {
}

func TestWithNoRetransmit(t *testing.T) {
response := MustBuild(TransactionID(), BindingSuccess)
response := MustBuild(TransactionID, BindingSuccess)
response.Encode()
connL, connR := net.Pipe()
defer connL.Close()
Expand Down Expand Up @@ -1052,7 +1052,7 @@ func (c callbackClock) Now() time.Time {
}

func TestClientRTOStartErr(t *testing.T) {
response := MustBuild(TransactionID(), BindingSuccess)
response := MustBuild(TransactionID, BindingSuccess)
response.Encode()
connL, connR := net.Pipe()
defer connL.Close()
Expand Down Expand Up @@ -1164,7 +1164,7 @@ func TestClientRTOStartErr(t *testing.T) {
}

func TestClientRTOWriteErr(t *testing.T) {
response := MustBuild(TransactionID(), BindingSuccess)
response := MustBuild(TransactionID, BindingSuccess)
response.Encode()
connL, connR := net.Pipe()
defer connL.Close()
Expand Down Expand Up @@ -1285,7 +1285,7 @@ func TestClientRTOWriteErr(t *testing.T) {
}

func TestClientRTOAgentErr(t *testing.T) {
response := MustBuild(TransactionID(), BindingSuccess)
response := MustBuild(TransactionID, BindingSuccess)
response.Encode()
connL, connR := net.Pipe()
defer connL.Close()
Expand Down Expand Up @@ -1349,7 +1349,7 @@ func TestClientRTOAgentErr(t *testing.T) {
}

func TestClient_HandleProcessError(t *testing.T) {
response := MustBuild(TransactionID(), BindingSuccess)
response := MustBuild(TransactionID, BindingSuccess)
response.Encode()
connL, connR := net.Pipe()
defer connL.Close()
Expand Down Expand Up @@ -1391,7 +1391,7 @@ func TestClient_HandleProcessError(t *testing.T) {
}

func TestClientImmediateTimeout(t *testing.T) {
response := MustBuild(TransactionID(), BindingSuccess)
response := MustBuild(TransactionID, BindingSuccess)
connL, connR := net.Pipe()
defer connL.Close()
collector := new(manualCollector)
Expand Down
2 changes: 1 addition & 1 deletion cmd/stun-client/stun_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func main() {
if err != nil {
log.Fatal("dial:", err)
}
if err = c.Do(stun.MustBuild(stun.TransactionID(), stun.BindingRequest), func(res stun.Event) {
if err = c.Do(stun.MustBuild(stun.TransactionID, stun.BindingRequest), func(res stun.Event) {
if res.Error != nil {
log.Fatalln(err)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/stun-multiplex/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func keepAlive(c *stun.Client) {
// Keep-alive for NAT binding.
t := time.NewTicker(time.Second * 5)
for range t.C {
if err := c.Do(stun.MustBuild(stun.TransactionID(), stun.BindingRequest), func(res stun.Event) {
if err := c.Do(stun.MustBuild(stun.TransactionID, stun.BindingRequest), func(res stun.Event) {
if res.Error != nil {
panic(res.Error)
}
Expand Down Expand Up @@ -119,7 +119,7 @@ func main() {
// This can fail if your NAT Server is strict and will use separate ports
// for application data and STUN
var gotAddr stun.XORMappedAddress
if err = c.Do(stun.MustBuild(stun.TransactionID(), stun.BindingRequest), func(res stun.Event) {
if err = c.Do(stun.MustBuild(stun.TransactionID, stun.BindingRequest), func(res stun.Event) {
if res.Error != nil {
panic(res.Error)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/stun-nat-behaviour/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func MappingTests(addrStr string) error {

// Test I: Regular binding request
log.Info("Mapping Test I: Regular binding request")
request := stun.MustBuild(stun.TransactionID(), stun.BindingRequest)
request := stun.MustBuild(stun.TransactionID, stun.BindingRequest)

resp, err := mapTestConn.roundTrip(request, mapTestConn.RemoteAddr)
if err != nil {
Expand Down Expand Up @@ -153,7 +153,7 @@ func FilteringTests(addrStr string) error {

// Test I: Regular binding request
log.Info("Filtering Test I: Regular binding request")
request := stun.MustBuild(stun.TransactionID(), stun.BindingRequest)
request := stun.MustBuild(stun.TransactionID, stun.BindingRequest)

resp, err := mapTestConn.roundTrip(request, mapTestConn.RemoteAddr)
if err != nil || errors.Is(err, ErrTimedOut) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/stun-traversal/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func listen(conn *net.UDPConn) <-chan []byte {
}

func sendBindingRequest(conn *net.UDPConn, addr *net.UDPAddr) error {
m := stun.MustBuild(stun.TransactionID(), stun.BindingRequest)
m := stun.MustBuild(stun.TransactionID, stun.BindingRequest)

err := send(m.Raw, conn, addr)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions e2e/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func test(network string) {
log.Fatal(err) // nolint
}
// First request should error.
request, err := stun.Build(stun.BindingRequest, stun.TransactionID(), stun.Fingerprint)
request, err := stun.Build(stun.BindingRequest, stun.TransactionID, stun.Fingerprint)
if err != nil {
log.Fatalln("failed to build:", err) // nolint
}
Expand Down Expand Up @@ -64,7 +64,7 @@ func test(network string) {
}

// Authenticating and sending second request.
request, err = stun.Build(stun.TransactionID(), stun.BindingRequest,
request, err = stun.Build(stun.TransactionID, stun.BindingRequest,
stun.NewUsername(username), nonce, realm,
stun.NewLongTermIntegrity(username, realm.String(), password),
stun.Fingerprint,
Expand Down
2 changes: 1 addition & 1 deletion helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestMessage_Apply(t *testing.T) {
integrity = NewShortTermIntegrity("password")
decoded = new(Message)
)
m, err := Build(BindingRequest, TransactionID(),
m, err := Build(BindingRequest, TransactionID,
NewUsername("username"),
NewNonce("nonce"),
NewRealm("example.org"),
Expand Down
4 changes: 2 additions & 2 deletions message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ func TestAllocations(t *testing.T) {
// Not testing AttrMessageIntegrity because it allocates.
setters := []Setter{
BindingRequest,
TransactionID(),
TransactionID,
Fingerprint,
NewNonce("nonce"),
NewUsername("username"),
Expand Down Expand Up @@ -788,7 +788,7 @@ func TestAllocationsGetters(t *testing.T) {
// Not testing AttrMessageIntegrity because it allocates.
setters := []Setter{
BindingRequest,
TransactionID(),
TransactionID,
NewNonce("nonce"),
NewUsername("username"),
XORMappedAddress{
Expand Down
4 changes: 1 addition & 3 deletions stun.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,4 @@ func (transactionIDSetter) AddTo(m *Message) error {
}

// TransactionID is Setter for m.TransactionID.
func TransactionID() Setter {
return transactionIDSetter{}
}
var TransactionID Setter = transactionIDSetter{} //nolint:gochecknoglobals

0 comments on commit 1d24ef2

Please sign in to comment.