|
|
ec8ce9 |
diff -up vsftpd-3.0.2/ftpdataio.c.mrate vsftpd-3.0.2/ftpdataio.c
|
|
|
ec8ce9 |
--- vsftpd-3.0.2/ftpdataio.c.mrate 2014-03-06 16:22:44.547366196 +0100
|
|
|
ec8ce9 |
+++ vsftpd-3.0.2/ftpdataio.c 2014-03-07 10:14:33.681097022 +0100
|
|
|
ec8ce9 |
@@ -251,7 +251,7 @@ handle_io(int retval, int fd, void* p_pr
|
|
|
ec8ce9 |
{
|
|
|
ec8ce9 |
long curr_sec;
|
|
|
ec8ce9 |
long curr_usec;
|
|
|
ec8ce9 |
- unsigned int bw_rate;
|
|
|
ec8ce9 |
+ unsigned long bw_rate;
|
|
|
ec8ce9 |
double elapsed;
|
|
|
ec8ce9 |
double pause_time;
|
|
|
ec8ce9 |
double rate_ratio;
|
|
|
ec8ce9 |
@@ -278,19 +278,16 @@ handle_io(int retval, int fd, void* p_pr
|
|
|
ec8ce9 |
{
|
|
|
ec8ce9 |
elapsed = (double) 0.01;
|
|
|
ec8ce9 |
}
|
|
|
ec8ce9 |
- bw_rate = (unsigned int) ((double) retval / elapsed);
|
|
|
ec8ce9 |
- if (bw_rate <= p_sess->bw_rate_max)
|
|
|
ec8ce9 |
+ p_sess->bw_retval += retval;
|
|
|
ec8ce9 |
+ bw_rate = (unsigned long) ((double) p_sess->bw_retval / elapsed);
|
|
|
ec8ce9 |
+ if (bw_rate <= p_sess->bw_rate_max || p_sess->bw_retval < (unsigned long)(10*retval))
|
|
|
ec8ce9 |
{
|
|
|
ec8ce9 |
- p_sess->bw_send_start_sec = curr_sec;
|
|
|
ec8ce9 |
- p_sess->bw_send_start_usec = curr_usec;
|
|
|
ec8ce9 |
return;
|
|
|
ec8ce9 |
}
|
|
|
ec8ce9 |
/* Tut! Rate exceeded, calculate a pause to bring things back into line */
|
|
|
ec8ce9 |
rate_ratio = (double) bw_rate / (double) p_sess->bw_rate_max;
|
|
|
ec8ce9 |
pause_time = (rate_ratio - (double) 1) * elapsed;
|
|
|
ec8ce9 |
vsf_sysutil_sleep(pause_time);
|
|
|
ec8ce9 |
- p_sess->bw_send_start_sec = vsf_sysutil_get_time_sec();
|
|
|
ec8ce9 |
- p_sess->bw_send_start_usec = vsf_sysutil_get_time_usec();
|
|
|
ec8ce9 |
}
|
|
|
ec8ce9 |
|
|
|
ec8ce9 |
int
|
|
|
ec8ce9 |
@@ -443,6 +440,9 @@ struct vsf_transfer_ret
|
|
|
ec8ce9 |
vsf_ftpdataio_transfer_file(struct vsf_session* p_sess, int remote_fd,
|
|
|
ec8ce9 |
int file_fd, int is_recv, int is_ascii)
|
|
|
ec8ce9 |
{
|
|
|
ec8ce9 |
+ p_sess->bw_send_start_sec = vsf_sysutil_get_time_sec();
|
|
|
ec8ce9 |
+ p_sess->bw_send_start_usec = vsf_sysutil_get_time_usec();
|
|
|
ec8ce9 |
+ p_sess->bw_retval = 0;
|
|
|
ec8ce9 |
if (!is_recv)
|
|
|
ec8ce9 |
{
|
|
|
ec8ce9 |
if (is_ascii || p_sess->data_use_ssl)
|
|
|
ec8ce9 |
diff -up vsftpd-3.0.2/main.c.mrate vsftpd-3.0.2/main.c
|
|
|
ec8ce9 |
--- vsftpd-3.0.2/main.c.mrate 2014-03-06 16:22:28.475362449 +0100
|
|
|
ec8ce9 |
+++ vsftpd-3.0.2/main.c 2014-03-06 16:24:27.056384556 +0100
|
|
|
ec8ce9 |
@@ -40,7 +40,7 @@ main(int argc, const char* argv[])
|
|
|
ec8ce9 |
/* Control connection */
|
|
|
ec8ce9 |
0, 0, 0, 0, 0,
|
|
|
ec8ce9 |
/* Data connection */
|
|
|
ec8ce9 |
- -1, 0, -1, 0, 0, 0, 0,
|
|
|
ec8ce9 |
+ -1, 0, -1, 0, 0, 0, 0, 0,
|
|
|
ec8ce9 |
/* Login */
|
|
|
ec8ce9 |
1, 0, INIT_MYSTR, INIT_MYSTR,
|
|
|
ec8ce9 |
/* Protocol state */
|
|
|
ec8ce9 |
diff -up vsftpd-3.0.2/session.h.mrate vsftpd-3.0.2/session.h
|
|
|
ec8ce9 |
--- vsftpd-3.0.2/session.h.mrate 2014-03-06 16:22:15.376359081 +0100
|
|
|
ec8ce9 |
+++ vsftpd-3.0.2/session.h 2014-03-06 16:23:58.860379868 +0100
|
|
|
ec8ce9 |
@@ -29,9 +29,10 @@ struct vsf_session
|
|
|
ec8ce9 |
struct vsf_sysutil_sockaddr* p_port_sockaddr;
|
|
|
ec8ce9 |
int data_fd;
|
|
|
ec8ce9 |
int data_progress;
|
|
|
ec8ce9 |
- unsigned int bw_rate_max;
|
|
|
ec8ce9 |
+ unsigned long bw_rate_max;
|
|
|
ec8ce9 |
long bw_send_start_sec;
|
|
|
ec8ce9 |
long bw_send_start_usec;
|
|
|
ec8ce9 |
+ unsigned long bw_retval;
|
|
|
ec8ce9 |
|
|
|
ec8ce9 |
/* Details of the login */
|
|
|
ec8ce9 |
int is_anonymous;
|