From 94272e41cba9382e2cb3c054d2976f82e25054f8 Mon Sep 17 00:00:00 2001 From: xicilion Date: Wed, 15 May 2024 14:18:11 +0800 Subject: [PATCH 01/12] support juice_bind_stun to reflect stun requests from unbound client. --- include/juice/juice.h | 2 ++ src/conn.c | 26 +++++++++++++++++++++++++- src/conn.h | 1 + src/conn_mux.c | 9 +++++++++ 4 files changed, 37 insertions(+), 1 deletion(-) diff --git a/include/juice/juice.h b/include/juice/juice.h index 594b5dde..65ed6b19 100644 --- a/include/juice/juice.h +++ b/include/juice/juice.h @@ -63,6 +63,7 @@ typedef void (*juice_cb_candidate_t)(juice_agent_t *agent, const char *sdp, void typedef void (*juice_cb_gathering_done_t)(juice_agent_t *agent, void *user_ptr); typedef void (*juice_cb_recv_t)(juice_agent_t *agent, const char *data, size_t size, void *user_ptr); +typedef void (*juice_cb_stun_binding_t)(const char *ufrag, const char *pwd, const char *bind_address); typedef struct juice_turn_server { const char *host; @@ -118,6 +119,7 @@ JUICE_EXPORT int juice_get_selected_addresses(juice_agent_t *agent, char *local, char *remote, size_t remote_size); JUICE_EXPORT int juice_set_local_ice_attributes(juice_agent_t *agent, const char *ufrag, const char *pwd); JUICE_EXPORT const char *juice_state_to_string(juice_state_t state); +JUICE_EXPORT int juice_bind_stun(const char *bind_address, int local_port, juice_cb_stun_binding_t cb); // ICE server diff --git a/src/conn.c b/src/conn.c index 4d7893a0..ccb453be 100644 --- a/src/conn.c +++ b/src/conn.c @@ -108,7 +108,7 @@ static void release_registry(conn_mode_entry_t *entry) { // registry must be locked - if (registry->agents_count == 0) { + if (registry->agents_count == 0 && registry->cb_stun_binding == NULL) { JLOG_DEBUG("No connection left, destroying connections registry"); mutex_unlock(®istry->mutex); @@ -247,3 +247,27 @@ int conn_get_addrs(juice_agent_t *agent, addr_record_t *records, size_t size) { return get_mode_entry(agent)->get_addrs_func(agent, records, size); } + +int juice_bind_stun(const char *bind_address, int local_port, juice_cb_stun_binding_t cb) +{ + conn_mode_entry_t *entry = &mode_entries[JUICE_CONCURRENCY_MODE_MUX]; + + udp_socket_config_t config; + config.bind_address = bind_address; + config.port_begin = config.port_end = local_port; + + mutex_lock(&entry->mutex); + + if (entry->registry) { + mutex_unlock(&entry->mutex); + return -1; + } + + conn_registry_t *registry = acquire_registry(entry, &config); + mutex_unlock(&entry->mutex); + + registry->cb_stun_binding = cb; + mutex_unlock(®istry->mutex); + + return 0; +} diff --git a/src/conn.h b/src/conn.h index 4aec7d0c..a06c53e5 100644 --- a/src/conn.h +++ b/src/conn.h @@ -30,6 +30,7 @@ typedef struct conn_registry { juice_agent_t **agents; int agents_size; int agents_count; + juice_cb_stun_binding_t cb_stun_binding; } conn_registry_t; int conn_create(juice_agent_t *agent, udp_socket_config_t *config); diff --git a/src/conn_mux.c b/src/conn_mux.c index a783b3f8..4d05de12 100644 --- a/src/conn_mux.c +++ b/src/conn_mux.c @@ -243,6 +243,8 @@ int conn_mux_prepare(conn_registry_t *registry, struct pollfd *pfd, timestamp_t } int count = registry->agents_count; + if (registry->cb_stun_binding) + ++count; mutex_unlock(®istry->mutex); return count; } @@ -295,6 +297,13 @@ static juice_agent_t *lookup_agent(conn_registry_t *registry, char *buf, size_t } } + if (registry->cb_stun_binding) { + JLOG_DEBUG("Found STUN agent for unknown ICE ufrag"); + char src_str[ADDR_MAX_STRING_LEN]; + addr_record_to_string(src, src_str, ADDR_MAX_STRING_LEN); + registry->cb_stun_binding(username, separator + 1, src_str); + return NULL; + } } else { if (!STUN_IS_RESPONSE(msg.msg_class)) { JLOG_INFO("Got unexpected STUN message from unknown source address"); From 59957aa442da8a687d6eb5024d06bf34717247bb Mon Sep 17 00:00:00 2001 From: xicilion Date: Sat, 8 Jun 2024 03:35:54 +0800 Subject: [PATCH 02/12] feat: Add support for reflecting STUN requests from unbound clients. --- include/juice/juice.h | 12 +++++++++++- src/conn_mux.c | 25 ++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/include/juice/juice.h b/include/juice/juice.h index 65ed6b19..d2fb521e 100644 --- a/include/juice/juice.h +++ b/include/juice/juice.h @@ -63,7 +63,17 @@ typedef void (*juice_cb_candidate_t)(juice_agent_t *agent, const char *sdp, void typedef void (*juice_cb_gathering_done_t)(juice_agent_t *agent, void *user_ptr); typedef void (*juice_cb_recv_t)(juice_agent_t *agent, const char *data, size_t size, void *user_ptr); -typedef void (*juice_cb_stun_binding_t)(const char *ufrag, const char *pwd, const char *bind_address); + +typedef struct juice_stun_binding { + const char *ufrag; + const char *pwd; + + uint8_t family; + const char *address; + uint16_t port; +} juice_stun_binding_t; + +typedef void (*juice_cb_stun_binding_t)(const juice_stun_binding_t *info); typedef struct juice_turn_server { const char *host; diff --git a/src/conn_mux.c b/src/conn_mux.c index 4d05de12..e711eb03 100644 --- a/src/conn_mux.c +++ b/src/conn_mux.c @@ -299,9 +299,28 @@ static juice_agent_t *lookup_agent(conn_registry_t *registry, char *buf, size_t if (registry->cb_stun_binding) { JLOG_DEBUG("Found STUN agent for unknown ICE ufrag"); - char src_str[ADDR_MAX_STRING_LEN]; - addr_record_to_string(src, src_str, ADDR_MAX_STRING_LEN); - registry->cb_stun_binding(username, separator + 1, src_str); + const struct sockaddr *sa = (const struct sockaddr *)&src->addr; + + socklen_t salen = addr_get_len(sa); + if (salen == 0) + return NULL; + + char host[ADDR_MAX_NUMERICHOST_LEN]; + if (getnameinfo(sa, salen, host, ADDR_MAX_NUMERICHOST_LEN, NULL, 0, NI_NUMERICHOST)) { + JLOG_ERROR("getnameinfo failed, errno=%d", sockerrno); + return NULL; + } + + juice_stun_binding_t binding_info; + + binding_info.ufrag = username; + binding_info.pwd = separator + 1; + binding_info.family = sa->sa_family; + binding_info.address = host; + binding_info.port = addr_get_port((struct sockaddr *)src); + + registry->cb_stun_binding(&binding_info); + return NULL; } } else { From 06a925b86ae625e965f09047f71e2d602e990ffb Mon Sep 17 00:00:00 2001 From: xicilion Date: Wed, 12 Jun 2024 05:02:08 +0800 Subject: [PATCH 03/12] Return the corresponding error code when binding the port fails. --- src/conn.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/conn.c b/src/conn.c index ccb453be..39ba4135 100644 --- a/src/conn.c +++ b/src/conn.c @@ -266,6 +266,9 @@ int juice_bind_stun(const char *bind_address, int local_port, juice_cb_stun_bind conn_registry_t *registry = acquire_registry(entry, &config); mutex_unlock(&entry->mutex); + if (!registry) + return -2; + registry->cb_stun_binding = cb; mutex_unlock(®istry->mutex); From 63651ed6f1aa88cde5f0720b7173054b542d079c Mon Sep 17 00:00:00 2001 From: xicilion Date: Wed, 12 Jun 2024 21:34:30 +0800 Subject: [PATCH 04/12] fix compile error on windows. --- src/conn_mux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/conn_mux.c b/src/conn_mux.c index e711eb03..c2432e2b 100644 --- a/src/conn_mux.c +++ b/src/conn_mux.c @@ -315,7 +315,7 @@ static juice_agent_t *lookup_agent(conn_registry_t *registry, char *buf, size_t binding_info.ufrag = username; binding_info.pwd = separator + 1; - binding_info.family = sa->sa_family; + binding_info.family = (uint8_t)sa->sa_family; binding_info.address = host; binding_info.port = addr_get_port((struct sockaddr *)src); From 50fa27afcb27e164cadbd3da36072bf1be412bc1 Mon Sep 17 00:00:00 2001 From: xicilion Date: Thu, 13 Jun 2024 21:33:07 +0800 Subject: [PATCH 05/12] support juice_unbind_stun. --- include/juice/juice.h | 1 + src/conn.c | 23 +++++++++++++++++++++++ src/conn_mux.c | 20 ++++++++++++-------- src/conn_mux.h | 1 + 4 files changed, 37 insertions(+), 8 deletions(-) diff --git a/include/juice/juice.h b/include/juice/juice.h index d2fb521e..9fbc9d8a 100644 --- a/include/juice/juice.h +++ b/include/juice/juice.h @@ -130,6 +130,7 @@ JUICE_EXPORT int juice_get_selected_addresses(juice_agent_t *agent, char *local, JUICE_EXPORT int juice_set_local_ice_attributes(juice_agent_t *agent, const char *ufrag, const char *pwd); JUICE_EXPORT const char *juice_state_to_string(juice_state_t state); JUICE_EXPORT int juice_bind_stun(const char *bind_address, int local_port, juice_cb_stun_binding_t cb); +JUICE_EXPORT int juice_unbind_stun(); // ICE server diff --git a/src/conn.c b/src/conn.c index 39ba4135..5b26dfe0 100644 --- a/src/conn.c +++ b/src/conn.c @@ -248,6 +248,29 @@ int conn_get_addrs(juice_agent_t *agent, addr_record_t *records, size_t size) { return get_mode_entry(agent)->get_addrs_func(agent, records, size); } +int juice_unbind_stun() { + conn_mode_entry_t *entry = &mode_entries[JUICE_CONCURRENCY_MODE_MUX]; + + mutex_lock(&entry->mutex); + + conn_registry_t *registry = entry->registry; + if (!registry) { + mutex_unlock(&entry->mutex); + return -1; + } + + mutex_lock(®istry->mutex); + + registry->cb_stun_binding = NULL; + conn_mux_interrupt_registry(registry); + + release_registry(entry); + + mutex_unlock(&entry->mutex); + + return 0; +} + int juice_bind_stun(const char *bind_address, int local_port, juice_cb_stun_binding_t cb) { conn_mode_entry_t *entry = &mode_entries[JUICE_CONCURRENCY_MODE_MUX]; diff --git a/src/conn_mux.c b/src/conn_mux.c index c2432e2b..fc3133a2 100644 --- a/src/conn_mux.c +++ b/src/conn_mux.c @@ -507,14 +507,7 @@ void conn_mux_unlock(juice_agent_t *agent) { mutex_unlock(®istry->mutex); } -int conn_mux_interrupt(juice_agent_t *agent) { - conn_impl_t *conn_impl = agent->conn_impl; - conn_registry_t *registry = conn_impl->registry; - - mutex_lock(®istry->mutex); - conn_impl->next_timestamp = current_timestamp(); - mutex_unlock(®istry->mutex); - +int conn_mux_interrupt_registry(conn_registry_t *registry) { JLOG_VERBOSE("Interrupting connections thread"); registry_impl_t *registry_impl = registry->impl; @@ -530,6 +523,17 @@ int conn_mux_interrupt(juice_agent_t *agent) { return 0; } +int conn_mux_interrupt(juice_agent_t *agent) { + conn_impl_t *conn_impl = agent->conn_impl; + conn_registry_t *registry = conn_impl->registry; + + mutex_lock(®istry->mutex); + conn_impl->next_timestamp = current_timestamp(); + mutex_unlock(®istry->mutex); + + return conn_mux_interrupt_registry(registry); +} + int conn_mux_send(juice_agent_t *agent, const addr_record_t *dst, const char *data, size_t size, int ds) { conn_impl_t *conn_impl = agent->conn_impl; diff --git a/src/conn_mux.h b/src/conn_mux.h index 9519f066..68b51b67 100644 --- a/src/conn_mux.h +++ b/src/conn_mux.h @@ -24,6 +24,7 @@ int conn_mux_init(juice_agent_t *agent, conn_registry_t *registry, udp_socket_co void conn_mux_cleanup(juice_agent_t *agent); void conn_mux_lock(juice_agent_t *agent); void conn_mux_unlock(juice_agent_t *agent); +int conn_mux_interrupt_registry(conn_registry_t *registry); int conn_mux_interrupt(juice_agent_t *agent); int conn_mux_send(juice_agent_t *agent, const addr_record_t *dst, const char *data, size_t size, int ds); From 5b818b1c399ea0e9ee430f167aa5d6e57f59fd46 Mon Sep 17 00:00:00 2001 From: xicilion Date: Fri, 14 Jun 2024 12:15:42 +0800 Subject: [PATCH 06/12] add user_ptr in callback. --- include/juice/juice.h | 4 ++-- src/conn.c | 4 +++- src/conn.h | 1 + src/conn_mux.c | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/include/juice/juice.h b/include/juice/juice.h index 9fbc9d8a..2920c953 100644 --- a/include/juice/juice.h +++ b/include/juice/juice.h @@ -73,7 +73,7 @@ typedef struct juice_stun_binding { uint16_t port; } juice_stun_binding_t; -typedef void (*juice_cb_stun_binding_t)(const juice_stun_binding_t *info); +typedef void (*juice_cb_stun_binding_t)(const juice_stun_binding_t *info, void *user_ptr); typedef struct juice_turn_server { const char *host; @@ -129,7 +129,7 @@ JUICE_EXPORT int juice_get_selected_addresses(juice_agent_t *agent, char *local, char *remote, size_t remote_size); JUICE_EXPORT int juice_set_local_ice_attributes(juice_agent_t *agent, const char *ufrag, const char *pwd); JUICE_EXPORT const char *juice_state_to_string(juice_state_t state); -JUICE_EXPORT int juice_bind_stun(const char *bind_address, int local_port, juice_cb_stun_binding_t cb); +JUICE_EXPORT int juice_bind_stun(const char *bind_address, int local_port, juice_cb_stun_binding_t cb, void *user_ptr); JUICE_EXPORT int juice_unbind_stun(); // ICE server diff --git a/src/conn.c b/src/conn.c index 5b26dfe0..a63e7eff 100644 --- a/src/conn.c +++ b/src/conn.c @@ -262,6 +262,7 @@ int juice_unbind_stun() { mutex_lock(®istry->mutex); registry->cb_stun_binding = NULL; + registry->stun_binding_user_ptr = NULL; conn_mux_interrupt_registry(registry); release_registry(entry); @@ -271,7 +272,7 @@ int juice_unbind_stun() { return 0; } -int juice_bind_stun(const char *bind_address, int local_port, juice_cb_stun_binding_t cb) +int juice_bind_stun(const char *bind_address, int local_port, juice_cb_stun_binding_t cb, void *user_ptr) { conn_mode_entry_t *entry = &mode_entries[JUICE_CONCURRENCY_MODE_MUX]; @@ -293,6 +294,7 @@ int juice_bind_stun(const char *bind_address, int local_port, juice_cb_stun_bind return -2; registry->cb_stun_binding = cb; + registry->stun_binding_user_ptr = user_ptr; mutex_unlock(®istry->mutex); return 0; diff --git a/src/conn.h b/src/conn.h index a06c53e5..bbe90e4f 100644 --- a/src/conn.h +++ b/src/conn.h @@ -31,6 +31,7 @@ typedef struct conn_registry { int agents_size; int agents_count; juice_cb_stun_binding_t cb_stun_binding; + void *stun_binding_user_ptr; } conn_registry_t; int conn_create(juice_agent_t *agent, udp_socket_config_t *config); diff --git a/src/conn_mux.c b/src/conn_mux.c index fc3133a2..d6196a71 100644 --- a/src/conn_mux.c +++ b/src/conn_mux.c @@ -319,7 +319,7 @@ static juice_agent_t *lookup_agent(conn_registry_t *registry, char *buf, size_t binding_info.address = host; binding_info.port = addr_get_port((struct sockaddr *)src); - registry->cb_stun_binding(&binding_info); + registry->cb_stun_binding(&binding_info, registry->stun_binding_user_ptr); return NULL; } From f17129c375fcb2bf1b4cc3edc14cc1ca8e4b1f9c Mon Sep 17 00:00:00 2001 From: xicilion Date: Thu, 4 Jul 2024 03:46:28 +0800 Subject: [PATCH 07/12] feat: Add support for reflecting STUN requests from unbound clients. --- include/juice/juice.h | 11 +++++------ src/conn.c | 18 +++++++++++------- src/conn.h | 4 ++-- src/conn_mux.c | 27 ++++++++++----------------- 4 files changed, 28 insertions(+), 32 deletions(-) diff --git a/include/juice/juice.h b/include/juice/juice.h index 2920c953..0afa85a3 100644 --- a/include/juice/juice.h +++ b/include/juice/juice.h @@ -64,16 +64,15 @@ typedef void (*juice_cb_gathering_done_t)(juice_agent_t *agent, void *user_ptr); typedef void (*juice_cb_recv_t)(juice_agent_t *agent, const char *data, size_t size, void *user_ptr); -typedef struct juice_stun_binding { +typedef struct juice_mux_incoming { const char *ufrag; const char *pwd; - uint8_t family; const char *address; uint16_t port; -} juice_stun_binding_t; +} juice_mux_incoming_t; -typedef void (*juice_cb_stun_binding_t)(const juice_stun_binding_t *info, void *user_ptr); +typedef void (*juice_cb_mux_incoming_t)(const juice_mux_incoming_t *info, void *user_ptr); typedef struct juice_turn_server { const char *host; @@ -129,8 +128,8 @@ JUICE_EXPORT int juice_get_selected_addresses(juice_agent_t *agent, char *local, char *remote, size_t remote_size); JUICE_EXPORT int juice_set_local_ice_attributes(juice_agent_t *agent, const char *ufrag, const char *pwd); JUICE_EXPORT const char *juice_state_to_string(juice_state_t state); -JUICE_EXPORT int juice_bind_stun(const char *bind_address, int local_port, juice_cb_stun_binding_t cb, void *user_ptr); -JUICE_EXPORT int juice_unbind_stun(); +JUICE_EXPORT int juice_mux_listen(const char *bind_address, int local_port, juice_cb_mux_incoming_t cb, void *user_ptr); +JUICE_EXPORT int juice_mux_stop_listen(const char *bind_address, int local_port); // ICE server diff --git a/src/conn.c b/src/conn.c index a63e7eff..da383c43 100644 --- a/src/conn.c +++ b/src/conn.c @@ -108,7 +108,7 @@ static void release_registry(conn_mode_entry_t *entry) { // registry must be locked - if (registry->agents_count == 0 && registry->cb_stun_binding == NULL) { + if (registry->agents_count == 0 && registry->cb_mux_incoming == NULL) { JLOG_DEBUG("No connection left, destroying connections registry"); mutex_unlock(®istry->mutex); @@ -248,7 +248,10 @@ int conn_get_addrs(juice_agent_t *agent, addr_record_t *records, size_t size) { return get_mode_entry(agent)->get_addrs_func(agent, records, size); } -int juice_unbind_stun() { +int juice_mux_stop_listen(const char *bind_address, int local_port) { + (void)bind_address; + (void)local_port; + conn_mode_entry_t *entry = &mode_entries[JUICE_CONCURRENCY_MODE_MUX]; mutex_lock(&entry->mutex); @@ -261,8 +264,8 @@ int juice_unbind_stun() { mutex_lock(®istry->mutex); - registry->cb_stun_binding = NULL; - registry->stun_binding_user_ptr = NULL; + registry->cb_mux_incoming = NULL; + registry->mux_incoming_user_ptr = NULL; conn_mux_interrupt_registry(registry); release_registry(entry); @@ -272,7 +275,7 @@ int juice_unbind_stun() { return 0; } -int juice_bind_stun(const char *bind_address, int local_port, juice_cb_stun_binding_t cb, void *user_ptr) +int juice_mux_listen(const char *bind_address, int local_port, juice_cb_mux_incoming_t cb, void *user_ptr) { conn_mode_entry_t *entry = &mode_entries[JUICE_CONCURRENCY_MODE_MUX]; @@ -284,6 +287,7 @@ int juice_bind_stun(const char *bind_address, int local_port, juice_cb_stun_bind if (entry->registry) { mutex_unlock(&entry->mutex); + JLOG_DEBUG("juice_mux_listen needs to be called before establishing any mux connection."); return -1; } @@ -293,8 +297,8 @@ int juice_bind_stun(const char *bind_address, int local_port, juice_cb_stun_bind if (!registry) return -2; - registry->cb_stun_binding = cb; - registry->stun_binding_user_ptr = user_ptr; + registry->cb_mux_incoming = cb; + registry->mux_incoming_user_ptr = user_ptr; mutex_unlock(®istry->mutex); return 0; diff --git a/src/conn.h b/src/conn.h index bbe90e4f..5986c1c3 100644 --- a/src/conn.h +++ b/src/conn.h @@ -30,8 +30,8 @@ typedef struct conn_registry { juice_agent_t **agents; int agents_size; int agents_count; - juice_cb_stun_binding_t cb_stun_binding; - void *stun_binding_user_ptr; + juice_cb_mux_incoming_t cb_mux_incoming; + void *mux_incoming_user_ptr; } conn_registry_t; int conn_create(juice_agent_t *agent, udp_socket_config_t *config); diff --git a/src/conn_mux.c b/src/conn_mux.c index d6196a71..7afc7ffb 100644 --- a/src/conn_mux.c +++ b/src/conn_mux.c @@ -243,7 +243,7 @@ int conn_mux_prepare(conn_registry_t *registry, struct pollfd *pfd, timestamp_t } int count = registry->agents_count; - if (registry->cb_stun_binding) + if (registry->cb_mux_incoming) ++count; mutex_unlock(®istry->mutex); return count; @@ -297,29 +297,22 @@ static juice_agent_t *lookup_agent(conn_registry_t *registry, char *buf, size_t } } - if (registry->cb_stun_binding) { - JLOG_DEBUG("Found STUN agent for unknown ICE ufrag"); - const struct sockaddr *sa = (const struct sockaddr *)&src->addr; - - socklen_t salen = addr_get_len(sa); - if (salen == 0) - return NULL; - + if (registry->cb_mux_incoming) { + JLOG_DEBUG("Found STUN request with unknown ICE ufrag"); char host[ADDR_MAX_NUMERICHOST_LEN]; - if (getnameinfo(sa, salen, host, ADDR_MAX_NUMERICHOST_LEN, NULL, 0, NI_NUMERICHOST)) { + if (getnameinfo((const struct sockaddr *)&src->addr, src->len, host, ADDR_MAX_NUMERICHOST_LEN, NULL, 0, NI_NUMERICHOST)) { JLOG_ERROR("getnameinfo failed, errno=%d", sockerrno); return NULL; } - juice_stun_binding_t binding_info; + juice_mux_incoming_t incoming_info; - binding_info.ufrag = username; - binding_info.pwd = separator + 1; - binding_info.family = (uint8_t)sa->sa_family; - binding_info.address = host; - binding_info.port = addr_get_port((struct sockaddr *)src); + incoming_info.ufrag = username; + incoming_info.pwd = separator + 1; + incoming_info.address = host; + incoming_info.port = addr_get_port((struct sockaddr *)src); - registry->cb_stun_binding(&binding_info, registry->stun_binding_user_ptr); + registry->cb_mux_incoming(&incoming_info, registry->mux_incoming_user_ptr); return NULL; } From 20755dcd760d63ffb18243c2faac57394d1cc027 Mon Sep 17 00:00:00 2001 From: xicilion Date: Thu, 4 Jul 2024 16:01:03 +0800 Subject: [PATCH 08/12] feat: Add support for reflecting STUN requests from unbound clients. --- include/juice/juice.h | 4 ++-- src/conn_mux.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/juice/juice.h b/include/juice/juice.h index 0afa85a3..ccc65e94 100644 --- a/include/juice/juice.h +++ b/include/juice/juice.h @@ -65,8 +65,8 @@ typedef void (*juice_cb_recv_t)(juice_agent_t *agent, const char *data, size_t s void *user_ptr); typedef struct juice_mux_incoming { - const char *ufrag; - const char *pwd; + const char *remote_ufrag; + const char *local_ufrag; const char *address; uint16_t port; diff --git a/src/conn_mux.c b/src/conn_mux.c index 7afc7ffb..9db89df8 100644 --- a/src/conn_mux.c +++ b/src/conn_mux.c @@ -307,8 +307,8 @@ static juice_agent_t *lookup_agent(conn_registry_t *registry, char *buf, size_t juice_mux_incoming_t incoming_info; - incoming_info.ufrag = username; - incoming_info.pwd = separator + 1; + incoming_info.remote_ufrag = username; + incoming_info.local_ufrag = separator + 1; incoming_info.address = host; incoming_info.port = addr_get_port((struct sockaddr *)src); From 9ede09b461321e5154b859bfd6e7143800fb8928 Mon Sep 17 00:00:00 2001 From: xicilion Date: Thu, 4 Jul 2024 16:06:06 +0800 Subject: [PATCH 09/12] feat: Add support for reflecting STUN requests from unbound clients. --- src/conn_mux.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/conn_mux.c b/src/conn_mux.c index 9db89df8..ea1da9aa 100644 --- a/src/conn_mux.c +++ b/src/conn_mux.c @@ -307,8 +307,8 @@ static juice_agent_t *lookup_agent(conn_registry_t *registry, char *buf, size_t juice_mux_incoming_t incoming_info; - incoming_info.remote_ufrag = username; - incoming_info.local_ufrag = separator + 1; + incoming_info.local_ufrag = local_ufrag; + incoming_info.remote_ufrag = separator + 1; incoming_info.address = host; incoming_info.port = addr_get_port((struct sockaddr *)src); From 2c155ae6c101f29e24c87598de35f4319ff217aa Mon Sep 17 00:00:00 2001 From: xicilion Date: Thu, 4 Jul 2024 16:09:55 +0800 Subject: [PATCH 10/12] feat: Add support for reflecting STUN requests from unbound clients. --- include/juice/juice.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/juice/juice.h b/include/juice/juice.h index ccc65e94..95cf9e72 100644 --- a/include/juice/juice.h +++ b/include/juice/juice.h @@ -65,8 +65,8 @@ typedef void (*juice_cb_recv_t)(juice_agent_t *agent, const char *data, size_t s void *user_ptr); typedef struct juice_mux_incoming { - const char *remote_ufrag; const char *local_ufrag; + const char *remote_ufrag; const char *address; uint16_t port; From 4a0a896593b6fe1bf9fca61f190e5ab49a4fa529 Mon Sep 17 00:00:00 2001 From: xicilion Date: Wed, 31 Jul 2024 20:30:34 +0800 Subject: [PATCH 11/12] feat: Add support for reflecting STUN requests from unbound clients. --- src/conn_mux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/conn_mux.c b/src/conn_mux.c index ea1da9aa..b64839a9 100644 --- a/src/conn_mux.c +++ b/src/conn_mux.c @@ -297,7 +297,7 @@ static juice_agent_t *lookup_agent(conn_registry_t *registry, char *buf, size_t } } - if (registry->cb_mux_incoming) { + if (registry->cb_mux_incoming && msg.use_candidate == 0) { JLOG_DEBUG("Found STUN request with unknown ICE ufrag"); char host[ADDR_MAX_NUMERICHOST_LEN]; if (getnameinfo((const struct sockaddr *)&src->addr, src->len, host, ADDR_MAX_NUMERICHOST_LEN, NULL, 0, NI_NUMERICHOST)) { From 1fb20f7014e401c222f70f02695fccf1d067d85c Mon Sep 17 00:00:00 2001 From: xicilion Date: Fri, 30 Aug 2024 01:40:29 +0800 Subject: [PATCH 12/12] feat: Add support for reflecting STUN requests from unbound clients. --- src/conn_mux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/conn_mux.c b/src/conn_mux.c index b64839a9..ea1da9aa 100644 --- a/src/conn_mux.c +++ b/src/conn_mux.c @@ -297,7 +297,7 @@ static juice_agent_t *lookup_agent(conn_registry_t *registry, char *buf, size_t } } - if (registry->cb_mux_incoming && msg.use_candidate == 0) { + if (registry->cb_mux_incoming) { JLOG_DEBUG("Found STUN request with unknown ICE ufrag"); char host[ADDR_MAX_NUMERICHOST_LEN]; if (getnameinfo((const struct sockaddr *)&src->addr, src->len, host, ADDR_MAX_NUMERICHOST_LEN, NULL, 0, NI_NUMERICHOST)) {