Skip to content

Commit

Permalink
refactored the hidden community to handle deferreds
Browse files Browse the repository at this point in the history
  • Loading branch information
lfdversluis committed Jul 22, 2016
1 parent 963730a commit a85117f
Show file tree
Hide file tree
Showing 6 changed files with 193 additions and 58 deletions.
10 changes: 6 additions & 4 deletions Tribler/Main/tribler_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#
# see LICENSE.txt for license information
#
from twisted.internet.defer import inlineCallbacks
from twisted.internet.defer import inlineCallbacks, returnValue

from Tribler.Core.Modules.process_checker import ProcessChecker
from Tribler.Main.Dialogs.NewVersionDialog import NewVersionDialog
Expand Down Expand Up @@ -466,9 +466,11 @@ def do_wx(delayedResult):
startWorker(do_wx, do_db, uId=u"tribler.set_reputation")
startWorker(None, self.set_reputation, delay=5.0, workerType="ThreadPool")

@inlineCallbacks
# TODO(Laurens): check callers
def sesscb_states_callback(self, dslist):
if not self.ready:
return 5.0, []
returnValue((5.0, []))

# update tray icon
total_download, total_upload = get_download_upload_speed(dslist)
Expand Down Expand Up @@ -570,12 +572,12 @@ def sesscb_states_callback(self, dslist):
adjustspeeds = True

if adjustspeeds and self.tunnel_community:
self.tunnel_community.monitor_downloads(dslist)
yield self.tunnel_community.monitor_downloads(dslist)

except:
print_exc()

return 1.0, wantpeers
returnValue((1.0, wantpeers))

def guiservthread_free_space_check(self):
if not (self and self.frame and self.frame.SRstatusbar):
Expand Down
16 changes: 10 additions & 6 deletions Tribler/Test/Community/Tunnel/FullSession/test_hidden_community.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from unittest.case import skip

from twisted.internet.defer import Deferred, inlineCallbacks
from twisted.internet.defer import Deferred, inlineCallbacks, returnValue

from Tribler.Core.DecentralizedTracking.pymdht.core.identifier import Id
from Tribler.Core.Utilities.twisted_thread import deferred
Expand Down Expand Up @@ -40,14 +40,16 @@ def setUp(self, autoload_discovery=True):
self.dht_deferred = Deferred()
self.dht_dict = {}

@inlineCallbacks
# TODO(Laurens): check callers
def configure_hidden_seeder(self):
"""
Setup the hidden seeder. This includes setting the right circuit parameters, creating the download callback and
waiting for the creation of an introduction point for the download.
"""
def download_states_callback(dslist):
self.tunnel_community_seeder.monitor_downloads(dslist)
return 1.0, []
yield self.tunnel_community_seeder.monitor_downloads(dslist)
returnValue((1.0, []))

self.tunnel_community_seeder.settings.min_circuits = 0
self.tunnel_community_seeder.settings.max_circuits = 0
Expand Down Expand Up @@ -83,13 +85,15 @@ def test_hidden_services(self):
self.setup_dht_bypass()
yield self.configure_hidden_seeder()

@inlineCallbacks
# TODO(Laurens): check callers
def download_state_callback(ds):
self.tunnel_community.monitor_downloads([ds])
yield self.tunnel_community.monitor_downloads([ds])
download = ds.get_download()
if download.get_progress() == 1.0 and ds.get_status() == DLSTATUS_SEEDING:
self.test_deferred.callback(None)
return 0.0, False
return 2.0, False
returnValue((0.0, False))
returnValue((2.0, False))

download = self.start_anon_download(hops=1)
download.set_state_callback(download_state_callback)
Expand Down
Loading

0 comments on commit a85117f

Please sign in to comment.