Esempio n. 1
0
    async def __anit__(self, certdir=None):

        await s_base.Base.__anit__(self)

        self._shareLoopTasks = set()

        if certdir is None:
            certdir = s_certdir.getCertDir()

        self.certdir = certdir
        self.televers = s_telepath.televers

        self.addr = None    # our main listen address
        self.cells = {}     # all cells are shared.  not all shared are cells.
        self.shared = {}    # objects provided by daemon
        self.listenservers = []  # the sockets we're listening on
        self.links = set()

        self.sessions = {}

        self.mesgfuncs = {
            'tele:syn': self._onTeleSyn,
            'task:init': self._onTaskInit,
            'share:fini': self._onShareFini,

            # task version 2 API
            't2:init': self._onTaskV2Init,
        }

        self.onfini(self._onDmonFini)

        # by default we are ready... ( backward compat )
        self.dmonready = True
Esempio n. 2
0
async def openinfo(info):

    scheme = info.get('scheme')

    if scheme == 'aha':
        return await getAhaProxy(info)

    if '+' in scheme:
        scheme, disc = scheme.split('+', 1)
        # Discovery protocols modify info dict inband?
        if disc == 'consul':
            await disc_consul(info)

        else:
            raise s_exc.BadUrl(mesg=f'Unknown discovery protocol [{disc}].',
                               disc=disc)

    host = info.get('host')
    port = info.get('port')

    auth = None

    user = info.get('user')
    if user is not None:
        passwd = info.get('passwd')
        auth = (user, {'passwd': passwd})

    if scheme == 'cell':
        # cell:///path/to/celldir:share
        # cell://rel/path/to/celldir:share
        path = info.get('path')

        name = info.get('name', '*')

        # support cell://<relpath>/<to>/<cell>
        # by detecting host...
        host = info.get('host')
        if host:
            path = path.strip('/')
            path = os.path.join(host, path)

        if ':' in path:
            path, name = path.split(':')

        full = os.path.join(path, 'sock')
        link = await s_link.unixconnect(full)

    elif scheme == 'unix':
        # unix:///path/to/sock:share
        name = '*'
        path = info.get('path')
        if ':' in path:
            path, name = path.split(':')
        link = await s_link.unixconnect(path)

    else:

        path = info.get('path')
        name = info.get('name', path[1:])

        hostname = None

        sslctx = None
        if scheme == 'ssl':

            certdir = info.get('certdir')
            certname = info.get('certname')
            hostname = info.get('hostname', host)

            if certdir is None:
                certdir = s_certdir.getCertDir()

            # if a TLS connection specifies a user with no password
            # attempt to auto-resolve a user certificate for the given
            # host/network.
            if certname is None and user is not None and passwd is None:
                certname = f'{user}@{hostname}'

            sslctx = certdir.getClientSSLContext(certname=certname)

            # do hostname checking manually to avoid DNS lookups
            # ( to support dynamic IP addresses on services )
            sslctx.check_hostname = False

        link = await s_link.connect(host, port, ssl=sslctx, hostname=hostname)

    prox = await Proxy.anit(link, name)
    prox.onfini(link)

    try:
        await prox.handshake(auth=auth)

    except (asyncio.CancelledError, Exception):
        await prox.fini()
        raise

    return prox