Skip to content

Commit

Permalink
juice, refactor: use new stun binding callback signature.
Browse files Browse the repository at this point in the history
  • Loading branch information
xicilion committed Jun 4, 2024
1 parent 96cb2d5 commit b42da32
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
12 changes: 11 additions & 1 deletion juice/include/juice/juice.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
26 changes: 23 additions & 3 deletions juice/src/conn_mux.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,29 @@ 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(src);

registry->cb_stun_binding(&binding_info);

return NULL;
}
} else {
Expand Down

0 comments on commit b42da32

Please sign in to comment.