@@ -12,7 +12,7 @@ defmodule ExICE.Priv.MDNS.Resolver do
1212 @ rtx_timeout_ms 500
1313
1414 @ spec start_link ( module ( ) ) :: GenServer . on_start ( )
15- def start_link ( transport_module \\ :gen_udp ) do
15+ def start_link ( transport_module \\ ExICE.Priv.Transport.UDP ) do
1616 GenServer . start_link ( __MODULE__ , transport_module , name: __MODULE__ )
1717 end
1818
@@ -28,39 +28,44 @@ defmodule ExICE.Priv.MDNS.Resolver do
2828
2929 @ impl true
3030 def init ( transport_module ) do
31- Logger . debug ( "Starting MDNS Resolver" )
31+ Logger . debug ( "Starting mDNS Resolver" )
3232 { :ok , % { transport_module: transport_module , cache: % { } } , { :continue , nil } }
3333 end
3434
3535 @ impl true
3636 def handle_continue ( _ , state ) do
3737 ret =
38- state . transport_module . open (
39- # Listen on the port specific to mDNS traffic.
40- # `add_membership` option only defines an address.
41- @ mdns_port ,
42- mode: :binary ,
43- reuseaddr: true ,
44- active: true ,
45- # Allow other apps to bind to @mdns_port.
46- # If there are multiple sockets, bound to the same port,
47- # and subscribed to the same group (in fact, if one socket
48- # subscribes to some group, all other sockets bound to
49- # the same port also join this group), all those sockets
50- # will receive every message. In other words, `reuseport` for
51- # multicast works differently than for casual sockets.
52- reuseport: true ,
53- # Support running two ICE agents on a single machine.
54- # In other case, our request won't be delivered to the mDNS address owner
55- # running on the same machine (e.g., a web browser).
56- multicast_loop: true ,
57- # Receive responses - they are sent to the multicast address.
58- # The second argument specifies interfaces where we should listen
59- # for multicast traffic.
60- # This option works on interfaces i.e. it affects all sockets
61- # bound to the same port.
62- add_membership: { { 224 , 0 , 0 , 251 } , { 0 , 0 , 0 , 0 } }
63- )
38+ if state . transport_module . transport ( ) == :udp do
39+ state . transport_module . setup_socket (
40+ nil ,
41+ # Listen on the port specific to mDNS traffic.
42+ # `add_membership` option only defines an address.
43+ @ mdns_port ,
44+ mode: :binary ,
45+ reuseaddr: true ,
46+ active: true ,
47+ # Allow other apps to bind to @mdns_port.
48+ # If there are multiple sockets, bound to the same port,
49+ # and subscribed to the same group (in fact, if one socket
50+ # subscribes to some group, all other sockets bound to
51+ # the same port also join this group), all those sockets
52+ # will receive every message. In other words, `reuseport` for
53+ # multicast works differently than for casual sockets.
54+ reuseport: true ,
55+ # Support running two ICE agents on a single machine.
56+ # In other case, our request won't be delivered to the mDNS address owner
57+ # running on the same machine (e.g., a web browser).
58+ multicast_loop: true ,
59+ # Receive responses - they are sent to the multicast address.
60+ # The second argument specifies interfaces where we should listen
61+ # for multicast traffic.
62+ # This option works on interfaces i.e. it affects all sockets
63+ # bound to the same port.
64+ add_membership: { { 224 , 0 , 0 , 251 } , { 0 , 0 , 0 , 0 } }
65+ )
66+ else
67+ { :error , :using_tcp_transport }
68+ end
6469
6570 case ret do
6671 { :ok , socket } ->
@@ -69,7 +74,7 @@ defmodule ExICE.Priv.MDNS.Resolver do
6974
7075 { :error , reason } ->
7176 Logger . warning ( """
72- Couldn't start MDNS resolver, reason: #{ reason } . MDNS candidates won't be resolved.
77+ Couldn't start mDNS resolver, reason: #{ reason } . mDNS candidates won't be resolved.
7378 """ )
7479
7580 { :stop , { :shutdown , reason } , state }
0 commit comments