From 7daae1d0c71127c189c79b4b10053a54f870df63 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 7 May 2010 20:08:59 +0000 Subject: [PATCH] - client: when emerge from bandwidth quota network suspension, add 0..1hr random delay to existing transfers, to avoid DDOS effect svn path=/trunk/boinc/; revision=21415 --- checkin_notes | 11 +++++++++++ client/client_state.cpp | 7 +++++++ client/pers_file_xfer.cpp | 14 +++++++++++++- client/pers_file_xfer.h | 1 + db/boinc_db.cpp | 2 +- 5 files changed, 33 insertions(+), 2 deletions(-) diff --git a/checkin_notes b/checkin_notes index 2e708afe84..010fe53bd9 100644 --- a/checkin_notes +++ b/checkin_notes @@ -3379,3 +3379,14 @@ David 7 May 2010 WelcomePage.cpp lib/ str_util.cpp,h + +David 7 May 2010 + - client: when emerge from bandwidth quota network suspension, + add 0..1hr random delay to existing transfers, + to avoid DDOS effect + + db/ + boinc_db.cpp + client/ + client_state.cpp + pers_file_xfer.cpp,h diff --git a/client/client_state.cpp b/client/client_state.cpp index 258311d26d..654c7399c4 100644 --- a/client/client_state.cpp +++ b/client/client_state.cpp @@ -679,6 +679,13 @@ bool CLIENT_STATE::poll_slow_events() { msg_printf(NULL, MSG_INFO, "Resuming file transfers"); } } + + // if we're emerging from a bandwidth quota suspension, + // add a random delay to avoid DDOS effect + // + if (old_network_suspend_reason == SUSPEND_REASON_NETWORK_QUOTA_EXCEEDED) { + pers_file_xfers->add_random_delay(3600); + } } // NOTE: diff --git a/client/pers_file_xfer.cpp b/client/pers_file_xfer.cpp index 6b9a55b009..5461f7a57c 100644 --- a/client/pers_file_xfer.cpp +++ b/client/pers_file_xfer.cpp @@ -30,6 +30,7 @@ #include "error_numbers.h" #include "md5_file.h" #include "parse.h" +#include "util.h" #include "str_util.h" #include "filesys.h" @@ -513,9 +514,20 @@ int PERS_FILE_XFER_SET::remove(PERS_FILE_XFER* pfx) { // void PERS_FILE_XFER_SET::suspend() { unsigned int i; - for (i=0; isuspend(); } } +// add a random delay 0..x to all transfers +// (used when emerging from bandwidth quota suspension) +// +void PERS_FILE_XFER_SET::add_random_delay(double x) { + unsigned int i; + for (i=0; i pers_file_xfers[i]->next_request_time) { + pers_file_xfers[i]->next_request_time = y; + } + } +} diff --git a/client/pers_file_xfer.h b/client/pers_file_xfer.h index 97d7e012f3..b0714ec4c3 100644 --- a/client/pers_file_xfer.h +++ b/client/pers_file_xfer.h @@ -125,6 +125,7 @@ public: int remove(PERS_FILE_XFER*); bool poll(); void suspend(); + void add_random_delay(double); }; #endif diff --git a/db/boinc_db.cpp b/db/boinc_db.cpp index 0bdda84c7f..3c8619178f 100644 --- a/db/boinc_db.cpp +++ b/db/boinc_db.cpp @@ -2042,7 +2042,7 @@ int DB_SCHED_RESULT_ITEM_SET::update_workunits() { void DB_FILE::db_print(char* buf){ snprintf(buf, MAX_QUERY_LEN, - "name='%s', md5sum=%s, size=%.15e", + "name='%s', md5sum='%s', size=%.15e", name, md5sum, size ); }