예제 #1
0
def openlink(link):
    '''
    Construct a telepath proxy from a link tufo.

    Example:

        foo = openlink(link)
        foo.bar(20)

    '''
    # special case for dmon://fooname/ which refers to a
    # named object within whatever dmon is currently in scope
    if link[0] == 'dmon':

        dmon = s_scope.get('dmon')
        if dmon is None:
            raise s_common.NoSuchName(name='dmon', link=link, mesg='no dmon instance in current scope')

        # the "host" part is really a dmon local
        host = link[1].get('host')
        item = dmon.locs.get(host)
        if item is None:
            raise s_common.NoSuchName(name=host, link=link, mesg='dmon instance has no local with that name')

        return item

    relay = s_link.getLinkRelay(link)
    name = link[1].get('path')[1:]

    sock = relay.connect()

    synack = teleSynAck(sock, name=name)
    bases = ()

    return Proxy(relay, sock=sock)
예제 #2
0
    def listen(self, linkurl, **opts):
        '''
        Create and run a link server by url.

        Example:

            link = dmon.listen('tcp://127.0.0.1:8888')

        Notes:

            * Returns the parsed link tufo

        '''
        link = s_link.chopLinkUrl(linkurl)
        link[1].update(opts)

        relay = s_link.getLinkRelay(link)

        sock = relay.listen()
        sock.on('link:sock:init', self.dist )

        self.plex.addPlexSock(sock)

        self._dmon_links.append(link)
        return link
예제 #3
0
def openclass(cls, url, **opts):
    plex = opts.pop('plex',None)

    link = s_link.chopLinkUrl(url)
    link[1].update(opts)

    relay = s_link.getLinkRelay(link)
    return cls(relay, plex=plex)
예제 #4
0
def openclass(cls, url, **opts):
    plex = opts.pop('plex',None)

    link = s_link.chopLinkUrl(url)
    link[1].update(opts)

    relay = s_link.getLinkRelay(link)
    return cls(relay, plex=plex)
예제 #5
0
def openlink(link):
    '''
    Construct a telepath proxy from a link tufo.

    Example:

        foo = openlink(link)
        foo.bar(20)

    '''
    relay = s_link.getLinkRelay(link)
    return Proxy(relay)
예제 #6
0
def openlink(link):
    '''
    Construct a telepath proxy from a link tufo.

    Example:

        foo = openlink(link)
        foo.bar(20)

    '''
    relay = s_link.getLinkRelay(link)
    return Proxy(relay)
예제 #7
0
    def test_daemon_timeout(self):

        daemon = s_daemon.Daemon()
        link = daemon.listen("tcp://127.0.0.1:0/?timeout=0.1")

        relay = s_link.getLinkRelay(link)
        sock = relay.connect()

        self.assertEqual(sock.recvobj(), None)

        sock.fini()
        daemon.fini()
예제 #8
0
    def test_daemon_timeout(self):

        daemon = s_daemon.Daemon()
        link = daemon.listen('tcp://127.0.0.1:0/?timeout=0.1')

        relay = s_link.getLinkRelay(link)
        sock = relay.connect()

        self.eq(sock.recvobj(), None)

        sock.fini()
        daemon.fini()
예제 #9
0
파일: telepath.py 프로젝트: mari0d/synapse
def openlink(link):
    '''
    Construct a Telepath Proxy from a link tufo.

    Args:
        link ((str, dict)): A link dictionary.

    Examples:
        Get a proxy object, call a function then close the object::

            foo = openlink(link)
            foo.bar(20)
            foo.fini()

        Get a proxy object as a context manager, which will result in the object being automatically closed::

            with openlink as foo:
                foo.dostuff(30)

    Returns:
        Proxy: A Proxy object for calling remote tasks.
    '''
    # special case for dmon://fooname/ which refers to a
    # named object within whatever dmon is currently in scope
    if link[0] == 'dmon':

        dmon = s_scope.get('dmon')
        if dmon is None:
            raise s_common.NoSuchName(name='dmon',
                                      link=link,
                                      mesg='no dmon instance in current scope')

        # the "host" part is really a dmon local
        host = link[1].get('host')
        item = dmon.locs.get(host)
        if item is None:
            raise s_common.NoSuchName(
                name=host,
                link=link,
                mesg='dmon instance has no local with that name')

        return item

    relay = s_link.getLinkRelay(link)
    name = link[1].get('path')[1:]

    sock = relay.connect()

    synack = teleSynAck(sock, name=name)
    bases = ()

    return Proxy(relay, sock=sock)
예제 #10
0
    def test_telepath_server_badvers(self):

        dmon = s_daemon.Daemon()
        link = dmon.listen('tcp://127.0.0.1:0/')

        rlay = s_link.getLinkRelay(link)

        jid = guid()
        sock = rlay.connect()

        sock.tx(tufo('tele:syn', jid=jid, vers=(0, 0)))

        mesg = sock.recvobj()

        sock.fini()

        self.eq(mesg[0], 'job:done')
        self.eq(mesg[1].get('err'), 'BadMesgVers')
예제 #11
0
    def test_telepath_server_badvers(self):

        dmon = s_daemon.Daemon()
        link = dmon.listen('tcp://127.0.0.1:0/')

        rlay = s_link.getLinkRelay(link)

        jid = guid()
        sock = rlay.connect()

        sock.tx( tufo('tele:syn', jid=jid, vers=(0,0)) )

        mesg = sock.recvobj()

        sock.fini()

        self.eq( mesg[0],'job:done')
        self.eq( mesg[1].get('err'), 'BadMesgVers' )
예제 #12
0
def openurl(url,**opts):
    '''
    Construct a telepath proxy from a url.

    Example:

        foo = openurl('tcp://1.2.3.4:90/foo')

        foo.dostuff(30) # call remote method

    '''
    plex = opts.pop('plex',None)

    link = s_link.chopLinkUrl(url)
    link[1].update(opts)

    relay = s_link.getLinkRelay(link)
    return Proxy(relay, plex=plex)
예제 #13
0
    def connect(self, url, **opts):
        '''
        Connect to a peer neuron

        This will attempt to bring up a permanent connection
        and reconnect if it is torn down.
        '''
        if self.isfini:
            return

        link = s_link.chopLinkUrl(url)
        link[1].update(opts)

        relay = s_link.getLinkRelay(link)

        sock = relay.connect()
        if sock == None:
            self.sched.insec(1, self.connect, url, **opts)
            return None

        self.runPlexSock(sock)

        sock.tx(tufo('peer:syn', iden=self.iden, mesh=self.mesh))
예제 #14
0
파일: neuron.py 프로젝트: jhsmith/synapse
    def connect(self, url, **opts):
        '''
        Connect to a peer neuron

        This will attempt to bring up a permanent connection
        and reconnect if it is torn down.
        '''
        if self.isfini:
            return

        link = s_link.chopLinkUrl(url)
        link[1].update(opts)

        relay = s_link.getLinkRelay(link)

        sock = relay.connect()
        if sock == None:
            self.sched.insec( 1, self.connect, url, **opts )
            return None

        self.runPlexSock(sock)

        sock.tx( tufo('peer:syn', iden=self.iden, mesh=self.mesh) )