Пример #1
0
    def __init__(self,
                 connections,
                 endpoint,
                 dispatcher,
                 zmq_identity,
                 secured,
                 server_public_key,
                 server_private_key,
                 heartbeat=False):
        self._futures = future.FutureCollection()
        self._zmq_identity = zmq_identity
        self._endpoint = endpoint
        self._dispatcher = dispatcher
        self._secured = secured
        self._server_public_key = server_public_key
        self._server_private_key = server_private_key
        self._heartbeat = heartbeat

        self._send_receive_thread = _SendReceive(
            "OutboundConnectionThread-{}".format(self._endpoint),
            endpoint,
            connections=connections,
            dispatcher=self._dispatcher,
            futures=self._futures,
            zmq_identity=zmq_identity,
            secured=secured,
            server_public_key=server_public_key,
            server_private_key=server_private_key,
            heartbeat=heartbeat)

        self._thread = None
Пример #2
0
    def __init__(self,
                 endpoint,
                 dispatcher,
                 identity,
                 secured,
                 server_public_key,
                 server_private_key):
        self._futures = future.FutureCollection()
        self._identity = identity
        self._endpoint = endpoint
        self._dispatcher = dispatcher
        self._secured = secured
        self._server_public_key = server_public_key
        self._server_private_key = server_private_key
        self._send_receive_thread = _SendReceive(
            "ConnectionThread-{}".format(self._endpoint),
            endpoint,
            dispatcher=self._dispatcher,
            futures=self._futures,
            identity=identity,
            secured=secured,
            server_public_key=server_public_key,
            server_private_key=server_private_key)

        self._thread = None
Пример #3
0
    def __init__(self,
                 endpoint,
                 dispatcher,
                 identity=None,
                 peer_connections=None,
                 secured=False,
                 server_public_key=None,
                 server_private_key=None,
                 heartbeat=False):
        """
        Constructor for Interconnect.

        Args:
            secured (bool): Whether or not to start the 'server' socket
                and associated Connection sockets in secure mode --
                using zmq auth.
            server_public_key (bytes): A public key to use in verifying
                server identity as part of the zmq auth handshake.
            server_private_key (bytes): A private key corresponding to
                server_public_key used by the server socket to sign
                messages are part of the zmq auth handshake.
            heartbeat (bool): Whether or not to send ping messages.
        """
        self._futures = future.FutureCollection()
        self._dispatcher = dispatcher
        self._identity = identity
        self._secured = secured
        self._server_public_key = server_public_key
        self._server_private_key = server_private_key
        self._heartbeat = heartbeat

        self._send_receive_thread = _SendReceive(
            "ServerThread",
            address=endpoint,
            dispatcher=dispatcher,
            futures=self._futures,
            secured=secured,
            server_public_key=server_public_key,
            server_private_key=server_private_key,
            heartbeat=heartbeat)

        self._thread = None

        if peer_connections is not None:
            self.connections = [
                Connection(endpoint=addr,
                           dispatcher=dispatcher,
                           identity=identity,
                           secured=secured,
                           server_public_key=server_public_key,
                           server_private_key=server_private_key)
                for addr in peer_connections
            ]
        else:
            self.connections = []
Пример #4
0
    def __init__(self,
                 endpoint,
                 dispatcher,
                 zmq_identity=None,
                 secured=False,
                 server_public_key=None,
                 server_private_key=None,
                 heartbeat=False,
                 public_endpoint=None,
                 connection_timeout=60,
                 max_incoming_connections=100,
                 monitor=False):
        """
        Constructor for Interconnect.

        Args:
            secured (bool): Whether or not to start the 'server' socket
                and associated Connection sockets in secure mode --
                using zmq auth.
            server_public_key (bytes): A public key to use in verifying
                server identity as part of the zmq auth handshake.
            server_private_key (bytes): A private key corresponding to
                server_public_key used by the server socket to sign
                messages are part of the zmq auth handshake.
            heartbeat (bool): Whether or not to send ping messages.
        """
        self._endpoint = endpoint
        self._public_endpoint = public_endpoint
        self._futures = future.FutureCollection()
        self._dispatcher = dispatcher
        self._zmq_identity = zmq_identity
        self._secured = secured
        self._server_public_key = server_public_key
        self._server_private_key = server_private_key
        self._heartbeat = heartbeat
        self._connection_timeout = connection_timeout
        self._connections = ThreadsafeDict()
        self.outbound_connections = ThreadsafeDict()
        self._max_incoming_connections = max_incoming_connections

        self._send_receive_thread = _SendReceive(
            "ServerThread",
            connections=self._connections,
            address=endpoint,
            dispatcher=dispatcher,
            futures=self._futures,
            secured=secured,
            server_public_key=server_public_key,
            server_private_key=server_private_key,
            heartbeat=heartbeat,
            connection_timeout=connection_timeout,
            monitor=monitor)

        self._thread = None
Пример #5
0
    def __init__(self,
                 endpoint,
                 identity):
        self._futures = future.FutureCollection()
        self._identity = identity
        self._endpoint = endpoint
        self._send_receive_thread = _SendReceive(
            endpoint,
            futures=self._futures,
            identity=identity)

        self._thread = None
Пример #6
0
    def __init__(self, endpoint, identity, secured, server_public_key,
                 server_private_key):
        self._futures = future.FutureCollection()
        self._identity = identity
        self._endpoint = endpoint
        self._secured = secured
        self._server_public_key = server_public_key
        self._server_private_key = server_private_key
        self._send_receive_thread = _SendReceive(
            endpoint,
            futures=self._futures,
            identity=identity,
            secured=secured,
            server_public_key=server_public_key,
            server_private_key=server_private_key)

        self._thread = None
Пример #7
0
    def __init__(self,
                 endpoint,
                 dispatcher,
                 identity=None,
                 peer_connections=None):
        self._futures = future.FutureCollection()
        self._send_receive_thread = _SendReceive(
            address=endpoint,
            dispatcher=dispatcher,
            futures=self._futures)

        self._thread = None

        if peer_connections is not None:
            self.connections = [
                Connection(
                    endpoint=addr,
                    identity=identity) for addr in peer_connections]
        else:
            self.connections = []
Пример #8
0
    def __init__(self,
                 connections,
                 endpoint,
                 dispatcher,
                 zmq_identity,
                 secured,
                 server_public_key,
                 server_private_key,
                 future_callback_threadpool,
                 heartbeat=True,
                 connection_timeout=60,
                 metrics_registry=None):
        self._futures = future.FutureCollection(
            resolving_threadpool=future_callback_threadpool)
        self._zmq_identity = zmq_identity
        self._endpoint = endpoint
        self._dispatcher = dispatcher
        self._secured = secured
        self._server_public_key = server_public_key
        self._server_private_key = server_private_key
        self._heartbeat = heartbeat
        self._connection_timeout = connection_timeout
        self._connection_id = None

        self._send_receive_thread = _SendReceive(
            "OutboundConnectionThread-{}".format(self._endpoint),
            endpoint,
            connections=connections,
            dispatcher=self._dispatcher,
            futures=self._futures,
            zmq_identity=zmq_identity,
            secured=secured,
            server_public_key=server_public_key,
            server_private_key=server_private_key,
            heartbeat=heartbeat,
            connection_timeout=connection_timeout,
            metrics_registry=metrics_registry)

        self._thread = None
        self._metrics_registry = metrics_registry
Пример #9
0
    def __init__(self,
                 endpoint,
                 dispatcher,
                 zmq_identity=None,
                 secured=False,
                 server_public_key=None,
                 server_private_key=None,
                 heartbeat=False,
                 public_endpoint=None,
                 connection_timeout=60,
                 max_incoming_connections=100,
                 monitor=False,
                 max_future_callback_workers=10,
                 roles=None,
                 authorize=False,
                 public_key=None,
                 priv_key=None,
                 metrics_registry=None):
        """
        Constructor for Interconnect.

        Args:
            secured (bool): Whether or not to start the 'server' socket
                and associated Connection sockets in secure mode --
                using zmq auth.
            server_public_key (bytes): A public key to use in verifying
                server identity as part of the zmq auth handshake.
            server_private_key (bytes): A private key corresponding to
                server_public_key used by the server socket to sign
                messages are part of the zmq auth handshake.
            heartbeat (bool): Whether or not to send ping messages.
            max_future_callback_workers (int): max number of workers for future
                callbacks, defaults to 10
        """
        self._endpoint = endpoint
        self._public_endpoint = public_endpoint
        self._future_callback_threadpool = ThreadPoolExecutor(
            max_workers=max_future_callback_workers)
        self._futures = future.FutureCollection(
            resolving_threadpool=self._future_callback_threadpool)
        self._dispatcher = dispatcher
        self._zmq_identity = zmq_identity
        self._secured = secured
        self._server_public_key = server_public_key
        self._server_private_key = server_private_key
        self._heartbeat = heartbeat
        self._connection_timeout = connection_timeout
        self._connections_lock = Lock()
        self._connections = {}
        self.outbound_connections = {}
        self._max_incoming_connections = max_incoming_connections
        self._roles = {}
        # if roles are None, default to AuthorizationType.TRUST
        if roles is None:
            self._roles["network"] = AuthorizationType.TRUST
        else:
            self._roles = {}
            for role in roles:
                if roles[role] == "challenge":
                    self._roles[role] = AuthorizationType.CHALLENGE
                else:
                    self._roles[role] = AuthorizationType.TRUST

        self._authorize = authorize
        self._public_key = public_key
        self._priv_key = priv_key

        self._send_receive_thread = _SendReceive(
            "ServerThread",
            connections=self._connections,
            address=endpoint,
            dispatcher=dispatcher,
            futures=self._futures,
            secured=secured,
            server_public_key=server_public_key,
            server_private_key=server_private_key,
            heartbeat=heartbeat,
            connection_timeout=connection_timeout,
            monitor=monitor,
            metrics_registry=metrics_registry)

        self._thread = None

        self._metrics_registry = metrics_registry
        self._send_response_timers = {}