@@ -208,8 +208,11 @@ defmodule ExWebRTC.DTLSTransport do
208208
209209 @ impl true
210210 def handle_info ( { :ex_ice , _from , { :data , _data } = msg } , state ) do
211- state = handle_ice_data ( msg , state )
212- { :noreply , state }
211+ case handle_ice_data ( msg , state ) do
212+ { :ok , state } -> { :noreply , state }
213+ # we use shutdown to avoid logging an error
214+ { :error , reason } -> { :stop , { :shutdown , reason } , state }
215+ end
213216 end
214217
215218 @ impl true
@@ -224,12 +227,12 @@ defmodule ExWebRTC.DTLSTransport do
224227 end
225228
226229 defp handle_ice_data ( { :data , << f , _rest :: binary >> = data } , state ) when f in 20 .. 64 do
227- # TODO: handle {:connection_closed, _}
228230 case ExDTLS . handle_data ( state . dtls , data ) do
229231 { :handshake_packets , packets , timeout } when state . ice_connected ->
230232 :ok = state . ice_transport . send_data ( state . ice_pid , packets )
231233 Process . send_after ( self ( ) , :dtls_timeout , timeout )
232- update_dtls_state ( state , :connecting )
234+ state = update_dtls_state ( state , :connecting )
235+ { :ok , state }
233236
234237 { :handshake_packets , packets , timeout } ->
235238 Logger . debug ( """
@@ -239,7 +242,8 @@ defmodule ExWebRTC.DTLSTransport do
239242
240243 Process . send_after ( self ( ) , :dtls_timeout , timeout )
241244 state = % { state | buffered_packets: packets }
242- update_dtls_state ( state , :connecting )
245+ state = update_dtls_state ( state , :connecting )
246+ { :ok , state }
243247
244248 { :handshake_finished , lkm , rkm , profile , packets } ->
245249 Logger . debug ( "DTLS handshake finished" )
@@ -253,19 +257,26 @@ defmodule ExWebRTC.DTLSTransport do
253257
254258 if peer_fingerprint == state . peer_fingerprint do
255259 :ok = setup_srtp ( state , lkm , rkm , profile )
256- update_dtls_state ( state , :connected )
260+ state = update_dtls_state ( state , :connected )
261+ { :ok , state }
257262 else
258263 Logger . debug ( "Non-matching peer cert fingerprint." )
259- update_dtls_state ( state , :failed )
264+ state = update_dtls_state ( state , :failed )
265+ { :ok , state }
260266 end
261267
262268 { :handshake_finished , lkm , rkm , profile } ->
263269 Logger . debug ( "DTLS handshake finished" )
264270 :ok = setup_srtp ( state , lkm , rkm , profile )
265- update_dtls_state ( state , :connected )
271+ state = update_dtls_state ( state , :connected )
272+ { :ok , state }
266273
267274 :handshake_want_read ->
268- state
275+ { :ok , state }
276+
277+ { :error , reason } = error ->
278+ Logger . debug ( "DTLS error: #{ reason } " )
279+ error
269280 end
270281 end
271282
@@ -285,15 +296,15 @@ defmodule ExWebRTC.DTLSTransport do
285296 Logger . error ( "Failed to decrypt SRTP/SRTCP, reason: #{ inspect ( reason ) } " )
286297 end
287298
288- state
299+ { :ok , state }
289300 end
290301
291302 defp handle_ice_data ( { :data , _data } , state ) do
292303 Logger . warning (
293304 "Received RTP/RTCP packets, but DTLS handshake hasn't been finished yet. Ignoring."
294305 )
295306
296- state
307+ { :ok , state }
297308 end
298309
299310 defp setup_srtp ( state , local_keying_material , remote_keying_material , profile ) do
0 commit comments