control traffic excluded from the bandwidth limitation

This commit is contained in:
mom040267 2015-03-01 01:37:44 +00:00
parent 3eacd81b40
commit 55ee70dea0
3 changed files with 26 additions and 14 deletions

View File

@ -367,7 +367,7 @@ static int handle_udp_packet(dtls_listener_relay_server_type *server,
}
}
if(ioa_socket_check_bandwidth(s,ioa_network_buffer_get_size(sm->m.sm.nd.nbh),1)) {
if(ioa_socket_check_bandwidth(s,sm->m.sm.nd.nbh,1)) {
s->e = ioa_eng;
if (s && s->read_cb && sm->m.sm.nd.nbh) {
s->read_cb(s, IOA_EV_READ, &(sm->m.sm.nd), s->read_ctx, 1);

View File

@ -637,12 +637,14 @@ void delete_ioa_timer(ioa_timer_handle th)
/************** SOCKETS HELPERS ***********************/
int ioa_socket_check_bandwidth(ioa_socket_handle s, size_t sz, int read)
int ioa_socket_check_bandwidth(ioa_socket_handle s, ioa_network_buffer_handle nbh, int read)
{
if(s && (s->e) && sz &&
if(s && (s->e) && nbh &&
((s->sat == CLIENT_SOCKET) || (s->sat == RELAY_SOCKET) || (s->sat == RELAY_RTCP_SOCKET)) &&
(s->session)) {
size_t sz = ioa_network_buffer_get_size(nbh);
band_limit_t max_bps = s->session->bps;
if(max_bps<1)
@ -657,9 +659,12 @@ int ioa_socket_check_bandwidth(ioa_socket_handle s, size_t sz, int read)
s->jiffie_bytes_write = 0;
if(bsz > max_bps) {
return 0;
u08bits *buf = ioa_network_buffer_data(nbh);
if((s->sat == CLIENT_SOCKET) && ((read && stun_is_request_str(buf,sz)) || (!read && stun_is_response_str(buf,sz)))) {
return 1;
} else {
return 0;
}
} else {
if(read)
s->jiffie_bytes_read = bsz;
@ -676,7 +681,12 @@ int ioa_socket_check_bandwidth(ioa_socket_handle s, size_t sz, int read)
else
nsz = s->jiffie_bytes_write + bsz;
if(nsz > max_bps) {
return 0;
u08bits *buf = ioa_network_buffer_data(nbh);
if((s->sat == CLIENT_SOCKET) && ((read && stun_is_request_str(buf,sz)) || (!read && stun_is_response_str(buf,sz)))) {
return 1;
} else {
return 0;
}
} else {
if(read)
s->jiffie_bytes_read = nsz;
@ -2382,11 +2392,13 @@ static int socket_input_worker(ioa_socket_handle s)
}
if ((ret!=-1) && (len >= 0)) {
if(ioa_socket_check_bandwidth(s,(size_t)len,1)) {
if(app_msg_len)
buf_elem->buf.len = app_msg_len;
else
buf_elem->buf.len = len;
if(app_msg_len)
buf_elem->buf.len = app_msg_len;
else
buf_elem->buf.len = len;
if(ioa_socket_check_bandwidth(s,buf_elem,1)) {
if(s->read_cb) {
ioa_net_data nd;
@ -2981,7 +2993,7 @@ int send_data_from_ioa_socket_nbh(ioa_socket_handle s, ioa_addr* dest_addr,
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "!!! %s socket: 0x%lx was closed\n", __FUNCTION__,(long)s);
} else if (nbh) {
if(!ioa_socket_check_bandwidth(s,ioa_network_buffer_get_size(nbh),0)) {
if(!ioa_socket_check_bandwidth(s,nbh,0)) {
/* Bandwidth exhausted, we pretend everything is fine: */
ret = (int)(ioa_network_buffer_get_size(nbh));
if(skip) *skip = 1;

View File

@ -303,7 +303,7 @@ int send_data_from_ioa_socket_tcp(ioa_socket_handle s, const void *data, size_t
int send_str_from_ioa_socket_tcp(ioa_socket_handle s, const void *data);
int send_ulong_from_ioa_socket_tcp(ioa_socket_handle s, size_t data);
int ioa_socket_check_bandwidth(ioa_socket_handle s, size_t sz, int read);
int ioa_socket_check_bandwidth(ioa_socket_handle s, ioa_network_buffer_handle nbh, int read);
///////////////////////// SUPER MEMORY ////////