'Load the tunnel community in a given session. We are using our own tunnel community here instead of the one
used in Tribler.'

@blocking_call_on_reactor_thread
def load_tunnel_community_in_session(self, session, exitnode=False):

    dispersy = session.get_dispersy_instance()
    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 self.crypto_enabled):
        settings.crypto = NoCrypto()
    settings.become_exitnode = exitnode
    return dispersy.define_auto_load(HiddenTunnelCommunityTests, dispersy_member, (session, settings), load=True)[0]
