Ejemplo n.º 1
0
    def __init__(self, auth, roots=()):

        SessBoss.__init__(self, auth, roots=roots)

        self.sessplex = s_net.ChanPlex()
        self.taskplex = s_net.ChanPlex()

        self.sessplex.setLinkProp('repr', 'CellUser.sessplex')
        self.taskplex.setLinkProp('repr', 'CellUser.taskplex')
Ejemplo n.º 2
0
    def __init__(self, chan, prox):
        Sess.__init__(self, chan, prox, lisn=False)
        self._sess_prox = prox
        self._txok_evnt = threading.Event()
        self.on('sess:txok', self._setTxOk)

        self.taskplex = s_net.ChanPlex()
        self.taskplex.setLinkProp('repr', 'UserSess.taskplex')
Ejemplo n.º 3
0
    def __init__(self, chan, cell):

        Sess.__init__(self, chan, cell, lisn=True)
        self._sess_cell = cell

        def onchan(chan):
            chan.onrx(self._sess_cell.rx)

        self.taskplex = s_net.ChanPlex(onchan=onchan)
        self.taskplex.setLinkProp('repr', 'CellSess.taskplex')
Ejemplo n.º 4
0
    def __init__(self, dirn, conf=None):

        s_net.Link.__init__(self)
        s_config.Config.__init__(self)

        self.dirn = dirn
        s_common.gendir(dirn)

        # config file in the dir first...
        self.loadConfPath(self._path('config.json'))
        if conf is not None:
            self.setConfOpts(conf)
        self.reqConfOpts()

        self.plex = s_net.Plex()
        self.kvstor = s_kv.KvStor(self._path('cell.lmdb'))
        self.kvinfo = self.kvstor.getKvDict('cell:info')

        # open our vault
        self.vault = s_vault.Vault(self._path('vault.lmdb'))
        self.root = self.vault.genRootCert()

        # setup our certificate and private key
        auth = None

        path = self._path('cell.auth')
        if os.path.isfile(path):
            with open(path, 'rb') as fd:
                auth = s_msgpack.un(fd.read())

        # if we dont have provided auth, assume we stand alone
        if auth is None:

            auth = self.vault.genUserAuth('root')
            with open(path, 'wb') as fd:
                fd.write(s_msgpack.en(auth))

            path = self._path('user.auth')
            auth = self.vault.genUserAuth('user')

            with open(path, 'wb') as fd:
                fd.write(s_msgpack.en(auth))

        roots = self.vault.getRootCerts()
        SessBoss.__init__(self, auth, roots)

        host = self.getConfOpt('host')
        port = self.getConfOpt('port')

        if port == 0:
            port = self.kvinfo.get('port', port)

        def onchan(chan):
            sess = CellSess(chan, self)
            chan.onrx(sess.rx)

        self.sessplex = s_net.ChanPlex(onchan=onchan)
        self.sessplex.setLinkProp('repr', 'Cell.sessplex')

        def onlink(link):
            link.onrx(self.sessplex.rx)

        self._cell_addr = self.plex.listen((host, port), onlink)

        # save the port so it can be semi-stable...
        self.kvinfo.set('port', self._cell_addr[1])

        # Give implementers the chance to hook into the cell
        self.postCell()

        # lock cell.lock
        self.lockfd = s_common.genfile(self._path('cell.lock'))
        try:
            fcntl.lockf(self.lockfd, fcntl.LOCK_EX | fcntl.LOCK_NB)
        except OSError as e:
            logger.exception('Failed to obtain lock for [%s]',
                             self.lockfd.name)
            raise
        self.onfini(self._onCellFini)
        self.onfini(self.finiCell)
        logger.debug('Cell is done initializing')