def _zmq_connect(self, connClass, address): """ Connect to an address. :param connClass: The connection class to be used. :type connClass: txzmq.ZmqConnection :param address: The address to connect to. :type address: str :return: The binded connection. :rtype: txzmq.ZmqConnection """ connection = connClass(self._factory) # create and configure socket socket = connection.socket if zmq_has_curve(): public, secret = maybe_create_and_get_certificates( self._config_prefix, self.component_type) server_public_file = os.path.join( self._config_prefix, PUBLIC_KEYS_PREFIX, "server.key") server_public, _ = zmq.auth.load_certificate(server_public_file) socket.curve_publickey = public socket.curve_secretkey = secret socket.curve_serverkey = server_public socket.connect(address) logger.debug("Connected %s to %s." % (connClass, address)) self._connections.append(connection) return connection
def _zmq_connect(self, socktype, address): """ Connect to an address using with a zmq socktype. :param socktype: The ZMQ socket type. :type socktype: int :param address: The address to connect to. :type address: str :return: A ZMQ connection stream. :rtype: ZMQStream """ logger.debug("Connecting %s to %s." % (socktype, address)) socket = self._context.socket(socktype) # configure curve authentication if zmq_has_curve(): public, private = maybe_create_and_get_certificates( self._config_prefix, "client") server_public_file = os.path.join(self._config_prefix, PUBLIC_KEYS_PREFIX, "server.key") server_public, _ = zmq.auth.load_certificate(server_public_file) socket.curve_publickey = public socket.curve_secretkey = private socket.curve_serverkey = server_public stream = zmqstream.ZMQStream(socket, self._loop) socket.connect(address) return stream
def _zmq_bind(self, connClass, address): """ Bind to an address. :param connClass: The connection class to be used. :type connClass: txzmq.ZmqConnection :param address: The address to bind to. :type address: str :return: The binded connection and port. :rtype: (txzmq.ZmqConnection, int) """ connection = connClass(self._factory) socket = connection.socket if zmq_has_curve(): public, secret = maybe_create_and_get_certificates( self._config_prefix, self.component_type) socket.curve_publickey = public socket.curve_secretkey = secret self._start_thread_auth(connection.socket) # check if port was given protocol, addr, port = ADDRESS_RE.match(address).groups() if port == "0": port = socket.bind_to_random_port("%s://%s" % (protocol, addr)) else: socket.bind(address) port = int(port) logger.debug("Binded %s to %s://%s:%d." % (connClass, protocol, addr, port)) self._connections.append(connection) return connection, port
def _zmq_connect(self, socktype, address): """ Connect to an address using with a zmq socktype. :param socktype: The ZMQ socket type. :type socktype: int :param address: The address to connect to. :type address: str :return: A ZMQ connection stream. :rtype: ZMQStream """ logger.debug("Connecting %s to %s." % (socktype, address)) socket = self._context.socket(socktype) # configure curve authentication if zmq_has_curve(): public, private = maybe_create_and_get_certificates( self._config_prefix, "client") server_public_file = os.path.join( self._config_prefix, PUBLIC_KEYS_PREFIX, "server.key") server_public, _ = zmq.auth.load_certificate(server_public_file) socket.curve_publickey = public socket.curve_secretkey = private socket.curve_serverkey = server_public stream = zmqstream.ZMQStream(socket, self._loop) socket.connect(address) return stream
def _zmq_bind(self, connClass, address): """ Bind to an address. :param connClass: The connection class to be used. :type connClass: txzmq.ZmqConnection :param address: The address to bind to. :type address: str :return: The binded connection and port. :rtype: (txzmq.ZmqConnection, int) """ connection = connClass(self._factory) socket = connection.socket if zmq_has_curve(): public, secret = maybe_create_and_get_certificates( self._config_prefix, self.component_type) socket.curve_publickey = public socket.curve_secretkey = secret self._start_thread_auth(connection.socket) proto, addr, port = ADDRESS_RE.search(address).groups() if port is None or port is '0': params = proto, addr port = socket.bind_to_random_port("%s://%s" % params) # XXX this log doesn't appear logger.debug("Binded %s to %s://%s." % ((connClass,) + params)) else: params = proto, addr, int(port) socket.bind("%s://%s:%d" % params) # XXX this log doesn't appear logger.debug("Binded %s to %s://%s:%d." % ((connClass,) + params)) self._connections.append(connection) return connection, port
def _zmq_connect(self, connClass, address): """ Connect to an address. :param connClass: The connection class to be used. :type connClass: txzmq.ZmqConnection :param address: The address to connect to. :type address: str :return: The binded connection. :rtype: txzmq.ZmqConnection """ connection = connClass(self._factory) # create and configure socket socket = connection.socket if zmq_has_curve(): public, secret = maybe_create_and_get_certificates( self._config_prefix, self.component_type) server_public_file = os.path.join(self._config_prefix, PUBLIC_KEYS_PREFIX, "server.key") server_public, _ = zmq.auth.load_certificate(server_public_file) socket.curve_publickey = public socket.curve_secretkey = secret socket.curve_serverkey = server_public socket.connect(address) logger.debug("Connected %s to %s." % (connClass, address)) self._connections.append(connection) return connection
def _zmq_bind(self, connClass, address): """ Bind to an address. :param connClass: The connection class to be used. :type connClass: txzmq.ZmqConnection :param address: The address to bind to. :type address: str :return: The binded connection and port. :rtype: (txzmq.ZmqConnection, int) """ connection = connClass(self._factory) socket = connection.socket if zmq_has_curve(): public, secret = maybe_create_and_get_certificates( self._config_prefix, self.component_type) socket.curve_publickey = public socket.curve_secretkey = secret self._start_thread_auth(connection.socket) proto, addr, port = ADDRESS_RE.search(address).groups() if port is None or port is '0': params = proto, addr port = socket.bind_to_random_port("%s://%s" % params) # XXX this log doesn't appear logger.debug("Binded %s to %s://%s." % ((connClass, ) + params)) else: params = proto, addr, int(port) socket.bind("%s://%s:%d" % params) # XXX this log doesn't appear logger.debug("Binded %s to %s://%s:%d." % ((connClass, ) + params)) self._connections.append(connection) return connection, port
def __init__(self, path_prefix=None, enable_curve=True, factory=None): """ Initialize the txzmq component. """ if path_prefix is None: path_prefix = get_path_prefix(flags.STANDALONE) if factory is not None: self._factory = factory self._config_prefix = os.path.join(path_prefix, "leap", "events") self._connections = [] if enable_curve: self.use_curve = zmq_has_curve() else: self.use_curve = False
def __init__(self, emit_addr, reg_addr, factory=None, enable_curve=True): """ Initialize the events client. """ threading.Thread.__init__(self) EventsClient.__init__(self, emit_addr, reg_addr) self._lock = threading.Lock() self._initialized = threading.Event() self._config_prefix = os.path.join( get_path_prefix(flags.STANDALONE), "leap", "events") self._loop = None self._factory = factory self._context = None self._push = None self._sub = None if enable_curve: self.use_curve = zmq_has_curve() else: self.use_curve = False
""" The server for the events mechanism. """ import logging import txzmq from leap.common.zmq_utils import zmq_has_curve from leap.common.events.zmq_components import TxZmqServerComponent if zmq_has_curve(): EMIT_ADDR = "tcp://127.0.0.1:9000" REG_ADDR = "tcp://127.0.0.1:9001" else: EMIT_ADDR = "ipc:///tmp/leap.common.events.socket.0" REG_ADDR = "ipc:///tmp/leap.common.events.socket.1" logger = logging.getLogger(__name__) def ensure_server(emit_addr=EMIT_ADDR, reg_addr=REG_ADDR): """ Make sure the server is running in the given addresses. :param emit_addr: The address in which to receive events from clients.
# GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. """ The server for the events mechanism. """ import logging import txzmq from leap.common.zmq_utils import zmq_has_curve from leap.common.events.zmq_components import TxZmqServerComponent if zmq_has_curve(): EMIT_ADDR = "tcp://127.0.0.1:9000" REG_ADDR = "tcp://127.0.0.1:9001" else: EMIT_ADDR = "ipc:///tmp/leap.common.events.socket.0" REG_ADDR = "ipc:///tmp/leap.common.events.socket.1" logger = logging.getLogger(__name__) def ensure_server(emit_addr=EMIT_ADDR, reg_addr=REG_ADDR): """ Make sure the server is running in the given addresses. :param emit_addr: The address in which to receive events from clients. :type emit_addr: str
# # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. """ The server for the events mechanism. """ import logging import platform import txzmq from leap.common.zmq_utils import zmq_has_curve from leap.common.events.zmq_components import TxZmqServerComponent if zmq_has_curve() or platform.system() == "Windows": # Windows doesn't have ipc sockets, we need to use always tcp EMIT_ADDR = "tcp://127.0.0.1:9000" REG_ADDR = "tcp://127.0.0.1:9001" else: EMIT_ADDR = "ipc:///tmp/leap.common.events.socket.0" REG_ADDR = "ipc:///tmp/leap.common.events.socket.1" logger = logging.getLogger(__name__) def ensure_server(emit_addr=EMIT_ADDR, reg_addr=REG_ADDR, path_prefix=None, factory=None, enable_curve=True): """ Make sure the server is running in the given addresses.