[erlang-questions] Handle incoming UDP packets in DTLS server

Ingela Andin ingela.andin@REDACTED
Thu Mar 14 13:58:23 CET 2019


Hi!

Den tis 12 mars 2019 kl 13:17 skrev pablo platt <pablo.platt@REDACTED>:

> 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?
>
>
It dispatches the packets in an active once manner to the DTLS connection
process that will tell the multiplexer when it wants more data.



> This is how I'm creating the dtls connection pid to bypass
> dtls_packet_demux:
>
>
I think what we really want is callbacks to the multiplexor so that it
should not need to be bypassed but extended.


Regards Ingela Erlang/OTP team - Ericsson AB



> -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
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20190314/4f29db83/attachment.htm>


More information about the erlang-questions mailing list