From 942347f69b594d701316dafb5acd2559dc14245b Mon Sep 17 00:00:00 2001 From: Rob Ruigrok Date: Thu, 26 Mar 2015 13:40:56 +0100 Subject: [PATCH 1/2] small improvements in coding style --- Tribler/Main/vwxGUI/MainFrame.py | 6 +---- Tribler/Main/vwxGUI/settingsDialog.py | 14 ++---------- Tribler/community/tunnel/tunnel_community.py | 23 +++++--------------- 3 files changed, 9 insertions(+), 34 deletions(-) diff --git a/Tribler/Main/vwxGUI/MainFrame.py b/Tribler/Main/vwxGUI/MainFrame.py index 4798e948aab..4c777e110db 100644 --- a/Tribler/Main/vwxGUI/MainFrame.py +++ b/Tribler/Main/vwxGUI/MainFrame.py @@ -616,11 +616,7 @@ def monitorHiddenSerivcesProgress(self, ds, tdef, dscfg, selectedFiles): if ds.get_status() in [DLSTATUS_ALLOCATING_DISKSPACE, DLSTATUS_HASHCHECKING, DLSTATUS_WAITING4HASHCHECK]: return (5.0, True) - state_dir = self.utility.session.get_state_dir() - cfgfilename = self.utility.session.get_default_config_filename(state_dir) - scfg = SessionStartupConfig.load(cfgfilename) - - if ds.get_current_speed(DOWNLOAD) == 0 and scfg.get_tunnel_community_hs_timeout_switch(): + if ds.get_current_speed(DOWNLOAD) == 0 and self.utility.session.get_tunnel_community_hs_timeout_switch(): download = ds.get_download() self.utility.session.remove_download(download) diff --git a/Tribler/Main/vwxGUI/settingsDialog.py b/Tribler/Main/vwxGUI/settingsDialog.py index f684a2899cb..ef5898d9282 100644 --- a/Tribler/Main/vwxGUI/settingsDialog.py +++ b/Tribler/Main/vwxGUI/settingsDialog.py @@ -209,17 +209,14 @@ def saveAll(self, event): self.utility.write_config('use_webui', useWebUI) restart = True - becomeExitNode = self._become_exitnode.IsChecked() if becomeExitNode != scfg.get_tunnel_community_exitnode_enabled(): scfg.set_tunnel_community_exitnode_enabled(becomeExitNode) - self.saveDefaultSessionConfig(scfg) restart = True switchHsOnTimeout = self._switch_hs_timeout.IsChecked() if switchHsOnTimeout != scfg.get_tunnel_community_hs_timeout_switch(): scfg.set_tunnel_community_hs_timeout_switch(switchHsOnTimeout) - self.saveDefaultSessionConfig(scfg) restart = True valwebuiport = self._webui_port.GetValue() @@ -369,10 +366,6 @@ def saveDefaultDownloadConfig(self, scfg): scfg.save(cfgfilename) - def saveDefaultSessionConfig(self, scfg): - cfgfilename = Session.get_default_config_filename(scfg.get_state_dir()) - scfg.save(cfgfilename) - def moveCollectedTorrents(self, old_dir, new_dir): def rename_or_merge(old, new, ignore=True): if os.path.exists(old): @@ -767,11 +760,8 @@ def __create_s6(self, tree_root, sizer): exp_vsizer.Add(exp_s1_faq_text, 0, wx.EXPAND | wx.TOP, 10) # load values - state_dir = self.utility.session.get_state_dir() - cfgfilename = self.utility.session.get_default_config_filename(state_dir) - scfg = SessionStartupConfig.load(cfgfilename) - self._become_exitnode.SetValue(scfg.get_tunnel_community_exitnode_enabled()) - self._switch_hs_timeout.SetValue(scfg.get_tunnel_community_hs_timeout_switch()) + self._become_exitnode.SetValue(self.utility.session.get_tunnel_community_exitnode_enabled()) + self._switch_hs_timeout.SetValue(self.utility.session.get_tunnel_community_hs_timeout_switch()) return exp_panel, item_id diff --git a/Tribler/community/tunnel/tunnel_community.py b/Tribler/community/tunnel/tunnel_community.py index 576ea97ab1a..8588f4ffc6c 100644 --- a/Tribler/community/tunnel/tunnel_community.py +++ b/Tribler/community/tunnel/tunnel_community.py @@ -314,24 +314,13 @@ def initiate_meta_messages(self): meta_messages = super(TunnelCommunity, self).initiate_meta_messages() for i, mm in enumerate(meta_messages): if mm.name == "dispersy-introduction-request": - meta_messages[i] = Message(self, u"dispersy-introduction-request", - MemberAuthentication(), - PublicResolution(), - DirectDistribution(), - CandidateDestination(), - TunnelIntroductionRequestPayload(), - self.check_introduction_request, - self.on_introduction_request) + meta_messages[i] = Message(self, mm.name, mm.authentication, mm.resolution, mm.distribution, + mm.destination, TunnelIntroductionRequestPayload(), + mm.check_callback, mm.handle_callback) elif mm.name == "dispersy-introduction-response": - meta_messages[i] = Message(self, u"dispersy-introduction-response", - MemberAuthentication(), - PublicResolution(), - DirectDistribution(), - CandidateDestination(), - TunnelIntroductionResponsePayload(), - self.check_introduction_response, - self.on_introduction_response) - + meta_messages[i] = Message(self, mm.name, mm.authentication, mm.resolution, mm.distribution, + mm.destination, TunnelIntroductionResponsePayload(), + mm.check_callback, mm.handle_callback) return meta_messages + [Message(self, u"cell", NoAuthentication(), PublicResolution(), DirectDistribution(), CandidateDestination(), CellPayload(), self._generic_timeline_check, self.on_cell), From 4c3478dae4d7af0ff6239e61dba828e96e51cee3 Mon Sep 17 00:00:00 2001 From: Rob Ruigrok Date: Thu, 26 Mar 2015 14:35:34 +0100 Subject: [PATCH 2/2] Fix check on return list of exitnodes --- .gitmodules | 2 +- Tribler/community/tunnel/tunnel_community.py | 13 +++++-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/.gitmodules b/.gitmodules index 308e73dcf8c..e647739f4fa 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,6 @@ [submodule "Tribler/dispersy"] path = Tribler/dispersy - url = https://github.com/tribler/dispersy.git + url = https://github.com/Tribler/dispersy.git [submodule "Tribler/Core/DecentralizedTracking/pymdht"] path = Tribler/Core/DecentralizedTracking/pymdht url = https://github.com/LipuFei/pymdht.git diff --git a/Tribler/community/tunnel/tunnel_community.py b/Tribler/community/tunnel/tunnel_community.py index 8588f4ffc6c..ec208027dd5 100644 --- a/Tribler/community/tunnel/tunnel_community.py +++ b/Tribler/community/tunnel/tunnel_community.py @@ -195,8 +195,7 @@ def __init__(self, install_dir=None, tribler_session=None): class ExitCandidate(object): - def __init__(self, connectable, become_exit): - self.connectable = connectable + def __init__(self, become_exit): self.become_exit = become_exit self.creation_time = time.time() @@ -810,8 +809,7 @@ def on_introduction_request(self, messages): super(TunnelCommunity, self).on_introduction_request(messages, extra_payload) for message in messages: pubkey = message.candidate.get_member().public_key - connectable = message.candidate.connection_type == u"public" - self.exit_candidates[pubkey] = ExitCandidate(message.payload.exitnode, connectable) + self.exit_candidates[pubkey] = ExitCandidate(message.payload.exitnode) def create_introduction_request(self, destination, allow_sync, forward=True, is_fast_walker=False): exitnode = self.settings.become_exitnode @@ -822,8 +820,7 @@ def on_introduction_response(self, messages): super(TunnelCommunity, self).on_introduction_response(messages) for message in messages: pubkey = message.candidate.get_member().public_key - connectable = message.candidate.connection_type == u"public" - self.exit_candidates[pubkey] = ExitCandidate(message.payload.exitnode, connectable) + self.exit_candidates[pubkey] = ExitCandidate(message.payload.exitnode) def on_cell(self, messages): for message in messages: @@ -876,8 +873,8 @@ def on_create(self, messages): for c in self.dispersy_yield_verified_candidates(): pubkey = c.get_member().public_key exit_candidate = self.exit_candidates[pubkey] - if message.payload.exit_candidates and not exit_candidate.connectable: - # Next candidates need to be exit nodes, and this candidate isn't + if message.payload.exit_candidates and not (exit_candidate.become_exit and message.candidate.connection_type == u"public"): + # Next candidates need to be connectable exit nodes, and this candidate isn't continue candidates[pubkey] = c