提交 6c135e15 authored 作者: Anthony Minessale's avatar Anthony Minessale

FS-7602 FS-7499 FS-7587 #comment another refactoring pass on candidate parsing and ipv4/6 parsing

上级 fc075a75
...@@ -103,7 +103,7 @@ typedef struct icand_s { ...@@ -103,7 +103,7 @@ typedef struct icand_s {
typedef struct ice_s { typedef struct ice_s {
icand_t cands[MAX_CAND][2]; icand_t cands[MAX_CAND][2];
int cand_idx; int cand_idx[2];
int chosen[2]; int chosen[2];
int is_chosen[2]; int is_chosen[2];
char *ufrag; char *ufrag;
......
...@@ -143,7 +143,7 @@ static void verto_deinit_ssl(verto_profile_t *profile) ...@@ -143,7 +143,7 @@ static void verto_deinit_ssl(verto_profile_t *profile)
static void close_file(ws_socket_t *sock) static void close_file(ws_socket_t *sock)
{ {
if (*sock > -1) { if (*sock != ws_sock_invalid) {
#ifndef WIN32 #ifndef WIN32
close(*sock); close(*sock);
#else #else
...@@ -155,7 +155,7 @@ static void close_file(ws_socket_t *sock) ...@@ -155,7 +155,7 @@ static void close_file(ws_socket_t *sock)
static void close_socket(ws_socket_t *sock) static void close_socket(ws_socket_t *sock)
{ {
if (*sock > -1) { if (*sock != ws_sock_invalid) {
shutdown(*sock, 2); shutdown(*sock, 2);
close_file(sock); close_file(sock);
} }
...@@ -1914,7 +1914,7 @@ static void *SWITCH_THREAD_FUNC client_thread(switch_thread_t *thread, void *obj ...@@ -1914,7 +1914,7 @@ static void *SWITCH_THREAD_FUNC client_thread(switch_thread_t *thread, void *obj
switch_event_destroy(&jsock->vars); switch_event_destroy(&jsock->vars);
switch_event_destroy(&jsock->user_vars); switch_event_destroy(&jsock->user_vars);
if (jsock->client_socket > -1) { if (jsock->client_socket != ws_sock_invalid) {
close_socket(&jsock->client_socket); close_socket(&jsock->client_socket);
} }
...@@ -3655,7 +3655,7 @@ static switch_bool_t verto__broadcast_func(const char *method, cJSON *params, js ...@@ -3655,7 +3655,7 @@ static switch_bool_t verto__broadcast_func(const char *method, cJSON *params, js
jevent = cJSON_Duplicate(params, 1); jevent = cJSON_Duplicate(params, 1);
switch_event_channel_broadcast(event_channel, &jevent, modname, globals.event_channel_id); switch_event_channel_broadcast(event_channel, &jevent, modname, globals.event_channel_id);
if (jsock->profile->mcast_pub.sock > -1) { if (jsock->profile->mcast_pub.sock != ws_sock_invalid) {
if ((json_text = cJSON_PrintUnformatted(params))) { if ((json_text = cJSON_PrintUnformatted(params))) {
if ( mcast_socket_send(&jsock->profile->mcast_pub, json_text, strlen(json_text) + 1) < 0 ) { if ( mcast_socket_send(&jsock->profile->mcast_pub, json_text, strlen(json_text) + 1) < 0 ) {
...@@ -3894,7 +3894,7 @@ static int start_jsock(verto_profile_t *profile, ws_socket_t sock, int family) ...@@ -3894,7 +3894,7 @@ static int start_jsock(verto_profile_t *profile, ws_socket_t sock, int family)
error: error:
if (jsock) { if (jsock) {
if (jsock->client_socket > -1) { if (jsock->client_socket != ws_sock_invalid) {
close_socket(&jsock->client_socket); close_socket(&jsock->client_socket);
} }
...@@ -3965,7 +3965,13 @@ static ws_socket_t prepare_socket(ips_t *ips) ...@@ -3965,7 +3965,13 @@ static ws_socket_t prepare_socket(ips_t *ips)
static void handle_mcast_sub(verto_profile_t *profile) static void handle_mcast_sub(verto_profile_t *profile)
{ {
int bytes = mcast_socket_recv(&profile->mcast_sub, NULL, 0, 0); int bytes;
if (profile->mcast_sub.sock == ws_sock_invalid) {
return;
}
bytes = mcast_socket_recv(&profile->mcast_sub, NULL, 0, 0);
if (bytes > 0) { if (bytes > 0) {
cJSON *json; cJSON *json;
...@@ -4100,27 +4106,36 @@ static int runtime(verto_profile_t *profile) ...@@ -4100,27 +4106,36 @@ static int runtime(verto_profile_t *profile)
{ {
int i; int i;
int r = 0; int r = 0;
int listeners = 0;
for (i = 0; i < profile->i; i++) { for (i = 0; i < profile->i; i++) {
//if ((profile->server_socket[i] = prepare_socket(profile->ip[i].local_ip_addr, profile->ip[i].local_port)) < 0) { //if ((profile->server_socket[i] = prepare_socket(profile->ip[i].local_ip_addr, profile->ip[i].local_port)) < 0) {
if ((profile->server_socket[i] = prepare_socket(&profile->ip[i])) < 0) { if ((profile->server_socket[i] = prepare_socket(&profile->ip[i])) != ws_sock_invalid) {
die("Client Socket Error!\n"); listeners++;
} }
} }
if (!listeners) {
die("Client Socket Error! No Listeners!\n");
}
if (profile->mcast_ip) { if (profile->mcast_ip) {
int ok = 1;
if (mcast_socket_create(profile->mcast_ip, profile->mcast_port, &profile->mcast_sub, MCAST_RECV | MCAST_TTL_HOST) < 0) { if (mcast_socket_create(profile->mcast_ip, profile->mcast_port, &profile->mcast_sub, MCAST_RECV | MCAST_TTL_HOST) < 0) {
r = -1; ok++;
die("mcast recv socket create\n");
} }
if (mcast_socket_create(profile->mcast_ip, profile->mcast_port + 1, &profile->mcast_pub, MCAST_SEND | MCAST_TTL_HOST) > 0) { if (ok && mcast_socket_create(profile->mcast_ip, profile->mcast_port + 1, &profile->mcast_pub, MCAST_SEND | MCAST_TTL_HOST) > 0) {
mcast_socket_close(&profile->mcast_sub); mcast_socket_close(&profile->mcast_sub);
r = -1; ok = 0;
die("mcast send socket create\n");
} }
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "MCAST Bound to %s:%d/%d\n", profile->mcast_ip, profile->mcast_port, profile->mcast_port + 1); if (ok) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "MCAST Bound to %s:%d/%d\n", profile->mcast_ip, profile->mcast_port, profile->mcast_port + 1);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "MCAST Disabled\n");
}
} }
...@@ -4132,11 +4147,11 @@ static int runtime(verto_profile_t *profile) ...@@ -4132,11 +4147,11 @@ static int runtime(verto_profile_t *profile)
error: error:
if (profile->mcast_sub.sock > -1) { if (profile->mcast_sub.sock != ws_sock_invalid) {
mcast_socket_close(&profile->mcast_sub); mcast_socket_close(&profile->mcast_sub);
} }
if (profile->mcast_pub.sock > -1) { if (profile->mcast_pub.sock != ws_sock_invalid) {
mcast_socket_close(&profile->mcast_pub); mcast_socket_close(&profile->mcast_pub);
} }
......
...@@ -864,11 +864,15 @@ SWITCH_DECLARE(const char *) switch_get_addr(char *buf, switch_size_t len, switc ...@@ -864,11 +864,15 @@ SWITCH_DECLARE(const char *) switch_get_addr(char *buf, switch_size_t len, switc
return SWITCH_BLANK_STRING; return SWITCH_BLANK_STRING;
} }
memset(buf, 0, len);
if (in->family == AF_INET) { if (in->family == AF_INET) {
return get_addr(buf, len, (struct sockaddr *) &in->sa, in->salen); get_addr(buf, len, (struct sockaddr *) &in->sa, in->salen);
return buf;
} }
return get_addr6(buf, len, (struct sockaddr_in6 *) &in->sa, in->salen); get_addr6(buf, len, (struct sockaddr_in6 *) &in->sa, in->salen);
return buf;
} }
SWITCH_DECLARE(uint16_t) switch_sockaddr_get_port(switch_sockaddr_t *sa) SWITCH_DECLARE(uint16_t) switch_sockaddr_get_port(switch_sockaddr_t *sa)
......
...@@ -1420,6 +1420,20 @@ SWITCH_DECLARE(void) switch_load_network_lists(switch_bool_t reload) ...@@ -1420,6 +1420,20 @@ SWITCH_DECLARE(void) switch_load_network_lists(switch_bool_t reload)
switch_core_hash_insert(IP_LIST.hash, tmp_name, rfc_list); switch_core_hash_insert(IP_LIST.hash, tmp_name, rfc_list);
tmp_name = "any_v6.auto";
switch_network_list_create(&rfc_list, tmp_name, SWITCH_TRUE, IP_LIST.pool);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Created ip list %s default (allow)\n", tmp_name);
switch_network_list_add_cidr(rfc_list, "0.0.0.0/0", SWITCH_FALSE);
switch_core_hash_insert(IP_LIST.hash, tmp_name, rfc_list);
tmp_name = "any_v4.auto";
switch_network_list_create(&rfc_list, tmp_name, SWITCH_TRUE, IP_LIST.pool);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Created ip list %s default (allow)\n", tmp_name);
switch_network_list_add_cidr(rfc_list, "::/0", SWITCH_FALSE);
switch_core_hash_insert(IP_LIST.hash, tmp_name, rfc_list);
tmp_name = "nat.auto"; tmp_name = "nat.auto";
switch_network_list_create(&rfc_list, tmp_name, SWITCH_FALSE, IP_LIST.pool); switch_network_list_create(&rfc_list, tmp_name, SWITCH_FALSE, IP_LIST.pool);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Created ip list %s default (deny)\n", tmp_name); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Created ip list %s default (deny)\n", tmp_name);
......
差异被折叠。
...@@ -1038,7 +1038,7 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d ...@@ -1038,7 +1038,7 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d
if (!icep[j] || !icep[j]->ice_params) { if (!icep[j] || !icep[j]->ice_params) {
continue; continue;
} }
for (i = 0; i < icep[j]->ice_params->cand_idx; i++) { for (i = 0; i < icep[j]->ice_params->cand_idx[icep[j]->proto]; i++) {
if (icep[j]->ice_params && icep[j]->ice_params->cands[i][icep[j]->proto].priority == *pri) { if (icep[j]->ice_params && icep[j]->ice_params->cands[i][icep[j]->proto].priority == *pri) {
if (j == IPR_RTP) { if (j == IPR_RTP) {
icep[j]->ice_params->chosen[j] = i; icep[j]->ice_params->chosen[j] = i;
...@@ -1191,7 +1191,7 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d ...@@ -1191,7 +1191,7 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d
for (i = 0; i <= ice->ice_params->cand_idx; i++) { for (i = 0; i <= ice->ice_params->cand_idx[ice->proto]; i++) {
if (ice->ice_params->cands[i][ice->proto].con_port == port) { if (ice->ice_params->cands[i][ice->proto].con_port == port) {
if (!strcmp(ice->ice_params->cands[i][ice->proto].con_addr, host) && if (!strcmp(ice->ice_params->cands[i][ice->proto].con_addr, host) &&
!strcmp(ice->ice_params->cands[i][ice->proto].cand_type, "relay")) { !strcmp(ice->ice_params->cands[i][ice->proto].cand_type, "relay")) {
...@@ -2404,7 +2404,7 @@ static switch_status_t enable_remote_rtcp_socket(switch_rtp_t *rtp_session, cons ...@@ -2404,7 +2404,7 @@ static switch_status_t enable_remote_rtcp_socket(switch_rtp_t *rtp_session, cons
host = switch_get_addr(bufa, sizeof(bufa), rtp_session->rtcp_remote_addr); host = switch_get_addr(bufa, sizeof(bufa), rtp_session->rtcp_remote_addr);
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG, switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG,
"Setting RTCP remote addr to %s:%d\n", host, rtp_session->remote_rtcp_port); "Setting RTCP remote addr to %s:%d %d\n", host, rtp_session->remote_rtcp_port, rtp_session->rtcp_remote_addr->family);
} }
if (rtp_session->rtcp_sock_input && switch_sockaddr_get_family(rtp_session->rtcp_remote_addr) == if (rtp_session->rtcp_sock_input && switch_sockaddr_get_family(rtp_session->rtcp_remote_addr) ==
...@@ -2846,25 +2846,26 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_set_remote_address(switch_rtp_t *rtp_ ...@@ -2846,25 +2846,26 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_set_remote_address(switch_rtp_t *rtp_
} }
if (rtp_session->flags[SWITCH_RTP_FLAG_ENABLE_RTCP] && !rtp_session->flags[SWITCH_RTP_FLAG_RTCP_MUX]) { if (rtp_session->flags[SWITCH_RTP_FLAG_ENABLE_RTCP]) {
if (remote_rtcp_port) { if (rtp_session->flags[SWITCH_RTP_FLAG_RTCP_MUX]) {
rtp_session->remote_rtcp_port = remote_rtcp_port; rtp_session->rtcp_remote_addr = rtp_session->remote_addr;
rtp_session->rtcp_sock_output = rtp_session->sock_output;
} else { } else {
rtp_session->remote_rtcp_port = rtp_session->eff_remote_port + 1; if (remote_rtcp_port) {
} rtp_session->remote_rtcp_port = remote_rtcp_port;
status = enable_remote_rtcp_socket(rtp_session, err); } else {
rtp_session->remote_rtcp_port = rtp_session->eff_remote_port + 1;
if (rtp_session->rtcp_dtls) { }
//switch_sockaddr_info_get(&rtp_session->rtcp_dtls->remote_addr, host, SWITCH_UNSPEC, port, 0, rtp_session->pool); status = enable_remote_rtcp_socket(rtp_session, err);
rtp_session->rtcp_dtls->remote_addr = rtp_session->rtcp_remote_addr;
rtp_session->rtcp_dtls->sock_output = rtp_session->rtcp_sock_output; if (rtp_session->rtcp_dtls) {
//switch_sockaddr_info_get(&rtp_session->rtcp_dtls->remote_addr, host, SWITCH_UNSPEC, port, 0, rtp_session->pool);
rtp_session->rtcp_dtls->remote_addr = rtp_session->rtcp_remote_addr;
rtp_session->rtcp_dtls->sock_output = rtp_session->rtcp_sock_output;
}
} }
} }
if (rtp_session->flags[SWITCH_RTP_FLAG_ENABLE_RTCP] && rtp_session->flags[SWITCH_RTP_FLAG_RTCP_MUX]) {
rtp_session->rtcp_remote_addr = rtp_session->remote_addr;
}
switch_mutex_unlock(rtp_session->write_mutex); switch_mutex_unlock(rtp_session->write_mutex);
return status; return status;
...@@ -4112,8 +4113,10 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_activate_rtcp(switch_rtp_t *rtp_sessi ...@@ -4112,8 +4113,10 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_activate_rtcp(switch_rtp_t *rtp_sessi
rtp_session->rtcp_sock_output = rtp_session->sock_output; rtp_session->rtcp_sock_output = rtp_session->sock_output;
rtp_session->rtcp_recv_msg_p = (rtcp_msg_t *) &rtp_session->recv_msg; rtp_session->rtcp_recv_msg_p = (rtcp_msg_t *) &rtp_session->recv_msg;
return SWITCH_STATUS_SUCCESS;
return enable_remote_rtcp_socket(rtp_session, &err); //return enable_remote_rtcp_socket(rtp_session, &err);
} else { } else {
rtp_session->rtcp_recv_msg_p = (rtcp_msg_t *) &rtp_session->rtcp_recv_msg; rtp_session->rtcp_recv_msg_p = (rtcp_msg_t *) &rtp_session->rtcp_recv_msg;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论