[erlang-questions] Handle incoming UDP packets in DTLS server
pablo platt
pablo.platt@REDACTED
Tue Mar 12 13:16:43 CET 2019
Hi,
I'm trying to handle DTLS with other protocols on the same port but my UDP
packets are ignored by the dtls_connection pid. I'm using OTP-22.0-rc1.
I'm creating a UDP socket and dtls_connection pid and pass incoming DTLS
UDP packets to the pid:
Pid ! {udp, Socket, IP, Port, Data}
The UDP packets are ignored in dtls_connection:init/3 [2].
> init(Type, Event, State) ->
> gen_handshake(?FUNCTION_NAME, Type, Event, State).
>
I think the packets should arrive instead to [3].
> init({call, _} = Type, Event, #state{static_env = #static_env{role =
> server},
> protocol_specific = PS} = State) ->
>
dtls_packet.demux:dispatch/3 just sends incoming UDP packets to the
connection pid as normal messages [3] so I don't understand how it's
different than what I'm doing. Does dtls_packet_demux changes the gen_statem
state somehow before sending the first packet?
This is how I'm creating the dtls connection pid to bypass
dtls_packet_demux:
-include_lib("ssl/src/ssl_internal.hrl").
> listen(Socket, Options) ->
> {ok, Config} = ssl:handle_options(Options, server),
> #config{ssl = DTLSOpts, emulated = EmOpts} = Config,
> {ok, {IP, Port}} = inet:peername(Socket),
> Client = {IP, Port},
> User = self(),
> ConnArgs = [server, "localhost", Port, {self(), {Client, Socket}},
> {DTLSOpts, EmOpts, dtls_listener}, User,
> dtls_socket:default_cb_info()],
> case dtls_connection_sup:start_child(ConnArgs) of
> {ok, Pid} ->
> erlang:monitor(process, Pid),
> {ok, Pid};
> {error, Reason} ->
> {error, Reason}
> end.
>
> handle_info({udp, Socket, Addr, Port, Data}, #state{pid=Pid} = State)
> Pid ! {udp, Socket, Addr, Port, Data},
> {noreply, State};
>
[1]
https://github.com/erlang/otp/blob/master/lib/ssl/src/dtls_connection.erl#L463
[2]
https://github.com/erlang/otp/blob/master/lib/ssl/src/dtls_connection.erl#L454
[3]
https://github.com/erlang/otp/blob/master/lib/ssl/src/dtls_packet_demux.erl#L203
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20190312/923afb15/attachment.htm>
More information about the erlang-questions
mailing list