From 38ba6e1ecffd80fc8e702f567bdf9279f7989c02 Mon Sep 17 00:00:00 2001 From: Marcos Pinto Date: Sun, 5 Aug 2007 05:09:03 +0000 Subject: [PATCH] add peer blocked alert - micah --- plugins/EventLogging/__init__.py | 78 +++++++++++++++---- .../event_logging_preferences.glade | 29 +++++-- plugins/EventLogging/tab_log.py | 8 ++ src/deluge_core.cpp | 12 ++- 4 files changed, 103 insertions(+), 24 deletions(-) diff --git a/plugins/EventLogging/__init__.py b/plugins/EventLogging/__init__.py index 29f4cc9ed..b9b09f91f 100644 --- a/plugins/EventLogging/__init__.py +++ b/plugins/EventLogging/__init__.py @@ -118,6 +118,8 @@ class EventLogging: self.manager.connect_event(self.manager.constants['EVENT_BLOCK_DOWNLOADING'], self.tab_log.handle_event) if self.config.get("enable_block_finished"): self.manager.connect_event(self.manager.constants['EVENT_BLOCK_FINISHED'], self.tab_log.handle_event) + if self.config.get("enable_peer_blocked"): + self.manager.connect_event(self.manager.constants['EVENT_PEER_BLOCKED'], self.tab_log.handle_event) if self.config.get("enable_other"): self.manager.connect_event(self.manager.constants['EVENT_OTHER'], self.tab_log.handle_event) if self.config.get("enable_log_files"): @@ -154,6 +156,8 @@ class EventLogging: self.manager.disconnect_event(self.manager.constants['EVENT_BLOCK_DOWNLOADING'], self.tab_log.handle_event) if self.config.get("enable_block_finished"): self.manager.disconnect_event(self.manager.constants['EVENT_BLOCK_FINISHED'], self.tab_log.handle_event) + if self.config.get("enable_peer_blocked"): + self.manager.disconnect_event(self.manager.constants['EVENT_PEER_BLOCKED'], self.tab_log.handle_event) if self.config.get("enable_other"): self.manager.disconnect_event(self.manager.constants['EVENT_OTHER'], self.tab_log.handle_event) self.tab_log.clear_log_store() @@ -245,6 +249,11 @@ class EventLogging: self.manager.connect_event(self.manager.constants['EVENT_BLOCK_FINISHED'], self.tab_log.handle_event) else: self.manager.disconnect_event(self.manager.constants['EVENT_BLOCK_FINISHED'], self.tab_log.handle_event) + if widget == self.glade.get_widget("chk_peer_blocked"): + if value: + self.manager.connect_event(self.manager.constants['EVENT_PEER_BLOCKED'], self.tab_log.handle_event) + else: + self.manager.disconnect_event(self.manager.constants['EVENT_PEER_BLOCKED'], self.tab_log.handle_event) if widget == self.glade.get_widget("chk_other"): if value: self.manager.connect_event(self.manager.constants['EVENT_OTHER'], self.tab_log.handle_event) @@ -260,39 +269,75 @@ class EventLogging: self.dialog_initialize = True try: self.glade.get_widget("chk_finished").set_active(self.config.get("enable_finished")) - self.glade.get_widget("chk_peer_error").set_active(self.config.get("enable_peer_error")) - self.glade.get_widget("chk_invalid_request").set_active(self.config.get("enable_invalid_request")) - self.glade.get_widget("chk_file_error").set_active(self.config.get("enable_file_error")) - self.glade.get_widget("chk_hash_failed_error").set_active(self.config.get("enable_hash_failed_error")) - self.glade.get_widget("chk_peer_ban_error").set_active(self.config.get("enable_peer_ban_error")) - self.glade.get_widget("chk_fastresume_rejected_error").set_active(self.config.get("enable_fastresume_rejected_error")) - self.glade.get_widget("chk_tracker_announce").set_active(self.config.get("enable_tracker_announce")) - self.glade.get_widget("chk_tracker_reply").set_active(self.config.get("enable_tracker_reply")) - self.glade.get_widget("chk_tracker_alert").set_active(self.config.get("enable_tracker_alert")) - self.glade.get_widget("chk_tracker_warning").set_active(self.config.get("enable_tracker_warning")) - self.glade.get_widget("chk_storage_moved").set_active(self.config.get("enable_storage_moved")) - self.glade.get_widget("chk_piece_finished").set_active(self.config.get("enable_piece_finished")) - self.glade.get_widget("chk_block_downloading").set_active(self.config.get("enable_block_downloading")) - self.glade.get_widget("chk_block_finished").set_active(self.config.get("enable_block_finished")) - self.glade.get_widget("chk_other").set_active(self.config.get("enable_other")) - self.glade.get_widget("chk_log_files").set_active(self.config.get("enable_log_files")) except: self.glade.get_widget("chk_finished").set_active(False) + try: + self.glade.get_widget("chk_peer_error").set_active(self.config.get("enable_peer_error")) + except: self.glade.get_widget("chk_peer_error").set_active(False) + try: + self.glade.get_widget("chk_invalid_request").set_active(self.config.get("enable_invalid_request")) + except: self.glade.get_widget("chk_invalid_request").set_active(False) + try: + self.glade.get_widget("chk_file_error").set_active(self.config.get("enable_file_error")) + except: self.glade.get_widget("chk_file_error").set_active(False) + try: + self.glade.get_widget("chk_hash_failed_error").set_active(self.config.get("enable_hash_failed_error")) + except: self.glade.get_widget("chk_hash_failed_error").set_active(False) + try: + self.glade.get_widget("chk_peer_ban_error").set_active(self.config.get("enable_peer_ban_error")) + except: self.glade.get_widget("chk_peer_ban_error").set_active(False) + try: + self.glade.get_widget("chk_fastresume_rejected_error").set_active(self.config.get("enable_fastresume_rejected_error")) + except: self.glade.get_widget("chk_fastresume_rejected_error").set_active(False) + try: + self.glade.get_widget("chk_tracker_announce").set_active(self.config.get("enable_tracker_announce")) + except: self.glade.get_widget("chk_tracker_announce").set_active(False) + try: + self.glade.get_widget("chk_tracker_reply").set_active(self.config.get("enable_tracker_reply")) + except: self.glade.get_widget("chk_tracker_reply").set_active(False) + try: + self.glade.get_widget("chk_tracker_alert").set_active(self.config.get("enable_tracker_alert")) + except: self.glade.get_widget("chk_tracker_alert").set_active(False) + try: + self.glade.get_widget("chk_tracker_warning").set_active(self.config.get("enable_tracker_warning")) + except: self.glade.get_widget("chk_tracker_warning").set_active(False) + try: + self.glade.get_widget("chk_storage_moved").set_active(self.config.get("enable_storage_moved")) + except: self.glade.get_widget("chk_storage_moved").set_active(False) + try: + self.glade.get_widget("chk_piece_finished").set_active(self.config.get("enable_piece_finished")) + except: self.glade.get_widget("chk_piece_finished").set_active(False) + try: + self.glade.get_widget("chk_block_downloading").set_active(self.config.get("enable_block_downloading")) + except: self.glade.get_widget("chk_block_downloading").set_active(False) + try: + self.glade.get_widget("chk_block_finished").set_active(self.config.get("enable_block_finished")) + except: self.glade.get_widget("chk_block_finished").set_active(False) + try: + self.glade.get_widget("chk_peer_blocked").set_active(self.config.get("enable_peer_blocked")) + except: + self.glade.get_widget("chk_peer_blocked").set_active(False) + try: + self.glade.get_widget("chk_other").set_active(self.config.get("enable_other")) + except: self.glade.get_widget("chk_other").set_active(False) + try: + self.glade.get_widget("chk_log_files").set_active(self.config.get("enable_log_files")) + except: self.glade.get_widget("chk_log_files").set_active(False) self.dialog_initialize = False self.dialog.show() @@ -314,5 +359,6 @@ class EventLogging: self.config.set("enable_piece_finished", self.glade.get_widget("chk_piece_finished").get_active()) self.config.set("enable_block_downloading", self.glade.get_widget("chk_block_downloading").get_active()) self.config.set("enable_block_finished", self.glade.get_widget("chk_block_finished").get_active()) + self.config.set("enable_peer_blocked", self.glade.get_widget("chk_peer_blocked").get_active()) self.config.set("enable_other", self.glade.get_widget("chk_other").get_active()) self.config.set("enable_log_files", self.glade.get_widget("chk_log_files").get_active()) diff --git a/plugins/EventLogging/event_logging_preferences.glade b/plugins/EventLogging/event_logging_preferences.glade index 1ed9dc2a0..b7977fe4a 100644 --- a/plugins/EventLogging/event_logging_preferences.glade +++ b/plugins/EventLogging/event_logging_preferences.glade @@ -16,7 +16,7 @@ True - 19 + 20 True @@ -249,10 +249,10 @@ - + True True - Other + Peer blocked True 0 True @@ -263,14 +263,29 @@ 17 + + + True + True + Other + True + 0 + True + + + + 17 + 18 + + True Log files - 17 - 18 + 18 + 19 @@ -284,8 +299,8 @@ - 18 - 19 + 19 + 20 diff --git a/plugins/EventLogging/tab_log.py b/plugins/EventLogging/tab_log.py index 1e30a161d..3970133bd 100644 --- a/plugins/EventLogging/tab_log.py +++ b/plugins/EventLogging/tab_log.py @@ -175,6 +175,14 @@ class LogTabManager(object): logfile = open(log, "a") logfile.write(time.asctime(time.localtime()) + ", " +event_message + '\n') logfile.close() + if event['event_type'] is self.manager.constants['EVENT_PEER_BLOCKED']: + event_message = _("Peer blocked") + " {" + _("event message: ") + event['message'] + ", "\ + + _("ip address: ") + event['ip'] + "}" + if self.log_files: + log = os.path.join(self.logdir, 'peer_blocked.log') + logfile = open(log, "a") + logfile.write(time.asctime(time.localtime()) + ", " +event_message + '\n') + logfile.close() if event['event_type'] is self.manager.constants['EVENT_OTHER']: event_message = _("Other") + " {" + _("event message: ") + event['message'] + "}" if self.log_files: diff --git a/src/deluge_core.cpp b/src/deluge_core.cpp index 76393b021..994b7898d 100644 --- a/src/deluge_core.cpp +++ b/src/deluge_core.cpp @@ -86,6 +86,7 @@ using namespace libtorrent; #define EVENT_PIECE_FINISHED 15 #define EVENT_BLOCK_DOWNLOADING 16 #define EVENT_BLOCK_FINISHED 17 +#define EVENT_PEER_BLOCKED 18 #define STATE_QUEUED 0 #define STATE_CHECKING 1 @@ -371,7 +372,7 @@ static PyObject *torrent_init(PyObject *self, PyObject *args) M_ses->add_extension(&libtorrent::create_metadata_plugin); - M_constants = Py_BuildValue("{s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i}", + M_constants = Py_BuildValue("{s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i}", "EVENT_NULL", EVENT_NULL, "EVENT_FINISHED", EVENT_FINISHED, "EVENT_PEER_ERROR", EVENT_PEER_ERROR, @@ -389,6 +390,7 @@ static PyObject *torrent_init(PyObject *self, PyObject *args) "EVENT_PIECE_FINISHED", EVENT_PIECE_FINISHED, "EVENT_BLOCK_DOWNLOADING", EVENT_BLOCK_DOWNLOADING, "EVENT_BLOCK_FINISHED", EVENT_BLOCK_FINISHED, + "EVENT_PEER_BLOCKED", EVENT_PEER_BLOCKED, "STATE_QUEUED", STATE_QUEUED, "STATE_CHECKING", STATE_CHECKING, "STATE_CONNECTING", STATE_CONNECTING, @@ -896,6 +898,14 @@ static PyObject *torrent_pop_event(PyObject *self, PyObject *args) if (!popped_alert) { Py_INCREF(Py_None); return Py_None; + } else if (dynamic_cast(popped_alert)) + { + std::string peer_IP = + (dynamic_cast(popped_alert))->ip.to_string(); + return Py_BuildValue("{s:i,s:s,s:s}", + "event_type", EVENT_PEER_BLOCKED, + "ip", peer_IP.c_str(), + "message", a->msg().c_str()); } else if (dynamic_cast(popped_alert)) { torrent_handle handle = (dynamic_cast(popped_alert))->handle;