Squashed 'third_party/rawrtc/rawrtc/' content from commit aa3ae4b24

Change-Id: I38a655a4259b62f591334e90a1315bd4e7e4d8ec
git-subtree-dir: third_party/rawrtc/rawrtc
git-subtree-split: aa3ae4b247275cc6e69c30613b3a4ba7fdc82d1b
diff --git a/tools/data-channel-sctp-echo.c b/tools/data-channel-sctp-echo.c
new file mode 100644
index 0000000..8dd10f0
--- /dev/null
+++ b/tools/data-channel-sctp-echo.c
@@ -0,0 +1,419 @@
+#include "helper/handler.h"
+#include "helper/parameters.h"
+#include "helper/utils.h"
+#include <rawrtc.h>
+#include <rawrtcc.h>
+#include <rawrtcdc.h>
+#include <re.h>
+#include <stdlib.h>  // exit
+#include <string.h>  // memcpy
+#include <unistd.h>  // STDIN_FILENO
+
+#define DEBUG_MODULE "data-channel-sctp-echo-app"
+#define DEBUG_LEVEL 7
+#include <re_dbg.h>
+
+enum {
+    TRANSPORT_BUFFER_LENGTH = 1048576,  // 1 MiB
+};
+
+struct parameters {
+    struct rawrtc_ice_parameters* ice_parameters;
+    struct rawrtc_ice_candidates* ice_candidates;
+    struct rawrtc_dtls_parameters* dtls_parameters;
+    struct sctp_parameters sctp_parameters;
+};
+
+// Note: Shadows struct client
+struct data_channel_sctp_client {
+    char* name;
+    char** ice_candidate_types;
+    size_t n_ice_candidate_types;
+    struct rawrtc_ice_gather_options* gather_options;
+    enum rawrtc_ice_role role;
+    struct rawrtc_certificate* certificate;
+    struct rawrtc_ice_gatherer* gatherer;
+    struct rawrtc_ice_transport* ice_transport;
+    struct rawrtc_dtls_transport* dtls_transport;
+    struct rawrtc_sctp_transport* sctp_transport;
+    struct rawrtc_data_transport* data_transport;
+    struct list data_channels;
+    struct parameters local_parameters;
+    struct parameters remote_parameters;
+};
+
+static void print_local_parameters(struct data_channel_sctp_client* client);
+
+static void ice_gatherer_local_candidate_handler(
+    struct rawrtc_ice_candidate* const candidate,
+    char const* const url,  // read-only
+    void* const arg) {
+    struct data_channel_sctp_client* const client = arg;
+
+    // Print local candidate
+    default_ice_gatherer_local_candidate_handler(candidate, url, arg);
+
+    // Print local parameters (if last candidate)
+    if (!candidate) {
+        print_local_parameters(client);
+    }
+}
+
+/*
+ * Print the data channel's received message's size and echo the
+ * message back.
+ */
+static void data_channel_message_handler(
+    struct mbuf* const buffer,
+    enum rawrtc_data_channel_message_flag const flags,
+    void* const arg  // will be casted to `struct data_channel_helper*`
+) {
+    struct data_channel_helper* const channel = arg;
+    struct data_channel_sctp_client* const client =
+        (struct data_channel_sctp_client*) channel->client;
+    enum rawrtc_code error;
+    (void) flags;
+
+    // Print message size
+    default_data_channel_message_handler(buffer, flags, arg);
+
+    // Send message
+    DEBUG_PRINTF("(%s) Sending %zu bytes\n", client->name, mbuf_get_left(buffer));
+    error = rawrtc_data_channel_send(
+        channel->channel, buffer,
+        flags & RAWRTC_DATA_CHANNEL_MESSAGE_FLAG_IS_BINARY ? true : false);
+    if (error) {
+        DEBUG_WARNING("Could not send, reason: %s\n", rawrtc_code_to_str(error));
+    }
+}
+
+/*
+ * Handle the newly created data channel.
+ */
+static void data_channel_handler(
+    struct rawrtc_data_channel* const channel,  // read-only, MUST be referenced when used
+    void* const arg  // will be casted to `struct client*`
+) {
+    struct data_channel_sctp_client* const client = arg;
+    struct data_channel_helper* channel_helper;
+
+    // Print channel
+    default_data_channel_handler(channel, arg);
+
+    // Create data channel helper instance & add to list
+    // Note: In this case we need to reference the channel because we have not created it
+    data_channel_helper_create_from_channel(&channel_helper, mem_ref(channel), arg, NULL);
+    list_append(&client->data_channels, &channel_helper->le, channel_helper);
+
+    // Set handler argument & handlers
+    EOE(rawrtc_data_channel_set_arg(channel, channel_helper));
+    EOE(rawrtc_data_channel_set_open_handler(channel, default_data_channel_open_handler));
+    EOE(rawrtc_data_channel_set_buffered_amount_low_handler(
+        channel, default_data_channel_buffered_amount_low_handler));
+    EOE(rawrtc_data_channel_set_error_handler(channel, default_data_channel_error_handler));
+    EOE(rawrtc_data_channel_set_close_handler(channel, default_data_channel_close_handler));
+    EOE(rawrtc_data_channel_set_message_handler(channel, data_channel_message_handler));
+}
+
+static void client_init(struct data_channel_sctp_client* const client) {
+    struct rawrtc_certificate* certificates[1];
+
+    // Generate certificates
+    EOE(rawrtc_certificate_generate(&client->certificate, NULL));
+    certificates[0] = client->certificate;
+
+    // Create ICE gatherer
+    EOE(rawrtc_ice_gatherer_create(
+        &client->gatherer, client->gather_options, default_ice_gatherer_state_change_handler,
+        default_ice_gatherer_error_handler, ice_gatherer_local_candidate_handler, client));
+
+    // Create ICE transport
+    EOE(rawrtc_ice_transport_create(
+        &client->ice_transport, client->gatherer, default_ice_transport_state_change_handler,
+        default_ice_transport_candidate_pair_change_handler, client));
+
+    // Create DTLS transport
+    EOE(rawrtc_dtls_transport_create(
+        &client->dtls_transport, client->ice_transport, certificates, ARRAY_SIZE(certificates),
+        default_dtls_transport_state_change_handler, default_dtls_transport_error_handler, client));
+
+    // Create SCTP transport
+    EOE(rawrtc_sctp_transport_create(
+        &client->sctp_transport, client->dtls_transport,
+        client->local_parameters.sctp_parameters.port, data_channel_handler,
+        default_sctp_transport_state_change_handler, client));
+    EOE(rawrtc_sctp_transport_set_buffer_length(
+        client->sctp_transport, TRANSPORT_BUFFER_LENGTH, TRANSPORT_BUFFER_LENGTH));
+
+    // Get data transport
+    EOE(rawrtc_sctp_transport_get_data_transport(&client->data_transport, client->sctp_transport));
+}
+
+static void client_start_gathering(struct data_channel_sctp_client* const client) {
+    // Start gathering
+    EOE(rawrtc_ice_gatherer_gather(client->gatherer, NULL));
+}
+
+static void client_start_transports(struct data_channel_sctp_client* const client) {
+    struct parameters* const remote_parameters = &client->remote_parameters;
+
+    // Start ICE transport
+    EOE(rawrtc_ice_transport_start(
+        client->ice_transport, client->gatherer, remote_parameters->ice_parameters, client->role));
+
+    // Start DTLS transport
+    EOE(rawrtc_dtls_transport_start(client->dtls_transport, remote_parameters->dtls_parameters));
+
+    // Start SCTP transport
+    EOE(rawrtc_sctp_transport_start(
+        client->sctp_transport, remote_parameters->sctp_parameters.capabilities,
+        remote_parameters->sctp_parameters.port));
+}
+
+static void parameters_destroy(struct parameters* const parameters) {
+    // Un-reference
+    parameters->ice_parameters = mem_deref(parameters->ice_parameters);
+    parameters->ice_candidates = mem_deref(parameters->ice_candidates);
+    parameters->dtls_parameters = mem_deref(parameters->dtls_parameters);
+    if (parameters->sctp_parameters.capabilities) {
+        parameters->sctp_parameters.capabilities =
+            mem_deref(parameters->sctp_parameters.capabilities);
+    }
+}
+
+static void client_stop(struct data_channel_sctp_client* const client) {
+    // Clear data channels
+    list_flush(&client->data_channels);
+
+    // Stop all transports & gatherer
+    if (client->sctp_transport) {
+        EOE(rawrtc_sctp_transport_stop(client->sctp_transport));
+    }
+    if (client->dtls_transport) {
+        EOE(rawrtc_dtls_transport_stop(client->dtls_transport));
+    }
+    if (client->ice_transport) {
+        EOE(rawrtc_ice_transport_stop(client->ice_transport));
+    }
+    if (client->gatherer) {
+        EOE(rawrtc_ice_gatherer_close(client->gatherer));
+    }
+
+    // Un-reference & close
+    parameters_destroy(&client->remote_parameters);
+    parameters_destroy(&client->local_parameters);
+    client->data_transport = mem_deref(client->data_transport);
+    client->sctp_transport = mem_deref(client->sctp_transport);
+    client->dtls_transport = mem_deref(client->dtls_transport);
+    client->ice_transport = mem_deref(client->ice_transport);
+    client->gatherer = mem_deref(client->gatherer);
+    client->certificate = mem_deref(client->certificate);
+    client->gather_options = mem_deref(client->gather_options);
+
+    // Stop listening on STDIN
+    fd_close(STDIN_FILENO);
+}
+
+static void client_set_parameters(struct data_channel_sctp_client* const client) {
+    struct parameters* const remote_parameters = &client->remote_parameters;
+
+    // Set remote ICE candidates
+    EOE(rawrtc_ice_transport_set_remote_candidates(
+        client->ice_transport, remote_parameters->ice_candidates->candidates,
+        remote_parameters->ice_candidates->n_candidates));
+}
+
+static void parse_remote_parameters(int flags, void* arg) {
+    struct data_channel_sctp_client* const client = arg;
+    enum rawrtc_code error;
+    struct odict* dict = NULL;
+    struct odict* node = NULL;
+    struct rawrtc_ice_parameters* ice_parameters = NULL;
+    struct rawrtc_ice_candidates* ice_candidates = NULL;
+    struct rawrtc_dtls_parameters* dtls_parameters = NULL;
+    struct sctp_parameters sctp_parameters = {0};
+    (void) flags;
+
+    // Get dict from JSON
+    error = get_json_stdin(&dict);
+    if (error) {
+        goto out;
+    }
+
+    // Decode JSON
+    error |= dict_get_entry(&node, dict, "iceParameters", ODICT_OBJECT, true);
+    error |= get_ice_parameters(&ice_parameters, node);
+    error |= dict_get_entry(&node, dict, "iceCandidates", ODICT_ARRAY, true);
+    error |= get_ice_candidates(&ice_candidates, node, arg);
+    error |= dict_get_entry(&node, dict, "dtlsParameters", ODICT_OBJECT, true);
+    error |= get_dtls_parameters(&dtls_parameters, node);
+    error |= dict_get_entry(&node, dict, "sctpParameters", ODICT_OBJECT, true);
+    error |= get_sctp_parameters(&sctp_parameters, node);
+
+    // Ok?
+    if (error) {
+        DEBUG_WARNING("Invalid remote parameters\n");
+        if (sctp_parameters.capabilities) {
+            mem_deref(sctp_parameters.capabilities);
+        }
+        goto out;
+    }
+
+    // Set parameters & start transports
+    client->remote_parameters.ice_parameters = mem_ref(ice_parameters);
+    client->remote_parameters.ice_candidates = mem_ref(ice_candidates);
+    client->remote_parameters.dtls_parameters = mem_ref(dtls_parameters);
+    memcpy(&client->remote_parameters.sctp_parameters, &sctp_parameters, sizeof(sctp_parameters));
+    DEBUG_INFO("Applying remote parameters\n");
+    client_set_parameters(client);
+    client_start_transports(client);
+
+out:
+    // Un-reference
+    mem_deref(dtls_parameters);
+    mem_deref(ice_candidates);
+    mem_deref(ice_parameters);
+    mem_deref(dict);
+
+    // Exit?
+    if (error == RAWRTC_CODE_NO_VALUE) {
+        DEBUG_NOTICE("Exiting\n");
+
+        // Stop client & bye
+        client_stop(client);
+        re_cancel();
+    }
+}
+
+static void client_get_parameters(struct data_channel_sctp_client* const client) {
+    struct parameters* const local_parameters = &client->local_parameters;
+
+    // Get local ICE parameters
+    EOE(rawrtc_ice_gatherer_get_local_parameters(
+        &local_parameters->ice_parameters, client->gatherer));
+
+    // Get local ICE candidates
+    EOE(rawrtc_ice_gatherer_get_local_candidates(
+        &local_parameters->ice_candidates, client->gatherer));
+
+    // Get local DTLS parameters
+    EOE(rawrtc_dtls_transport_get_local_parameters(
+        &local_parameters->dtls_parameters, client->dtls_transport));
+
+    // Get local SCTP parameters
+    EOE(rawrtc_sctp_transport_get_capabilities(&local_parameters->sctp_parameters.capabilities));
+    EOE(rawrtc_sctp_transport_get_port(
+        &local_parameters->sctp_parameters.port, client->sctp_transport));
+}
+
+static void print_local_parameters(struct data_channel_sctp_client* client) {
+    struct odict* dict;
+    struct odict* node;
+
+    // Get local parameters
+    client_get_parameters(client);
+
+    // Create dict
+    EOR(odict_alloc(&dict, 16));
+
+    // Create nodes
+    EOR(odict_alloc(&node, 16));
+    set_ice_parameters(client->local_parameters.ice_parameters, node);
+    EOR(odict_entry_add(dict, "iceParameters", ODICT_OBJECT, node));
+    mem_deref(node);
+    EOR(odict_alloc(&node, 16));
+    set_ice_candidates(client->local_parameters.ice_candidates, node);
+    EOR(odict_entry_add(dict, "iceCandidates", ODICT_ARRAY, node));
+    mem_deref(node);
+    EOR(odict_alloc(&node, 16));
+    set_dtls_parameters(client->local_parameters.dtls_parameters, node);
+    EOR(odict_entry_add(dict, "dtlsParameters", ODICT_OBJECT, node));
+    mem_deref(node);
+    EOR(odict_alloc(&node, 16));
+    set_sctp_parameters(client->sctp_transport, &client->local_parameters.sctp_parameters, node);
+    EOR(odict_entry_add(dict, "sctpParameters", ODICT_OBJECT, node));
+    mem_deref(node);
+
+    // Print JSON
+    DEBUG_INFO("Local Parameters:\n%H\n", json_encode_odict, dict);
+
+    // Un-reference
+    mem_deref(dict);
+}
+
+static void exit_with_usage(char* program) {
+    DEBUG_WARNING("Usage: %s <0|1 (ice-role)> [<sctp-port>] [<ice-candidate-type> ...]", program);
+    exit(1);
+}
+
+int main(int argc, char* argv[argc + 1]) {
+    char** ice_candidate_types = NULL;
+    size_t n_ice_candidate_types = 0;
+    enum rawrtc_ice_role role;
+    struct rawrtc_ice_gather_options* gather_options;
+    char* const turn_zwuenf_org_urls[] = {"stun:turn.zwuenf.org"};
+    struct data_channel_sctp_client client = {0};
+    (void) client.ice_candidate_types;
+    (void) client.n_ice_candidate_types;
+
+    // Debug
+    dbg_init(DBG_DEBUG, DBG_ALL);
+    DEBUG_PRINTF("Init\n");
+
+    // Initialise
+    EOE(rawrtc_init(true));
+
+    // Check arguments length
+    if (argc < 2) {
+        exit_with_usage(argv[0]);
+    }
+
+    // Get ICE role
+    if (get_ice_role(&role, argv[1])) {
+        exit_with_usage(argv[0]);
+    }
+
+    // Get SCTP port (optional)
+    if (argc >= 3 && !str_to_uint16(&client.local_parameters.sctp_parameters.port, argv[2])) {
+        exit_with_usage(argv[0]);
+    }
+
+    // Get enabled ICE candidate types to be added (optional)
+    if (argc >= 4) {
+        ice_candidate_types = &argv[3];
+        n_ice_candidate_types = (size_t) argc - 3;
+    }
+
+    // Create ICE gather options
+    EOE(rawrtc_ice_gather_options_create(&gather_options, RAWRTC_ICE_GATHER_POLICY_ALL));
+
+    // Add ICE servers to ICE gather options
+    EOE(rawrtc_ice_gather_options_add_server(
+        gather_options, turn_zwuenf_org_urls, ARRAY_SIZE(turn_zwuenf_org_urls), NULL, NULL,
+        RAWRTC_ICE_CREDENTIAL_TYPE_NONE));
+
+    // Set client fields
+    client.name = "A";
+    client.ice_candidate_types = ice_candidate_types;
+    client.n_ice_candidate_types = n_ice_candidate_types;
+    client.gather_options = gather_options;
+    client.role = role;
+    list_init(&client.data_channels);
+
+    // Setup client
+    client_init(&client);
+
+    // Start gathering
+    client_start_gathering(&client);
+
+    // Listen on stdin
+    EOR(fd_listen(STDIN_FILENO, FD_READ, parse_remote_parameters, &client));
+
+    // Start main loop
+    EOR(re_main(default_signal_handler));
+
+    // Stop client & bye
+    client_stop(&client);
+    before_exit();
+    return 0;
+}
diff --git a/tools/data-channel-sctp-loopback.c b/tools/data-channel-sctp-loopback.c
new file mode 100644
index 0000000..0426209
--- /dev/null
+++ b/tools/data-channel-sctp-loopback.c
@@ -0,0 +1,348 @@
+#include "helper/handler.h"
+#include "helper/utils.h"
+#include <rawrtc.h>
+#include <rawrtcc.h>
+#include <rawrtcdc.h>
+#include <re.h>
+#include <stdlib.h>  // exit
+#include <unistd.h>  // STDIN_FILENO
+
+#define DEBUG_MODULE "data-channel-sctp-loopback-app"
+#define DEBUG_LEVEL 7
+#include <re_dbg.h>
+
+enum {
+    TRANSPORT_BUFFER_LENGTH = 1048576,  // 1 MiB
+};
+
+// Note: Shadows struct client
+struct data_channel_sctp_client {
+    char* name;
+    char** ice_candidate_types;
+    size_t n_ice_candidate_types;
+    struct rawrtc_ice_gather_options* gather_options;
+    struct rawrtc_ice_parameters* ice_parameters;
+    struct rawrtc_dtls_parameters* dtls_parameters;
+    struct rawrtc_sctp_capabilities* sctp_capabilities;
+    enum rawrtc_ice_role role;
+    struct rawrtc_certificate* certificate;
+    uint16_t sctp_port;
+    struct rawrtc_ice_gatherer* gatherer;
+    struct rawrtc_ice_transport* ice_transport;
+    struct rawrtc_dtls_transport* dtls_transport;
+    struct rawrtc_sctp_transport* sctp_transport;
+    struct rawrtc_data_transport* data_transport;
+    struct data_channel_helper* data_channel_negotiated;
+    struct data_channel_helper* data_channel;
+    struct data_channel_sctp_client* other_client;
+};
+
+static struct tmr timer = {0};
+
+static void timer_handler(void* arg) {
+    struct data_channel_helper* const channel = arg;
+    struct data_channel_sctp_client* const client =
+        (struct data_channel_sctp_client*) channel->client;
+    struct mbuf* buffer;
+    enum rawrtc_code error;
+    enum rawrtc_dtls_role role;
+
+    // Compose message (16 MiB)
+    buffer = mbuf_alloc(1 << 24);
+    EOE(buffer ? RAWRTC_CODE_SUCCESS : RAWRTC_CODE_NO_MEMORY);
+    EOR(mbuf_fill(buffer, 'M', mbuf_get_space(buffer)));
+    mbuf_set_pos(buffer, 0);
+
+    // Send message
+    DEBUG_PRINTF("(%s) Sending %zu bytes\n", client->name, mbuf_get_left(buffer));
+    error = rawrtc_data_channel_send(channel->channel, buffer, true);
+    if (error) {
+        DEBUG_WARNING("Could not send, reason: %s\n", rawrtc_code_to_str(error));
+    }
+    mem_deref(buffer);
+
+    // Get DTLS role
+    EOE(rawrtc_dtls_parameters_get_role(&role, client->dtls_parameters));
+    if (role == RAWRTC_DTLS_ROLE_CLIENT) {
+        // Close bear-noises
+        DEBUG_PRINTF("(%s) Closing channel\n", client->name, channel->label);
+        EOR(rawrtc_data_channel_close(client->data_channel->channel));
+    }
+}
+
+static void data_channel_open_handler(void* const arg) {
+    struct data_channel_helper* const channel = arg;
+    struct data_channel_sctp_client* const client =
+        (struct data_channel_sctp_client*) channel->client;
+    struct mbuf* buffer;
+    enum rawrtc_code error;
+
+    // Print open event
+    default_data_channel_open_handler(arg);
+
+    // Send data delayed on bear-noises
+    if (str_cmp(channel->label, "bear-noises") == 0) {
+        tmr_start(&timer, 1000, timer_handler, channel);
+        return;
+    }
+
+    // Compose message (256 KiB)
+    buffer = mbuf_alloc(1 << 18);
+    EOE(buffer ? RAWRTC_CODE_SUCCESS : RAWRTC_CODE_NO_MEMORY);
+    EOR(mbuf_fill(buffer, 'M', mbuf_get_space(buffer)));
+    mbuf_set_pos(buffer, 0);
+
+    // Send message
+    DEBUG_PRINTF("(%s) Sending %zu bytes\n", client->name, mbuf_get_left(buffer));
+    error = rawrtc_data_channel_send(channel->channel, buffer, true);
+    if (error) {
+        DEBUG_WARNING("Could not send, reason: %s\n", rawrtc_code_to_str(error));
+    }
+    mem_deref(buffer);
+}
+
+static void ice_gatherer_local_candidate_handler(
+    struct rawrtc_ice_candidate* const candidate,
+    char const* const url,  // read-only
+    void* const arg) {
+    struct data_channel_sctp_client* const client = arg;
+
+    // Print local candidate
+    default_ice_gatherer_local_candidate_handler(candidate, url, arg);
+
+    // Add to other client as remote candidate (if type enabled)
+    add_to_other_if_ice_candidate_type_enabled(arg, candidate, client->other_client->ice_transport);
+}
+
+static void dtls_transport_state_change_handler(
+    enum rawrtc_dtls_transport_state const state,  // read-only
+    void* const arg) {
+    struct data_channel_sctp_client* const client = arg;
+
+    // Print state
+    default_dtls_transport_state_change_handler(state, arg);
+
+    // Open? Create new data channel
+    // TODO: Move this once we can create data channels earlier
+    if (state == RAWRTC_DTLS_TRANSPORT_STATE_CONNECTED) {
+        enum rawrtc_dtls_role role;
+
+        // Renew DTLS parameters
+        mem_deref(client->dtls_parameters);
+        EOE(rawrtc_dtls_transport_get_local_parameters(
+            &client->dtls_parameters, client->dtls_transport));
+
+        // Get DTLS role
+        EOE(rawrtc_dtls_parameters_get_role(&role, client->dtls_parameters));
+        DEBUG_PRINTF("(%s) DTLS role: %s\n", client->name, rawrtc_dtls_role_to_str(role));
+
+        // Client? Create data channel
+        if (role == RAWRTC_DTLS_ROLE_CLIENT) {
+            struct rawrtc_data_channel_parameters* channel_parameters;
+
+            // Create data channel helper
+            data_channel_helper_create(
+                &client->data_channel, (struct client*) client, "bear-noises");
+
+            // Create data channel parameters
+            EOE(rawrtc_data_channel_parameters_create(
+                &channel_parameters, client->data_channel->label,
+                RAWRTC_DATA_CHANNEL_TYPE_RELIABLE_UNORDERED, 0, NULL, false, 0));
+
+            // Create data channel
+            EOE(rawrtc_data_channel_create(
+                &client->data_channel->channel, client->data_transport, channel_parameters,
+                data_channel_open_handler, default_data_channel_buffered_amount_low_handler,
+                default_data_channel_error_handler, default_data_channel_close_handler,
+                default_data_channel_message_handler, client->data_channel));
+
+            // Un-reference
+            mem_deref(channel_parameters);
+        }
+    }
+}
+
+static void client_init(struct data_channel_sctp_client* const local) {
+    struct rawrtc_certificate* certificates[1];
+    struct rawrtc_data_channel_parameters* channel_parameters;
+
+    // Generate certificates
+    EOE(rawrtc_certificate_generate(&local->certificate, NULL));
+    certificates[0] = local->certificate;
+
+    // Create ICE gatherer
+    EOE(rawrtc_ice_gatherer_create(
+        &local->gatherer, local->gather_options, default_ice_gatherer_state_change_handler,
+        default_ice_gatherer_error_handler, ice_gatherer_local_candidate_handler, local));
+
+    // Create ICE transport
+    EOE(rawrtc_ice_transport_create(
+        &local->ice_transport, local->gatherer, default_ice_transport_state_change_handler,
+        default_ice_transport_candidate_pair_change_handler, local));
+
+    // Create DTLS transport
+    EOE(rawrtc_dtls_transport_create(
+        &local->dtls_transport, local->ice_transport, certificates, ARRAY_SIZE(certificates),
+        dtls_transport_state_change_handler, default_dtls_transport_error_handler, local));
+
+    // Create SCTP transport
+    EOE(rawrtc_sctp_transport_create(
+        &local->sctp_transport, local->dtls_transport, local->sctp_port,
+        default_data_channel_handler, default_sctp_transport_state_change_handler, local));
+    EOE(rawrtc_sctp_transport_set_buffer_length(
+        local->sctp_transport, TRANSPORT_BUFFER_LENGTH, TRANSPORT_BUFFER_LENGTH));
+
+    // Get SCTP capabilities
+    EOE(rawrtc_sctp_transport_get_capabilities(&local->sctp_capabilities));
+
+    // Get data transport
+    EOE(rawrtc_sctp_transport_get_data_transport(&local->data_transport, local->sctp_transport));
+
+    // Create data channel helper
+    data_channel_helper_create(
+        &local->data_channel_negotiated, (struct client*) local, "cat-noises");
+
+    // Create data channel parameters
+    EOE(rawrtc_data_channel_parameters_create(
+        &channel_parameters, local->data_channel_negotiated->label,
+        RAWRTC_DATA_CHANNEL_TYPE_RELIABLE_ORDERED, 0, NULL, true, 0));
+
+    // Create pre-negotiated data channel
+    EOE(rawrtc_data_channel_create(
+        &local->data_channel_negotiated->channel, local->data_transport, channel_parameters,
+        data_channel_open_handler, default_data_channel_buffered_amount_low_handler,
+        default_data_channel_error_handler, default_data_channel_close_handler,
+        default_data_channel_message_handler, local->data_channel_negotiated));
+
+    // Un-reference
+    mem_deref(channel_parameters);
+}
+
+static void client_start(
+    struct data_channel_sctp_client* const local, struct data_channel_sctp_client* const remote) {
+    // Get & set ICE parameters
+    EOE(rawrtc_ice_gatherer_get_local_parameters(&local->ice_parameters, remote->gatherer));
+
+    // Start gathering
+    EOE(rawrtc_ice_gatherer_gather(local->gatherer, NULL));
+
+    // Start ICE transport
+    EOE(rawrtc_ice_transport_start(
+        local->ice_transport, local->gatherer, local->ice_parameters, local->role));
+
+    // Get DTLS parameters
+    EOE(rawrtc_dtls_transport_get_local_parameters(
+        &remote->dtls_parameters, remote->dtls_transport));
+
+    // Start DTLS transport
+    EOE(rawrtc_dtls_transport_start(local->dtls_transport, remote->dtls_parameters));
+
+    // Start SCTP transport
+    EOE(rawrtc_sctp_transport_start(
+        local->sctp_transport, remote->sctp_capabilities, remote->sctp_port));
+}
+
+static void client_stop(struct data_channel_sctp_client* const client) {
+    // Stop transports & close gatherer
+    if (client->data_channel) {
+        EOE(rawrtc_data_channel_close(client->data_channel->channel));
+    }
+    EOE(rawrtc_data_channel_close(client->data_channel_negotiated->channel));
+    EOE(rawrtc_sctp_transport_stop(client->sctp_transport));
+    EOE(rawrtc_dtls_transport_stop(client->dtls_transport));
+    EOE(rawrtc_ice_transport_stop(client->ice_transport));
+    EOE(rawrtc_ice_gatherer_close(client->gatherer));
+
+    // Un-reference & close
+    client->data_channel = mem_deref(client->data_channel);
+    client->data_channel_negotiated = mem_deref(client->data_channel_negotiated);
+    client->sctp_capabilities = mem_deref(client->sctp_capabilities);
+    client->dtls_parameters = mem_deref(client->dtls_parameters);
+    client->ice_parameters = mem_deref(client->ice_parameters);
+    client->data_transport = mem_deref(client->data_transport);
+    client->sctp_transport = mem_deref(client->sctp_transport);
+    client->dtls_transport = mem_deref(client->dtls_transport);
+    client->ice_transport = mem_deref(client->ice_transport);
+    client->gatherer = mem_deref(client->gatherer);
+    client->certificate = mem_deref(client->certificate);
+}
+
+int main(int argc, char* argv[argc + 1]) {
+    char** ice_candidate_types = NULL;
+    size_t n_ice_candidate_types = 0;
+    struct rawrtc_ice_gather_options* gather_options;
+    char* const turn_zwuenf_org_urls[] = {"stun:turn.zwuenf.org"};
+    struct data_channel_sctp_client a = {0};
+    struct data_channel_sctp_client b = {0};
+    (void) a.ice_candidate_types;
+    (void) a.n_ice_candidate_types;
+    (void) b.ice_candidate_types;
+    (void) b.n_ice_candidate_types;
+
+    // Debug
+    dbg_init(DBG_DEBUG, DBG_ALL);
+    DEBUG_PRINTF("Init\n");
+
+    // Initialise
+    EOE(rawrtc_init(true));
+
+    // Get enabled ICE candidate types to be added (optional)
+    if (argc > 1) {
+        ice_candidate_types = &argv[1];
+        n_ice_candidate_types = (size_t) argc - 1;
+    }
+
+    // Create ICE gather options
+    EOE(rawrtc_ice_gather_options_create(&gather_options, RAWRTC_ICE_GATHER_POLICY_ALL));
+
+    // Add ICE servers to ICE gather options
+    EOE(rawrtc_ice_gather_options_add_server(
+        gather_options, turn_zwuenf_org_urls, ARRAY_SIZE(turn_zwuenf_org_urls), NULL, NULL,
+        RAWRTC_ICE_CREDENTIAL_TYPE_NONE));
+
+    // Setup client A
+    a.name = "A";
+    a.ice_candidate_types = ice_candidate_types;
+    a.n_ice_candidate_types = n_ice_candidate_types;
+    a.gather_options = gather_options;
+    a.role = RAWRTC_ICE_ROLE_CONTROLLING;
+    a.sctp_port = 6000;
+    a.other_client = &b;
+
+    // Setup client B
+    b.name = "B";
+    b.ice_candidate_types = ice_candidate_types;
+    b.n_ice_candidate_types = n_ice_candidate_types;
+    b.gather_options = gather_options;
+    b.role = RAWRTC_ICE_ROLE_CONTROLLED;
+    b.sctp_port = 5000;
+    b.other_client = &a;
+
+    // Initialise clients
+    client_init(&a);
+    client_init(&b);
+
+    // Start clients
+    client_start(&a, &b);
+    client_start(&b, &a);
+
+    // Listen on stdin
+    EOR(fd_listen(STDIN_FILENO, FD_READ, stop_on_return_handler, NULL));
+
+    // Start main loop
+    EOR(re_main(default_signal_handler));
+
+    // Stop clients
+    client_stop(&a);
+    client_stop(&b);
+
+    // Stop listening on STDIN
+    fd_close(STDIN_FILENO);
+
+    // Free
+    mem_deref(gather_options);
+
+    // Bye
+    before_exit();
+    return 0;
+}
diff --git a/tools/data-channel-sctp-streamed.c b/tools/data-channel-sctp-streamed.c
new file mode 100644
index 0000000..c998238
--- /dev/null
+++ b/tools/data-channel-sctp-streamed.c
@@ -0,0 +1,545 @@
+#include "helper/handler.h"
+#include "helper/parameters.h"
+#include "helper/utils.h"
+#include <rawrtc.h>
+#include <rawrtcc.h>
+#include <rawrtcdc.h>
+#include <re.h>
+#include <stdlib.h>  // exit
+#include <string.h>  // memcpy
+#include <unistd.h>  // STDIN_FILENO
+
+#define DEBUG_MODULE "data-channel-sctp-streamed-app"
+#define DEBUG_LEVEL 7
+#include <re_dbg.h>
+
+enum {
+    TRANSPORT_BUFFER_LENGTH = 1048576,  // 1 MiB
+    DEFAULT_MESSAGE_LENGTH = 1073741823,  // 1 GiB
+};
+
+struct parameters {
+    struct rawrtc_ice_parameters* ice_parameters;
+    struct rawrtc_ice_candidates* ice_candidates;
+    struct rawrtc_dtls_parameters* dtls_parameters;
+    struct sctp_parameters sctp_parameters;
+};
+
+// Note: Shadows struct client
+struct data_channel_sctp_streamed_client {
+    char* name;
+    char** ice_candidate_types;
+    size_t n_ice_candidate_types;
+    struct rawrtc_ice_gather_options* gather_options;
+    enum rawrtc_ice_role role;
+    struct rawrtc_certificate* certificate;
+    struct rawrtc_ice_gatherer* gatherer;
+    struct rawrtc_ice_transport* ice_transport;
+    struct rawrtc_dtls_transport* dtls_transport;
+    struct rawrtc_sctp_transport* sctp_transport;
+    struct rawrtc_data_transport* data_transport;
+    struct data_channel_helper* data_channel_negotiated;
+    struct data_channel_helper* data_channel;
+    struct list other_data_channels;
+    struct parameters local_parameters;
+    struct parameters remote_parameters;
+};
+
+static void print_local_parameters(struct data_channel_sctp_streamed_client* client);
+
+static struct tmr timer = {0};
+
+static void timer_handler(void* arg) {
+    struct data_channel_helper* const channel = arg;
+    struct data_channel_sctp_streamed_client* const client =
+        (struct data_channel_sctp_streamed_client*) channel->client;
+    uint64_t max_message_size = DEFAULT_MESSAGE_LENGTH;  // Default to 1 GiB
+    struct mbuf* buffer;
+    enum rawrtc_code error;
+    enum rawrtc_dtls_role role;
+
+    // Get the remote peer's maximum message size
+    EOE(rawrtc_sctp_capabilities_get_max_message_size(
+        &max_message_size, client->remote_parameters.sctp_parameters.capabilities));
+    if (max_message_size > 0) {
+        max_message_size = min(DEFAULT_MESSAGE_LENGTH, max_message_size);
+    } else {
+        max_message_size = DEFAULT_MESSAGE_LENGTH;
+    }
+
+    // Compose message
+    buffer = mbuf_alloc(max_message_size);
+    EOE(buffer ? RAWRTC_CODE_SUCCESS : RAWRTC_CODE_NO_MEMORY);
+    EOR(mbuf_fill(buffer, 'M', mbuf_get_space(buffer)));
+    mbuf_set_pos(buffer, 0);
+
+    // Send message
+    // TODO: Send streamed once this is implemented
+    DEBUG_PRINTF("(%s) Sending %zu bytes\n", client->name, mbuf_get_left(buffer));
+    error = rawrtc_data_channel_send(channel->channel, buffer, true);
+    if (error) {
+        DEBUG_WARNING("Could not send, reason: %s\n", rawrtc_code_to_str(error));
+    }
+    mem_deref(buffer);
+
+    // Get DTLS role
+    EOE(rawrtc_dtls_parameters_get_role(&role, client->local_parameters.dtls_parameters));
+    if (role == RAWRTC_DTLS_ROLE_CLIENT) {
+        // Close bear-noises
+        DEBUG_PRINTF("(%s) Closing channel\n", client->name, channel->label);
+        EOR(rawrtc_data_channel_close(client->data_channel->channel));
+    }
+}
+
+static void data_channel_open_handler(void* const arg) {
+    struct data_channel_helper* const channel = arg;
+    struct data_channel_sctp_streamed_client* const client =
+        (struct data_channel_sctp_streamed_client*) channel->client;
+    struct mbuf* buffer;
+    enum rawrtc_code error;
+
+    // Print open event
+    default_data_channel_open_handler(arg);
+
+    // Send data delayed on bear-noises
+    if (str_cmp(channel->label, "bear-noises") == 0) {
+        tmr_start(&timer, 30000, timer_handler, channel);
+        return;
+    }
+
+    // Compose message (8 KiB)
+    buffer = mbuf_alloc(1 << 13);
+    EOE(buffer ? RAWRTC_CODE_SUCCESS : RAWRTC_CODE_NO_MEMORY);
+    EOR(mbuf_fill(buffer, 'M', mbuf_get_space(buffer)));
+    mbuf_set_pos(buffer, 0);
+
+    // Send message
+    // TODO: Send streamed once this is implemented
+    DEBUG_PRINTF("(%s) Sending %zu bytes\n", client->name, mbuf_get_left(buffer));
+    error = rawrtc_data_channel_send(channel->channel, buffer, true);
+    if (error) {
+        DEBUG_WARNING("Could not send, reason: %s\n", rawrtc_code_to_str(error));
+    }
+    mem_deref(buffer);
+}
+
+static void data_channel_handler(
+    struct rawrtc_data_channel* const channel,  // read-only, MUST be referenced when used
+    void* const arg) {
+    struct data_channel_sctp_streamed_client* const client = arg;
+    struct data_channel_helper* channel_helper;
+
+    // Print data channel event
+    default_data_channel_handler(channel, arg);
+
+    // Create data channel helper instance & add to list
+    // Note: In this case we need to reference the channel because we have not created it
+    data_channel_helper_create_from_channel(&channel_helper, mem_ref(channel), arg, NULL);
+    list_append(&client->other_data_channels, &channel_helper->le, channel_helper);
+
+    // Set handler argument & handlers
+    EOE(rawrtc_data_channel_set_arg(channel, channel_helper));
+    EOE(rawrtc_data_channel_set_open_handler(channel, data_channel_open_handler));
+    EOE(rawrtc_data_channel_set_buffered_amount_low_handler(
+        channel, default_data_channel_buffered_amount_low_handler));
+    EOE(rawrtc_data_channel_set_error_handler(channel, default_data_channel_error_handler));
+    EOE(rawrtc_data_channel_set_close_handler(channel, default_data_channel_close_handler));
+    EOE(rawrtc_data_channel_set_message_handler(channel, default_data_channel_message_handler));
+
+    // Enable streaming mode
+    EOE(rawrtc_data_channel_set_streaming(channel, true));
+}
+
+static void ice_gatherer_local_candidate_handler(
+    struct rawrtc_ice_candidate* const candidate,
+    char const* const url,  // read-only
+    void* const arg) {
+    struct data_channel_sctp_streamed_client* const client = arg;
+
+    // Print local candidate
+    default_ice_gatherer_local_candidate_handler(candidate, url, arg);
+
+    // Print local parameters (if last candidate)
+    if (!candidate) {
+        print_local_parameters(client);
+    }
+}
+
+static void dtls_transport_state_change_handler(
+    enum rawrtc_dtls_transport_state const state,  // read-only
+    void* const arg) {
+    struct data_channel_sctp_streamed_client* const client = arg;
+
+    // Print state
+    default_dtls_transport_state_change_handler(state, arg);
+
+    // Open? Create new data channel
+    // TODO: Move this once we can create data channels earlier
+    if (state == RAWRTC_DTLS_TRANSPORT_STATE_CONNECTED) {
+        enum rawrtc_dtls_role role;
+
+        // Renew DTLS parameters
+        mem_deref(client->local_parameters.dtls_parameters);
+        EOE(rawrtc_dtls_transport_get_local_parameters(
+            &client->local_parameters.dtls_parameters, client->dtls_transport));
+
+        // Get DTLS role
+        EOE(rawrtc_dtls_parameters_get_role(&role, client->local_parameters.dtls_parameters));
+        DEBUG_PRINTF("(%s) DTLS role: %s\n", client->name, rawrtc_dtls_role_to_str(role));
+
+        // Client? Create data channel
+        if (role == RAWRTC_DTLS_ROLE_CLIENT) {
+            struct rawrtc_data_channel_parameters* channel_parameters;
+
+            // Create data channel helper
+            data_channel_helper_create(
+                &client->data_channel, (struct client*) client, "bear-noises");
+
+            // Create data channel parameters
+            EOE(rawrtc_data_channel_parameters_create(
+                &channel_parameters, client->data_channel->label,
+                RAWRTC_DATA_CHANNEL_TYPE_RELIABLE_UNORDERED, 0, NULL, false, 0));
+
+            // Create data channel
+            EOE(rawrtc_data_channel_create(
+                &client->data_channel->channel, client->data_transport, channel_parameters,
+                data_channel_open_handler, default_data_channel_buffered_amount_low_handler,
+                default_data_channel_error_handler, default_data_channel_close_handler,
+                default_data_channel_message_handler, client->data_channel));
+
+            // Enable streaming mode
+            EOE(rawrtc_data_channel_set_streaming(client->data_channel->channel, true));
+
+            // Un-reference
+            mem_deref(channel_parameters);
+        }
+    }
+}
+
+static void client_init(struct data_channel_sctp_streamed_client* const client) {
+    struct rawrtc_certificate* certificates[1];
+    struct rawrtc_data_channel_parameters* channel_parameters;
+
+    // Generate certificates
+    EOE(rawrtc_certificate_generate(&client->certificate, NULL));
+    certificates[0] = client->certificate;
+
+    // Create ICE gatherer
+    EOE(rawrtc_ice_gatherer_create(
+        &client->gatherer, client->gather_options, default_ice_gatherer_state_change_handler,
+        default_ice_gatherer_error_handler, ice_gatherer_local_candidate_handler, client));
+
+    // Create ICE transport
+    EOE(rawrtc_ice_transport_create(
+        &client->ice_transport, client->gatherer, default_ice_transport_state_change_handler,
+        default_ice_transport_candidate_pair_change_handler, client));
+
+    // Create DTLS transport
+    EOE(rawrtc_dtls_transport_create(
+        &client->dtls_transport, client->ice_transport, certificates, ARRAY_SIZE(certificates),
+        dtls_transport_state_change_handler, default_dtls_transport_error_handler, client));
+
+    // Create SCTP transport
+    EOE(rawrtc_sctp_transport_create(
+        &client->sctp_transport, client->dtls_transport,
+        client->local_parameters.sctp_parameters.port, data_channel_handler,
+        default_sctp_transport_state_change_handler, client));
+    EOE(rawrtc_sctp_transport_set_buffer_length(
+        client->sctp_transport, TRANSPORT_BUFFER_LENGTH, TRANSPORT_BUFFER_LENGTH));
+
+    // Get data transport
+    EOE(rawrtc_sctp_transport_get_data_transport(&client->data_transport, client->sctp_transport));
+
+    // Create data channel helper
+    data_channel_helper_create(
+        &client->data_channel_negotiated, (struct client*) client, "cat-noises");
+
+    // Create data channel parameters
+    EOE(rawrtc_data_channel_parameters_create(
+        &channel_parameters, client->data_channel_negotiated->label,
+        RAWRTC_DATA_CHANNEL_TYPE_RELIABLE_ORDERED, 0, NULL, true, 0));
+
+    // Create pre-negotiated data channel
+    EOE(rawrtc_data_channel_create(
+        &client->data_channel_negotiated->channel, client->data_transport, channel_parameters,
+        data_channel_open_handler, default_data_channel_buffered_amount_low_handler,
+        default_data_channel_error_handler, default_data_channel_close_handler,
+        default_data_channel_message_handler, client->data_channel_negotiated));
+
+    // Enable streaming mode
+    EOE(rawrtc_data_channel_set_streaming(client->data_channel_negotiated->channel, true));
+
+    // Un-reference
+    mem_deref(channel_parameters);
+}
+
+static void client_start_gathering(struct data_channel_sctp_streamed_client* const client) {
+    // Start gathering
+    EOE(rawrtc_ice_gatherer_gather(client->gatherer, NULL));
+}
+
+static void client_start_transports(struct data_channel_sctp_streamed_client* const client) {
+    struct parameters* const remote_parameters = &client->remote_parameters;
+
+    // Start ICE transport
+    EOE(rawrtc_ice_transport_start(
+        client->ice_transport, client->gatherer, remote_parameters->ice_parameters, client->role));
+
+    // Start DTLS transport
+    EOE(rawrtc_dtls_transport_start(client->dtls_transport, remote_parameters->dtls_parameters));
+
+    // Start SCTP transport
+    EOE(rawrtc_sctp_transport_start(
+        client->sctp_transport, remote_parameters->sctp_parameters.capabilities,
+        remote_parameters->sctp_parameters.port));
+}
+
+static void parameters_destroy(struct parameters* const parameters) {
+    // Un-reference
+    parameters->ice_parameters = mem_deref(parameters->ice_parameters);
+    parameters->ice_candidates = mem_deref(parameters->ice_candidates);
+    parameters->dtls_parameters = mem_deref(parameters->dtls_parameters);
+    if (parameters->sctp_parameters.capabilities) {
+        parameters->sctp_parameters.capabilities =
+            mem_deref(parameters->sctp_parameters.capabilities);
+    }
+}
+
+static void client_stop(struct data_channel_sctp_streamed_client* const client) {
+    // Clear other data channels
+    list_flush(&client->other_data_channels);
+
+    if (client->sctp_transport) {
+        EOE(rawrtc_sctp_transport_stop(client->sctp_transport));
+    }
+    if (client->dtls_transport) {
+        EOE(rawrtc_dtls_transport_stop(client->dtls_transport));
+    }
+    if (client->ice_transport) {
+        EOE(rawrtc_ice_transport_stop(client->ice_transport));
+    }
+    if (client->gatherer) {
+        EOE(rawrtc_ice_gatherer_close(client->gatherer));
+    }
+
+    // Un-reference & close
+    parameters_destroy(&client->remote_parameters);
+    parameters_destroy(&client->local_parameters);
+    client->data_channel = mem_deref(client->data_channel);
+    client->data_channel_negotiated = mem_deref(client->data_channel_negotiated);
+    client->data_transport = mem_deref(client->data_transport);
+    client->sctp_transport = mem_deref(client->sctp_transport);
+    client->dtls_transport = mem_deref(client->dtls_transport);
+    client->ice_transport = mem_deref(client->ice_transport);
+    client->gatherer = mem_deref(client->gatherer);
+    client->certificate = mem_deref(client->certificate);
+    client->gather_options = mem_deref(client->gather_options);
+
+    // Stop listening on STDIN
+    fd_close(STDIN_FILENO);
+}
+
+static void client_set_parameters(struct data_channel_sctp_streamed_client* const client) {
+    struct parameters* const remote_parameters = &client->remote_parameters;
+
+    // Set remote ICE candidates
+    EOE(rawrtc_ice_transport_set_remote_candidates(
+        client->ice_transport, remote_parameters->ice_candidates->candidates,
+        remote_parameters->ice_candidates->n_candidates));
+}
+
+static void parse_remote_parameters(int flags, void* arg) {
+    struct data_channel_sctp_streamed_client* const client = arg;
+    enum rawrtc_code error;
+    struct odict* dict = NULL;
+    struct odict* node = NULL;
+    struct rawrtc_ice_parameters* ice_parameters = NULL;
+    struct rawrtc_ice_candidates* ice_candidates = NULL;
+    struct rawrtc_dtls_parameters* dtls_parameters = NULL;
+    struct sctp_parameters sctp_parameters = {0};
+    (void) flags;
+
+    // Get dict from JSON
+    error = get_json_stdin(&dict);
+    if (error) {
+        goto out;
+    }
+
+    // Decode JSON
+    error |= dict_get_entry(&node, dict, "iceParameters", ODICT_OBJECT, true);
+    error |= get_ice_parameters(&ice_parameters, node);
+    error |= dict_get_entry(&node, dict, "iceCandidates", ODICT_ARRAY, true);
+    error |= get_ice_candidates(&ice_candidates, node, arg);
+    error |= dict_get_entry(&node, dict, "dtlsParameters", ODICT_OBJECT, true);
+    error |= get_dtls_parameters(&dtls_parameters, node);
+    error |= dict_get_entry(&node, dict, "sctpParameters", ODICT_OBJECT, true);
+    error |= get_sctp_parameters(&sctp_parameters, node);
+
+    // Ok?
+    if (error) {
+        DEBUG_WARNING("Invalid remote parameters\n");
+        if (sctp_parameters.capabilities) {
+            mem_deref(sctp_parameters.capabilities);
+        }
+        goto out;
+    }
+
+    // Set parameters & start transports
+    client->remote_parameters.ice_parameters = mem_ref(ice_parameters);
+    client->remote_parameters.ice_candidates = mem_ref(ice_candidates);
+    client->remote_parameters.dtls_parameters = mem_ref(dtls_parameters);
+    memcpy(&client->remote_parameters.sctp_parameters, &sctp_parameters, sizeof(sctp_parameters));
+    DEBUG_INFO("Applying remote parameters\n");
+    client_set_parameters(client);
+    client_start_transports(client);
+
+out:
+    // Un-reference
+    mem_deref(dtls_parameters);
+    mem_deref(ice_candidates);
+    mem_deref(ice_parameters);
+    mem_deref(dict);
+
+    // Exit?
+    if (error == RAWRTC_CODE_NO_VALUE) {
+        DEBUG_NOTICE("Exiting\n");
+
+        // Stop client & bye
+        client_stop(client);
+        tmr_cancel(&timer);
+        re_cancel();
+    }
+}
+
+static void client_get_parameters(struct data_channel_sctp_streamed_client* const client) {
+    struct parameters* const local_parameters = &client->local_parameters;
+
+    // Get local ICE parameters
+    EOE(rawrtc_ice_gatherer_get_local_parameters(
+        &local_parameters->ice_parameters, client->gatherer));
+
+    // Get local ICE candidates
+    EOE(rawrtc_ice_gatherer_get_local_candidates(
+        &local_parameters->ice_candidates, client->gatherer));
+
+    // Get local DTLS parameters
+    EOE(rawrtc_dtls_transport_get_local_parameters(
+        &local_parameters->dtls_parameters, client->dtls_transport));
+
+    // Get local SCTP parameters
+    EOE(rawrtc_sctp_transport_get_capabilities(&local_parameters->sctp_parameters.capabilities));
+    EOE(rawrtc_sctp_transport_get_port(
+        &local_parameters->sctp_parameters.port, client->sctp_transport));
+}
+
+static void print_local_parameters(struct data_channel_sctp_streamed_client* client) {
+    struct odict* dict;
+    struct odict* node;
+
+    // Get local parameters
+    client_get_parameters(client);
+
+    // Create dict
+    EOR(odict_alloc(&dict, 16));
+
+    // Create nodes
+    EOR(odict_alloc(&node, 16));
+    set_ice_parameters(client->local_parameters.ice_parameters, node);
+    EOR(odict_entry_add(dict, "iceParameters", ODICT_OBJECT, node));
+    mem_deref(node);
+    EOR(odict_alloc(&node, 16));
+    set_ice_candidates(client->local_parameters.ice_candidates, node);
+    EOR(odict_entry_add(dict, "iceCandidates", ODICT_ARRAY, node));
+    mem_deref(node);
+    EOR(odict_alloc(&node, 16));
+    set_dtls_parameters(client->local_parameters.dtls_parameters, node);
+    EOR(odict_entry_add(dict, "dtlsParameters", ODICT_OBJECT, node));
+    mem_deref(node);
+    EOR(odict_alloc(&node, 16));
+    set_sctp_parameters(client->sctp_transport, &client->local_parameters.sctp_parameters, node);
+    EOR(odict_entry_add(dict, "sctpParameters", ODICT_OBJECT, node));
+    mem_deref(node);
+
+    // Print JSON
+    DEBUG_INFO("Local Parameters:\n%H\n", json_encode_odict, dict);
+
+    // Un-reference
+    mem_deref(dict);
+}
+
+static void exit_with_usage(char* program) {
+    DEBUG_WARNING("Usage: %s <0|1 (ice-role)> [<sctp-port>] [<ice-candidate-type> ...]", program);
+    exit(1);
+}
+
+int main(int argc, char* argv[argc + 1]) {
+    char** ice_candidate_types = NULL;
+    size_t n_ice_candidate_types = 0;
+    enum rawrtc_ice_role role;
+    struct rawrtc_ice_gather_options* gather_options;
+    char* const turn_zwuenf_org_urls[] = {"stun:turn.zwuenf.org"};
+    struct data_channel_sctp_streamed_client client = {0};
+    (void) client.ice_candidate_types;
+    (void) client.n_ice_candidate_types;
+
+    // Debug
+    dbg_init(DBG_DEBUG, DBG_ALL);
+    DEBUG_PRINTF("Init\n");
+
+    // Initialise
+    EOE(rawrtc_init(true));
+
+    // Check arguments length
+    if (argc < 2) {
+        exit_with_usage(argv[0]);
+    }
+
+    // Get ICE role
+    if (get_ice_role(&role, argv[1])) {
+        exit_with_usage(argv[0]);
+    }
+
+    // Get SCTP port (optional)
+    if (argc >= 3 && !str_to_uint16(&client.local_parameters.sctp_parameters.port, argv[2])) {
+        exit_with_usage(argv[0]);
+    }
+
+    // Get enabled ICE candidate types to be added (optional)
+    if (argc >= 4) {
+        ice_candidate_types = &argv[3];
+        n_ice_candidate_types = (size_t) argc - 3;
+    }
+
+    // Create ICE gather options
+    EOE(rawrtc_ice_gather_options_create(&gather_options, RAWRTC_ICE_GATHER_POLICY_ALL));
+
+    // Add ICE servers to ICE gather options
+    EOE(rawrtc_ice_gather_options_add_server(
+        gather_options, turn_zwuenf_org_urls, ARRAY_SIZE(turn_zwuenf_org_urls), NULL, NULL,
+        RAWRTC_ICE_CREDENTIAL_TYPE_NONE));
+
+    // Set client fields
+    client.name = "A";
+    client.ice_candidate_types = ice_candidate_types;
+    client.n_ice_candidate_types = n_ice_candidate_types;
+    client.gather_options = gather_options;
+    client.role = role;
+    list_init(&client.other_data_channels);
+
+    // Setup client
+    client_init(&client);
+
+    // Start gathering
+    client_start_gathering(&client);
+
+    // Listen on stdin
+    EOR(fd_listen(STDIN_FILENO, FD_READ, parse_remote_parameters, &client));
+
+    // Start main loop
+    EOR(re_main(default_signal_handler));
+
+    // Stop client & bye
+    client_stop(&client);
+    before_exit();
+    return 0;
+}
diff --git a/tools/data-channel-sctp-throughput.c b/tools/data-channel-sctp-throughput.c
new file mode 100644
index 0000000..3bd9aea
--- /dev/null
+++ b/tools/data-channel-sctp-throughput.c
@@ -0,0 +1,556 @@
+#include "helper/handler.h"
+#include "helper/parameters.h"
+#include "helper/utils.h"
+#include <rawrtc.h>
+#include <rawrtcc.h>
+#include <rawrtcdc.h>
+#include <re.h>
+#include <stdlib.h>  // exit
+#include <string.h>  // memcpy
+#include <unistd.h>  // STDIN_FILENO
+
+#define DEBUG_MODULE "data-channel-sctp-throughput-app"
+#define DEBUG_LEVEL 7
+#include <re_dbg.h>
+
+enum {
+    TRANSPORT_BUFFER_LENGTH = 1048576,  // 1 MiB
+};
+
+struct parameters {
+    struct rawrtc_ice_parameters* ice_parameters;
+    struct rawrtc_ice_candidates* ice_candidates;
+    struct rawrtc_dtls_parameters* dtls_parameters;
+    struct sctp_parameters sctp_parameters;
+};
+
+// Note: Shadows struct client
+struct data_channel_sctp_throughput_client {
+    char* name;
+    char** ice_candidate_types;
+    size_t n_ice_candidate_types;
+    uint64_t message_size;
+    uint16_t n_times_left;
+    uint32_t buffer_length;
+    enum rawrtc_sctp_transport_congestion_ctrl congestion_ctrl_algorithm;
+    uint32_t mtu;
+    struct rawrtc_ice_gather_options* gather_options;
+    enum rawrtc_ice_role role;
+    struct mbuf* start_buffer;
+    struct mbuf* throughput_buffer;
+    struct rawrtc_certificate* certificate;
+    struct rawrtc_ice_gatherer* gatherer;
+    struct rawrtc_ice_transport* ice_transport;
+    struct rawrtc_dtls_transport* dtls_transport;
+    struct rawrtc_sctp_transport* sctp_transport;
+    struct rawrtc_data_transport* data_transport;
+    struct data_channel_helper* data_channel;
+    struct parameters local_parameters;
+    struct parameters remote_parameters;
+    uint64_t start_time;
+};
+
+static void print_local_parameters(struct data_channel_sctp_throughput_client* client);
+
+static struct tmr timer = {0};
+
+static void timer_handler(void* arg) {
+    struct data_channel_helper* const channel = arg;
+    struct data_channel_sctp_throughput_client* const client =
+        (struct data_channel_sctp_throughput_client*) channel->client;
+    enum rawrtc_code error;
+    enum rawrtc_dtls_role role;
+
+    // Send start indicator
+    mbuf_set_pos(client->start_buffer, 0);
+    DEBUG_PRINTF("(%s) Sending start indicator\n", client->name);
+    error = rawrtc_data_channel_send(channel->channel, client->start_buffer, false);
+    if (error) {
+        DEBUG_WARNING("Could not send, reason: %s\n", rawrtc_code_to_str(error));
+        goto out;
+    }
+
+    // Send message
+    DEBUG_PRINTF(
+        "(%s) Sending %zu bytes\n", client->name, mbuf_get_left(client->throughput_buffer));
+    error = rawrtc_data_channel_send(channel->channel, client->throughput_buffer, true);
+    if (error) {
+        DEBUG_WARNING("Could not send, reason: %s\n", rawrtc_code_to_str(error));
+        goto out;
+    }
+
+out:
+    // Get DTLS role
+    EOE(rawrtc_dtls_parameters_get_role(&role, client->local_parameters.dtls_parameters));
+    if (role == RAWRTC_DTLS_ROLE_CLIENT) {
+        // Close bear-noises
+        DEBUG_PRINTF("(%s) Closing channel\n", client->name, channel->label);
+        EOR(rawrtc_data_channel_close(client->data_channel->channel));
+    }
+}
+
+static void data_channel_message_handler(
+    struct mbuf* const buffer, enum rawrtc_data_channel_message_flag const flags, void* const arg) {
+    struct data_channel_helper* const channel = arg;
+    struct data_channel_sctp_throughput_client* const client =
+        (struct data_channel_sctp_throughput_client*) channel->client;
+    size_t const length = mbuf_get_left(buffer);
+
+    // Check role
+    if (client->role != RAWRTC_ICE_ROLE_CONTROLLED) {
+        DEBUG_WARNING(
+            "(%s) Unexpected message on data channel %s of size %zu\n", client->name,
+            channel->label, length);
+    }
+
+    if (flags & RAWRTC_DATA_CHANNEL_MESSAGE_FLAG_IS_STRING) {
+        // Start indicator message
+        uint64_t expected_size;
+
+        // Check size
+        if (mbuf_get_left(buffer) < 8) {
+            EOE(RAWRTC_CODE_INVALID_MESSAGE);
+        }
+
+        // Parse message
+        expected_size = sys_ntohll(mbuf_read_u64(buffer));
+        EOE(expected_size > 0 ? RAWRTC_CODE_SUCCESS : RAWRTC_CODE_INVALID_MESSAGE);
+        client->start_time = tmr_jiffies();
+        DEBUG_INFO(
+            "(%s) Started throughput test of %.2f MiB\n", client->name,
+            ((double) expected_size) / 1048576);
+        return;
+    } else if (flags & RAWRTC_DATA_CHANNEL_MESSAGE_FLAG_IS_BINARY) {
+        // Check expected message size and print results
+        double const delta = ((double) (tmr_jiffies() - client->start_time)) / 1000;
+        DEBUG_INFO(
+            "(%s) Completed throughput test after %.2f seconds: %.2f Mbit/s\n", client->name, delta,
+            ((double) length) / 131072 / delta);
+
+        // Check size
+        if (length != client->message_size) {
+            DEBUG_WARNING(
+                "(%s) Expected %zu bytes, received %zu bytes\n", client->name, client->message_size,
+                length);
+            return;
+        }
+    }
+}
+
+static void start_throughput_test(struct data_channel_helper* const channel) {
+    struct data_channel_sctp_throughput_client* const client =
+        (struct data_channel_sctp_throughput_client*) channel->client;
+
+    // Start throughput test delayed (if controlling)
+    if (client->role == RAWRTC_ICE_ROLE_CONTROLLING && client->n_times_left > 0) {
+        size_t length;
+        mbuf_set_pos(client->throughput_buffer, 0);
+        length = mbuf_get_left(client->throughput_buffer);
+        DEBUG_INFO(
+            "Starting throughput test of %.2f MiB in 1 second\n",
+            (double) length / (double) 1048576);
+        tmr_start(&timer, 1000, timer_handler, channel);
+        --client->n_times_left;
+    }
+}
+
+static void data_channel_buffered_amount_low_handler(void* const arg) {
+    struct data_channel_helper* const channel = arg;
+
+    // Print buffered amount low event
+    default_data_channel_buffered_amount_low_handler(arg);
+
+    // Restart throughput test
+    start_throughput_test(channel);
+}
+
+static void data_channel_open_handler(void* const arg) {
+    struct data_channel_helper* const channel = arg;
+
+    // Print open event
+    default_data_channel_open_handler(arg);
+
+    // Start throughput test
+    start_throughput_test(channel);
+}
+
+static void ice_gatherer_local_candidate_handler(
+    struct rawrtc_ice_candidate* const candidate,
+    char const* const url,  // read-only
+    void* const arg) {
+    struct data_channel_sctp_throughput_client* const client = arg;
+
+    // Print local candidate
+    default_ice_gatherer_local_candidate_handler(candidate, url, arg);
+
+    // Print local parameters (if last candidate)
+    if (!candidate) {
+        print_local_parameters(client);
+    }
+}
+
+static void client_init(struct data_channel_sctp_throughput_client* const client) {
+    struct rawrtc_certificate* certificates[1];
+    struct rawrtc_data_channel_parameters* channel_parameters;
+
+    // Generate certificates
+    EOE(rawrtc_certificate_generate(&client->certificate, NULL));
+    certificates[0] = client->certificate;
+
+    // Create ICE gatherer
+    EOE(rawrtc_ice_gatherer_create(
+        &client->gatherer, client->gather_options, default_ice_gatherer_state_change_handler,
+        default_ice_gatherer_error_handler, ice_gatherer_local_candidate_handler, client));
+
+    // Create ICE transport
+    EOE(rawrtc_ice_transport_create(
+        &client->ice_transport, client->gatherer, default_ice_transport_state_change_handler,
+        default_ice_transport_candidate_pair_change_handler, client));
+
+    // Create DTLS transport
+    EOE(rawrtc_dtls_transport_create(
+        &client->dtls_transport, client->ice_transport, certificates, ARRAY_SIZE(certificates),
+        default_dtls_transport_state_change_handler, default_dtls_transport_error_handler, client));
+
+    // Create SCTP transport
+    EOE(rawrtc_sctp_transport_create(
+        &client->sctp_transport, client->dtls_transport,
+        client->local_parameters.sctp_parameters.port, default_data_channel_handler,
+        default_sctp_transport_state_change_handler, client));
+    EOE(rawrtc_sctp_transport_set_buffer_length(
+        client->sctp_transport, client->buffer_length, client->buffer_length));
+    EOE(rawrtc_sctp_transport_set_congestion_ctrl_algorithm(
+        client->sctp_transport, client->congestion_ctrl_algorithm));
+
+    // Get data transport
+    EOE(rawrtc_sctp_transport_get_data_transport(&client->data_transport, client->sctp_transport));
+
+    // Create data channel helper
+    data_channel_helper_create(&client->data_channel, (struct client*) client, "throughput");
+
+    // Create data channel parameters
+    EOE(rawrtc_data_channel_parameters_create(
+        &channel_parameters, client->data_channel->label, RAWRTC_DATA_CHANNEL_TYPE_RELIABLE_ORDERED,
+        0, NULL, true, 0));
+
+    // Create pre-negotiated data channel
+    EOE(rawrtc_data_channel_create(
+        &client->data_channel->channel, client->data_transport, channel_parameters,
+        data_channel_open_handler, data_channel_buffered_amount_low_handler,
+        default_data_channel_error_handler, default_data_channel_close_handler,
+        data_channel_message_handler, client->data_channel));
+
+    // Un-reference
+    mem_deref(channel_parameters);
+}
+
+static void client_start_gathering(struct data_channel_sctp_throughput_client* const client) {
+    // Start gathering
+    EOE(rawrtc_ice_gatherer_gather(client->gatherer, NULL));
+}
+
+static void client_start_transports(struct data_channel_sctp_throughput_client* const client) {
+    struct parameters* const remote_parameters = &client->remote_parameters;
+
+    // Start ICE transport
+    EOE(rawrtc_ice_transport_start(
+        client->ice_transport, client->gatherer, remote_parameters->ice_parameters, client->role));
+
+    // Start DTLS transport
+    EOE(rawrtc_dtls_transport_start(client->dtls_transport, remote_parameters->dtls_parameters));
+
+    // Start SCTP transport
+    EOE(rawrtc_sctp_transport_start(
+        client->sctp_transport, remote_parameters->sctp_parameters.capabilities,
+        remote_parameters->sctp_parameters.port));
+    if (client->mtu != 0) {
+        EOE(rawrtc_sctp_transport_set_mtu(client->sctp_transport, client->mtu));
+    }
+}
+
+static void parameters_destroy(struct parameters* const parameters) {
+    // Un-reference
+    parameters->ice_parameters = mem_deref(parameters->ice_parameters);
+    parameters->ice_candidates = mem_deref(parameters->ice_candidates);
+    parameters->dtls_parameters = mem_deref(parameters->dtls_parameters);
+    if (parameters->sctp_parameters.capabilities) {
+        parameters->sctp_parameters.capabilities =
+            mem_deref(parameters->sctp_parameters.capabilities);
+    }
+}
+
+static void client_stop(struct data_channel_sctp_throughput_client* const client) {
+    if (client->sctp_transport) {
+        EOE(rawrtc_sctp_transport_stop(client->sctp_transport));
+    }
+    if (client->dtls_transport) {
+        EOE(rawrtc_dtls_transport_stop(client->dtls_transport));
+    }
+    if (client->ice_transport) {
+        EOE(rawrtc_ice_transport_stop(client->ice_transport));
+    }
+    if (client->gatherer) {
+        EOE(rawrtc_ice_gatherer_close(client->gatherer));
+    }
+
+    // Un-reference & close
+    parameters_destroy(&client->remote_parameters);
+    parameters_destroy(&client->local_parameters);
+    client->data_channel = mem_deref(client->data_channel);
+    client->data_transport = mem_deref(client->data_transport);
+    client->sctp_transport = mem_deref(client->sctp_transport);
+    client->dtls_transport = mem_deref(client->dtls_transport);
+    client->ice_transport = mem_deref(client->ice_transport);
+    client->gatherer = mem_deref(client->gatherer);
+    client->certificate = mem_deref(client->certificate);
+    client->throughput_buffer = mem_deref(client->throughput_buffer);
+    client->start_buffer = mem_deref(client->start_buffer);
+    client->gather_options = mem_deref(client->gather_options);
+
+    // Stop listening on STDIN
+    fd_close(STDIN_FILENO);
+}
+
+static void client_set_parameters(struct data_channel_sctp_throughput_client* const client) {
+    struct parameters* const remote_parameters = &client->remote_parameters;
+
+    // Set remote ICE candidates
+    EOE(rawrtc_ice_transport_set_remote_candidates(
+        client->ice_transport, remote_parameters->ice_candidates->candidates,
+        remote_parameters->ice_candidates->n_candidates));
+}
+
+static void parse_remote_parameters(int flags, void* arg) {
+    struct data_channel_sctp_throughput_client* const client = arg;
+    enum rawrtc_code error;
+    struct odict* dict = NULL;
+    struct odict* node = NULL;
+    struct rawrtc_ice_parameters* ice_parameters = NULL;
+    struct rawrtc_ice_candidates* ice_candidates = NULL;
+    struct rawrtc_dtls_parameters* dtls_parameters = NULL;
+    struct sctp_parameters sctp_parameters = {0};
+    (void) flags;
+
+    // Get dict from JSON
+    error = get_json_stdin(&dict);
+    if (error) {
+        goto out;
+    }
+
+    // Decode JSON
+    error |= dict_get_entry(&node, dict, "iceParameters", ODICT_OBJECT, true);
+    error |= get_ice_parameters(&ice_parameters, node);
+    error |= dict_get_entry(&node, dict, "iceCandidates", ODICT_ARRAY, true);
+    error |= get_ice_candidates(&ice_candidates, node, arg);
+    error |= dict_get_entry(&node, dict, "dtlsParameters", ODICT_OBJECT, true);
+    error |= get_dtls_parameters(&dtls_parameters, node);
+    error |= dict_get_entry(&node, dict, "sctpParameters", ODICT_OBJECT, true);
+    error |= get_sctp_parameters(&sctp_parameters, node);
+
+    // Ok?
+    if (error) {
+        DEBUG_WARNING("Invalid remote parameters\n");
+        if (sctp_parameters.capabilities) {
+            mem_deref(sctp_parameters.capabilities);
+        }
+        goto out;
+    }
+
+    // Set parameters & start transports
+    client->remote_parameters.ice_parameters = mem_ref(ice_parameters);
+    client->remote_parameters.ice_candidates = mem_ref(ice_candidates);
+    client->remote_parameters.dtls_parameters = mem_ref(dtls_parameters);
+    memcpy(&client->remote_parameters.sctp_parameters, &sctp_parameters, sizeof(sctp_parameters));
+    DEBUG_INFO("Applying remote parameters\n");
+    client_set_parameters(client);
+    client_start_transports(client);
+
+out:
+    // Un-reference
+    mem_deref(dtls_parameters);
+    mem_deref(ice_candidates);
+    mem_deref(ice_parameters);
+    mem_deref(dict);
+
+    // Exit?
+    if (error == RAWRTC_CODE_NO_VALUE) {
+        DEBUG_NOTICE("Exiting\n");
+
+        // Stop client & bye
+        client_stop(client);
+        tmr_cancel(&timer);
+        re_cancel();
+    }
+}
+
+static void client_get_parameters(struct data_channel_sctp_throughput_client* const client) {
+    struct parameters* const local_parameters = &client->local_parameters;
+
+    // Get local ICE parameters
+    EOE(rawrtc_ice_gatherer_get_local_parameters(
+        &local_parameters->ice_parameters, client->gatherer));
+
+    // Get local ICE candidates
+    EOE(rawrtc_ice_gatherer_get_local_candidates(
+        &local_parameters->ice_candidates, client->gatherer));
+
+    // Get local DTLS parameters
+    EOE(rawrtc_dtls_transport_get_local_parameters(
+        &local_parameters->dtls_parameters, client->dtls_transport));
+
+    // Get local SCTP parameters
+    EOE(rawrtc_sctp_transport_get_capabilities(&local_parameters->sctp_parameters.capabilities));
+    EOE(rawrtc_sctp_transport_get_port(
+        &local_parameters->sctp_parameters.port, client->sctp_transport));
+}
+
+static void print_local_parameters(struct data_channel_sctp_throughput_client* client) {
+    struct odict* dict;
+    struct odict* node;
+
+    // Get local parameters
+    client_get_parameters(client);
+
+    // Create dict
+    EOR(odict_alloc(&dict, 16));
+
+    // Create nodes
+    EOR(odict_alloc(&node, 16));
+    set_ice_parameters(client->local_parameters.ice_parameters, node);
+    EOR(odict_entry_add(dict, "iceParameters", ODICT_OBJECT, node));
+    mem_deref(node);
+    EOR(odict_alloc(&node, 16));
+    set_ice_candidates(client->local_parameters.ice_candidates, node);
+    EOR(odict_entry_add(dict, "iceCandidates", ODICT_ARRAY, node));
+    mem_deref(node);
+    EOR(odict_alloc(&node, 16));
+    set_dtls_parameters(client->local_parameters.dtls_parameters, node);
+    EOR(odict_entry_add(dict, "dtlsParameters", ODICT_OBJECT, node));
+    mem_deref(node);
+    EOR(odict_alloc(&node, 16));
+    set_sctp_parameters(client->sctp_transport, &client->local_parameters.sctp_parameters, node);
+    EOR(odict_entry_add(dict, "sctpParameters", ODICT_OBJECT, node));
+    mem_deref(node);
+
+    // Print JSON
+    DEBUG_INFO("Local Parameters:\n%H\n", json_encode_odict, dict);
+
+    // Un-reference
+    mem_deref(dict);
+}
+
+static void exit_with_usage(char* program) {
+    DEBUG_WARNING(
+        "Usage: %s <0|1 (ice-role)> <message-size> [<n-times>] [<sctp-port>] "
+        "[<buffer-length>] [<cc-algorithm>] [<mtu>] [<ice-candidate-type> ...]\n",
+        program);
+    exit(1);
+}
+
+int main(int argc, char* argv[argc + 1]) {
+    char** ice_candidate_types = NULL;
+    size_t n_ice_candidate_types = 0;
+    enum rawrtc_ice_role role;
+    struct rawrtc_ice_gather_options* gather_options;
+    struct data_channel_sctp_throughput_client client = {0};
+    (void) client.ice_candidate_types;
+    (void) client.n_ice_candidate_types;
+
+    // Debug
+    dbg_init(DBG_DEBUG, DBG_ALL);
+    DEBUG_PRINTF("Init\n");
+
+    // Initialise
+    EOE(rawrtc_init(true));
+
+    // Check arguments length
+    if (argc < 3) {
+        exit_with_usage(argv[0]);
+    }
+
+    // Get ICE role
+    if (get_ice_role(&role, argv[1])) {
+        exit_with_usage(argv[0]);
+    }
+
+    // Get message size
+    if (!str_to_uint64(&client.message_size, argv[2])) {
+        exit_with_usage(argv[0]);
+    }
+
+    // Get number of times the test should run (optional)
+    client.n_times_left = 1;
+    if (argc >= 4 && !str_to_uint16(&client.n_times_left, argv[3])) {
+        exit_with_usage(argv[0]);
+    }
+
+    // TODO: Add possibility to turn checksum generation/validation on or off
+
+    // Get SCTP port (optional)
+    if (argc >= 5 && !str_to_uint16(&client.local_parameters.sctp_parameters.port, argv[4])) {
+        exit_with_usage(argv[0]);
+    }
+
+    // Get send/receiver buffer length (optional)
+    client.buffer_length = TRANSPORT_BUFFER_LENGTH;
+    if (argc >= 6 && !str_to_uint32(&client.buffer_length, argv[5])) {
+        exit_with_usage(argv[0]);
+    }
+
+    // Get congestion control algorithm (optional)
+    client.congestion_ctrl_algorithm = RAWRTC_SCTP_TRANSPORT_CONGESTION_CTRL_RFC2581;
+    if (argc >= 7 && get_congestion_control_algorithm(&client.congestion_ctrl_algorithm, argv[6])) {
+        exit_with_usage(argv[0]);
+    }
+
+    // Get MTU (optional)
+    if (argc >= 8 && !str_to_uint32(&client.mtu, argv[7])) {
+        exit_with_usage(argv[0]);
+    }
+
+    // Get enabled ICE candidate types to be added (optional)
+    if (argc >= 9) {
+        ice_candidate_types = &argv[8];
+        n_ice_candidate_types = (size_t) argc - 8;
+    }
+
+    // Create ICE gather options
+    EOE(rawrtc_ice_gather_options_create(&gather_options, RAWRTC_ICE_GATHER_POLICY_ALL));
+
+    // Set client fields
+    client.name = "A";
+    client.ice_candidate_types = ice_candidate_types;
+    client.n_ice_candidate_types = n_ice_candidate_types;
+    client.gather_options = gather_options;
+    client.role = role;
+
+    // Pre-generate messages (if 'controlling')
+    if (role == RAWRTC_ICE_ROLE_CONTROLLING) {
+        // Start indicator
+        client.start_buffer = mbuf_alloc(8);
+        EOE(client.start_buffer ? RAWRTC_CODE_SUCCESS : RAWRTC_CODE_NO_MEMORY);
+        EOR(mbuf_write_u64(client.start_buffer, sys_htonll(client.message_size)));
+
+        // Throughput test buffer
+        client.throughput_buffer = mbuf_alloc(client.message_size);
+        EOE(client.throughput_buffer ? RAWRTC_CODE_SUCCESS : RAWRTC_CODE_NO_MEMORY);
+        EOR(mbuf_fill(client.throughput_buffer, 0x01, mbuf_get_space(client.throughput_buffer)));
+    }
+
+    // Setup client
+    client_init(&client);
+
+    // Start gathering
+    client_start_gathering(&client);
+
+    // Listen on stdin
+    EOR(fd_listen(STDIN_FILENO, FD_READ, parse_remote_parameters, &client));
+
+    // Start main loop
+    EOR(re_main(default_signal_handler));
+
+    // Stop client & bye
+    client_stop(&client);
+    before_exit();
+    return 0;
+}
diff --git a/tools/data-channel-sctp.c b/tools/data-channel-sctp.c
new file mode 100644
index 0000000..7de1cd2
--- /dev/null
+++ b/tools/data-channel-sctp.c
@@ -0,0 +1,505 @@
+#include "helper/handler.h"
+#include "helper/parameters.h"
+#include "helper/utils.h"
+#include <rawrtc.h>
+#include <rawrtcc.h>
+#include <rawrtcdc.h>
+#include <re.h>
+#include <stdlib.h>  // exit
+#include <string.h>  // memcpy
+#include <unistd.h>  // STDIN_FILENO
+
+#define DEBUG_MODULE "data-channel-sctp-app"
+#define DEBUG_LEVEL 7
+#include <re_dbg.h>
+
+enum {
+    TRANSPORT_BUFFER_LENGTH = 1048576,  // 1 MiB
+    DEFAULT_MESSAGE_LENGTH = 1073741823,  // 1 GiB
+};
+
+struct parameters {
+    struct rawrtc_ice_parameters* ice_parameters;
+    struct rawrtc_ice_candidates* ice_candidates;
+    struct rawrtc_dtls_parameters* dtls_parameters;
+    struct sctp_parameters sctp_parameters;
+};
+
+// Note: Shadows struct client
+struct data_channel_sctp_client {
+    char* name;
+    char** ice_candidate_types;
+    size_t n_ice_candidate_types;
+    struct rawrtc_ice_gather_options* gather_options;
+    enum rawrtc_ice_role role;
+    struct rawrtc_certificate* certificate;
+    struct rawrtc_ice_gatherer* gatherer;
+    struct rawrtc_ice_transport* ice_transport;
+    struct rawrtc_dtls_transport* dtls_transport;
+    struct rawrtc_sctp_transport* sctp_transport;
+    struct rawrtc_data_transport* data_transport;
+    struct data_channel_helper* data_channel_negotiated;
+    struct data_channel_helper* data_channel;
+    struct parameters local_parameters;
+    struct parameters remote_parameters;
+};
+
+static void print_local_parameters(struct data_channel_sctp_client* client);
+
+static struct tmr timer = {0};
+
+static void timer_handler(void* arg) {
+    struct data_channel_helper* const channel = arg;
+    struct data_channel_sctp_client* const client =
+        (struct data_channel_sctp_client*) channel->client;
+    uint64_t max_message_size = DEFAULT_MESSAGE_LENGTH;
+    struct mbuf* buffer;
+    enum rawrtc_code error;
+    enum rawrtc_dtls_role role;
+
+    // Get the remote peer's maximum message size
+    EOE(rawrtc_sctp_capabilities_get_max_message_size(
+        &max_message_size, client->remote_parameters.sctp_parameters.capabilities));
+    if (max_message_size > 0) {
+        max_message_size = min(DEFAULT_MESSAGE_LENGTH, max_message_size);
+    } else {
+        max_message_size = DEFAULT_MESSAGE_LENGTH;
+    }
+
+    // Compose message
+    buffer = mbuf_alloc(max_message_size);
+    EOE(buffer ? RAWRTC_CODE_SUCCESS : RAWRTC_CODE_NO_MEMORY);
+    EOR(mbuf_fill(buffer, 'M', mbuf_get_space(buffer)));
+    mbuf_set_pos(buffer, 0);
+
+    // Send message
+    DEBUG_PRINTF("(%s) Sending %zu bytes\n", client->name, mbuf_get_left(buffer));
+    error = rawrtc_data_channel_send(channel->channel, buffer, true);
+    if (error) {
+        DEBUG_WARNING("Could not send, reason: %s\n", rawrtc_code_to_str(error));
+    }
+    mem_deref(buffer);
+
+    // Get DTLS role
+    EOE(rawrtc_dtls_parameters_get_role(&role, client->local_parameters.dtls_parameters));
+    if (role == RAWRTC_DTLS_ROLE_CLIENT) {
+        // Close bear-noises
+        DEBUG_PRINTF("(%s) Closing channel\n", client->name, channel->label);
+        EOR(rawrtc_data_channel_close(client->data_channel->channel));
+    }
+}
+
+static void data_channel_open_handler(void* const arg) {
+    struct data_channel_helper* const channel = arg;
+    struct data_channel_sctp_client* const client =
+        (struct data_channel_sctp_client*) channel->client;
+    struct mbuf* buffer;
+    enum rawrtc_code error;
+
+    // Print open event
+    default_data_channel_open_handler(arg);
+
+    // Send data delayed on bear-noises
+    if (str_cmp(channel->label, "bear-noises") == 0) {
+        tmr_start(&timer, 30000, timer_handler, channel);
+        return;
+    }
+
+    // Compose message (8 KiB)
+    buffer = mbuf_alloc(1 << 13);
+    EOE(buffer ? RAWRTC_CODE_SUCCESS : RAWRTC_CODE_NO_MEMORY);
+    EOR(mbuf_fill(buffer, 'M', mbuf_get_space(buffer)));
+    mbuf_set_pos(buffer, 0);
+
+    // Send message
+    DEBUG_PRINTF("(%s) Sending %zu bytes\n", client->name, mbuf_get_left(buffer));
+    error = rawrtc_data_channel_send(channel->channel, buffer, true);
+    if (error) {
+        DEBUG_WARNING("Could not send, reason: %s\n", rawrtc_code_to_str(error));
+    }
+    mem_deref(buffer);
+}
+
+static void ice_gatherer_local_candidate_handler(
+    struct rawrtc_ice_candidate* const candidate,
+    char const* const url,  // read-only
+    void* const arg) {
+    struct data_channel_sctp_client* const client = arg;
+
+    // Print local candidate
+    default_ice_gatherer_local_candidate_handler(candidate, url, arg);
+
+    // Print local parameters (if last candidate)
+    if (!candidate) {
+        print_local_parameters(client);
+    }
+}
+
+static void dtls_transport_state_change_handler(
+    enum rawrtc_dtls_transport_state const state,  // read-only
+    void* const arg) {
+    struct data_channel_sctp_client* const client = arg;
+
+    // Print state
+    default_dtls_transport_state_change_handler(state, arg);
+
+    // Open? Create new data channel
+    // TODO: Move this once we can create data channels earlier
+    if (state == RAWRTC_DTLS_TRANSPORT_STATE_CONNECTED) {
+        enum rawrtc_dtls_role role;
+
+        // Renew DTLS parameters
+        mem_deref(client->local_parameters.dtls_parameters);
+        EOE(rawrtc_dtls_transport_get_local_parameters(
+            &client->local_parameters.dtls_parameters, client->dtls_transport));
+
+        // Get DTLS role
+        EOE(rawrtc_dtls_parameters_get_role(&role, client->local_parameters.dtls_parameters));
+        DEBUG_PRINTF("(%s) DTLS role: %s\n", client->name, rawrtc_dtls_role_to_str(role));
+
+        // Client? Create data channel
+        if (role == RAWRTC_DTLS_ROLE_CLIENT) {
+            struct rawrtc_data_channel_parameters* channel_parameters;
+
+            // Create data channel helper
+            data_channel_helper_create(
+                &client->data_channel, (struct client*) client, "bear-noises");
+
+            // Create data channel parameters
+            EOE(rawrtc_data_channel_parameters_create(
+                &channel_parameters, client->data_channel->label,
+                RAWRTC_DATA_CHANNEL_TYPE_RELIABLE_UNORDERED, 0, NULL, false, 0));
+
+            // Create data channel
+            EOE(rawrtc_data_channel_create(
+                &client->data_channel->channel, client->data_transport, channel_parameters,
+                data_channel_open_handler, default_data_channel_buffered_amount_low_handler,
+                default_data_channel_error_handler, default_data_channel_close_handler,
+                default_data_channel_message_handler, client->data_channel));
+
+            // Un-reference
+            mem_deref(channel_parameters);
+        }
+    }
+}
+
+static void client_init(struct data_channel_sctp_client* const client) {
+    struct rawrtc_certificate* certificates[1];
+    struct rawrtc_data_channel_parameters* channel_parameters;
+
+    // Generate certificates
+    EOE(rawrtc_certificate_generate(&client->certificate, NULL));
+    certificates[0] = client->certificate;
+
+    // Create ICE gatherer
+    EOE(rawrtc_ice_gatherer_create(
+        &client->gatherer, client->gather_options, default_ice_gatherer_state_change_handler,
+        default_ice_gatherer_error_handler, ice_gatherer_local_candidate_handler, client));
+
+    // Create ICE transport
+    EOE(rawrtc_ice_transport_create(
+        &client->ice_transport, client->gatherer, default_ice_transport_state_change_handler,
+        default_ice_transport_candidate_pair_change_handler, client));
+
+    // Create DTLS transport
+    EOE(rawrtc_dtls_transport_create(
+        &client->dtls_transport, client->ice_transport, certificates, ARRAY_SIZE(certificates),
+        dtls_transport_state_change_handler, default_dtls_transport_error_handler, client));
+
+    // Create SCTP transport
+    EOE(rawrtc_sctp_transport_create(
+        &client->sctp_transport, client->dtls_transport,
+        client->local_parameters.sctp_parameters.port, default_data_channel_handler,
+        default_sctp_transport_state_change_handler, client));
+    EOE(rawrtc_sctp_transport_set_buffer_length(
+        client->sctp_transport, TRANSPORT_BUFFER_LENGTH, TRANSPORT_BUFFER_LENGTH));
+
+    // Get data transport
+    EOE(rawrtc_sctp_transport_get_data_transport(&client->data_transport, client->sctp_transport));
+
+    // Create data channel helper
+    data_channel_helper_create(
+        &client->data_channel_negotiated, (struct client*) client, "cat-noises");
+
+    // Create data channel parameters
+    EOE(rawrtc_data_channel_parameters_create(
+        &channel_parameters, client->data_channel_negotiated->label,
+        RAWRTC_DATA_CHANNEL_TYPE_RELIABLE_ORDERED, 0, NULL, true, 0));
+
+    // Create pre-negotiated data channel
+    EOE(rawrtc_data_channel_create(
+        &client->data_channel_negotiated->channel, client->data_transport, channel_parameters,
+        data_channel_open_handler, default_data_channel_buffered_amount_low_handler,
+        default_data_channel_error_handler, default_data_channel_close_handler,
+        default_data_channel_message_handler, client->data_channel_negotiated));
+
+    // Un-reference
+    mem_deref(channel_parameters);
+}
+
+static void client_start_gathering(struct data_channel_sctp_client* const client) {
+    // Start gathering
+    EOE(rawrtc_ice_gatherer_gather(client->gatherer, NULL));
+}
+
+static void client_start_transports(struct data_channel_sctp_client* const client) {
+    struct parameters* const remote_parameters = &client->remote_parameters;
+
+    // Start ICE transport
+    EOE(rawrtc_ice_transport_start(
+        client->ice_transport, client->gatherer, remote_parameters->ice_parameters, client->role));
+
+    // Start DTLS transport
+    EOE(rawrtc_dtls_transport_start(client->dtls_transport, remote_parameters->dtls_parameters));
+
+    // Start SCTP transport
+    EOE(rawrtc_sctp_transport_start(
+        client->sctp_transport, remote_parameters->sctp_parameters.capabilities,
+        remote_parameters->sctp_parameters.port));
+}
+
+static void parameters_destroy(struct parameters* const parameters) {
+    // Un-reference
+    parameters->ice_parameters = mem_deref(parameters->ice_parameters);
+    parameters->ice_candidates = mem_deref(parameters->ice_candidates);
+    parameters->dtls_parameters = mem_deref(parameters->dtls_parameters);
+    if (parameters->sctp_parameters.capabilities) {
+        parameters->sctp_parameters.capabilities =
+            mem_deref(parameters->sctp_parameters.capabilities);
+    }
+}
+
+static void client_stop(struct data_channel_sctp_client* const client) {
+    if (client->sctp_transport) {
+        EOE(rawrtc_sctp_transport_stop(client->sctp_transport));
+    }
+    if (client->dtls_transport) {
+        EOE(rawrtc_dtls_transport_stop(client->dtls_transport));
+    }
+    if (client->ice_transport) {
+        EOE(rawrtc_ice_transport_stop(client->ice_transport));
+    }
+    if (client->gatherer) {
+        EOE(rawrtc_ice_gatherer_close(client->gatherer));
+    }
+
+    // Un-reference & close
+    parameters_destroy(&client->remote_parameters);
+    parameters_destroy(&client->local_parameters);
+    client->data_channel = mem_deref(client->data_channel);
+    client->data_channel_negotiated = mem_deref(client->data_channel_negotiated);
+    client->data_transport = mem_deref(client->data_transport);
+    client->sctp_transport = mem_deref(client->sctp_transport);
+    client->dtls_transport = mem_deref(client->dtls_transport);
+    client->ice_transport = mem_deref(client->ice_transport);
+    client->gatherer = mem_deref(client->gatherer);
+    client->certificate = mem_deref(client->certificate);
+    client->gather_options = mem_deref(client->gather_options);
+
+    // Stop listening on STDIN
+    fd_close(STDIN_FILENO);
+}
+
+static void client_set_parameters(struct data_channel_sctp_client* const client) {
+    struct parameters* const remote_parameters = &client->remote_parameters;
+
+    // Set remote ICE candidates
+    EOE(rawrtc_ice_transport_set_remote_candidates(
+        client->ice_transport, remote_parameters->ice_candidates->candidates,
+        remote_parameters->ice_candidates->n_candidates));
+}
+
+static void parse_remote_parameters(int flags, void* arg) {
+    struct data_channel_sctp_client* const client = arg;
+    enum rawrtc_code error;
+    struct odict* dict = NULL;
+    struct odict* node = NULL;
+    struct rawrtc_ice_parameters* ice_parameters = NULL;
+    struct rawrtc_ice_candidates* ice_candidates = NULL;
+    struct rawrtc_dtls_parameters* dtls_parameters = NULL;
+    struct sctp_parameters sctp_parameters = {0};
+    (void) flags;
+
+    // Get dict from JSON
+    error = get_json_stdin(&dict);
+    if (error) {
+        goto out;
+    }
+
+    // Decode JSON
+    error |= dict_get_entry(&node, dict, "iceParameters", ODICT_OBJECT, true);
+    error |= get_ice_parameters(&ice_parameters, node);
+    error |= dict_get_entry(&node, dict, "iceCandidates", ODICT_ARRAY, true);
+    error |= get_ice_candidates(&ice_candidates, node, arg);
+    error |= dict_get_entry(&node, dict, "dtlsParameters", ODICT_OBJECT, true);
+    error |= get_dtls_parameters(&dtls_parameters, node);
+    error |= dict_get_entry(&node, dict, "sctpParameters", ODICT_OBJECT, true);
+    error |= get_sctp_parameters(&sctp_parameters, node);
+
+    // Ok?
+    if (error) {
+        DEBUG_WARNING("Invalid remote parameters\n");
+        if (sctp_parameters.capabilities) {
+            mem_deref(sctp_parameters.capabilities);
+        }
+        goto out;
+    }
+
+    // Set parameters & start transports
+    client->remote_parameters.ice_parameters = mem_ref(ice_parameters);
+    client->remote_parameters.ice_candidates = mem_ref(ice_candidates);
+    client->remote_parameters.dtls_parameters = mem_ref(dtls_parameters);
+    memcpy(&client->remote_parameters.sctp_parameters, &sctp_parameters, sizeof(sctp_parameters));
+    DEBUG_INFO("Applying remote parameters\n");
+    client_set_parameters(client);
+    client_start_transports(client);
+
+out:
+    // Un-reference
+    mem_deref(dtls_parameters);
+    mem_deref(ice_candidates);
+    mem_deref(ice_parameters);
+    mem_deref(dict);
+
+    // Exit?
+    if (error == RAWRTC_CODE_NO_VALUE) {
+        DEBUG_NOTICE("Exiting\n");
+
+        // Stop client & bye
+        client_stop(client);
+        tmr_cancel(&timer);
+        re_cancel();
+    }
+}
+
+static void client_get_parameters(struct data_channel_sctp_client* const client) {
+    struct parameters* const local_parameters = &client->local_parameters;
+
+    // Get local ICE parameters
+    EOE(rawrtc_ice_gatherer_get_local_parameters(
+        &local_parameters->ice_parameters, client->gatherer));
+
+    // Get local ICE candidates
+    EOE(rawrtc_ice_gatherer_get_local_candidates(
+        &local_parameters->ice_candidates, client->gatherer));
+
+    // Get local DTLS parameters
+    EOE(rawrtc_dtls_transport_get_local_parameters(
+        &local_parameters->dtls_parameters, client->dtls_transport));
+
+    // Get local SCTP parameters
+    EOE(rawrtc_sctp_transport_get_capabilities(&local_parameters->sctp_parameters.capabilities));
+    EOE(rawrtc_sctp_transport_get_port(
+        &local_parameters->sctp_parameters.port, client->sctp_transport));
+}
+
+static void print_local_parameters(struct data_channel_sctp_client* client) {
+    struct odict* dict;
+    struct odict* node;
+
+    // Get local parameters
+    client_get_parameters(client);
+
+    // Create dict
+    EOR(odict_alloc(&dict, 16));
+
+    // Create nodes
+    EOR(odict_alloc(&node, 16));
+    set_ice_parameters(client->local_parameters.ice_parameters, node);
+    EOR(odict_entry_add(dict, "iceParameters", ODICT_OBJECT, node));
+    mem_deref(node);
+    EOR(odict_alloc(&node, 16));
+    set_ice_candidates(client->local_parameters.ice_candidates, node);
+    EOR(odict_entry_add(dict, "iceCandidates", ODICT_ARRAY, node));
+    mem_deref(node);
+    EOR(odict_alloc(&node, 16));
+    set_dtls_parameters(client->local_parameters.dtls_parameters, node);
+    EOR(odict_entry_add(dict, "dtlsParameters", ODICT_OBJECT, node));
+    mem_deref(node);
+    EOR(odict_alloc(&node, 16));
+    set_sctp_parameters(client->sctp_transport, &client->local_parameters.sctp_parameters, node);
+    EOR(odict_entry_add(dict, "sctpParameters", ODICT_OBJECT, node));
+    mem_deref(node);
+
+    // Print JSON
+    DEBUG_INFO("Local Parameters:\n%H\n", json_encode_odict, dict);
+
+    // Un-reference
+    mem_deref(dict);
+}
+
+static void exit_with_usage(char* program) {
+    DEBUG_WARNING("Usage: %s <0|1 (ice-role)> [<sctp-port>] [<ice-candidate-type> ...]", program);
+    exit(1);
+}
+
+int main(int argc, char* argv[argc + 1]) {
+    char** ice_candidate_types = NULL;
+    size_t n_ice_candidate_types = 0;
+    enum rawrtc_ice_role role;
+    struct rawrtc_ice_gather_options* gather_options;
+    char* const turn_zwuenf_org_urls[] = {"stun:turn.zwuenf.org"};
+    struct data_channel_sctp_client client = {0};
+    (void) client.ice_candidate_types;
+    (void) client.n_ice_candidate_types;
+
+    // Debug
+    dbg_init(DBG_DEBUG, DBG_ALL);
+    DEBUG_PRINTF("Init\n");
+
+    // Initialise
+    EOE(rawrtc_init(true));
+
+    // Check arguments length
+    if (argc < 2) {
+        exit_with_usage(argv[0]);
+    }
+
+    // Get ICE role
+    if (get_ice_role(&role, argv[1])) {
+        exit_with_usage(argv[0]);
+    }
+
+    // Get SCTP port (optional)
+    if (argc >= 3 && !str_to_uint16(&client.local_parameters.sctp_parameters.port, argv[2])) {
+        exit_with_usage(argv[0]);
+    }
+
+    // Get enabled ICE candidate types to be added (optional)
+    if (argc >= 4) {
+        ice_candidate_types = &argv[3];
+        n_ice_candidate_types = (size_t) argc - 3;
+    }
+
+    // Create ICE gather options
+    EOE(rawrtc_ice_gather_options_create(&gather_options, RAWRTC_ICE_GATHER_POLICY_ALL));
+
+    // Add ICE servers to ICE gather options
+    EOE(rawrtc_ice_gather_options_add_server(
+        gather_options, turn_zwuenf_org_urls, ARRAY_SIZE(turn_zwuenf_org_urls), NULL, NULL,
+        RAWRTC_ICE_CREDENTIAL_TYPE_NONE));
+
+    // Set client fields
+    client.name = "A";
+    client.ice_candidate_types = ice_candidate_types;
+    client.n_ice_candidate_types = n_ice_candidate_types;
+    client.gather_options = gather_options;
+    client.role = role;
+
+    // Setup client
+    client_init(&client);
+
+    // Start gathering
+    client_start_gathering(&client);
+
+    // Listen on stdin
+    EOR(fd_listen(STDIN_FILENO, FD_READ, parse_remote_parameters, &client));
+
+    // Start main loop
+    EOR(re_main(default_signal_handler));
+
+    // Stop client & bye
+    client_stop(&client);
+    before_exit();
+    return 0;
+}
diff --git a/tools/dtls-transport-loopback.c b/tools/dtls-transport-loopback.c
new file mode 100644
index 0000000..bf05dd5
--- /dev/null
+++ b/tools/dtls-transport-loopback.c
@@ -0,0 +1,177 @@
+#include "helper/handler.h"
+#include "helper/utils.h"
+#include <rawrtc.h>
+#include <rawrtcc.h>
+#include <rawrtcdc.h>
+#include <re.h>
+#include <stdlib.h>  // exit
+#include <unistd.h>  // STDIN_FILENO
+
+#define DEBUG_MODULE "dtls-transport-loopback-app"
+#define DEBUG_LEVEL 7
+#include <re_dbg.h>
+
+// Note: Shadows struct client
+struct dtls_transport_client {
+    char* name;
+    char** ice_candidate_types;
+    size_t n_ice_candidate_types;
+    struct rawrtc_ice_gather_options* gather_options;
+    struct rawrtc_ice_parameters* ice_parameters;
+    struct rawrtc_dtls_parameters* dtls_parameters;
+    enum rawrtc_ice_role role;
+    struct rawrtc_certificate* certificate;
+    struct rawrtc_ice_gatherer* gatherer;
+    struct rawrtc_ice_transport* ice_transport;
+    struct rawrtc_dtls_transport* dtls_transport;
+    struct dtls_transport_client* other_client;
+};
+
+static void ice_gatherer_local_candidate_handler(
+    struct rawrtc_ice_candidate* const candidate,
+    char const* const url,  // read-only
+    void* const arg) {
+    struct dtls_transport_client* const client = arg;
+
+    // Print local candidate
+    default_ice_gatherer_local_candidate_handler(candidate, url, arg);
+
+    // Add to other client as remote candidate (if type enabled)
+    add_to_other_if_ice_candidate_type_enabled(arg, candidate, client->other_client->ice_transport);
+}
+
+static void client_init(struct dtls_transport_client* const local) {
+    struct rawrtc_certificate* certificates[1];
+
+    // Generate certificates
+    EOE(rawrtc_certificate_generate(&local->certificate, NULL));
+    certificates[0] = local->certificate;
+
+    // Create ICE gatherer
+    EOE(rawrtc_ice_gatherer_create(
+        &local->gatherer, local->gather_options, default_ice_gatherer_state_change_handler,
+        default_ice_gatherer_error_handler, ice_gatherer_local_candidate_handler, local));
+
+    // Create ICE transport
+    EOE(rawrtc_ice_transport_create(
+        &local->ice_transport, local->gatherer, default_ice_transport_state_change_handler,
+        default_ice_transport_candidate_pair_change_handler, local));
+
+    // Create DTLS transport
+    EOE(rawrtc_dtls_transport_create(
+        &local->dtls_transport, local->ice_transport, certificates, ARRAY_SIZE(certificates),
+        default_dtls_transport_state_change_handler, default_dtls_transport_error_handler, local));
+}
+
+static void client_start(
+    struct dtls_transport_client* const local, struct dtls_transport_client* const remote) {
+    // Get & set ICE parameters
+    EOE(rawrtc_ice_gatherer_get_local_parameters(&local->ice_parameters, remote->gatherer));
+
+    // Start gathering
+    EOE(rawrtc_ice_gatherer_gather(local->gatherer, NULL));
+
+    // Start ICE transport
+    EOE(rawrtc_ice_transport_start(
+        local->ice_transport, local->gatherer, local->ice_parameters, local->role));
+
+    // Get & set DTLS parameters
+    EOE(rawrtc_dtls_transport_get_local_parameters(
+        &local->dtls_parameters, remote->dtls_transport));
+
+    // Start DTLS transport
+    EOE(rawrtc_dtls_transport_start(local->dtls_transport, local->dtls_parameters));
+}
+
+static void client_stop(struct dtls_transport_client* const client) {
+    // Stop transports & close gatherer
+    EOE(rawrtc_dtls_transport_stop(client->dtls_transport));
+    EOE(rawrtc_ice_transport_stop(client->ice_transport));
+    EOE(rawrtc_ice_gatherer_close(client->gatherer));
+
+    // Un-reference & close
+    client->dtls_parameters = mem_deref(client->dtls_parameters);
+    client->ice_parameters = mem_deref(client->ice_parameters);
+    client->dtls_transport = mem_deref(client->dtls_transport);
+    client->ice_transport = mem_deref(client->ice_transport);
+    client->gatherer = mem_deref(client->gatherer);
+    client->certificate = mem_deref(client->certificate);
+}
+
+int main(int argc, char* argv[argc + 1]) {
+    char** ice_candidate_types = NULL;
+    size_t n_ice_candidate_types = 0;
+    struct rawrtc_ice_gather_options* gather_options;
+    char* const turn_zwuenf_org_urls[] = {"stun:turn.zwuenf.org"};
+    struct dtls_transport_client a = {0};
+    struct dtls_transport_client b = {0};
+    (void) a.ice_candidate_types;
+    (void) a.n_ice_candidate_types;
+    (void) b.ice_candidate_types;
+    (void) b.n_ice_candidate_types;
+
+    // Debug
+    dbg_init(DBG_DEBUG, DBG_ALL);
+    DEBUG_PRINTF("Init\n");
+
+    // Initialise
+    EOE(rawrtc_init(true));
+
+    // Get enabled ICE candidate types to be added (optional)
+    if (argc > 1) {
+        ice_candidate_types = &argv[1];
+        n_ice_candidate_types = (size_t) argc - 1;
+    }
+
+    // Create ICE gather options
+    EOE(rawrtc_ice_gather_options_create(&gather_options, RAWRTC_ICE_GATHER_POLICY_ALL));
+
+    // Add ICE servers to ICE gather options
+    EOE(rawrtc_ice_gather_options_add_server(
+        gather_options, turn_zwuenf_org_urls, ARRAY_SIZE(turn_zwuenf_org_urls), NULL, NULL,
+        RAWRTC_ICE_CREDENTIAL_TYPE_NONE));
+
+    // Setup client A
+    a.name = "A";
+    a.ice_candidate_types = ice_candidate_types;
+    a.n_ice_candidate_types = n_ice_candidate_types;
+    a.gather_options = gather_options;
+    a.role = RAWRTC_ICE_ROLE_CONTROLLING;
+    a.other_client = &b;
+
+    // Setup client B
+    b.name = "B";
+    b.ice_candidate_types = ice_candidate_types;
+    b.n_ice_candidate_types = n_ice_candidate_types;
+    b.gather_options = gather_options;
+    b.role = RAWRTC_ICE_ROLE_CONTROLLED;
+    b.other_client = &a;
+
+    // Initialise clients
+    client_init(&a);
+    client_init(&b);
+
+    // Start clients
+    client_start(&a, &b);
+    client_start(&b, &a);
+
+    // Listen on stdin
+    EOR(fd_listen(STDIN_FILENO, FD_READ, stop_on_return_handler, NULL));
+
+    // Start main loop
+    EOR(re_main(default_signal_handler));
+
+    // Stop clients
+    client_stop(&a);
+    client_stop(&b);
+
+    // Stop listening on STDIN
+    fd_close(STDIN_FILENO);
+
+    // Free
+    mem_deref(gather_options);
+
+    // Bye
+    before_exit();
+    return 0;
+}
diff --git a/tools/helper/common.c b/tools/helper/common.c
new file mode 100644
index 0000000..e4be7a2
--- /dev/null
+++ b/tools/helper/common.c
@@ -0,0 +1,225 @@
+#include "common.h"
+#include <rawrtc.h>
+#include <rawrtcc.h>
+#include <rawrtcdc.h>
+#include <re.h>
+#include <stdlib.h>  // exit
+#include <string.h>  // strerror
+
+#define DEBUG_MODULE "helper-common"
+#define DEBUG_LEVEL 7
+#include <re_dbg.h>
+
+/*
+ * Ignore success code list.
+ */
+enum rawrtc_code const ignore_success[] = {RAWRTC_CODE_SUCCESS};
+size_t const ignore_success_length = ARRAY_SIZE(ignore_success);
+
+/*
+ * Function to be called before exiting.
+ */
+void before_exit(void) {
+    // Close
+    rawrtc_close(true);
+
+    // Check memory leaks
+    tmr_debug();
+    mem_debug();
+}
+
+/*
+ * Exit on error code.
+ */
+void exit_on_error(
+    enum rawrtc_code const code,
+    enum rawrtc_code const ignore[],
+    size_t const n_ignore,
+    char const* const file,
+    uint32_t const line) {
+    size_t i;
+
+    // Ignore?
+    for (i = 0; i < n_ignore; ++i) {
+        if (code == ignore[i]) {
+            return;
+        }
+    }
+
+    // Handle
+    switch (code) {
+        case RAWRTC_CODE_SUCCESS:
+            return;
+        case RAWRTC_CODE_NOT_IMPLEMENTED:
+            DEBUG_WARNING("Not implemented in %s %" PRIu32 "\n", file, line);
+            return;
+        default:
+            DEBUG_WARNING(
+                "Error in %s %" PRIu32 " (%d): %s\n", file, line, code, rawrtc_code_to_str(code));
+            before_exit();
+            exit((int) code);
+    }
+}
+
+/*
+ * Exit on POSIX error code.
+ */
+void exit_on_posix_error(int code, char const* const file, uint32_t line) {
+    if (code != 0) {
+        DEBUG_WARNING("Error in %s %" PRIu32 " (%d): %s\n", file, line, code, strerror(code));
+        before_exit();
+        exit(code);
+    }
+}
+
+/*
+ * Exit with a custom error message.
+ */
+void exit_with_error(char const* const file, uint32_t line, char const* const formatter, ...) {
+    char* message;
+
+    // Format message
+    va_list ap;
+    va_start(ap, formatter);
+    re_vsdprintf(&message, formatter, ap);
+    va_end(ap);
+
+    // Print message
+    DEBUG_WARNING("%s %" PRIu32 ": %s\n", file, line, message);
+
+    // Un-reference & bye
+    mem_deref(message);
+    before_exit();
+    exit(1);
+}
+
+/*
+ * Check if the ICE candidate type is enabled.
+ */
+bool ice_candidate_type_enabled(
+    struct client* const client, enum rawrtc_ice_candidate_type const type) {
+    char const* const type_str = rawrtc_ice_candidate_type_to_str(type);
+    size_t i;
+
+    // All enabled?
+    if (client->n_ice_candidate_types == 0) {
+        return true;
+    }
+
+    // Specifically enabled?
+    for (i = 0; i < client->n_ice_candidate_types; ++i) {
+        if (str_cmp(client->ice_candidate_types[i], type_str) == 0) {
+            return true;
+        }
+    }
+
+    // Nope
+    return false;
+}
+
+/*
+ * Print ICE candidate information.
+ */
+void print_ice_candidate(
+    struct rawrtc_ice_candidate* const candidate,
+    char const* const url,  // read-only
+    struct rawrtc_peer_connection_ice_candidate* const pc_candidate,  // nullable
+    struct client* const client) {
+    if (candidate) {
+        enum rawrtc_code const ignore[] = {RAWRTC_CODE_NO_VALUE};
+        enum rawrtc_code error;
+        char* foundation;
+        enum rawrtc_ice_protocol protocol;
+        uint32_t priority;
+        char* ip;
+        uint16_t port;
+        enum rawrtc_ice_candidate_type type;
+        enum rawrtc_ice_tcp_candidate_type tcp_type;
+        char const* tcp_type_str = "n/a";
+        char* related_address = NULL;
+        uint16_t related_port = 0;
+        char* mid = NULL;
+        uint8_t media_line_index = UINT8_MAX;
+        char* media_line_index_str = NULL;
+        char* username_fragment = NULL;
+        bool is_enabled;
+        int level;
+
+        // Get candidate information
+        EOE(rawrtc_ice_candidate_get_foundation(&foundation, candidate));
+        EOE(rawrtc_ice_candidate_get_protocol(&protocol, candidate));
+        EOE(rawrtc_ice_candidate_get_priority(&priority, candidate));
+        EOE(rawrtc_ice_candidate_get_ip(&ip, candidate));
+        EOE(rawrtc_ice_candidate_get_port(&port, candidate));
+        EOE(rawrtc_ice_candidate_get_type(&type, candidate));
+        error = rawrtc_ice_candidate_get_tcp_type(&tcp_type, candidate);
+        switch (error) {
+            case RAWRTC_CODE_SUCCESS:
+                tcp_type_str = rawrtc_ice_tcp_candidate_type_to_str(tcp_type);
+                break;
+            case RAWRTC_CODE_NO_VALUE:
+                break;
+            default:
+                EOE(error);
+                break;
+        }
+        EOEIGN(rawrtc_ice_candidate_get_related_address(&related_address, candidate), ignore);
+        EOEIGN(rawrtc_ice_candidate_get_related_port(&related_port, candidate), ignore);
+        if (pc_candidate) {
+            EOEIGN(rawrtc_peer_connection_ice_candidate_get_sdp_mid(&mid, pc_candidate), ignore);
+            error = rawrtc_peer_connection_ice_candidate_get_sdp_media_line_index(
+                &media_line_index, pc_candidate);
+            switch (error) {
+                case RAWRTC_CODE_SUCCESS:
+                    EOE(rawrtc_sdprintf(&media_line_index_str, "%" PRIu8, media_line_index));
+                    break;
+                case RAWRTC_CODE_NO_VALUE:
+                    break;
+                default:
+                    EOE(error);
+                    break;
+            }
+            EOEIGN(
+                rawrtc_peer_connection_ice_candidate_get_username_fragment(
+                    &username_fragment, pc_candidate),
+                ignore);
+        }
+        is_enabled = ice_candidate_type_enabled(client, type);
+
+        // Print candidate (meh, lot's of repeated code... feel free to suggest an alternative)
+        level = is_enabled ? DBG_INFO : DBG_DEBUG;
+        if (!pc_candidate) {
+            dbg_printf(
+                level,
+                "(%s) ICE candidate: foundation=%s, protocol=%s"
+                ", priority=%" PRIu32 ", ip=%s, port=%" PRIu16 ", type=%s, tcp-type=%s"
+                ", related-address=%s, related-port=%" PRIu16 "; URL: %s; %s\n",
+                client->name, foundation, rawrtc_ice_protocol_to_str(protocol), priority, ip, port,
+                rawrtc_ice_candidate_type_to_str(type), tcp_type_str,
+                related_address ? related_address : "n/a", related_port, url ? url : "n/a",
+                is_enabled ? "enabled" : "disabled");
+        } else {
+            dbg_printf(
+                level,
+                "(%s) ICE candidate: foundation=%s, protocol=%s"
+                ", priority=%" PRIu32 ", ip=%s, port=%" PRIu16 ", type=%s, tcp-type=%s"
+                ", related-address=%s, related-port=%" PRIu16 "; URL: %s"
+                "; mid=%s, media_line_index=%s, username_fragment=%s; %s\n",
+                client->name, foundation, rawrtc_ice_protocol_to_str(protocol), priority, ip, port,
+                rawrtc_ice_candidate_type_to_str(type), tcp_type_str,
+                related_address ? related_address : "n/a", related_port, url ? url : "n/a",
+                mid ? mid : "n/a", media_line_index_str ? media_line_index_str : "n/a",
+                username_fragment ? username_fragment : "n/a", is_enabled ? "enabled" : "disabled");
+        }
+
+        // Unreference
+        mem_deref(username_fragment);
+        mem_deref(media_line_index_str);
+        mem_deref(mid);
+        mem_deref(related_address);
+        mem_deref(ip);
+        mem_deref(foundation);
+    } else {
+        DEBUG_INFO("(%s) ICE gatherer last local candidate\n", client->name);
+    }
+}
diff --git a/tools/helper/common.h b/tools/helper/common.h
new file mode 100644
index 0000000..e2a34ad
--- /dev/null
+++ b/tools/helper/common.h
@@ -0,0 +1,95 @@
+#pragma once
+#include <rawrtc.h>
+#include <rawrtcc.h>
+#include <rawrtcdc.h>
+#include <re.h>
+
+enum {
+    PARAMETERS_MAX_LENGTH = 8192,
+};
+
+/*
+ * SCTP parameters that need to be negotiated.
+ */
+struct sctp_parameters {
+    struct rawrtc_sctp_capabilities* capabilities;
+    uint16_t port;
+};
+
+/*
+ * Client structure. Can be extended.
+ */
+struct client {
+    char* name;
+    char** ice_candidate_types;
+    size_t n_ice_candidate_types;
+};
+
+/*
+ * Data channel helper structure. Can be extended.
+ */
+struct data_channel_helper {
+    struct le le;
+    struct rawrtc_data_channel* channel;
+    char* label;
+    struct client* client;
+    void* arg;
+};
+
+/*
+ * Ignore success code list.
+ */
+extern enum rawrtc_code const ignore_success[];
+extern size_t const ignore_success_length;
+
+/*
+ * Helper macros for exiting with error messages.
+ */
+#define EOE(code) exit_on_error(code, ignore_success, ignore_success_length, __FILE__, __LINE__)
+#define EOEIGN(code, ignore) exit_on_error(code, ignore, ARRAY_SIZE(ignore), __FILE__, __LINE__)
+#define EOR(code) exit_on_posix_error(code, __FILE__, __LINE__)
+#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || (__GNUC__ >= 3)
+#    define EWE(...) exit_with_error(__FILE__, __LINE__, __VA_ARGS__)
+#elif defined(__GNUC__)
+#    define EWE(args...) exit_with_error(__FILE__, __LINE__, args)
+#endif
+
+/*
+ * Function to be called before exiting.
+ */
+void before_exit(void);
+
+/*
+ * Exit on error code.
+ */
+void exit_on_error(
+    enum rawrtc_code const code,
+    enum rawrtc_code const ignore[],
+    size_t const n_ignore,
+    char const* const file,
+    uint32_t const line);
+
+/*
+ * Exit on POSIX error code.
+ */
+void exit_on_posix_error(int code, char const* const file, uint32_t line);
+
+/*
+ * Exit with a custom error message.
+ */
+void exit_with_error(char const* const file, uint32_t line, char const* const formatter, ...);
+
+/*
+ * Check if the ICE candidate type is enabled.
+ */
+bool ice_candidate_type_enabled(
+    struct client* const client, enum rawrtc_ice_candidate_type const type);
+
+/*
+ * Print ICE candidate information.
+ */
+void print_ice_candidate(
+    struct rawrtc_ice_candidate* const candidate,
+    char const* const url,  // read-only
+    struct rawrtc_peer_connection_ice_candidate* const pc_candidate,  // nullable
+    struct client* const client);
diff --git a/tools/helper/handler.c b/tools/helper/handler.c
new file mode 100644
index 0000000..f6d8d1a
--- /dev/null
+++ b/tools/helper/handler.c
@@ -0,0 +1,337 @@
+#include "handler.h"
+#include "common.h"
+#include "utils.h"
+#include <rawrtc.h>
+#include <rawrtcc.h>
+#include <rawrtcdc.h>
+#include <re.h>
+#include <string.h>  // strlen
+
+#define DEBUG_MODULE "helper-handler"
+#define DEBUG_LEVEL 7
+#include <re_dbg.h>
+
+/*
+ * Print the ICE gatherer's state.
+ */
+void default_ice_gatherer_state_change_handler(
+    enum rawrtc_ice_gatherer_state const state,  // read-only
+    void* const arg  // will be casted to `struct client*`
+) {
+    struct client* const client = arg;
+    char const* const state_name = rawrtc_ice_gatherer_state_to_name(state);
+    (void) arg;
+    DEBUG_PRINTF("(%s) ICE gatherer state: %s\n", client->name, state_name);
+}
+
+/*
+ * Print the ICE gatherer's error event.
+ */
+void default_ice_gatherer_error_handler(
+    struct rawrtc_ice_candidate* const candidate,  // read-only, nullable
+    char const* const url,  // read-only
+    uint16_t const error_code,  // read-only
+    char const* const error_text,  // read-only
+    void* const arg  // will be casted to `struct client*`
+) {
+    struct client* const client = arg;
+    (void) candidate;
+    (void) error_code;
+    (void) arg;
+    DEBUG_NOTICE("(%s) ICE gatherer error, URL: %s, reason: %s\n", client->name, url, error_text);
+}
+
+/*
+ * Print the newly gathered local candidate.
+ */
+void default_ice_gatherer_local_candidate_handler(
+    struct rawrtc_ice_candidate* const candidate,
+    char const* const url,  // read-only
+    void* const arg  // will be casted to `struct client*`
+) {
+    struct client* const client = arg;
+    (void) arg;
+    print_ice_candidate(candidate, url, NULL, client);
+}
+
+/*
+ * Print the ICE transport's state.
+ */
+void default_ice_transport_state_change_handler(
+    enum rawrtc_ice_transport_state const state,
+    void* const arg  // will be casted to `struct client*`
+) {
+    struct client* const client = arg;
+    char const* const state_name = rawrtc_ice_transport_state_to_name(state);
+    (void) arg;
+    DEBUG_PRINTF("(%s) ICE transport state: %s\n", client->name, state_name);
+}
+
+/*
+ * Print the ICE candidate pair change event.
+ */
+void default_ice_transport_candidate_pair_change_handler(
+    struct rawrtc_ice_candidate* const local,  // read-only
+    struct rawrtc_ice_candidate* const remote,  // read-only
+    void* const arg  // will be casted to `struct client*`
+) {
+    struct client* const client = arg;
+    (void) local;
+    (void) remote;
+    DEBUG_PRINTF("(%s) ICE transport candidate pair change\n", client->name);
+}
+
+/*
+ * Print the DTLS transport's state.
+ */
+void default_dtls_transport_state_change_handler(
+    enum rawrtc_dtls_transport_state const state,  // read-only
+    void* const arg  // will be casted to `struct client*`
+) {
+    struct client* const client = arg;
+    char const* const state_name = rawrtc_dtls_transport_state_to_name(state);
+    DEBUG_PRINTF("(%s) DTLS transport state change: %s\n", client->name, state_name);
+}
+
+/*
+ * Print the DTLS transport's error event.
+ */
+void default_dtls_transport_error_handler(
+    // TODO: error.message (probably from OpenSSL)
+    void* const arg  // will be casted to `struct client*`
+) {
+    struct client* const client = arg;
+    // TODO: Print error message
+    DEBUG_WARNING("(%s) DTLS transport error: %s\n", client->name, "???");
+}
+
+#if RAWRTC_HAVE_SCTP_REDIRECT_TRANSPORT
+/*
+ * Print the SCTP redirect transport's state.
+ */
+void default_sctp_redirect_transport_state_change_handler(
+    enum rawrtc_sctp_redirect_transport_state const state,
+    void* const arg  // will be casted to `struct client*`
+) {
+    struct client* const client = arg;
+    char const* const state_name = rawrtc_sctp_redirect_transport_state_to_name(state);
+    DEBUG_PRINTF("(%s) SCTP redirect transport state change: %s\n", client->name, state_name);
+}
+#endif
+
+/*
+ * Print the SCTP transport's state.
+ */
+void default_sctp_transport_state_change_handler(
+    enum rawrtc_sctp_transport_state const state,
+    void* const arg  // will be casted to `struct client*`
+) {
+    struct client* const client = arg;
+    char const* const state_name = rawrtc_sctp_transport_state_to_name(state);
+    DEBUG_PRINTF("(%s) SCTP transport state change: %s\n", client->name, state_name);
+}
+
+/*
+ * Print the newly created data channel's parameter.
+ */
+void default_data_channel_handler(
+    struct rawrtc_data_channel* const channel,  // read-only, MUST be referenced when used
+    void* const arg  // will be casted to `struct client*`
+) {
+    struct client* const client = arg;
+    struct rawrtc_data_channel_parameters* parameters;
+    enum rawrtc_code const ignore[] = {RAWRTC_CODE_NO_VALUE};
+    char* label = NULL;
+
+    // Get data channel label and protocol
+    EOE(rawrtc_data_channel_get_parameters(&parameters, channel));
+    EOEIGN(rawrtc_data_channel_parameters_get_label(&label, parameters), ignore);
+    DEBUG_INFO("(%s) New data channel instance: %s\n", client->name, label ? label : "n/a");
+    mem_deref(label);
+    mem_deref(parameters);
+}
+
+/*
+ * Print the data channel open event.
+ */
+void default_data_channel_open_handler(
+    void* const arg  // will be casted to `struct data_channel_helper*`
+) {
+    struct data_channel_helper* const channel = arg;
+    struct client* const client = channel->client;
+    DEBUG_PRINTF("(%s) Data channel open: %s\n", client->name, channel->label);
+}
+
+/*
+ * Print the data channel buffered amount low event.
+ */
+void default_data_channel_buffered_amount_low_handler(
+    void* const arg  // will be casted to `struct data_channel_helper*`
+) {
+    struct data_channel_helper* const channel = arg;
+    struct client* const client = channel->client;
+    DEBUG_PRINTF("(%s) Data channel buffered amount low: %s\n", client->name, channel->label);
+}
+
+/*
+ * Print the data channel error event.
+ */
+void default_data_channel_error_handler(
+    void* const arg  // will be casted to `struct data_channel_helper*`
+) {
+    struct data_channel_helper* const channel = arg;
+    struct client* const client = channel->client;
+    DEBUG_WARNING("(%s) Data channel error: %s\n", client->name, channel->label);
+}
+
+/*
+ * Print the data channel close event.
+ */
+void default_data_channel_close_handler(
+    void* const arg  // will be casted to `struct data_channel_helper*`
+) {
+    struct data_channel_helper* const channel = arg;
+    struct client* const client = channel->client;
+    DEBUG_PRINTF("(%s) Data channel closed: %s\n", client->name, channel->label);
+}
+
+char const* const separator = ", ";
+
+static int debug_data_channel_message_flags(
+    struct re_printf* const pf, enum rawrtc_data_channel_message_flag const flags) {
+    int err = 0;
+    char const* prefix = "";
+
+    if (flags & RAWRTC_DATA_CHANNEL_MESSAGE_FLAG_IS_ABORTED) {
+        err |= re_hprintf(pf, "%saborted", prefix);
+        prefix = separator;
+    }
+    if (flags & RAWRTC_DATA_CHANNEL_MESSAGE_FLAG_IS_COMPLETE) {
+        err |= re_hprintf(pf, "%scomplete", prefix);
+        prefix = separator;
+    }
+    if (flags & RAWRTC_DATA_CHANNEL_MESSAGE_FLAG_IS_STRING) {
+        err |= re_hprintf(pf, "%sstring", prefix);
+        prefix = separator;
+    }
+    if (flags & RAWRTC_DATA_CHANNEL_MESSAGE_FLAG_IS_BINARY) {
+        err |= re_hprintf(pf, "%sbinary", prefix);
+    }
+
+    return err;
+}
+
+/*
+ * Print the data channel's received message's size.
+ */
+void default_data_channel_message_handler(
+    struct mbuf* const buffer,
+    enum rawrtc_data_channel_message_flag const flags,
+    void* const arg  // will be casted to `struct data_channel_helper*`
+) {
+    struct data_channel_helper* const channel = arg;
+    struct client* const client = channel->client;
+    DEBUG_PRINTF(
+        "(%s) Incoming message for data channel %s: %zu bytes; flags=(%H)\n", client->name,
+        channel->label, mbuf_get_left(buffer), debug_data_channel_message_flags, flags);
+}
+
+/*
+ * Print negotiation needed (duh!)
+ */
+void default_negotiation_needed_handler(void* const arg) {
+    struct client* const client = arg;
+    DEBUG_PRINTF("(%s) Negotiation needed\n", client->name);
+}
+
+/*
+ * Print the peer connection's state.
+ */
+void default_peer_connection_state_change_handler(
+    enum rawrtc_peer_connection_state const state,  // read-only
+    void* const arg  // will be casted to `struct client*`
+) {
+    struct client* const client = arg;
+    char const* const state_name = rawrtc_peer_connection_state_to_name(state);
+    DEBUG_PRINTF("(%s) Peer connection state change: %s\n", client->name, state_name);
+}
+
+/*
+ * Print the newly gathered local candidate (peer connection variant).
+ */
+void default_peer_connection_local_candidate_handler(
+    struct rawrtc_peer_connection_ice_candidate* const candidate,
+    char const* const url,  // read-only
+    void* const arg) {
+    struct client* const client = arg;
+    struct rawrtc_ice_candidate* ortc_candidate = NULL;
+
+    // Get underlying ORTC ICE candidate (if any)
+    if (candidate) {
+        EOE(rawrtc_peer_connection_ice_candidate_get_ortc_candidate(&ortc_candidate, candidate));
+    }
+
+    // Print local candidate
+    print_ice_candidate(ortc_candidate, url, candidate, client);
+    mem_deref(ortc_candidate);
+}
+
+/*
+ * Print the peer connections local candidate error event.
+ */
+void default_peer_connection_local_candidate_error_handler(
+    struct rawrtc_peer_connection_ice_candidate* const candidate,  // read-only, nullable
+    char const* const url,  // read-only
+    uint16_t const error_code,  // read-only
+    char const* const error_text,  // read-only
+    void* const arg  // will be casted to `struct client*`
+) {
+    struct client* const client = arg;
+    (void) candidate;
+    (void) error_code;
+    (void) arg;
+    DEBUG_NOTICE("(%s) ICE candidate error, URL: %s, reason: %s\n", client->name, url, error_text);
+}
+
+/*
+ * Print the signaling state.
+ */
+void default_signaling_state_change_handler(
+    enum rawrtc_signaling_state const state,  // read-only
+    void* const arg) {
+    struct client* const client = arg;
+    char const* const state_name = rawrtc_signaling_state_to_name(state);
+    DEBUG_PRINTF("(%s) Signaling state change: %s\n", client->name, state_name);
+}
+
+/*
+ * Stop the main loop.
+ */
+void default_signal_handler(int sig) {
+    DEBUG_INFO("Got signal: %d, terminating...\n", sig);
+    re_cancel();
+}
+
+/*
+ * FD-listener that stops the main loop in case the input buffer
+ * contains a line feed or a carriage return.
+ */
+void stop_on_return_handler(int flags, void* arg) {
+    char buffer[128];
+    size_t length;
+    (void) flags;
+    (void) arg;
+
+    // Get message from stdin
+    if (!fgets((char*) buffer, 128, stdin)) {
+        EOR(errno);
+    }
+    length = strlen(buffer);
+
+    // Exit?
+    if (length > 0 && length < 3 && (buffer[0] == '\n' || buffer[0] == '\r')) {
+        // Stop main loop
+        DEBUG_INFO("Exiting\n");
+        re_cancel();
+    }
+}
diff --git a/tools/helper/handler.h b/tools/helper/handler.h
new file mode 100644
index 0000000..56d4211
--- /dev/null
+++ b/tools/helper/handler.h
@@ -0,0 +1,181 @@
+#pragma once
+#include "common.h"
+#include <rawrtc.h>
+#include <rawrtcc.h>
+#include <rawrtcdc.h>
+#include <re.h>
+
+/*
+ * Print the ICE gatherer's state.
+ */
+void default_ice_gatherer_state_change_handler(
+    enum rawrtc_ice_gatherer_state const state,  // read-only
+    void* const arg);
+
+/*
+ * Print the ICE gatherer's error event.
+ */
+void default_ice_gatherer_error_handler(
+    struct rawrtc_ice_candidate* const host_candidate,  // read-only, nullable
+    char const* const url,  // read-only
+    uint16_t const error_code,  // read-only
+    char const* const error_text,  // read-only
+    void* const arg  // will be casted to `struct client*`
+);
+
+/*
+ * Print the newly gatherered local candidate.
+ * Will print local parameters on stdout in case the client is not
+ * used in loopback mode.
+ */
+void default_ice_gatherer_local_candidate_handler(
+    struct rawrtc_ice_candidate* const candidate,
+    char const* const url,  // read-only
+    void* const arg  // will be casted to `struct client*`
+);
+
+/*
+ * Print the ICE transport's state.
+ */
+void default_ice_transport_state_change_handler(
+    enum rawrtc_ice_transport_state const state,
+    void* const arg  // will be casted to `struct client*`
+);
+
+/*
+ * Print the ICE candidate pair change event.
+ */
+void default_ice_transport_candidate_pair_change_handler(
+    struct rawrtc_ice_candidate* const local,  // read-only
+    struct rawrtc_ice_candidate* const remote,  // read-only
+    void* const arg  // will be casted to `struct client*`
+);
+
+/*
+ * Print the DTLS transport's state.
+ */
+void default_dtls_transport_state_change_handler(
+    enum rawrtc_dtls_transport_state const state,  // read-only
+    void* const arg  // will be casted to `struct client*`
+);
+
+/*
+ * Print the DTLS transport's error event.
+ */
+void default_dtls_transport_error_handler(
+    // TODO: error.message (probably from OpenSSL)
+    void* const arg  // will be casted to `struct client*`
+);
+
+#if RAWRTC_HAVE_SCTP_REDIRECT_TRANSPORT
+/*
+ * Print the SCTP redirect transport's state.
+ */
+void default_sctp_redirect_transport_state_change_handler(
+    enum rawrtc_sctp_redirect_transport_state const state,
+    void* const arg  // will be casted to `struct client*`
+);
+#endif
+
+/*
+ * Print the SCTP transport's state.
+ */
+void default_sctp_transport_state_change_handler(
+    enum rawrtc_sctp_transport_state const state,
+    void* const arg  // will be casted to `struct client*`
+);
+
+/*
+ * Print the newly created data channel's parameter.
+ */
+void default_data_channel_handler(
+    struct rawrtc_data_channel* const data_channel,  // read-only, MUST be referenced when used
+    void* const arg  // will be casted to `struct data_channel_helper*`
+);
+
+/*
+ * Print the data channel open event.
+ */
+void default_data_channel_open_handler(
+    void* const arg  // will be casted to `struct data_channel_helper*`
+);
+
+/*
+ * Print the data channel buffered amount low event.
+ */
+void default_data_channel_buffered_amount_low_handler(
+    void* const arg  // will be casted to `struct data_channel_helper*`
+);
+
+/*
+ * Print the data channel error event.
+ */
+void default_data_channel_error_handler(
+    void* const arg  // will be casted to `struct data_channel_helper*`
+);
+
+/*
+ * Print the data channel close event.
+ */
+void default_data_channel_close_handler(
+    void* const arg  // will be casted to `struct data_channel_helper*`
+);
+
+/*
+ * Print the data channel's received message's size.
+ */
+void default_data_channel_message_handler(
+    struct mbuf* const buffer,
+    enum rawrtc_data_channel_message_flag const flags,
+    void* const arg  // will be casted to `struct data_channel_helper*`
+);
+
+/*
+ * Print negotiation needed (duh!)
+ */
+void default_negotiation_needed_handler(void* const arg);
+
+/*
+ * Print the peer connection's state.
+ */
+void default_peer_connection_state_change_handler(
+    enum rawrtc_peer_connection_state const state,  // read-only
+    void* const arg  // will be casted to `struct client*`
+);
+
+/*
+ * Print the newly gathered local candidate (peer connection variant).
+ */
+void default_peer_connection_local_candidate_handler(
+    struct rawrtc_peer_connection_ice_candidate* const candidate,
+    char const* const url,  // read-only
+    void* const arg);
+
+/*
+ * Print the peer connections local candidate error event.
+ */
+void default_peer_connection_local_candidate_error_handler(
+    struct rawrtc_peer_connection_ice_candidate* const candidate,  // read-only, nullable
+    char const* const url,  // read-only
+    uint16_t const error_code,  // read-only
+    char const* const error_text,  // read-only
+    void* const arg  // will be casted to `struct client*`
+);
+
+/*
+ * Print the signaling state.
+ */
+void default_signaling_state_change_handler(
+    enum rawrtc_signaling_state const state,  // read-only
+    void* const arg);
+
+/*
+ * Stop the main loop.
+ */
+void default_signal_handler(int sig);
+
+/*
+ * FD-listener that stops the main loop in case the input buffer is
+ * empty.
+ */
+void stop_on_return_handler(int flags, void* arg);
diff --git a/tools/helper/meson.build b/tools/helper/meson.build
new file mode 100644
index 0000000..b9ef950
--- /dev/null
+++ b/tools/helper/meson.build
@@ -0,0 +1,6 @@
+helper_sources = files([
+    'common.c',
+    'handler.c',
+    'parameters.c',
+    'utils.c',
+])
diff --git a/tools/helper/parameters.c b/tools/helper/parameters.c
new file mode 100644
index 0000000..46ae22b
--- /dev/null
+++ b/tools/helper/parameters.c
@@ -0,0 +1,448 @@
+#include "parameters.h"
+#include "common.h"
+#include "utils.h"
+#include <rawrtc.h>
+#include <rawrtcc.h>
+#include <rawrtcdc.h>
+#include <re.h>
+
+#define DEBUG_MODULE "helper-parameters"
+#define DEBUG_LEVEL 7
+#include <re_dbg.h>
+
+/*
+ * Set ICE parameters in dictionary.
+ */
+void set_ice_parameters(struct rawrtc_ice_parameters* const parameters, struct odict* const dict) {
+    char* username_fragment;
+    char* password;
+    bool ice_lite;
+
+    // Get values
+    EOE(rawrtc_ice_parameters_get_username_fragment(&username_fragment, parameters));
+    EOE(rawrtc_ice_parameters_get_password(&password, parameters));
+    EOE(rawrtc_ice_parameters_get_ice_lite(&ice_lite, parameters));
+
+    // Set ICE parameters
+    EOR(odict_entry_add(dict, "usernameFragment", ODICT_STRING, username_fragment));
+    EOR(odict_entry_add(dict, "password", ODICT_STRING, password));
+    EOR(odict_entry_add(dict, "iceLite", ODICT_BOOL, ice_lite));
+
+    // Un-reference values
+    mem_deref(password);
+    mem_deref(username_fragment);
+}
+
+/*
+ * Set ICE candidates in dictionary.
+ */
+void set_ice_candidates(struct rawrtc_ice_candidates* const parameters, struct odict* const array) {
+    size_t i;
+    struct odict* node;
+
+    // Set ICE candidates
+    for (i = 0; i < parameters->n_candidates; ++i) {
+        enum rawrtc_code error;
+        struct rawrtc_ice_candidate* const candidate = parameters->candidates[i];
+        char* foundation;
+        uint32_t priority;
+        char* ip;
+        enum rawrtc_ice_protocol protocol;
+        uint16_t port;
+        enum rawrtc_ice_candidate_type type;
+        enum rawrtc_ice_tcp_candidate_type tcp_type = RAWRTC_ICE_TCP_CANDIDATE_TYPE_ACTIVE;
+        char* related_address = NULL;
+        uint16_t related_port = 0;
+        char* key;
+
+        // Create object
+        EOR(odict_alloc(&node, 16));
+
+        // Get values
+        EOE(rawrtc_ice_candidate_get_foundation(&foundation, candidate));
+        EOE(rawrtc_ice_candidate_get_priority(&priority, candidate));
+        EOE(rawrtc_ice_candidate_get_ip(&ip, candidate));
+        EOE(rawrtc_ice_candidate_get_protocol(&protocol, candidate));
+        EOE(rawrtc_ice_candidate_get_port(&port, candidate));
+        EOE(rawrtc_ice_candidate_get_type(&type, candidate));
+        error = rawrtc_ice_candidate_get_tcp_type(&tcp_type, candidate);
+        EOE(error == RAWRTC_CODE_NO_VALUE ? RAWRTC_CODE_SUCCESS : error);
+        error = rawrtc_ice_candidate_get_related_address(&related_address, candidate);
+        EOE(error == RAWRTC_CODE_NO_VALUE ? RAWRTC_CODE_SUCCESS : error);
+        error = rawrtc_ice_candidate_get_related_port(&related_port, candidate);
+        EOE(error == RAWRTC_CODE_NO_VALUE ? RAWRTC_CODE_SUCCESS : error);
+
+        // Set ICE candidate values
+        EOR(odict_entry_add(node, "foundation", ODICT_STRING, foundation));
+        EOR(odict_entry_add(node, "priority", ODICT_INT, (int64_t) priority));
+        EOR(odict_entry_add(node, "ip", ODICT_STRING, ip));
+        EOR(odict_entry_add(node, "protocol", ODICT_STRING, rawrtc_ice_protocol_to_str(protocol)));
+        EOR(odict_entry_add(node, "port", ODICT_INT, (int64_t) port));
+        EOR(odict_entry_add(node, "type", ODICT_STRING, rawrtc_ice_candidate_type_to_str(type)));
+        if (protocol == RAWRTC_ICE_PROTOCOL_TCP) {
+            EOR(odict_entry_add(
+                node, "tcpType", ODICT_STRING, rawrtc_ice_tcp_candidate_type_to_str(tcp_type)));
+        }
+        if (related_address) {
+            EOR(odict_entry_add(node, "relatedAddress", ODICT_STRING, related_address));
+        }
+        if (related_port > 0) {
+            EOR(odict_entry_add(node, "relatedPort", (int64_t) ODICT_INT, related_port));
+        }
+
+        // Add to array
+        EOE(rawrtc_sdprintf(&key, "%zu", i));
+        EOR(odict_entry_add(array, key, ODICT_OBJECT, node));
+
+        // Un-reference values
+        mem_deref(key);
+        mem_deref(related_address);
+        mem_deref(ip);
+        mem_deref(foundation);
+        mem_deref(node);
+    }
+}
+
+/*
+ * Set DTLS parameters in dictionary.
+ */
+void set_dtls_parameters(
+    struct rawrtc_dtls_parameters* const parameters, struct odict* const dict) {
+    enum rawrtc_dtls_role role;
+    struct odict* array;
+    struct odict* node;
+    struct rawrtc_dtls_fingerprints* fingerprints;
+    size_t i;
+
+    // Get and set DTLS role
+    EOE(rawrtc_dtls_parameters_get_role(&role, parameters));
+    EOR(odict_entry_add(dict, "role", ODICT_STRING, rawrtc_dtls_role_to_str(role)));
+
+    // Create array
+    EOR(odict_alloc(&array, 16));
+
+    // Get and set fingerprints
+    EOE(rawrtc_dtls_parameters_get_fingerprints(&fingerprints, parameters));
+    for (i = 0; i < fingerprints->n_fingerprints; ++i) {
+        struct rawrtc_dtls_fingerprint* const fingerprint = fingerprints->fingerprints[i];
+        enum rawrtc_certificate_sign_algorithm sign_algorithm;
+        char* value;
+        char* key;
+
+        // Create object
+        EOR(odict_alloc(&node, 16));
+
+        // Get values
+        EOE(rawrtc_dtls_fingerprint_get_sign_algorithm(&sign_algorithm, fingerprint));
+        EOE(rawrtc_dtls_fingerprint_get_value(&value, fingerprint));
+
+        // Set fingerprint values
+        EOR(odict_entry_add(
+            node, "algorithm", ODICT_STRING,
+            rawrtc_certificate_sign_algorithm_to_str(sign_algorithm)));
+        EOR(odict_entry_add(node, "value", ODICT_STRING, value));
+
+        // Add to array
+        EOE(rawrtc_sdprintf(&key, "%zu", i));
+        EOR(odict_entry_add(array, key, ODICT_OBJECT, node));
+
+        // Un-reference values
+        mem_deref(key);
+        mem_deref(value);
+        mem_deref(node);
+    }
+
+    // Un-reference fingerprints
+    mem_deref(fingerprints);
+
+    // Add array to object
+    EOR(odict_entry_add(dict, "fingerprints", ODICT_ARRAY, array));
+    mem_deref(array);
+}
+
+/*
+ * Set SCTP parameters in dictionary.
+ */
+void set_sctp_parameters(
+    struct rawrtc_sctp_transport* const transport,
+    struct sctp_parameters* const parameters,
+    struct odict* const dict) {
+    uint64_t max_message_size;
+    uint16_t port;
+
+    // Get values
+    EOE(rawrtc_sctp_capabilities_get_max_message_size(&max_message_size, parameters->capabilities));
+    EOE(rawrtc_sctp_transport_get_port(&port, transport));
+
+    // Ensure maximum message size fits into int64
+    if (max_message_size > INT64_MAX) {
+        EOE(RAWRTC_CODE_INSUFFICIENT_SPACE);
+    }
+
+    // Set ICE parameters
+    EOR(odict_entry_add(dict, "maxMessageSize", ODICT_INT, (int64_t) max_message_size));
+    EOR(odict_entry_add(dict, "port", ODICT_INT, (int64_t) port));
+}
+
+#if RAWRTC_HAVE_SCTP_REDIRECT_TRANSPORT
+/*
+ * Set SCTP redirect parameters in dictionary.
+ */
+void set_sctp_redirect_parameters(
+    struct rawrtc_sctp_redirect_transport* const transport,
+    struct sctp_parameters* const parameters,
+    struct odict* const dict) {
+    uint64_t max_message_size;
+    uint16_t port;
+
+    // Get values
+    EOE(rawrtc_sctp_capabilities_get_max_message_size(&max_message_size, parameters->capabilities));
+    EOE(rawrtc_sctp_redirect_transport_get_port(&port, transport));
+
+    // Ensure maximum message size fits into int64
+    if (max_message_size > INT64_MAX) {
+        EOE(RAWRTC_CODE_INSUFFICIENT_SPACE);
+    }
+
+    // Set ICE parameters
+    EOR(odict_entry_add(dict, "maxMessageSize", ODICT_INT, (int64_t) max_message_size));
+    EOR(odict_entry_add(dict, "port", ODICT_INT, (int64_t) port));
+}
+#endif
+
+/*
+ * Get ICE parameters from dictionary.
+ */
+enum rawrtc_code get_ice_parameters(
+    struct rawrtc_ice_parameters** const parametersp, struct odict* const dict) {
+    enum rawrtc_code error = RAWRTC_CODE_SUCCESS;
+    char* username_fragment;
+    char* password;
+    bool ice_lite;
+
+    // Get ICE parameters
+    error |= dict_get_entry(&username_fragment, dict, "usernameFragment", ODICT_STRING, true);
+    error |= dict_get_entry(&password, dict, "password", ODICT_STRING, true);
+    error |= dict_get_entry(&ice_lite, dict, "iceLite", ODICT_BOOL, true);
+    if (error) {
+        return error;
+    }
+
+    // Create ICE parameters instance
+    return rawrtc_ice_parameters_create(parametersp, username_fragment, password, ice_lite);
+}
+
+static void ice_candidates_destroy(void* arg) {
+    struct rawrtc_ice_candidates* const candidates = arg;
+    size_t i;
+
+    // Un-reference each item
+    for (i = 0; i < candidates->n_candidates; ++i) {
+        mem_deref(candidates->candidates[i]);
+    }
+}
+
+/*
+ * Get ICE candidates from dictionary.
+ * Filter by enabled ICE candidate types if `client` argument is set to
+ * non-NULL.
+ */
+enum rawrtc_code get_ice_candidates(
+    struct rawrtc_ice_candidates** const candidatesp,
+    struct odict* const dict,
+    struct client* const client) {
+    size_t n;
+    struct rawrtc_ice_candidates* candidates;
+    enum rawrtc_code error = RAWRTC_CODE_SUCCESS;
+    struct le* le;
+
+    // Get length
+    n = list_count(&dict->lst) + 1;
+
+    // Allocate & set length immediately
+    // Note: We allocate more than we need in case ICE candidate types are being filtered but... meh
+    candidates = mem_zalloc(
+        sizeof(*candidates) + (sizeof(struct rawrtc_ice_candidate*) * n), ice_candidates_destroy);
+    if (!candidates) {
+        EWE("No memory to allocate ICE candidates array");
+    }
+    candidates->n_candidates = 0;
+
+    // Get ICE candidates
+    for (le = list_head(&dict->lst); le != NULL; le = le->next) {
+        struct odict* const node = ((struct odict_entry*) le->data)->u.odict;
+        char const* type_str = NULL;
+        enum rawrtc_ice_candidate_type type;
+        char* foundation;
+        uint32_t priority;
+        char* ip;
+        char const* protocol_str = NULL;
+        enum rawrtc_ice_protocol protocol;
+        uint16_t port;
+        char const* tcp_type_str = NULL;
+        enum rawrtc_ice_tcp_candidate_type tcp_type = RAWRTC_ICE_TCP_CANDIDATE_TYPE_ACTIVE;
+        char* related_address = NULL;
+        uint16_t related_port = 0;
+        struct rawrtc_ice_candidate* candidate;
+
+        // Get ICE candidate
+        error |= dict_get_entry(&type_str, node, "type", ODICT_STRING, true);
+        error |= rawrtc_str_to_ice_candidate_type(&type, type_str);
+        error |= dict_get_entry(&foundation, node, "foundation", ODICT_STRING, true);
+        error |= dict_get_uint32(&priority, node, "priority", true);
+        error |= dict_get_entry(&ip, node, "ip", ODICT_STRING, true);
+        error |= dict_get_entry(&protocol_str, node, "protocol", ODICT_STRING, true);
+        error |= rawrtc_str_to_ice_protocol(&protocol, protocol_str);
+        error |= dict_get_uint16(&port, node, "port", true);
+        if (protocol == RAWRTC_ICE_PROTOCOL_TCP) {
+            error |= dict_get_entry(&tcp_type_str, node, "tcpType", ODICT_STRING, true);
+            error |= rawrtc_str_to_ice_tcp_candidate_type(&tcp_type, tcp_type_str);
+        }
+        dict_get_entry(&related_address, node, "relatedAddress", ODICT_STRING, false);
+        dict_get_uint16(&related_port, node, "relatedPort", false);
+        if (error) {
+            goto out;
+        }
+
+        // Create and add ICE candidate
+        error = rawrtc_ice_candidate_create(
+            &candidate, foundation, priority, ip, protocol, port, type, tcp_type, related_address,
+            related_port);
+        if (error) {
+            goto out;
+        }
+
+        // Print ICE candidate
+        print_ice_candidate(candidate, NULL, NULL, client);
+
+        // Store if ICE candidate type enabled
+        if (ice_candidate_type_enabled(client, type)) {
+            candidates->candidates[candidates->n_candidates++] = candidate;
+        } else {
+            mem_deref(candidate);
+        }
+    }
+
+    // End-of-candidates
+    candidates->candidates[candidates->n_candidates++] = NULL;
+
+out:
+    if (error) {
+        mem_deref(candidates);
+    } else {
+        // Set pointer
+        *candidatesp = candidates;
+    }
+    return error;
+}
+
+static void dtls_fingerprints_destroy(void* arg) {
+    struct rawrtc_dtls_fingerprints* const fingerprints = arg;
+    size_t i;
+
+    // Un-reference each item
+    for (i = 0; i < fingerprints->n_fingerprints; ++i) {
+        mem_deref(fingerprints->fingerprints[i]);
+    }
+}
+
+/*
+ * Get DTLS parameters from dictionary.
+ */
+enum rawrtc_code get_dtls_parameters(
+    struct rawrtc_dtls_parameters** const parametersp, struct odict* const dict) {
+    size_t n;
+    struct rawrtc_dtls_parameters* parameters = NULL;
+    struct rawrtc_dtls_fingerprints* fingerprints;
+    enum rawrtc_code error;
+    char const* role_str = NULL;
+    enum rawrtc_dtls_role role;
+    struct odict* node;
+    struct le* le;
+    size_t i;
+
+    // Get fingerprints array and length
+    error = dict_get_entry(&node, dict, "fingerprints", ODICT_ARRAY, true);
+    if (error) {
+        return error;
+    }
+    n = list_count(&node->lst);
+
+    // Allocate & set length immediately
+    fingerprints = mem_zalloc(
+        sizeof(*fingerprints) + (sizeof(struct rawrtc_dtls_fingerprints*) * n),
+        dtls_fingerprints_destroy);
+    if (!fingerprints) {
+        EWE("No memory to allocate DTLS fingerprint array");
+    }
+    fingerprints->n_fingerprints = n;
+
+    // Get role
+    error |= dict_get_entry(&role_str, dict, "role", ODICT_STRING, true);
+    error |= rawrtc_str_to_dtls_role(&role, role_str);
+    if (error) {
+        role = RAWRTC_DTLS_ROLE_AUTO;
+    }
+
+    // Get fingerprints
+    for (le = list_head(&node->lst), i = 0; le != NULL; le = le->next, ++i) {
+        char* algorithm_str = NULL;
+        enum rawrtc_certificate_sign_algorithm algorithm;
+        char* value;
+        node = ((struct odict_entry*) le->data)->u.odict;
+
+        // Get fingerprint
+        error |= dict_get_entry(&algorithm_str, node, "algorithm", ODICT_STRING, true);
+        error |= rawrtc_str_to_certificate_sign_algorithm(&algorithm, algorithm_str);
+        error |= dict_get_entry(&value, node, "value", ODICT_STRING, true);
+        if (error) {
+            goto out;
+        }
+
+        // Create and add fingerprint
+        error = rawrtc_dtls_fingerprint_create(&fingerprints->fingerprints[i], algorithm, value);
+        if (error) {
+            goto out;
+        }
+    }
+
+    // Create DTLS parameters
+    error = rawrtc_dtls_parameters_create(
+        &parameters, role, fingerprints->fingerprints, fingerprints->n_fingerprints);
+
+out:
+    mem_deref(fingerprints);
+
+    if (error) {
+        mem_deref(parameters);
+    } else {
+        // Set pointer
+        *parametersp = parameters;
+    }
+    return error;
+}
+
+/*
+ * Get SCTP parameters from dictionary.
+ */
+enum rawrtc_code get_sctp_parameters(
+    struct sctp_parameters* const parameters, struct odict* const dict) {
+    enum rawrtc_code error;
+    uint64_t max_message_size;
+
+    // Get maximum message size
+    error = dict_get_entry(&max_message_size, dict, "maxMessageSize", ODICT_INT, true);
+    if (error) {
+        return error;
+    }
+
+    // Get port
+    error = dict_get_uint16(&parameters->port, dict, "port", false);
+    if (error && error != RAWRTC_CODE_NO_VALUE) {
+        // Note: Nothing to do in NO VALUE case as port has been set to 0 by default
+        return error;
+    }
+
+    // Create SCTP capabilities instance
+    return rawrtc_sctp_capabilities_create(&parameters->capabilities, max_message_size);
+}
diff --git a/tools/helper/parameters.h b/tools/helper/parameters.h
new file mode 100644
index 0000000..bc6a5aa
--- /dev/null
+++ b/tools/helper/parameters.h
@@ -0,0 +1,67 @@
+#pragma once
+#include "common.h"
+#include <rawrtc.h>
+#include <rawrtcc.h>
+#include <rawrtcdc.h>
+#include <re.h>
+
+/*
+ * Set ICE parameters in dictionary.
+ */
+void set_ice_parameters(struct rawrtc_ice_parameters* const parameters, struct odict* const dict);
+
+/*
+ * Set ICE candidates in dictionary.
+ */
+void set_ice_candidates(struct rawrtc_ice_candidates* const parameters, struct odict* const array);
+
+/*
+ * Set DTLS parameters in dictionary.
+ */
+void set_dtls_parameters(struct rawrtc_dtls_parameters* const parameters, struct odict* const dict);
+
+/*
+ * Set SCTP parameters in dictionary.
+ */
+void set_sctp_parameters(
+    struct rawrtc_sctp_transport* const transport,
+    struct sctp_parameters* const parameters,
+    struct odict* const dict);
+
+#if RAWRTC_HAVE_SCTP_REDIRECT_TRANSPORT
+/*
+ * Set SCTP redirect parameters in dictionary.
+ */
+void set_sctp_redirect_parameters(
+    struct rawrtc_sctp_redirect_transport* const transport,
+    struct sctp_parameters* const parameters,
+    struct odict* const dict);
+#endif
+
+/*
+ * Get ICE parameters from dictionary.
+ */
+enum rawrtc_code get_ice_parameters(
+    struct rawrtc_ice_parameters** const parametersp, struct odict* const dict);
+
+/*
+ * Get ICE candidates from dictionary.
+ * Filter by enabled ICE candidate types if `client` argument is set to
+ * non-NULL.
+ */
+enum rawrtc_code get_ice_candidates(
+    struct rawrtc_ice_candidates** const candidatesp,
+    struct odict* const dict,
+    struct client* const client);
+
+/*
+ * Get DTLS parameters from dictionary.
+ */
+enum rawrtc_code get_dtls_parameters(
+    struct rawrtc_dtls_parameters** const parametersp, struct odict* const dict);
+
+/*
+ * Get SCTP parameters from dictionary.
+ */
+enum rawrtc_code get_sctp_parameters(
+    struct sctp_parameters* const parameters, struct odict* const dict);
diff --git a/tools/helper/utils.c b/tools/helper/utils.c
new file mode 100644
index 0000000..2c15b00
--- /dev/null
+++ b/tools/helper/utils.c
@@ -0,0 +1,380 @@
+#include "utils.h"
+#include "common.h"
+#include <rawrtc.h>
+#include <rawrtcc.h>
+#include <rawrtcdc.h>
+#include <re.h>
+#include <limits.h>  // ULONG_MAX
+#include <stdlib.h>  // strto*
+#include <string.h>  // strlen
+
+#define DEBUG_MODULE "helper-utils"
+#define DEBUG_LEVEL 7
+#include <re_dbg.h>
+
+/*
+ * Convert string to uint16.
+ */
+bool str_to_uint16(uint16_t* const numberp, char* const str) {
+    char* end;
+    unsigned long number = strtoul(str, &end, 10);
+
+    // Check result (this function is insane, srsly...)
+    if (*end != '\0' || (number == ULONG_MAX && errno == ERANGE)) {
+        return false;
+    }
+
+    // Check bounds
+#if (ULONG_MAX > UINT16_MAX)
+    if (number > UINT16_MAX) {
+        return false;
+    }
+#endif
+
+    // Done
+    *numberp = (uint16_t) number;
+    return true;
+}
+
+/*
+ * Convert string to uint64.
+ */
+bool str_to_uint64(uint64_t* const numberp, char* const str) {
+    char* end;
+    unsigned long long number = strtoull(str, &end, 10);
+
+    // Check result (this function is insane, srsly...)
+    if (*end != '\0' || (number == ULONG_MAX && errno == ERANGE)) {
+        return false;
+    }
+
+    // Check bounds
+#if (ULONG_MAX > UINT64_MAX)
+    if (number > UINT64_MAX) {
+        return false;
+    }
+#endif
+
+    // Done
+    *numberp = (uint64_t) number;
+    return true;
+}
+
+/*
+ * Convert string to uint32.
+ */
+bool str_to_uint32(uint32_t* const numberp, char* const str) {
+    uint64_t number;
+    bool success = str_to_uint64(&number, str);
+
+    // Validate
+    if (!success || number > UINT32_MAX) {
+        return false;
+    }
+
+    // Done
+    *numberp = (uint32_t) number;
+    return true;
+}
+
+/*
+ * Get a dictionary entry and store it in `*valuep`.
+ */
+enum rawrtc_code dict_get_entry(
+    void* const valuep,
+    struct odict* const parent,
+    char* const key,
+    enum odict_type const type,
+    bool required) {
+    struct odict_entry const* entry;
+
+    // Check arguments
+    if (!valuep || !parent || !key) {
+        return RAWRTC_CODE_INVALID_ARGUMENT;
+    }
+
+    // Do lookup
+    entry = odict_lookup(parent, key);
+
+    // Check for entry
+    if (!entry) {
+        if (required) {
+            DEBUG_WARNING("'%s' missing\n", key);
+            return RAWRTC_CODE_INVALID_ARGUMENT;
+        } else {
+            return RAWRTC_CODE_NO_VALUE;
+        }
+    }
+
+    // Check for type
+    if (entry->type != type) {
+        DEBUG_WARNING("'%s' is of different type than expected\n", key);
+        return RAWRTC_CODE_INVALID_ARGUMENT;
+    }
+
+    // Set value according to type
+    switch (type) {
+        case ODICT_OBJECT:
+        case ODICT_ARRAY:
+            *((struct odict * * const) valuep) = entry->u.odict;
+            break;
+        case ODICT_STRING:
+            *((char** const) valuep) = entry->u.str;
+            break;
+        case ODICT_INT:
+            *((int64_t* const) valuep) = entry->u.integer;
+            break;
+        case ODICT_DOUBLE:
+            *((double* const) valuep) = entry->u.dbl;
+            break;
+        case ODICT_BOOL:
+            *((bool* const) valuep) = entry->u.boolean;
+            break;
+        case ODICT_NULL:
+            *((char** const) valuep) = NULL;  // meh!
+            break;
+        default:
+            return RAWRTC_CODE_INVALID_ARGUMENT;
+    }
+
+    // Done
+    return RAWRTC_CODE_SUCCESS;
+}
+
+/*
+ * Get a uint32 entry and store it in `*valuep`.
+ */
+enum rawrtc_code dict_get_uint32(
+    uint32_t* const valuep, struct odict* const parent, char* const key, bool required) {
+    enum rawrtc_code error;
+    int64_t value;
+
+    // Check arguments
+    if (!valuep || !parent || !key) {
+        return RAWRTC_CODE_INVALID_ARGUMENT;
+    }
+
+    // Get int64_t
+    error = dict_get_entry(&value, parent, key, ODICT_INT, required);
+    if (error) {
+        return error;
+    }
+
+    // Check bounds
+    if (value < 0 || value > UINT32_MAX) {
+        return RAWRTC_CODE_INVALID_ARGUMENT;
+    }
+
+    // Set value & done
+    *valuep = (uint32_t) value;
+    return RAWRTC_CODE_SUCCESS;
+}
+
+/*
+ * Get a uint16 entry and store it in `*valuep`.
+ */
+enum rawrtc_code dict_get_uint16(
+    uint16_t* const valuep, struct odict* const parent, char* const key, bool required) {
+    enum rawrtc_code error;
+    int64_t value;
+
+    // Check arguments
+    if (!valuep || !parent || !key) {
+        return RAWRTC_CODE_INVALID_ARGUMENT;
+    }
+
+    // Get int64_t
+    error = dict_get_entry(&value, parent, key, ODICT_INT, required);
+    if (error) {
+        return error;
+    }
+
+    // Check bounds
+    if (value < 0 || value > UINT16_MAX) {
+        return RAWRTC_CODE_INVALID_ARGUMENT;
+    }
+
+    // Set value & done
+    *valuep = (uint16_t) value;
+    return RAWRTC_CODE_SUCCESS;
+}
+
+/*
+ * Get JSON from stdin and parse it to a dictionary.
+ */
+enum rawrtc_code get_json_stdin(struct odict** const dictp  // de-referenced
+) {
+    char buffer[PARAMETERS_MAX_LENGTH];
+    size_t length;
+
+    // Get message from stdin
+    if (!fgets((char*) buffer, PARAMETERS_MAX_LENGTH, stdin)) {
+        EWE("Error polling stdin");
+    }
+    length = strlen(buffer);
+
+    // Exit?
+    if (length == 1 && buffer[0] == '\n') {
+        return RAWRTC_CODE_NO_VALUE;
+    }
+
+    // Decode JSON
+    EOR(json_decode_odict(dictp, 16, buffer, length, 3));
+    return RAWRTC_CODE_SUCCESS;
+}
+
+/*
+ * Get the ICE role from a string.
+ */
+enum rawrtc_code get_ice_role(
+    enum rawrtc_ice_role* const rolep,  // de-referenced
+    char const* const str) {
+    // Get ICE role
+    switch (str[0]) {
+        case '0':
+            *rolep = RAWRTC_ICE_ROLE_CONTROLLED;
+            return RAWRTC_CODE_SUCCESS;
+        case '1':
+            *rolep = RAWRTC_ICE_ROLE_CONTROLLING;
+            return RAWRTC_CODE_SUCCESS;
+        default:
+            return RAWRTC_CODE_INVALID_ARGUMENT;
+    }
+}
+
+/*
+ * Get the congestion control algorithm from a string.
+ */
+enum rawrtc_code get_congestion_control_algorithm(
+    enum rawrtc_sctp_transport_congestion_ctrl* const algorithmp,  // de-referenced
+    char const* const str) {
+    if (str_casecmp(str, "RFC2581") == 0) {
+        *algorithmp = RAWRTC_SCTP_TRANSPORT_CONGESTION_CTRL_RFC2581;
+        return RAWRTC_CODE_SUCCESS;
+    } else if (str_casecmp(str, "HSTCP") == 0) {
+        *algorithmp = RAWRTC_SCTP_TRANSPORT_CONGESTION_CTRL_HSTCP;
+        return RAWRTC_CODE_SUCCESS;
+    } else if (str_casecmp(str, "HTCP") == 0) {
+        *algorithmp = RAWRTC_SCTP_TRANSPORT_CONGESTION_CTRL_HTCP;
+        return RAWRTC_CODE_SUCCESS;
+    } else if (str_casecmp(str, "RTCC") == 0) {
+        *algorithmp = RAWRTC_SCTP_TRANSPORT_CONGESTION_CTRL_RTCC;
+        return RAWRTC_CODE_SUCCESS;
+    } else {
+        return RAWRTC_CODE_INVALID_ARGUMENT;
+    }
+}
+
+static void data_channel_helper_destroy(void* arg) {
+    struct data_channel_helper* const channel = arg;
+
+    // Unset handler argument & handlers of the channel
+    if (channel->channel) {
+        EOE(rawrtc_data_channel_unset_handlers(channel->channel));
+    }
+
+    // Remove from list
+    list_unlink(&channel->le);
+
+    // Un-reference
+    mem_deref(channel->arg);
+    mem_deref(channel->label);
+    mem_deref(channel->channel);
+}
+
+/*
+ * Create a data channel helper instance.
+ */
+void data_channel_helper_create(
+    struct data_channel_helper** const channel_helperp,  // de-referenced
+    struct client* const client,
+    char* const label) {
+    // Allocate
+    struct data_channel_helper* const channel =
+        mem_zalloc(sizeof(*channel), data_channel_helper_destroy);
+    if (!channel) {
+        EOE(RAWRTC_CODE_NO_MEMORY);
+        return;
+    }
+
+    // Set fields
+    channel->client = client;
+    EOE(rawrtc_strdup(&channel->label, label));
+
+    // Set pointer & done
+    *channel_helperp = channel;
+}
+
+/*
+ * Create a data channel helper instance from parameters.
+ */
+void data_channel_helper_create_from_channel(
+    struct data_channel_helper** const channel_helperp,  // de-referenced
+    struct rawrtc_data_channel* channel,
+    struct client* const client,
+    void* const arg  // nullable
+) {
+    enum rawrtc_code error;
+    struct rawrtc_data_channel_parameters* parameters;
+    char* label;
+
+    // Allocate
+    struct data_channel_helper* const channel_helper =
+        mem_zalloc(sizeof(*channel_helper), data_channel_helper_destroy);
+    if (!channel_helper) {
+        EOE(RAWRTC_CODE_NO_MEMORY);
+        return;
+    }
+
+    // Get parameters
+    EOE(rawrtc_data_channel_get_parameters(&parameters, channel));
+
+    // Get & set label
+    error = rawrtc_data_channel_parameters_get_label(&label, parameters);
+    switch (error) {
+        case RAWRTC_CODE_SUCCESS:
+            EOE(rawrtc_strdup(&channel_helper->label, label));
+            mem_deref(label);
+            break;
+        case RAWRTC_CODE_NO_VALUE:
+            EOE(rawrtc_strdup(&channel_helper->label, "n/a"));
+            break;
+        default:
+            EOE(error);
+    }
+
+    // Set fields
+    channel_helper->client = client;
+    channel_helper->channel = channel;
+    channel_helper->arg = mem_ref(arg);
+
+    // Set pointer
+    *channel_helperp = channel_helper;
+
+    // Un-reference & done
+    mem_deref(parameters);
+}
+
+/*
+ * Add the ICE candidate to the remote ICE transport if the ICE
+ * candidate type is enabled.
+ */
+void add_to_other_if_ice_candidate_type_enabled(
+    struct client* const client,
+    struct rawrtc_ice_candidate* const candidate,
+    struct rawrtc_ice_transport* const transport) {
+    if (candidate) {
+        enum rawrtc_ice_candidate_type type;
+
+        // Get ICE candidate type
+        EOE(rawrtc_ice_candidate_get_type(&type, candidate));
+
+        // Add to other client as remote candidate (if type enabled)
+        if (ice_candidate_type_enabled(client, type)) {
+            EOE(rawrtc_ice_transport_add_remote_candidate(transport, candidate));
+        }
+    } else {
+        // Last candidate is always being added
+        EOE(rawrtc_ice_transport_add_remote_candidate(transport, candidate));
+    }
+}
diff --git a/tools/helper/utils.h b/tools/helper/utils.h
new file mode 100644
index 0000000..d521b80
--- /dev/null
+++ b/tools/helper/utils.h
@@ -0,0 +1,90 @@
+#pragma once
+#include "common.h"
+#include <rawrtc.h>
+#include <rawrtcc.h>
+#include <rawrtcdc.h>
+#include <re.h>
+
+/*
+ * Convert string to uint16.
+ */
+bool str_to_uint16(uint16_t* const numberp, char* const str);
+
+/*
+ * Convert string to uint64.
+ */
+bool str_to_uint64(uint64_t* const numberp, char* const str);
+
+/*
+ * Convert string to uint32.
+ */
+bool str_to_uint32(uint32_t* const numberp, char* const str);
+
+/*
+ * Get a dictionary entry and store it in `*valuep`.
+ */
+enum rawrtc_code dict_get_entry(
+    void* const valuep,
+    struct odict* const parent,
+    char* const key,
+    enum odict_type const type,
+    bool required);
+
+/*
+ * Get a uint32 entry and store it in `*valuep`.
+ */
+enum rawrtc_code dict_get_uint32(
+    uint32_t* const valuep, struct odict* const parent, char* const key, bool required);
+
+/*
+ * Get a uint16 entry and store it in `*valuep`.
+ */
+enum rawrtc_code dict_get_uint16(
+    uint16_t* const valuep, struct odict* const parent, char* const key, bool required);
+
+/*
+ * Get JSON from stdin and parse it to a dictionary.
+ */
+enum rawrtc_code get_json_stdin(struct odict** const dictp  // de-referenced
+);
+
+/*
+ * Get the ICE role from a string.
+ */
+enum rawrtc_code get_ice_role(
+    enum rawrtc_ice_role* const rolep,  // de-referenced
+    char const* const str);
+
+/*
+ * Get the congestion control algorithm from a string.
+ */
+enum rawrtc_code get_congestion_control_algorithm(
+    enum rawrtc_sctp_transport_congestion_ctrl* const algorithmp,  // de-referenced
+    char const* const str);
+
+/*
+ * Create a data channel helper instance.
+ */
+void data_channel_helper_create(
+    struct data_channel_helper** const channel_helperp,  // de-referenced
+    struct client* const client,
+    char* const label);
+
+/*
+ * Create a data channel helper instance from parameters.
+ */
+void data_channel_helper_create_from_channel(
+    struct data_channel_helper** const channel_helperp,  // de-referenced
+    struct rawrtc_data_channel* channel,
+    struct client* const client,
+    void* const arg  // nullable
+);
+
+/*
+ * Add the ICE candidate to the remote ICE transport if the ICE
+ * candidate type is enabled.
+ */
+void add_to_other_if_ice_candidate_type_enabled(
+    struct client* const client,
+    struct rawrtc_ice_candidate* const candidate,
+    struct rawrtc_ice_transport* const transport);
diff --git a/tools/ice-gatherer.c b/tools/ice-gatherer.c
new file mode 100644
index 0000000..bd490d7
--- /dev/null
+++ b/tools/ice-gatherer.c
@@ -0,0 +1,81 @@
+#include "helper/handler.h"
+#include "helper/utils.h"
+#include <rawrtc.h>
+#include <rawrtcc.h>
+#include <rawrtcdc.h>
+#include <re.h>
+
+#define DEBUG_MODULE "ice-gatherer-app"
+#define DEBUG_LEVEL 7
+#include <re_dbg.h>
+
+/*
+ * Print the ICE gatherer's state. Stop once complete.
+ */
+static void gatherer_state_change_handler(
+    enum rawrtc_ice_gatherer_state const state,  // read-only
+    void* const arg  // will be casted to `struct client*`
+) {
+    default_ice_gatherer_state_change_handler(state, arg);
+    if (state == RAWRTC_ICE_GATHERER_STATE_COMPLETE) {
+        re_cancel();
+    }
+}
+
+int main(int argc, char* argv[argc + 1]) {
+    struct rawrtc_ice_gather_options* gather_options;
+    struct rawrtc_ice_gatherer* gatherer;
+    char* const turn_zwuenf_org_urls[] = {"stun:turn.zwuenf.org"};
+    char* const stun_google_com_ip_urls[] = {"stun:[2a00:1450:400c:c08::7f]:19302",
+                                             "stun:74.125.140.127:19302"};
+    char* const unreachable_urls[] = {"stun:example.com:12345",
+                                      "stun:lets.assume.no-one-will-ever-register-this"};
+    struct client client = {0};
+    (void) argv;
+
+    // Debug
+    dbg_init(DBG_DEBUG, DBG_ALL);
+    DEBUG_PRINTF("Init\n");
+
+    // Initialise
+    EOE(rawrtc_init(true));
+
+    // Create ICE gather options
+    EOE(rawrtc_ice_gather_options_create(&gather_options, RAWRTC_ICE_GATHER_POLICY_ALL));
+
+    // Add ICE servers to ICE gather options
+    EOE(rawrtc_ice_gather_options_add_server(
+        gather_options, turn_zwuenf_org_urls, ARRAY_SIZE(turn_zwuenf_org_urls), NULL, NULL,
+        RAWRTC_ICE_CREDENTIAL_TYPE_NONE));
+    EOE(rawrtc_ice_gather_options_add_server(
+        gather_options, stun_google_com_ip_urls, ARRAY_SIZE(stun_google_com_ip_urls), NULL, NULL,
+        RAWRTC_ICE_CREDENTIAL_TYPE_NONE));
+    EOE(rawrtc_ice_gather_options_add_server(
+        gather_options, unreachable_urls, ARRAY_SIZE(unreachable_urls), NULL, NULL,
+        RAWRTC_ICE_CREDENTIAL_TYPE_NONE));
+
+    // Setup client
+    client.name = "A";
+
+    // Create ICE gatherer
+    EOE(rawrtc_ice_gatherer_create(
+        &gatherer, gather_options, gatherer_state_change_handler,
+        default_ice_gatherer_error_handler, default_ice_gatherer_local_candidate_handler, &client));
+
+    // Start gathering
+    EOE(rawrtc_ice_gatherer_gather(gatherer, NULL));
+
+    // Start main loop
+    EOR(re_main(default_signal_handler));
+
+    // Close gatherer
+    EOE(rawrtc_ice_gatherer_close(gatherer));
+
+    // Un-reference & close
+    mem_deref(gatherer);
+    mem_deref(gather_options);
+
+    // Bye
+    before_exit();
+    return 0;
+}
diff --git a/tools/ice-transport-loopback.c b/tools/ice-transport-loopback.c
new file mode 100644
index 0000000..008c9a0
--- /dev/null
+++ b/tools/ice-transport-loopback.c
@@ -0,0 +1,152 @@
+#include "helper/handler.h"
+#include "helper/utils.h"
+#include <rawrtc.h>
+#include <rawrtcc.h>
+#include <rawrtcdc.h>
+#include <re.h>
+#include <stdlib.h>  // exit
+#include <unistd.h>  // STDIN_FILENO
+
+#define DEBUG_MODULE "ice-transport-loopback-app"
+#define DEBUG_LEVEL 7
+#include <re_dbg.h>
+
+// Note: Shadows struct client
+struct ice_transport_client {
+    char* name;
+    char** ice_candidate_types;
+    size_t n_ice_candidate_types;
+    struct rawrtc_ice_gather_options* gather_options;
+    struct rawrtc_ice_parameters* ice_parameters;
+    enum rawrtc_ice_role role;
+    struct rawrtc_ice_gatherer* gatherer;
+    struct rawrtc_ice_transport* ice_transport;
+    struct ice_transport_client* other_client;
+};
+
+static void ice_gatherer_local_candidate_handler(
+    struct rawrtc_ice_candidate* const candidate,
+    char const* const url,  // read-only
+    void* const arg) {
+    struct ice_transport_client* const client = arg;
+
+    // Print local candidate
+    default_ice_gatherer_local_candidate_handler(candidate, url, arg);
+
+    // Add to other client as remote candidate (if type enabled)
+    add_to_other_if_ice_candidate_type_enabled(arg, candidate, client->other_client->ice_transport);
+}
+
+static void client_init(struct ice_transport_client* const local) {
+    // Create ICE gatherer
+    EOE(rawrtc_ice_gatherer_create(
+        &local->gatherer, local->gather_options, default_ice_gatherer_state_change_handler,
+        default_ice_gatherer_error_handler, ice_gatherer_local_candidate_handler, local));
+
+    // Create ICE transport
+    EOE(rawrtc_ice_transport_create(
+        &local->ice_transport, local->gatherer, default_ice_transport_state_change_handler,
+        default_ice_transport_candidate_pair_change_handler, local));
+}
+
+static void client_start(
+    struct ice_transport_client* const local, struct ice_transport_client* const remote) {
+    // Get & set ICE parameters
+    EOE(rawrtc_ice_gatherer_get_local_parameters(&local->ice_parameters, remote->gatherer));
+
+    // Start gathering
+    EOE(rawrtc_ice_gatherer_gather(local->gatherer, NULL));
+
+    // Start ICE transport
+    EOE(rawrtc_ice_transport_start(
+        local->ice_transport, local->gatherer, local->ice_parameters, local->role));
+}
+
+static void client_stop(struct ice_transport_client* const client) {
+    // Stop transport & close gatherer
+    EOE(rawrtc_ice_transport_stop(client->ice_transport));
+    EOE(rawrtc_ice_gatherer_close(client->gatherer));
+
+    // Un-reference & close
+    client->ice_parameters = mem_deref(client->ice_parameters);
+    client->ice_transport = mem_deref(client->ice_transport);
+    client->gatherer = mem_deref(client->gatherer);
+}
+
+int main(int argc, char* argv[argc + 1]) {
+    char** ice_candidate_types = NULL;
+    size_t n_ice_candidate_types = 0;
+    struct rawrtc_ice_gather_options* gather_options;
+    char* const turn_zwuenf_org_urls[] = {"stun:turn.zwuenf.org"};
+    struct ice_transport_client a = {0};
+    struct ice_transport_client b = {0};
+    (void) a.ice_candidate_types;
+    (void) a.n_ice_candidate_types;
+    (void) b.ice_candidate_types;
+    (void) b.n_ice_candidate_types;
+
+    // Debug
+    dbg_init(DBG_DEBUG, DBG_ALL);
+    DEBUG_PRINTF("Init\n");
+
+    // Initialise
+    EOE(rawrtc_init(true));
+
+    // Get enabled ICE candidate types to be added (optional)
+    if (argc > 1) {
+        ice_candidate_types = &argv[1];
+        n_ice_candidate_types = (size_t) argc - 1;
+    }
+
+    // Create ICE gather options
+    EOE(rawrtc_ice_gather_options_create(&gather_options, RAWRTC_ICE_GATHER_POLICY_ALL));
+
+    // Add ICE servers to ICE gather options
+    EOE(rawrtc_ice_gather_options_add_server(
+        gather_options, turn_zwuenf_org_urls, ARRAY_SIZE(turn_zwuenf_org_urls), NULL, NULL,
+        RAWRTC_ICE_CREDENTIAL_TYPE_NONE));
+
+    // Setup client A
+    a.name = "A";
+    a.ice_candidate_types = ice_candidate_types;
+    a.n_ice_candidate_types = n_ice_candidate_types;
+    a.gather_options = gather_options;
+    a.role = RAWRTC_ICE_ROLE_CONTROLLING;
+    a.other_client = &b;
+
+    // Setup client B
+    b.name = "B";
+    b.ice_candidate_types = ice_candidate_types;
+    b.n_ice_candidate_types = n_ice_candidate_types;
+    b.gather_options = gather_options;
+    b.role = RAWRTC_ICE_ROLE_CONTROLLED;
+    b.other_client = &a;
+
+    // Initialise clients
+    client_init(&a);
+    client_init(&b);
+
+    // Start clients
+    client_start(&a, &b);
+    client_start(&b, &a);
+
+    // Listen on stdin
+    EOR(fd_listen(STDIN_FILENO, FD_READ, stop_on_return_handler, NULL));
+
+    // Start main loop
+    EOR(re_main(default_signal_handler));
+
+    // Stop clients
+    client_stop(&a);
+    client_stop(&b);
+
+    // Stop listening on STDIN
+    fd_close(STDIN_FILENO);
+
+    // Free
+    mem_deref(gather_options);
+
+    // Bye
+    before_exit();
+    return 0;
+}
diff --git a/tools/meson.build b/tools/meson.build
new file mode 100644
index 0000000..62a1e59
--- /dev/null
+++ b/tools/meson.build
@@ -0,0 +1,32 @@
+# Build helper library
+subdir('helper')
+rawrtc_helper = static_library('rawrtc-helper', helper_sources,
+    dependencies: dependencies,
+    include_directories: include_dir)
+
+# Tools and their sources
+tools = {
+    'data-channel-sctp': files('data-channel-sctp.c'),
+    'data-channel-sctp-echo': files('data-channel-sctp-echo.c'),
+    'data-channel-sctp-loopback': files('data-channel-sctp-loopback.c'),
+    'data-channel-sctp-streamed': files('data-channel-sctp-streamed.c'),
+    'data-channel-sctp-throughput': files('data-channel-sctp-throughput.c'),
+    'dtls-transport-loopback': files('dtls-transport-loopback.c'),
+    'ice-gatherer': files('ice-gatherer.c'),
+    'ice-transport-loopback': files('ice-transport-loopback.c'),
+    'peer-connection': files('peer-connection.c'),
+}
+if get_option('sctp_redirect_transport')
+    tools += {'sctp-redirect-transport': files('sctp-redirect-transport.c')}
+endif
+
+# Build executables
+foreach name, sources : tools
+    executable(
+        name,
+        sources,
+        dependencies: [re_dep, rawrtcc_dep, rawrtcdc_dep],
+        include_directories: include_dir,
+        install: true,
+        link_with: [rawrtc, rawrtc_helper])
+endforeach
diff --git a/tools/peer-connection.c b/tools/peer-connection.c
new file mode 100644
index 0000000..1156244
--- /dev/null
+++ b/tools/peer-connection.c
@@ -0,0 +1,368 @@
+#include "helper/handler.h"
+#include "helper/utils.h"
+#include <rawrtc.h>
+#include <rawrtcc.h>
+#include <rawrtcdc.h>
+#include <re.h>
+#include <stdlib.h>  // exit
+#include <unistd.h>  // STDIN_FILENO
+
+#define DEBUG_MODULE "peer-connection-app"
+#define DEBUG_LEVEL 7
+#include <re_dbg.h>
+
+enum {
+    TRANSPORT_BUFFER_LENGTH = 1048576,  // 1 MiB
+};
+
+// Note: Shadows struct client
+struct peer_connection_client {
+    char* name;
+    char** ice_candidate_types;
+    size_t n_ice_candidate_types;
+    bool offering;
+    struct rawrtc_peer_connection_configuration* configuration;
+    struct rawrtc_peer_connection* connection;
+    struct data_channel_helper* data_channel_negotiated;
+    struct data_channel_helper* data_channel;
+};
+
+static void print_local_description(struct peer_connection_client* const client);
+
+static struct tmr timer = {0};
+
+static void timer_handler(void* arg) {
+    struct data_channel_helper* const channel = arg;
+    struct peer_connection_client* const client = (struct peer_connection_client*) channel->client;
+    struct mbuf* buffer;
+    enum rawrtc_code error;
+
+    // Compose message (16 KiB)
+    buffer = mbuf_alloc(1 << 14);
+    EOE(buffer ? RAWRTC_CODE_SUCCESS : RAWRTC_CODE_NO_MEMORY);
+    EOR(mbuf_fill(buffer, 'M', mbuf_get_space(buffer)));
+    mbuf_set_pos(buffer, 0);
+
+    // Send message
+    DEBUG_PRINTF("(%s) Sending %zu bytes\n", client->name, mbuf_get_left(buffer));
+    error = rawrtc_data_channel_send(channel->channel, buffer, true);
+    if (error) {
+        DEBUG_WARNING("Could not send, reason: %s\n", rawrtc_code_to_str(error));
+    }
+    mem_deref(buffer);
+
+    // Close if offering
+    if (client->offering) {
+        // Close bear-noises
+        DEBUG_PRINTF("(%s) Closing channel\n", client->name, channel->label);
+        EOR(rawrtc_data_channel_close(client->data_channel->channel));
+    }
+}
+
+static void data_channel_open_handler(void* const arg) {
+    struct data_channel_helper* const channel = arg;
+    struct peer_connection_client* const client = (struct peer_connection_client*) channel->client;
+    struct mbuf* buffer;
+    enum rawrtc_code error;
+
+    // Print open event
+    default_data_channel_open_handler(arg);
+
+    // Send data delayed on bear-noises
+    if (str_cmp(channel->label, "bear-noises") == 0) {
+        tmr_start(&timer, 30000, timer_handler, channel);
+        return;
+    }
+
+    // Compose message (8 KiB)
+    buffer = mbuf_alloc(1 << 13);
+    EOE(buffer ? RAWRTC_CODE_SUCCESS : RAWRTC_CODE_NO_MEMORY);
+    EOR(mbuf_fill(buffer, 'M', mbuf_get_space(buffer)));
+    mbuf_set_pos(buffer, 0);
+
+    // Send message
+    DEBUG_PRINTF("(%s) Sending %zu bytes\n", client->name, mbuf_get_left(buffer));
+    error = rawrtc_data_channel_send(channel->channel, buffer, true);
+    if (error) {
+        DEBUG_WARNING("Could not send, reason: %s\n", rawrtc_code_to_str(error));
+    }
+    mem_deref(buffer);
+}
+
+static void negotiation_needed_handler(void* const arg) {
+    struct peer_connection_client* const client = arg;
+
+    // Print negotiation needed
+    default_negotiation_needed_handler(arg);
+
+    // Offering: Create and set local description
+    if (client->offering) {
+        struct rawrtc_peer_connection_description* description;
+        EOE(rawrtc_peer_connection_create_offer(&description, client->connection, false));
+        EOE(rawrtc_peer_connection_set_local_description(client->connection, description));
+        mem_deref(description);
+    }
+}
+
+static void connection_state_change_handler(
+    enum rawrtc_peer_connection_state const state,  // read-only
+    void* const arg) {
+    struct peer_connection_client* const client = arg;
+
+    // Print state
+    default_peer_connection_state_change_handler(state, arg);
+
+    // Open? Create new channel
+    // Note: Since this state can switch from 'connected' to 'disconnected' and back again, we
+    //       need to make sure we don't re-create data channels unintended.
+    // TODO: Move this once we can create data channels earlier
+    if (!client->data_channel && state == RAWRTC_PEER_CONNECTION_STATE_CONNECTED) {
+        struct rawrtc_data_channel_parameters* channel_parameters;
+        char* const label = client->offering ? "bear-noises" : "lion-noises";
+
+        // Create data channel helper for in-band negotiated data channel
+        data_channel_helper_create(&client->data_channel, (struct client*) client, label);
+
+        // Create data channel parameters
+        EOE(rawrtc_data_channel_parameters_create(
+            &channel_parameters, client->data_channel->label,
+            RAWRTC_DATA_CHANNEL_TYPE_RELIABLE_UNORDERED, 0, NULL, false, 0));
+
+        // Create data channel
+        EOE(rawrtc_peer_connection_create_data_channel(
+            &client->data_channel->channel, client->connection, channel_parameters,
+            data_channel_open_handler, default_data_channel_buffered_amount_low_handler,
+            default_data_channel_error_handler, default_data_channel_close_handler,
+            default_data_channel_message_handler, client->data_channel));
+
+        // Un-reference data channel parameters
+        mem_deref(channel_parameters);
+    }
+}
+
+static void local_candidate_handler(
+    struct rawrtc_peer_connection_ice_candidate* const candidate,
+    char const* const url,  // read-only
+    void* const arg) {
+    struct peer_connection_client* const client = arg;
+
+    // Print local candidate
+    default_peer_connection_local_candidate_handler(candidate, url, arg);
+
+    // Print local description (if last candidate)
+    if (!candidate) {
+        print_local_description(client);
+    }
+}
+
+static void client_init(struct peer_connection_client* const client) {
+    struct rawrtc_data_channel_parameters* channel_parameters;
+
+    // Create peer connection
+    EOE(rawrtc_peer_connection_create(
+        &client->connection, client->configuration, negotiation_needed_handler,
+        local_candidate_handler, default_peer_connection_local_candidate_error_handler,
+        default_signaling_state_change_handler, default_ice_transport_state_change_handler,
+        default_ice_gatherer_state_change_handler, connection_state_change_handler,
+        default_data_channel_handler, client));
+
+    // Create data channel helper for pre-negotiated data channel
+    data_channel_helper_create(
+        &client->data_channel_negotiated, (struct client*) client, "cat-noises");
+
+    // Create data channel parameters
+    EOE(rawrtc_data_channel_parameters_create(
+        &channel_parameters, client->data_channel_negotiated->label,
+        RAWRTC_DATA_CHANNEL_TYPE_RELIABLE_ORDERED, 0, NULL, true, 0));
+
+    // Create pre-negotiated data channel
+    EOE(rawrtc_peer_connection_create_data_channel(
+        &client->data_channel_negotiated->channel, client->connection, channel_parameters,
+        data_channel_open_handler, default_data_channel_buffered_amount_low_handler,
+        default_data_channel_error_handler, default_data_channel_close_handler,
+        default_data_channel_message_handler, client->data_channel_negotiated));
+
+    // TODO: Create in-band negotiated data channel
+    // TODO: Return some kind of promise that resolves once the data channel can be created
+
+    // Un-reference data channel parameters
+    mem_deref(channel_parameters);
+}
+
+static void client_stop(struct peer_connection_client* const client) {
+    EOE(rawrtc_peer_connection_close(client->connection));
+
+    // Un-reference & close
+    client->data_channel = mem_deref(client->data_channel);
+    client->data_channel_negotiated = mem_deref(client->data_channel_negotiated);
+    client->connection = mem_deref(client->connection);
+    client->configuration = mem_deref(client->configuration);
+
+    // Stop listening on STDIN
+    fd_close(STDIN_FILENO);
+}
+
+static void parse_remote_description(int flags, void* arg) {
+    struct peer_connection_client* const client = arg;
+    enum rawrtc_code error;
+    bool do_exit = false;
+    struct odict* dict = NULL;
+    char* type_str;
+    char* sdp;
+    enum rawrtc_sdp_type type;
+    struct rawrtc_peer_connection_description* remote_description = NULL;
+    (void) flags;
+
+    // Get dict from JSON
+    error = get_json_stdin(&dict);
+    if (error) {
+        do_exit = error == RAWRTC_CODE_NO_VALUE;
+        goto out;
+    }
+
+    // Decode JSON
+    error |= dict_get_entry(&type_str, dict, "type", ODICT_STRING, true);
+    error |= dict_get_entry(&sdp, dict, "sdp", ODICT_STRING, true);
+    if (error) {
+        DEBUG_WARNING("Invalid remote description\n");
+        goto out;
+    }
+
+    // Convert to description
+    error = rawrtc_str_to_sdp_type(&type, type_str);
+    if (error) {
+        DEBUG_WARNING("Invalid SDP type in remote description: '%s'\n", type_str);
+        goto out;
+    }
+    error = rawrtc_peer_connection_description_create(&remote_description, type, sdp);
+    if (error) {
+        DEBUG_WARNING("Cannot parse remote description: %s\n", rawrtc_code_to_str(error));
+        goto out;
+    }
+
+    // Set remote description
+    DEBUG_INFO("Applying remote description\n");
+    EOE(rawrtc_peer_connection_set_remote_description(client->connection, remote_description));
+
+    // Answering: Create and set local description
+    if (!client->offering) {
+        struct rawrtc_peer_connection_description* local_description;
+        EOE(rawrtc_peer_connection_create_answer(&local_description, client->connection));
+        EOE(rawrtc_peer_connection_set_local_description(client->connection, local_description));
+        mem_deref(local_description);
+    }
+
+out:
+    // Un-reference
+    mem_deref(remote_description);
+    mem_deref(dict);
+
+    // Exit?
+    if (do_exit) {
+        DEBUG_NOTICE("Exiting\n");
+
+        // Stop client & bye
+        tmr_cancel(&timer);
+        re_cancel();
+    }
+}
+
+static void print_local_description(struct peer_connection_client* const client) {
+    struct rawrtc_peer_connection_description* description;
+    enum rawrtc_sdp_type type;
+    char* sdp;
+    struct odict* dict;
+
+    // Get description
+    EOE(rawrtc_peer_connection_get_local_description(&description, client->connection));
+
+    // Get SDP type & the SDP itself
+    EOE(rawrtc_peer_connection_description_get_sdp_type(&type, description));
+    EOE(rawrtc_peer_connection_description_get_sdp(&sdp, description));
+
+    // Create dict & add entries
+    EOR(odict_alloc(&dict, 16));
+    EOR(odict_entry_add(dict, "type", ODICT_STRING, rawrtc_sdp_type_to_str(type)));
+    EOR(odict_entry_add(dict, "sdp", ODICT_STRING, sdp));
+
+    // Print local description as JSON
+    DEBUG_INFO("Local Description:\n%H\n", json_encode_odict, dict);
+
+    // Un-reference
+    mem_deref(dict);
+    mem_deref(sdp);
+    mem_deref(description);
+}
+
+static void exit_with_usage(char* program) {
+    DEBUG_WARNING("Usage: %s <0|1 (offering)> [<ice-candidate-type> ...]", program);
+    exit(1);
+}
+
+int main(int argc, char* argv[argc + 1]) {
+    char** ice_candidate_types = NULL;
+    size_t n_ice_candidate_types = 0;
+    enum rawrtc_ice_role role;
+    struct rawrtc_peer_connection_configuration* configuration;
+    char* const turn_zwuenf_org_urls[] = {"stun:turn.zwuenf.org"};
+    struct peer_connection_client client = {0};
+    (void) client.ice_candidate_types;
+    (void) client.n_ice_candidate_types;
+
+    // Debug
+    dbg_init(DBG_DEBUG, DBG_ALL);
+    DEBUG_PRINTF("Init\n");
+
+    // Initialise
+    EOE(rawrtc_init(true));
+
+    // Check arguments length
+    if (argc < 2) {
+        exit_with_usage(argv[0]);
+    }
+
+    // Get role
+    // Note: We handle it as an ICE role (because that is pretty close)
+    if (get_ice_role(&role, argv[1])) {
+        exit_with_usage(argv[0]);
+    }
+
+    // Get enabled ICE candidate types to be added (optional)
+    if (argc >= 3) {
+        ice_candidate_types = &argv[2];
+        n_ice_candidate_types = (size_t) argc - 2;
+    }
+
+    // Create peer connection configuration
+    EOE(rawrtc_peer_connection_configuration_create(&configuration, RAWRTC_ICE_GATHER_POLICY_ALL));
+
+    // Add ICE servers to configuration
+    EOE(rawrtc_peer_connection_configuration_add_ice_server(
+        configuration, turn_zwuenf_org_urls, ARRAY_SIZE(turn_zwuenf_org_urls), NULL, NULL,
+        RAWRTC_ICE_CREDENTIAL_TYPE_NONE));
+
+    // Set the SCTP transport's buffer length
+    EOE(rawrtc_peer_connection_configuration_set_sctp_buffer_length(
+        configuration, TRANSPORT_BUFFER_LENGTH, TRANSPORT_BUFFER_LENGTH));
+
+    // Set client fields
+    client.name = "A";
+    client.ice_candidate_types = ice_candidate_types;
+    client.n_ice_candidate_types = n_ice_candidate_types;
+    client.configuration = configuration;
+    client.offering = role == RAWRTC_ICE_ROLE_CONTROLLING ? true : false;
+
+    // Setup client
+    client_init(&client);
+
+    // Listen on stdin
+    EOR(fd_listen(STDIN_FILENO, FD_READ, parse_remote_description, &client));
+
+    // Start main loop
+    EOR(re_main(default_signal_handler));
+
+    // Stop client & bye
+    client_stop(&client);
+    before_exit();
+    return 0;
+}
diff --git a/tools/sctp-redirect-transport.c b/tools/sctp-redirect-transport.c
new file mode 100644
index 0000000..ac1199e
--- /dev/null
+++ b/tools/sctp-redirect-transport.c
@@ -0,0 +1,370 @@
+#include "helper/handler.h"
+#include "helper/parameters.h"
+#include "helper/utils.h"
+#include <rawrtc.h>
+#include <rawrtcc.h>
+#include <rawrtcdc.h>
+#include <re.h>
+#include <stdlib.h>  // exit
+#include <string.h>  // memcpy
+#include <unistd.h>  // STDIN_FILENO
+
+#define DEBUG_MODULE "sctp-redirect-transport-app"
+#define DEBUG_LEVEL 7
+#include <re_dbg.h>
+
+struct parameters {
+    struct rawrtc_ice_parameters* ice_parameters;
+    struct rawrtc_ice_candidates* ice_candidates;
+    struct rawrtc_dtls_parameters* dtls_parameters;
+    struct sctp_parameters sctp_parameters;
+};
+
+// Note: Shadows struct client
+struct sctp_redirect_transport_client {
+    char* name;
+    char** ice_candidate_types;
+    size_t n_ice_candidate_types;
+    struct rawrtc_ice_gather_options* gather_options;
+    char* redirect_ip;
+    uint16_t redirect_port;
+    enum rawrtc_ice_role role;
+    struct rawrtc_certificate* certificate;
+    struct rawrtc_ice_gatherer* gatherer;
+    struct rawrtc_ice_transport* ice_transport;
+    struct rawrtc_dtls_transport* dtls_transport;
+    struct rawrtc_sctp_redirect_transport* sctp_redirect_transport;
+    struct parameters local_parameters;
+    struct parameters remote_parameters;
+};
+
+static void print_local_parameters(struct sctp_redirect_transport_client* client);
+
+static void ice_gatherer_local_candidate_handler(
+    struct rawrtc_ice_candidate* const candidate,
+    char const* const url,  // read-only
+    void* const arg) {
+    struct sctp_redirect_transport_client* const client = arg;
+
+    // Print local candidate
+    default_ice_gatherer_local_candidate_handler(candidate, url, arg);
+
+    // Print local parameters (if last candidate)
+    if (!candidate) {
+        print_local_parameters(client);
+    }
+}
+
+static void client_init(struct sctp_redirect_transport_client* const client) {
+    struct rawrtc_certificate* certificates[1];
+
+    // Generate certificates
+    EOE(rawrtc_certificate_generate(&client->certificate, NULL));
+    certificates[0] = client->certificate;
+
+    // Create ICE gatherer
+    EOE(rawrtc_ice_gatherer_create(
+        &client->gatherer, client->gather_options, default_ice_gatherer_state_change_handler,
+        default_ice_gatherer_error_handler, ice_gatherer_local_candidate_handler, client));
+
+    // Create ICE transport
+    EOE(rawrtc_ice_transport_create(
+        &client->ice_transport, client->gatherer, default_ice_transport_state_change_handler,
+        default_ice_transport_candidate_pair_change_handler, client));
+
+    // Create DTLS transport
+    EOE(rawrtc_dtls_transport_create(
+        &client->dtls_transport, client->ice_transport, certificates, ARRAY_SIZE(certificates),
+        default_dtls_transport_state_change_handler, default_dtls_transport_error_handler, client));
+
+    // Create SCTP redirect transport
+    EOE(rawrtc_sctp_redirect_transport_create(
+        &client->sctp_redirect_transport, client->dtls_transport, 0, client->redirect_ip,
+        client->redirect_port, default_sctp_redirect_transport_state_change_handler, client));
+}
+
+static void client_start_gathering(struct sctp_redirect_transport_client* const client) {
+    // Start gathering
+    EOE(rawrtc_ice_gatherer_gather(client->gatherer, NULL));
+}
+
+static void client_set_parameters(struct sctp_redirect_transport_client* const client) {
+    struct parameters* const remote_parameters = &client->remote_parameters;
+
+    // Set remote ICE candidates
+    EOE(rawrtc_ice_transport_set_remote_candidates(
+        client->ice_transport, remote_parameters->ice_candidates->candidates,
+        remote_parameters->ice_candidates->n_candidates));
+}
+
+static void client_start_transports(struct sctp_redirect_transport_client* const client) {
+    struct parameters* const remote_parameters = &client->remote_parameters;
+
+    // Start ICE transport
+    EOE(rawrtc_ice_transport_start(
+        client->ice_transport, client->gatherer, remote_parameters->ice_parameters, client->role));
+
+    // Start DTLS transport
+    EOE(rawrtc_dtls_transport_start(client->dtls_transport, remote_parameters->dtls_parameters));
+
+    // Start SCTP redirect transport
+    EOE(rawrtc_sctp_redirect_transport_start(
+        client->sctp_redirect_transport, remote_parameters->sctp_parameters.capabilities,
+        remote_parameters->sctp_parameters.port));
+}
+
+static void parameters_destroy(struct parameters* const parameters) {
+    // Un-reference
+    parameters->ice_parameters = mem_deref(parameters->ice_parameters);
+    parameters->ice_candidates = mem_deref(parameters->ice_candidates);
+    parameters->dtls_parameters = mem_deref(parameters->dtls_parameters);
+    if (parameters->sctp_parameters.capabilities) {
+        parameters->sctp_parameters.capabilities =
+            mem_deref(parameters->sctp_parameters.capabilities);
+    }
+}
+
+static void client_stop(struct sctp_redirect_transport_client* const client) {
+    if (client->sctp_redirect_transport) {
+        EOE(rawrtc_sctp_redirect_transport_stop(client->sctp_redirect_transport));
+    }
+    if (client->dtls_transport) {
+        EOE(rawrtc_dtls_transport_stop(client->dtls_transport));
+    }
+    if (client->ice_transport) {
+        EOE(rawrtc_ice_transport_stop(client->ice_transport));
+    }
+    if (client->gatherer) {
+        EOE(rawrtc_ice_gatherer_close(client->gatherer));
+    }
+
+    // Un-reference & close
+    parameters_destroy(&client->remote_parameters);
+    parameters_destroy(&client->local_parameters);
+    client->sctp_redirect_transport = mem_deref(client->sctp_redirect_transport);
+    client->dtls_transport = mem_deref(client->dtls_transport);
+    client->ice_transport = mem_deref(client->ice_transport);
+    client->gatherer = mem_deref(client->gatherer);
+    client->certificate = mem_deref(client->certificate);
+    client->gather_options = mem_deref(client->gather_options);
+
+    // Stop listening on STDIN
+    fd_close(STDIN_FILENO);
+}
+
+static void parse_remote_parameters(int flags, void* arg) {
+    struct sctp_redirect_transport_client* const client = arg;
+    enum rawrtc_code error;
+    struct odict* dict = NULL;
+    struct odict* node = NULL;
+    struct rawrtc_ice_parameters* ice_parameters = NULL;
+    struct rawrtc_ice_candidates* ice_candidates = NULL;
+    struct rawrtc_dtls_parameters* dtls_parameters = NULL;
+    struct sctp_parameters sctp_parameters = {0};
+    (void) flags;
+
+    // Get dict from JSON
+    error = get_json_stdin(&dict);
+    if (error) {
+        goto out;
+    }
+
+    // Decode JSON
+    error |= dict_get_entry(&node, dict, "iceParameters", ODICT_OBJECT, true);
+    error |= get_ice_parameters(&ice_parameters, node);
+    error |= dict_get_entry(&node, dict, "iceCandidates", ODICT_ARRAY, true);
+    error |= get_ice_candidates(&ice_candidates, node, arg);
+    error |= dict_get_entry(&node, dict, "dtlsParameters", ODICT_OBJECT, true);
+    error |= get_dtls_parameters(&dtls_parameters, node);
+    error |= dict_get_entry(&node, dict, "sctpParameters", ODICT_OBJECT, true);
+    error |= get_sctp_parameters(&sctp_parameters, node);
+
+    // Ok?
+    if (error) {
+        DEBUG_WARNING("Invalid remote parameters\n");
+        if (sctp_parameters.capabilities) {
+            mem_deref(sctp_parameters.capabilities);
+        }
+        goto out;
+    }
+
+    // Set parameters & start transports
+    client->remote_parameters.ice_parameters = mem_ref(ice_parameters);
+    client->remote_parameters.ice_candidates = mem_ref(ice_candidates);
+    client->remote_parameters.dtls_parameters = mem_ref(dtls_parameters);
+    memcpy(&client->remote_parameters.sctp_parameters, &sctp_parameters, sizeof(sctp_parameters));
+    DEBUG_INFO("Applying remote parameters\n");
+    client_set_parameters(client);
+    client_start_transports(client);
+
+out:
+    // Un-reference
+    mem_deref(dtls_parameters);
+    mem_deref(ice_candidates);
+    mem_deref(ice_parameters);
+    mem_deref(dict);
+
+    // Exit?
+    if (error == RAWRTC_CODE_NO_VALUE) {
+        DEBUG_NOTICE("Exiting\n");
+
+        // Stop client & bye
+        client_stop(client);
+        re_cancel();
+    }
+}
+
+static void client_get_parameters(struct sctp_redirect_transport_client* const client) {
+    struct parameters* const local_parameters = &client->local_parameters;
+
+    // Get local ICE parameters
+    EOE(rawrtc_ice_gatherer_get_local_parameters(
+        &local_parameters->ice_parameters, client->gatherer));
+
+    // Get local ICE candidates
+    EOE(rawrtc_ice_gatherer_get_local_candidates(
+        &local_parameters->ice_candidates, client->gatherer));
+
+    // Get local DTLS parameters
+    EOE(rawrtc_dtls_transport_get_local_parameters(
+        &local_parameters->dtls_parameters, client->dtls_transport));
+
+    // Get redirected local SCTP port
+    EOE(rawrtc_sctp_redirect_transport_get_port(
+        &local_parameters->sctp_parameters.port, client->sctp_redirect_transport));
+}
+
+static void print_local_parameters(struct sctp_redirect_transport_client* client) {
+    struct odict* dict;
+    struct odict* node;
+
+    // Get local parameters
+    client_get_parameters(client);
+
+    // Create dict
+    EOR(odict_alloc(&dict, 16));
+
+    // Create nodes
+    EOR(odict_alloc(&node, 16));
+    set_ice_parameters(client->local_parameters.ice_parameters, node);
+    EOR(odict_entry_add(dict, "iceParameters", ODICT_OBJECT, node));
+    mem_deref(node);
+    EOR(odict_alloc(&node, 16));
+    set_ice_candidates(client->local_parameters.ice_candidates, node);
+    EOR(odict_entry_add(dict, "iceCandidates", ODICT_ARRAY, node));
+    mem_deref(node);
+    EOR(odict_alloc(&node, 16));
+    set_dtls_parameters(client->local_parameters.dtls_parameters, node);
+    EOR(odict_entry_add(dict, "dtlsParameters", ODICT_OBJECT, node));
+    mem_deref(node);
+    EOR(odict_alloc(&node, 16));
+    set_sctp_redirect_parameters(
+        client->sctp_redirect_transport, &client->local_parameters.sctp_parameters, node);
+    EOR(odict_entry_add(dict, "sctpParameters", ODICT_OBJECT, node));
+    mem_deref(node);
+
+    // Print JSON
+    DEBUG_INFO("Local Parameters:\n%H\n", json_encode_odict, dict);
+
+    // Un-reference
+    mem_deref(dict);
+}
+
+static void exit_with_usage(char* program) {
+    DEBUG_WARNING(
+        "Usage: %s <0|1 (ice-role)> <redirect-ip> <redirect-port> [<sctp-port>] "
+        "[<maximum-message-size>] [<ice-candidate-type> ...]",
+        program);
+    exit(1);
+}
+
+int main(int argc, char* argv[argc + 1]) {
+    char** ice_candidate_types = NULL;
+    size_t n_ice_candidate_types = 0;
+    enum rawrtc_ice_role role;
+    uint16_t redirect_port;
+    uint64_t maximum_message_size;
+    struct rawrtc_ice_gather_options* gather_options;
+    char* const turn_zwuenf_org_urls[] = {"stun:turn.zwuenf.org"};
+    struct sctp_redirect_transport_client client = {0};
+    (void) client.ice_candidate_types;
+    (void) client.n_ice_candidate_types;
+
+    // Debug
+    dbg_init(DBG_DEBUG, DBG_ALL);
+    DEBUG_PRINTF("Init\n");
+
+    // Initialise
+    EOE(rawrtc_init(true));
+
+    // Check arguments length
+    if (argc < 4) {
+        exit_with_usage(argv[0]);
+    }
+
+    // Get ICE role
+    if (get_ice_role(&role, argv[1])) {
+        exit_with_usage(argv[0]);
+    }
+
+    // Get redirect port
+    if (!str_to_uint16(&redirect_port, argv[3])) {
+        exit_with_usage(argv[0]);
+    }
+
+    // Get SCTP port (optional)
+    if (argc >= 5 && !str_to_uint16(&client.local_parameters.sctp_parameters.port, argv[4])) {
+        exit_with_usage(argv[0]);
+    }
+
+    // Get maximum message size (optional)
+    if (argc >= 6 && !str_to_uint64(&maximum_message_size, argv[5])) {
+        exit_with_usage(argv[0]);
+    } else {
+        maximum_message_size = 0;
+    }
+
+    // Get enabled ICE candidate types to be added (optional)
+    if (argc >= 7) {
+        ice_candidate_types = &argv[6];
+        n_ice_candidate_types = (size_t) argc - 6;
+    }
+
+    // Create local SCTP capabilities
+    rawrtc_sctp_capabilities_create(
+        &client.local_parameters.sctp_parameters.capabilities, maximum_message_size);
+
+    // Create ICE gather options
+    EOE(rawrtc_ice_gather_options_create(&gather_options, RAWRTC_ICE_GATHER_POLICY_ALL));
+
+    // Add ICE servers to ICE gather options
+    EOE(rawrtc_ice_gather_options_add_server(
+        gather_options, turn_zwuenf_org_urls, ARRAY_SIZE(turn_zwuenf_org_urls), NULL, NULL,
+        RAWRTC_ICE_CREDENTIAL_TYPE_NONE));
+
+    // Set client fields
+    client.name = "A";
+    client.ice_candidate_types = ice_candidate_types;
+    client.n_ice_candidate_types = n_ice_candidate_types;
+    client.gather_options = gather_options;
+    client.role = role;
+    client.redirect_ip = argv[2];
+    client.redirect_port = redirect_port;
+
+    // Setup client
+    client_init(&client);
+
+    // Start gathering
+    client_start_gathering(&client);
+
+    // Listen on stdin
+    EOR(fd_listen(STDIN_FILENO, FD_READ, parse_remote_parameters, &client));
+
+    // Start main loop
+    EOR(re_main(default_signal_handler));
+
+    // Stop client & bye
+    client_stop(&client);
+    before_exit();
+    return 0;
+}