def tearDown(self): if self.session2: self._shutdown_session(self.session2) for session in self.sessions: self._shutdown_session(session) TestGuiAsServer.tearDown(self)
def quit(self): if self.session2: self._shutdown_session(self.session2) for session in self.sessions: self._shutdown_session(session) self.session2 = None self.sessions = [] TestGuiAsServer.quit(self)
def startTest(self, callback): def get_and_modify_dispersy(): from Tribler.dispersy.endpoint import NullEndpoint self._logger.debug("Frame ready, replacing dispersy endpoint") dispersy = self.session.get_dispersy_instance() dispersy._endpoint = NullEndpoint() dispersy._endpoint.open(dispersy) callback() TestGuiAsServer.startTest(self, get_and_modify_dispersy)
def startTest(self, callback): def get_and_modify_dispersy(): from Tribler.dispersy.endpoint import NullEndpoint print >> sys.stderr, "tgs: frame ready, replacing dispersy endpoint" dispersy = self.session.get_dispersy_instance() dispersy._endpoint = NullEndpoint() dispersy._endpoint.open(dispersy) callback() TestGuiAsServer.startTest(self, get_and_modify_dispersy)
def startTest(self, callback, searchComm=True): if searchComm: def wait_for_search(): print >> sys.stderr, "tgs: frame ready, staring to wait for search to be ready" self.CallConditional(300, lambda: self.frame.SRstatusbar.GetConnections() > 0.5, callback, 'did not connect to 50% of expected peers within 300s') TestGuiAsServer.startTest(self, wait_for_search) else: def wait_for_chansearch(): print >> sys.stderr, "tgs: frame ready, staring to wait for channelsearch to be ready" self.CallConditional(300, lambda: self.frame.SRstatusbar.GetChannelConnections() > 5, callback, 'did not connect to more than 5 peers within 300s') TestGuiAsServer.startTest(self, wait_for_chansearch)
def startTest(self, callback, searchComm=True): if searchComm: def wait_for_search(): print >> sys.stderr, "tgs: frame ready, staring to wait for search to be ready" self.CallConditional( 300, lambda: self.frame.SRstatusbar.GetConnections() > 0.5, callback, 'did not connect to 50% of expected peers within 300s') TestGuiAsServer.startTest(self, wait_for_search) else: def wait_for_chansearch(): print >> sys.stderr, "tgs: frame ready, staring to wait for channelsearch to be ready" self.CallConditional( 300, lambda: self.frame.SRstatusbar.GetChannelConnections() > 5, callback, 'did not connect to more than 5 peers within 300s') TestGuiAsServer.startTest(self, wait_for_chansearch)
def startTest(self, callback, min_timeout=5, nr_relays=12, nr_exitnodes=4, crypto_enabled=True, bypass_dht=False): self.getStateDir( ) # getStateDir copies the bootstrap file into the statedir def setup_proxies(): tunnel_communities = [] baseindex = 3 for i in range(baseindex, baseindex + nr_relays): # Normal relays tunnel_communities.append( create_proxy(i, False, crypto_enabled)) baseindex += nr_relays + 1 for i in range(baseindex, baseindex + nr_exitnodes): # Exit nodes tunnel_communities.append(create_proxy(i, True, crypto_enabled)) if bypass_dht: # Replace pymdht with a fake one class FakeDHT(object): def __init__(self, dht_dict, mainline_dht): self.dht_dict = dht_dict self.mainline_dht = mainline_dht def get_peers(self, lookup_id, _, callback_f, bt_port=0): if bt_port != 0: self.dht_dict[lookup_id] = self.dht_dict.get( lookup_id, []) + [('127.0.0.1', bt_port)] callback_f(lookup_id, self.dht_dict.get(lookup_id, None), None) def stop(self): self.mainline_dht.stop() dht_dict = {} for session in self.sessions + [self.session]: session.lm.mainline_dht = FakeDHT(dht_dict, session.lm.mainline_dht) # Connect the proxies to the Tribler instance for community in self.lm.dispersy.get_communities(): if isinstance(community, HiddenTunnelCommunity): self._logger.debug( "Hidden tunnel community appended to the list") tunnel_communities.append(community) candidates = [] for session in self.sessions: self._logger.debug( "Appending candidate from this session to the list") dispersy = session.get_dispersy_instance() candidates.append(Candidate(dispersy.lan_address, tunnel=False)) for community in tunnel_communities: for candidate in candidates: self._logger.debug( "Add appended candidate as discovered candidate to this community" ) # We are letting dispersy deal with addins the community's candidate to itself. community.add_discovered_candidate(candidate) callback(tunnel_communities) def create_proxy(index, become_exit_node, crypto_enabled): from Tribler.Core.Session import Session self.setUpPreSession() config = self.config.copy() config.set_libtorrent(True) config.set_dispersy(True) config.set_state_dir(self.getStateDir(index)) session = Session(config, ignore_singleton=True, autoload_discovery=False) upgrader = session.prestart() session.start() self.sessions.append(session) while not session.lm.initComplete: time.sleep(1) dispersy = session.get_dispersy_instance() def load_community(session): keypair = dispersy.crypto.generate_key(u"curve25519") dispersy_member = dispersy.get_member( private_key=dispersy.crypto.key_to_bin(keypair)) settings = TunnelSettings(tribler_session=session) if not crypto_enabled: settings.crypto = NoCrypto() settings.become_exitnode = become_exit_node return dispersy.define_auto_load(HiddenTunnelCommunity, dispersy_member, (session, settings), load=True)[0] return blockingCallFromThread(reactor, load_community, session) TestGuiAsServer.startTest(self, setup_proxies, autoload_discovery=False)
def setUp(self): TestGuiAsServer.setUp(self) self.sessions = [] self.session2 = None
def tearDown(self): if self.session2: self._shutdown_session(self.session2) time.sleep(10) TestGuiAsServer.tearDown(self)
def setUp(self): TestGuiAsServer.setUp(self) self.session2 = None
def startTest(self, callback, min_timeout=5, nr_relays=12, nr_exitnodes=4, crypto_enabled=True, bypass_dht=False): self.getStateDir() # getStateDir copies the bootstrap file into the statedir def setup_proxies(): tunnel_communities = [] baseindex = 3 for i in range(baseindex, baseindex + nr_relays): # Normal relays tunnel_communities.append(create_proxy(i, False, crypto_enabled)) baseindex += nr_relays + 1 for i in range(baseindex, baseindex + nr_exitnodes): # Exit nodes tunnel_communities.append(create_proxy(i, True, crypto_enabled)) if bypass_dht: # Replace pymdht with a fake one class FakeDHT(object): def __init__(self, dht_dict, mainline_dht): self.dht_dict = dht_dict self.mainline_dht = mainline_dht def get_peers(self, lookup_id, _, callback_f, bt_port=0): if bt_port != 0: self.dht_dict[lookup_id] = self.dht_dict.get(lookup_id, []) + [('127.0.0.1', bt_port)] callback_f(lookup_id, self.dht_dict.get(lookup_id, None), None) def stop(self): self.mainline_dht.stop() dht_dict = {} for session in self.sessions + [self.session]: session.lm.mainline_dht = FakeDHT(dht_dict, session.lm.mainline_dht) # Connect the proxies to the Tribler instance for community in self.lm.dispersy.get_communities(): if isinstance(community, HiddenTunnelCommunity): self._logger.debug("Hidden tunnel community appended to the list") tunnel_communities.append(community) candidates = [] for session in self.sessions: self._logger.debug("Appending candidate from this session to the list") dispersy = session.get_dispersy_instance() candidates.append(Candidate(dispersy.lan_address, tunnel=False)) for community in tunnel_communities: for candidate in candidates: self._logger.debug("Add appended candidate as discovered candidate to this community") # We are letting dispersy deal with addins the community's candidate to itself. community.add_discovered_candidate(candidate) callback(tunnel_communities) def create_proxy(index, become_exit_node, crypto_enabled): from Tribler.Core.Session import Session self.setUpPreSession() config = self.config.copy() config.set_libtorrent(True) config.set_dispersy(True) config.set_state_dir(self.getStateDir(index)) session = Session(config, ignore_singleton=True, autoload_discovery=False) upgrader = session.prestart() session.start() self.sessions.append(session) while not session.lm.initComplete: time.sleep(1) dispersy = session.get_dispersy_instance() def load_community(session): keypair = dispersy.crypto.generate_key(u"curve25519") dispersy_member = dispersy.get_member(private_key=dispersy.crypto.key_to_bin(keypair)) settings = TunnelSettings(tribler_session=session) if not crypto_enabled: settings.crypto = NoCrypto() settings.become_exitnode = become_exit_node return dispersy.define_auto_load(HiddenTunnelCommunity, dispersy_member, (session, settings), load=True)[0] return blockingCallFromThread(reactor, load_community, session) TestGuiAsServer.startTest(self, setup_proxies, autoload_discovery=False)