示例#1
0
def _hgx_server(host, port, cache_dir, debug, traceur, aengel=None):
    ''' Simple remote persistence server over websockets.
    Explicitly pass None to cache_dir to use in-memory only.
    '''
    if not aengel:
        aengel = Aengel()

    remote = RemotePersistenceServer(cache_dir)
    server = Autocomms(
        autoresponder_name='reremser',
        autoresponder_class=PersisterBridgeServer,
        connector_name='wsremser',
        connector_class=WSBasicServer,
        connector_kwargs={
            'host': host,
            'port': port,
            'tls': False,
            # 48 bits = 1% collisions at 2.4 e 10^6 connections
            'birthday_bits': 48,
        },
        debug=debug,
        aengel=aengel,
    )
    remote.assemble(server)

    return remote, server
 def setUpClass(cls):
     cls.aengel = Aengel()
     cls.embed = MockEmbed(
         threaded=True,
         thread_name='mockembed',
         aengel=cls.aengel,
     )
示例#3
0
 def setUpClass(cls):
     cls.aengel = Aengel()
     cls.remote_server = RemotePersistenceServer()
     cls.vault = cls.remote_server.librarian
     cls.debound_by_ghid = cls.remote_server.bookie._debound_by_ghid
     
     cls.server = Autocomms(
         autoresponder_class = PersisterBridgeServer,
         # autoresponder_kwargs = { 'persister': cls.backend, },
         connector_class = WSBasicServer,
         connector_kwargs = {
             'host': 'localhost',
             'port': 5358,
             # 48 bits = 1% collisions at 2.4 e 10^6 connections
             'birthday_bits': 48,
             'tls': False
         },
         debug = True,
         aengel = cls.aengel,
     )
     cls.remote_server.assemble(cls.server)
     
     cls.remote1 = Autocomms(
         autoresponder_class = PersisterBridgeClient,
         connector_class = WSBasicClient,
         connector_kwargs = {
             'host': 'localhost',
             'port': 5358,
             'tls': False,
         },
         debug = True,
         aengel = cls.aengel,
     )
     cls.remote2 = Autocomms(
         autoresponder_class = PersisterBridgeClient,
         connector_class = WSBasicClient,
         connector_kwargs = {
             'host': 'localhost',
             'port': 5358,
             'tls': False,
         },
         debug = True,
         aengel = cls.aengel,
     )
示例#4
0
def make_fixtures(debug, hgx_root_1, hgx_root_2):
    ''' Makes fixtures for the test.
    hgx_root_# is the root app directory, used by config. It contains
    the cache directory.
    '''
    server_port = 6022
    aengel = Aengel()

    with Config(hgx_root_1) as config:
        config.set_remote('127.0.0.1', server_port, False)
        config.ipc_port = 6023

    with Config(hgx_root_2) as config:
        config.set_remote('127.0.0.1', server_port, False)
        config.ipc_port = 6024

    hgxserver = _hgx_server(
        host='127.0.0.1',
        port=server_port,
        cache_dir=None,
        debug=debug,
        traceur=False,
        aengel=aengel,
    )
    # localhost:6023, no tls
    hgxraz = app_core(user_id=None,
                      password='******',
                      startup_logger=None,
                      aengel=aengel,
                      _scrypt_hardness=1024,
                      hgx_root=hgx_root_1,
                      enable_logs=False)

    # localhost:6024, no tls
    hgxdes = app_core(user_id=None,
                      password='******',
                      startup_logger=None,
                      aengel=aengel,
                      _scrypt_hardness=1024,
                      hgx_root=hgx_root_2,
                      enable_logs=False)

    return hgxserver, hgxraz, hgxdes, aengel
示例#5
0
 def setUpClass(cls):
     cls.aengel = Aengel()
     
     cls.server = Autocomms(
         autoresponder_class = TestParrot,
         connector_class = WSBasicServer,
         connector_kwargs = {
             'host': 'localhost',
             'port': 9319,
             'tls': False,
         },
         debug = True,
         aengel = cls.aengel,
     )
     
     cls.client1 = Autocomms(
         autoresponder_class = TestParrot,
         autoresponder_args = ('OneTrueMorty',),
         connector_class = WSBasicClient,
         connector_kwargs = {
             'host': 'localhost',
             'port': 9319,
             'tls': False,
         },
         debug = True,
         aengel = cls.aengel,
     )
     
     cls.client2 = Autocomms(
         autoresponder_class = TestParrot,
         autoresponder_args = ('HammerMorty',),
         connector_class = WSBasicClient,
         connector_kwargs = {
             'host': 'localhost',
             'port': 9319,
             'tls': False,
         },
         debug = True,
         aengel = cls.aengel,
     )
示例#6
0
 def setUp(self):
     # SO BEGINS SERVER SETUP!
     self.aengel = Aengel()
     self.ipccore = IPCCore(
         aengel = self.aengel,
         debug = True,
         threaded = True,
         thread_name = 'IPCCore'
     )
     
     self.golcore = MockGolcore(TEST_AGENT1)
     self.oracle = MockOracle(TEST_AGENT1)
     self.dispatch = MockDispatch()
     self.rolodex = MockRolodex()
     self.salmonator = SalmonatorNoop()
     
     self.ipccore.assemble(
         self.golcore, self.oracle, self.dispatch, self.rolodex, 
         self.salmonator
     )
     self.ipccore.bootstrap(
         incoming_shares = set(),
         orphan_acks = SetMap(),
         orphan_naks = SetMap()
     )
     
     self.ipccore.add_ipc_server(
         'websockets', 
         WSBasicServer, 
         host = 'localhost',
         port = 4628,
         aengel = self.aengel,
         debug = True,
         threaded = True,
         tls = False,
         thread_name = 'IPC server'
     )
     
     # AND THUS BEGINS CLIENT/APPLICATION SETUP!
     self.app1 = IPCEmbed(
         aengel = self.aengel,
         debug = True,
         threaded = True,
         thread_name = 'app1em'
     )
     self.app1.add_ipc_threadsafe(
         WSBasicClient,
         host = 'localhost',
         port = 4628,
         debug = True,
         tls = False,
         aengel = self.aengel,
         threaded = True,
         thread_name = 'app1WS',
     )
     # self.app1endpoint = self.ipccore.any_session
     
     self.app2 = IPCEmbed(
         aengel = self.aengel,
         debug = True,
         threaded = True,
         thread_name = 'app2em'
     )
     self.app2.add_ipc_threadsafe(
         WSBasicClient,
         host = 'localhost',
         port = 4628,
         debug = True,
         tls = False,
         aengel = self.aengel,
         threaded = True,
         thread_name = 'app2WS',
     )
     # endpoints = set(self.ipccore.sessions)
     # self.app2endpoint = list(endpoints - {self.app1endpoint})[0]
     
     self.__api_id = bytes(64) + b'1'
示例#7
0
def app_core(user_id, password, startup_logger, aengel=None,
             _scrypt_hardness=None, hgx_root=None, enable_logs=True):
    ''' This is where all of the UX goes for the service itself. From
    here, we build a credential, then a bootstrap, and then persisters,
    IPC, etc.
    
    Expected defaults:
    host:       'localhost'
    port:       7770
    tls:        True
    ipc_port:   7772
    debug:      False
    logfile:    None
    verbosity:  'warning'
    traceur:    False
    '''
    if startup_logger is not None:
        # At some point, this will need to restore the module logger, but for
        # now it really doesn't make any difference whatsoever
        effective_logger = startup_logger
    else:
        effective_logger = logger
    
    with Config(hgx_root) as config:
        # Convert paths to strs
        cache_dir = str(config.cache_dir)
        log_dir = str(config.log_dir)
            
        if user_id is None:
            user_id = config.user_id
        
        debug = config.debug_mode
        verbosity = config.log_verbosity
        ipc_port = config.ipc_port
        remotes = config.remotes
        
    if enable_logs:
        logutils.autoconfig(
            tofile = True,
            logdirname = log_dir,
            loglevel = verbosity,
            logname = 'hgxapp'
        )
    
    if not aengel:
        aengel = Aengel()
    
    core = AgentBootstrap(aengel=aengel, debug=debug, cache_dir=cache_dir)
    core.assemble()
    
    # In this case, we have no existing user_id.
    if user_id is None:
        user_id = core.bootstrap_zero(
            password = password,
            _scrypt_hardness = _scrypt_hardness
        )
        effective_logger.critical(
            'Identity created. Your user ID is ' + str(user_id) + '. You ' +
            'will need your user ID to log in to Hypergolix from another ' +
            'machine, or if your Hypergolix configuration file is corrupted ' +
            'or lost.'
        )
        with Config(hgx_root) as config:
            config.fingerprint = core.whoami
            config.user_id = user_id
        
    # Hey look, we have an existing user.
    else:
        core.bootstrap(
            user_id = user_id,
            password = password,
            _scrypt_hardness = _scrypt_hardness,
        )
        effective_logger.info('Login successful.')
        
    # Add all of the remotes to a namespace preserver
    persisters = []
    for remote in remotes:
        try:
            persister = Autocomms(
                autoresponder_name = 'remrecli',
                autoresponder_class = PersisterBridgeClient,
                connector_name = 'remwscli',
                connector_class = WSBasicClient,
                connector_kwargs = {
                    'host': remote.host,
                    'port': remote.port,
                    'tls': remote.tls,
                },
                debug = debug,
                aengel = aengel,
            )
            
        except CancelledError:
            effective_logger.error(
                'Error while connecting to upstream remote at ' +
                remote.host + ':' + str(remote.port) + '. Connection will ' +
                'only be reattempted after restarting Hypergolix.'
            )
            
        else:
            core.salmonator.add_upstream_remote(persister)
            persisters.append(persister)
        
    # Finally, add the ipc system
    core.ipccore.add_ipc_server(
        'wslocal',
        WSBasicServer,
        host = 'localhost',
        port = ipc_port,
        tls = False,
        debug = debug,
        aengel = aengel,
        threaded = True,
        thread_name = _generate_threadnames('ipc-ws')[0],
    )
        
    return persisters, core, aengel
示例#8
0
 def setUpClass(cls):
     cls.aengel = Aengel()