Handle incoming UDP packets in DTLS server

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Handle incoming UDP packets in DTLS server

pablo platt-3
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};




_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Handle incoming UDP packets in DTLS server

Ingela Andin
Hi!

Den tis 12 mars 2019 kl 13:17 skrev pablo platt <[hidden email]>:
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};



_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions