dtls icon indicating copy to clipboard operation
dtls copied to clipboard

Handshaker doesn't handle "Read retransmit" event

Open mniestroj opened this issue 3 years ago • 1 comments

Your environment.

  • Version: v2.1.5
  • Other Information - stacktraces, related issues, suggestions how to fix, links for us to have context

What did you do?

  1. Run server: PION_LOG_TRACE=all go run ./examples/listen/psk/main.go from https://github.com/mniestroj/pion-dtls/tree/read-retransmit-reproduction
  2. Run client: PION_LOG_TRACE=all go run ./examples/dial/psk/main.go from https://github.com/pion/dtls/tree/v2.1.5

There is no valid handling of "Read retransmit" messages. Some additional logs here: wireshark client.log server.log

What did you expect?

According to "DTLS Timeout and Retransmission State Machine" in https://datatracker.ietf.org/doc/html/rfc6347#section-4.2.4 whenever a message is read that is a retransmit, it should make state machine to switch from "WAITING" to "SENDING" phase. This does not happen. In other words, "Read retransmit" from the following diagram is ignored:

                      +-----------+
                      | PREPARING |
                +---> |           | <--------------------+
                |     |           |                      |
                |     +-----------+                      |
                |           |                            |
                |           | Buffer next flight         |
                |           |                            |
                |          \|/                           |
                |     +-----------+                      |
                |     |           |                      |
                |     |  SENDING  |<------------------+  |
                |     |           |                   |  | Send
                |     +-----------+                   |  | HelloRequest
        Receive |           |                         |  |
           next |           | Send flight             |  | or
         flight |  +--------+                         |  |
                |  |        | Set retransmit timer    |  | Receive
                |  |       \|/                        |  | HelloRequest
                |  |  +-----------+                   |  | Send
                |  |  |           |                   |  | ClientHello
                +--)--|  WAITING  |-------------------+  |
                |  |  |           |   Timer expires   |  |
                |  |  +-----------+                   |  |
                |  |         |                        |  |
                |  |         |                        |  |
                |  |         +------------------------+  |
                |  |                Read retransmit      |
        Receive |  |                                     |
           last |  |                                     |
         flight |  |                                     |
                |  |                                     |
               \|/\|/                                    |
                                                         |
            +-----------+                                |
            |           |                                |
            | FINISHED  | -------------------------------+
            |           |
            +-----------+
                 |  /|\
                 |   |
                 |   |
                 +---+

              Read retransmit
           Retransmit last flight

          Figure 3. DTLS Timeout and Retransmission State Machine

What happened?

Handshaker's state machine only relies on "Timer expires", which is suboptimal for handling lossy communication with low-power and/or low-bandwidth nodes.

mniestroj avatar Jun 22 '22 15:06 mniestroj

I can pick this one up! Thanks for the detailed report @mniestroj!

hasheddan avatar Jul 06 '23 16:07 hasheddan