How to use the txzmq.connection.ZmqConnection function in txZMQ

To help you get started, we’ve selected a few txZMQ examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github opencord / voltha / voltha / adapters / adtran_olt / net / adtran_zmq.py View on Github external
raise Exception('Failed to complete endpoint setup')

        self.auth = TwistedZmqAuthenticator()

        d = self.auth.start()
        d.addCallbacks(configure_plain, config_failure)
        d.addCallbacks(add_endoints, endpoint_failure)

        return d

    def setup_curve_security(self):
        self.log.debug('setup-curve-security')
        raise NotImplementedError('TODO: curve transport security is not yet supported')


class ZmqPairConnection(ZmqConnection):
    """
    Bidirectional messages to/from the socket.

    Wrapper around ZeroMQ PUSH socket.
    """
    socketType = constants.PAIR

    def messageReceived(self, message):
        """
        Called on incoming message from ZeroMQ.

        :param message: message data
        """
        self.onReceive(message)

    def onReceive(self, message):
github leapcode / leap_pycommon / src / leap / common / events / auth.py View on Github external
Send a ZAP reply to finish the authentication.
        """
        user_id = user_id if status_code == b'200' else b''
        if isinstance(user_id, unicode):
            user_id = user_id.encode(self.encoding, 'replace')
        metadata = b''  # not currently used
        reply = [VERSION, request_id, status_code, status_text,
                 user_id, metadata]
        self.send(reply)

    def shutdown(self):
        if self.factory:
            super(TxAuthenticator, self).shutdown()


class TxAuthenticationRequest(ZmqConnection):

    socketType = PAIR
    address = 'inproc://zeromq.zap.01'
    encoding = 'utf-8'

    def start(self):
        endpoint = ZmqEndpoint(ZmqEndpointType.connect, self.address)
        self.addEndpoints([endpoint])

    def allow(self, *addresses):
        self.send([b'ALLOW'] + [b(a, self.encoding) for a in addresses])

    def configure_curve(self, domain='*', location=''):
        domain = b(domain, self.encoding)
        location = b(location, self.encoding)
        self.send([b'CURVE', domain, location])
github leapcode / leap_pycommon / src / leap / common / events / auth.py View on Github external
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see .
"""
ZAP authentication, twisted style.
"""
from zmq import PAIR
from zmq.auth.base import Authenticator, VERSION
from txzmq.connection import ZmqConnection
from zmq.utils.strtypes import b, u

from twisted.python import log

from txzmq.connection import ZmqEndpoint, ZmqEndpointType


class TxAuthenticator(ZmqConnection):

    """
    This does not implement the whole ZAP protocol, but the bare minimum that
    we need.
    """

    socketType = PAIR
    address = 'inproc://zeromq.zap.01'
    encoding = 'utf-8'

    def __init__(self, factory, *args, **kw):
        super(TxAuthenticator, self).__init__(factory, *args, **kw)
        self.authenticator = Authenticator(factory.context)
        self.authenticator._send_zap_reply = self._send_zap_reply

    def start(self):