James Kuszmaul | 6439136 | 2021-01-17 11:32:00 -0800 | [diff] [blame^] | 1 | #pragma once |
| 2 | #include <rawrtcc/code.h> |
| 3 | #include <re.h> |
| 4 | |
| 5 | /** |
| 6 | * External DTLS role. |
| 7 | */ |
| 8 | enum rawrtc_external_dtls_role { |
| 9 | RAWRTC_EXTERNAL_DTLS_ROLE_CLIENT, |
| 10 | RAWRTC_EXTERNAL_DTLS_ROLE_SERVER, |
| 11 | }; |
| 12 | |
| 13 | /** |
| 14 | * External DTLS transport state. |
| 15 | */ |
| 16 | enum rawrtc_external_dtls_transport_state { |
| 17 | RAWRTC_EXTERNAL_DTLS_TRANSPORT_STATE_NEW_OR_CONNECTING, |
| 18 | RAWRTC_EXTERNAL_DTLS_TRANSPORT_STATE_CONNECTED, |
| 19 | RAWRTC_EXTERNAL_DTLS_TRANSPORT_STATE_CLOSED_OR_FAILED, |
| 20 | }; |
| 21 | |
| 22 | /** |
| 23 | * DTLS role getter. |
| 24 | * |
| 25 | * `*rolep` will contain the current external DTLS role. |
| 26 | * `arg` is the argument passed to the SCTP transport context. |
| 27 | * |
| 28 | * Return `RAWRTC_CODE_SUCCESS` in case the role has been set or any |
| 29 | * other code in case of an error. |
| 30 | */ |
| 31 | typedef enum rawrtc_code (*rawrtc_dtls_role_getter)( |
| 32 | enum rawrtc_external_dtls_role* const rolep, // de-referenced |
| 33 | void* const arg); |
| 34 | |
| 35 | /** |
| 36 | * DTLS transport state getter. |
| 37 | * |
| 38 | * `*statep` will contain the current external DTLS transport state. |
| 39 | * `arg` is the argument passed to the SCTP transport context. |
| 40 | * |
| 41 | * Return `RAWRTC_CODE_SUCCESS` in case the state has been set or any |
| 42 | * other code in case of an error. |
| 43 | */ |
| 44 | typedef enum rawrtc_code (*rawrtc_dtls_transport_state_getter)( |
| 45 | enum rawrtc_external_dtls_transport_state* const statep, // de-referenced |
| 46 | void* const arg); |
| 47 | |
| 48 | /** |
| 49 | * SCTP transport outbound data handler. |
| 50 | * |
| 51 | * `buffer` contains the data to be fed to the DTLS transport. |
| 52 | * Note that the `mbuf` structure shall not be `mem_ref`ed or |
| 53 | * `mem_deref`ed since it hasn't been allocated properly for |
| 54 | * optimisation purposes. This has been done since we expect you to |
| 55 | * either send this data directly or drop it. There's no need to hold |
| 56 | * data back. If you for any reason need the data after the callback |
| 57 | * returned, you are required to copy it. |
| 58 | * `tos` contains the type of service field as reported by usrsctp. |
| 59 | * `set_df` TODO: Probably don't fragment bit? Dunno... |
| 60 | * |
| 61 | * Return `RAWRTC_CODE_SUCCESS` in case the packet has been sent (or |
| 62 | * dropped) or any other code in case of an error. |
| 63 | */ |
| 64 | typedef enum rawrtc_code (*rawrtc_sctp_transport_outbound_handler)( |
| 65 | struct mbuf* const buffer, uint8_t const tos, uint8_t const set_df, void* const arg); |
| 66 | |
| 67 | /** |
| 68 | * SCTP transport detach handler. |
| 69 | * Will be called when the SCTP transport is about to be closed and |
| 70 | * should be detached from the underlying DTLS transport. At this |
| 71 | * point, no further data should be fed to the SCTP transport. |
| 72 | * |
| 73 | * `arg` is the argument passed to the SCTP transport context. |
| 74 | */ |
| 75 | typedef void (*rawrtc_sctp_transport_detach_handler)(void* const arg); |
| 76 | |
| 77 | /** |
| 78 | * SCTP transport destroyed handler. |
| 79 | * Will be called when the SCTP transport is about to be free'd. |
| 80 | * |
| 81 | * Note: This handler only exists for cleanup purposes. You may not use |
| 82 | * any of the transport's functions at this point. |
| 83 | * |
| 84 | * `arg` is the argument passed to the SCTP transport context. |
| 85 | */ |
| 86 | typedef void (*rawrtc_sctp_transport_destroyed_handler)(void* const arg); |
| 87 | |
| 88 | /** |
| 89 | * SCTP transport context. |
| 90 | */ |
| 91 | struct rawrtc_sctp_transport_context { |
| 92 | rawrtc_dtls_role_getter role_getter; |
| 93 | rawrtc_dtls_transport_state_getter state_getter; |
| 94 | rawrtc_sctp_transport_outbound_handler outbound_handler; |
| 95 | rawrtc_sctp_transport_detach_handler detach_handler; // nullable |
| 96 | rawrtc_sctp_transport_destroyed_handler destroyed_handler; // nullable |
| 97 | bool trace_packets; |
| 98 | void* arg; // nullable |
| 99 | }; |