Skip to content

Commit

Permalink
Merge pull request #1 from rjruigrok/exitnode-switch
Browse files Browse the repository at this point in the history
TestExitnode switch
  • Loading branch information
rjruigrok committed Mar 26, 2015
2 parents 92282ba + 4c3478d commit 91c0bb1
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -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
6 changes: 1 addition & 5 deletions Tribler/Main/vwxGUI/MainFrame.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
14 changes: 2 additions & 12 deletions Tribler/Main/vwxGUI/settingsDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
36 changes: 11 additions & 25 deletions Tribler/community/tunnel/tunnel_community.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -314,24 +313,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),
Expand Down Expand Up @@ -821,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
Expand All @@ -833,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:
Expand Down Expand Up @@ -887,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
Expand Down

0 comments on commit 91c0bb1

Please sign in to comment.