From 4afd423beff71568d8eb2e07d03fdbb848beb0ec Mon Sep 17 00:00:00 2001 From: mom040267 Date: Thu, 26 Feb 2015 06:39:45 +0000 Subject: [PATCH] working on bw limitations --- src/apps/relay/http_server.c | 2 +- src/apps/relay/ns_ioalib_engine_impl.c | 11 ++++------ src/server/ns_turn_ioalib.h | 2 +- src/server/ns_turn_server.c | 29 ++++++++++++++------------ 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/apps/relay/http_server.c b/src/apps/relay/http_server.c index 7b0b0b8f..72288131 100644 --- a/src/apps/relay/http_server.c +++ b/src/apps/relay/http_server.c @@ -68,7 +68,7 @@ static void write_http_echo(ioa_socket_handle s) len_http = strlen(data_http); ns_bcopy(data_http,data,len_http); ioa_network_buffer_set_size(nbh_http,len_http); - send_data_from_ioa_socket_nbh(s, NULL, nbh_http, TTL_IGNORE, TOS_IGNORE); + send_data_from_ioa_socket_nbh(s, NULL, nbh_http, TTL_IGNORE, TOS_IGNORE,NULL); } } } diff --git a/src/apps/relay/ns_ioalib_engine_impl.c b/src/apps/relay/ns_ioalib_engine_impl.c index ce51d279..381942e6 100644 --- a/src/apps/relay/ns_ioalib_engine_impl.c +++ b/src/apps/relay/ns_ioalib_engine_impl.c @@ -326,8 +326,6 @@ static void free_blist_elem(ioa_engine_handle e, stun_buffer_list_elem *buf_elem /************** ENGINE *************************/ -#define TURN_JIFFIE_SIZE (3) - static void timer_handler(ioa_engine_handle e, void* arg) { UNUSED_ARG(arg); @@ -335,7 +333,7 @@ static void timer_handler(ioa_engine_handle e, void* arg) { _log_time_value = turn_time(); _log_time_value_set = 1; - e->jiffie = _log_time_value >> TURN_JIFFIE_SIZE; + e->jiffie = _log_time_value; } ioa_engine_handle create_ioa_engine(super_memory_t *sm, @@ -641,15 +639,13 @@ void delete_ioa_timer(ioa_timer_handle th) static int ioa_socket_check_bandwidth(ioa_socket_handle s, size_t sz, int read) { - if(s && (s->e) && sz && (s->sat == CLIENT_SOCKET) && (s->session)) { + if(s && (s->e) && sz && ((s->sat == CLIENT_SOCKET) || (s->sat == LISTENER_SOCKET)) && (s->session)) { band_limit_t max_bps = s->session->bps; if(max_bps<1) return 1; - max_bps = max_bps<jiffie != s->e->jiffie) { @@ -2965,7 +2961,7 @@ int udp_send(ioa_socket_handle s, const ioa_addr* dest_addr, const s08bits* buff int send_data_from_ioa_socket_nbh(ioa_socket_handle s, ioa_addr* dest_addr, ioa_network_buffer_handle nbh, - int ttl, int tos) + int ttl, int tos, int *skip) { int ret = -1; @@ -2986,6 +2982,7 @@ int send_data_from_ioa_socket_nbh(ioa_socket_handle s, ioa_addr* dest_addr, if(!ioa_socket_check_bandwidth(s,ioa_network_buffer_get_size(nbh),0)) { /* Bandwidth exhausted, we pretend everything is fine: */ ret = (int)(ioa_network_buffer_get_size(nbh)); + if(skip) *skip = 1; } else { if (!ioa_socket_tobeclosed(s) && s->e) { diff --git a/src/server/ns_turn_ioalib.h b/src/server/ns_turn_ioalib.h index 5abc1d51..4e6cb518 100644 --- a/src/server/ns_turn_ioalib.h +++ b/src/server/ns_turn_ioalib.h @@ -243,7 +243,7 @@ void clear_ioa_socket_session_if(ioa_socket_handle s, void *ss); tcp_connection *get_ioa_socket_sub_session(ioa_socket_handle s); void set_ioa_socket_sub_session(ioa_socket_handle s, tcp_connection *tc); int register_callback_on_ioa_socket(ioa_engine_handle e, ioa_socket_handle s, int event_type, ioa_net_event_handler cb, void *ctx, int clean_preexisting); -int send_data_from_ioa_socket_nbh(ioa_socket_handle s, ioa_addr* dest_addr, ioa_network_buffer_handle nbh, int ttl, int tos); +int send_data_from_ioa_socket_nbh(ioa_socket_handle s, ioa_addr* dest_addr, ioa_network_buffer_handle nbh, int ttl, int tos, int *skip); void close_ioa_socket(ioa_socket_handle s); #define IOA_CLOSE_SOCKET(S) do { if(S) { close_ioa_socket(S); S = NULL; } } while(0) ioa_socket_handle detach_ioa_socket(ioa_socket_handle s); diff --git a/src/server/ns_turn_server.c b/src/server/ns_turn_server.c index 55bc3b85..cbf4fd93 100644 --- a/src/server/ns_turn_server.c +++ b/src/server/ns_turn_server.c @@ -1838,7 +1838,7 @@ static void tcp_deliver_delayed_buffer(unsent_buffer *ub, ioa_socket_handle s, t u32bits bytes = (u32bits)ioa_network_buffer_get_size(nbh); - int ret = send_data_from_ioa_socket_nbh(s, NULL, nbh, TTL_IGNORE, TOS_IGNORE); + int ret = send_data_from_ioa_socket_nbh(s, NULL, nbh, TTL_IGNORE, TOS_IGNORE, NULL); if (ret < 0) { set_ioa_socket_tobeclosed(s); } else { @@ -1877,7 +1877,7 @@ static void tcp_peer_input_handler(ioa_socket_handle s, int event_type, ioa_net_ u32bits bytes = (u32bits)ioa_network_buffer_get_size(nbh); - int ret = send_data_from_ioa_socket_nbh(tc->client_s, NULL, nbh, TTL_IGNORE, TOS_IGNORE); + int ret = send_data_from_ioa_socket_nbh(tc->client_s, NULL, nbh, TTL_IGNORE, TOS_IGNORE, NULL); if (ret < 0) { set_ioa_socket_tobeclosed(s); } else if(ss) { @@ -1917,7 +1917,7 @@ static void tcp_client_input_handler_rfc6062data(ioa_socket_handle s, int event_ ss->received_bytes += bytes; } - int ret = send_data_from_ioa_socket_nbh(tc->peer_s, NULL, nbh, TTL_IGNORE, TOS_IGNORE); + int ret = send_data_from_ioa_socket_nbh(tc->peer_s, NULL, nbh, TTL_IGNORE, TOS_IGNORE, NULL); if (ret < 0) { set_ioa_socket_tobeclosed(s); } @@ -2009,7 +2009,7 @@ static void tcp_peer_connection_completed_callback(int success, void *arg) len_test = strlen(data_test); ns_bcopy(data_test,data,len_test); ioa_network_buffer_set_size(nbh_test,len_test); - send_data_from_ioa_socket_nbh(tc->peer_s, NULL, nbh_test, TTL_IGNORE, TOS_IGNORE); + send_data_from_ioa_socket_nbh(tc->peer_s, NULL, nbh_test, TTL_IGNORE, TOS_IGNORE, NULL); } } } @@ -2490,7 +2490,7 @@ int turnserver_accept_tcp_client_data_connection(turn_turnserver *server, tcp_co } if(ss && !err_code) { - send_data_from_ioa_socket_nbh(s, NULL, nbh, TTL_IGNORE, TOS_IGNORE); + send_data_from_ioa_socket_nbh(s, NULL, nbh, TTL_IGNORE, TOS_IGNORE, NULL); tcp_deliver_delayed_buffer(&(tc->ub_to_client),s,ss); IOA_CLOSE_SOCKET(s_to_delete); FUNCEND; @@ -2501,7 +2501,7 @@ int turnserver_accept_tcp_client_data_connection(turn_turnserver *server, tcp_co TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR, "%s: cannot set TCP tmp client data input callback\n", __FUNCTION__); ioa_network_buffer_delete(server->e, nbh); } else { - send_data_from_ioa_socket_nbh(s, NULL, nbh, TTL_IGNORE, TOS_IGNORE); + send_data_from_ioa_socket_nbh(s, NULL, nbh, TTL_IGNORE, TOS_IGNORE, NULL); } } } @@ -2978,7 +2978,7 @@ static int handle_turn_send(turn_turnserver *server, ts_ur_super_session *ss, ioa_network_buffer_set_size(nbh,len); } ioa_network_buffer_header_init(nbh); - send_data_from_ioa_socket_nbh(get_relay_socket_ss(ss,peer_addr.ss.sa_family), &peer_addr, nbh, in_buffer->recv_ttl-1, in_buffer->recv_tos); + send_data_from_ioa_socket_nbh(get_relay_socket_ss(ss,peer_addr.ss.sa_family), &peer_addr, nbh, in_buffer->recv_ttl-1, in_buffer->recv_tos, NULL); in_buffer->nbh = NULL; } @@ -4103,7 +4103,7 @@ static int write_to_peerchannel(ts_ur_super_session* ss, u16bits chnum, ioa_net_ ioa_network_buffer_header_init(nbh); - rc = send_data_from_ioa_socket_nbh(get_relay_socket_ss(ss, chn->peer_addr.ss.sa_family), &(chn->peer_addr), nbh, in_buffer->recv_ttl-1, in_buffer->recv_tos); + rc = send_data_from_ioa_socket_nbh(get_relay_socket_ss(ss, chn->peer_addr.ss.sa_family), &(chn->peer_addr), nbh, in_buffer->recv_ttl-1, in_buffer->recv_tos, NULL); in_buffer->nbh = NULL; } } @@ -4248,17 +4248,20 @@ static int write_client_connection(turn_turnserver *server, ts_ur_super_session* return -1; } else { - ++(ss->sent_packets); - ss->sent_bytes += (u32bits)ioa_network_buffer_get_size(nbh); - turn_report_session_usage(ss); - if (eve(server->verbose)) { TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "%s: prepare to write to s 0x%lx\n", __FUNCTION__, (long) (ss->client_socket)); } - int ret = send_data_from_ioa_socket_nbh(ss->client_socket, NULL, nbh, ttl, tos); + int skip = 0; + int ret = send_data_from_ioa_socket_nbh(ss->client_socket, NULL, nbh, ttl, tos, &skip); + + if(!skip) { + ++(ss->sent_packets); + ss->sent_bytes += (u32bits)ioa_network_buffer_get_size(nbh); + turn_report_session_usage(ss); + } FUNCEND; return ret;