Skip to content

Commit

Permalink
FireFox now works with pion-TURN
Browse files Browse the repository at this point in the history
We were creating a reservation for every request (this is incorrect) a
reservation should only be created when EVEN-PORT is supplied.

FireFox would reject our STUN packets because it failed to comprehend
the reservation attribute
  • Loading branch information
Sean-Der committed May 18, 2018
1 parent 80cf10d commit 35054fc
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions internal/server/turn.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ func (s *Server) handleAllocateRequest(srcAddr *stun.TransportAddr, dstAddr *stu
Protocol: allocation.UDP,
}
requestedPort := 0
reservationToken := ""

// 2. The server checks if the 5-tuple is currently in use by an
// existing allocation. If yes, the server rejects the request with
Expand Down Expand Up @@ -210,6 +211,7 @@ func (s *Server) handleAllocateRequest(srcAddr *stun.TransportAddr, dstAddr *stu
return respondWithError(err, messageIntegrity, &stun.Err508InsufficentCapacity)
}
requestedPort = randomPort
reservationToken = randSeq(8)
}

// 7. At any point, the server MAY choose to reject the request with a
Expand Down Expand Up @@ -239,9 +241,6 @@ func (s *Server) handleAllocateRequest(srcAddr *stun.TransportAddr, dstAddr *stu
return respondWithError(err, messageIntegrity, &stun.Err508InsufficentCapacity)
}

reservationToken := randSeq(8)
allocation.CreateReservation(reservationToken, a.RelayAddr.Port)

// Once the allocation is created, the server replies with a success
// response. The success response contains:
// * An XOR-RELAYED-ADDRESS attribute containing the relayed transport
Expand All @@ -252,7 +251,7 @@ func (s *Server) handleAllocateRequest(srcAddr *stun.TransportAddr, dstAddr *stu
// address was reserved).
// * An XOR-MAPPED-ADDRESS attribute containing the client's IP address
// and port (from the 5-tuple).
return curriedSend(stun.ClassSuccessResponse, stun.MethodAllocate, m.TransactionID,
responseAttrs := []stun.Attribute{
&stun.XorRelayedAddress{
XorAddress: stun.XorAddress{
IP: dstAddr.IP,
Expand All @@ -262,17 +261,22 @@ func (s *Server) handleAllocateRequest(srcAddr *stun.TransportAddr, dstAddr *stu
&stun.Lifetime{
Duration: lifetimeDuration,
},
&stun.ReservationToken{
ReservationToken: reservationToken,
},
&stun.XorMappedAddress{
XorAddress: stun.XorAddress{
IP: srcAddr.IP,
Port: srcAddr.Port,
},
},
messageIntegrity,
)
}

if reservationToken != "" {
allocation.CreateReservation(reservationToken, a.RelayAddr.Port)
responseAttrs = append(responseAttrs, &stun.ReservationToken{
ReservationToken: reservationToken,
})
}

return curriedSend(stun.ClassSuccessResponse, stun.MethodAllocate, m.TransactionID, append(responseAttrs, messageIntegrity)...)
}

func (s *Server) handleRefreshRequest(srcAddr *stun.TransportAddr, dstAddr *stun.TransportAddr, m *stun.Message) error {
Expand Down

0 comments on commit 35054fc

Please sign in to comment.