Пример #1
0
    def __init__(self, identity, endpoint, peer_list, dispatcher):
        LOGGER.debug("Initializing Network service")
        self._identity = identity
        self._dispatcher = dispatcher
        self._handlers = {}
        self._peered_with_us = {}
        self.inbound_queue = queue.Queue()
        self.dispatcher_queue = queue.Queue()
        self._signature_condition = Condition()
        self._dispatcher_condition = Condition()
        self._futures = future.FutureCollection()
        self._send_receive_thread = _ServerSendReceiveThread(
            endpoint, self._handlers, self._futures, self._put_on_inbound)

        self._send_receive_thread.daemon = True

        self._signature_verifier = SignatureVerifier(
            self.inbound_queue, self.dispatcher_queue,
            self._signature_condition, self._dispatcher_condition,
            self.broadcast_message)
        self._dispatcher.set_incoming_msg_queue(self.dispatcher_queue)
        self._dispatcher.set_condition(self._dispatcher_condition)
        self.add_handler(validator_pb2.Message.DEFAULT, DefaultHandler())
        self.add_handler(validator_pb2.Message.GOSSIP_REGISTER,
                         PeerRegisterHandler(self))
        self.add_handler(validator_pb2.Message.GOSSIP_UNREGISTER,
                         PeerUnregisterHandler(self))
        self.add_handler(validator_pb2.Message.GOSSIP_MESSAGE,
                         GossipMessageHandler(self._put_on_inbound))
        self.start()
        self._dispatcher.start()

        if peer_list is not None:
            for peer in peer_list:
                self._send_receive_thread.add_connection(self._identity, peer)
Пример #2
0
    def __init__(self, url):
        self._handlers = {}
        self._processors = processor_iterator.ProcessorIteratorCollection(
            processor_iterator.RoundRobinProcessorIterator)

        self._futures = future.FutureCollection()
        self._send_receive_thread = _SendReceiveThread(url, self._handlers,
                                                       self._futures)
Пример #3
0
    def __init__(self, url, ingest_message_func):
        self._url = url
        self._futures = future.FutureCollection()
        self._handlers = {}

        self.add_handler(validator_pb2.Message.DEFAULT, DefaultHandler())
        self.add_handler(validator_pb2.Message.GOSSIP_MESSAGE,
                         GossipMessageHandler(ingest_message_func))
        self.add_handler(validator_pb2.Message.GOSSIP_PING, PingHandler(self))

        self._send_receive_thread = _ClientSendReceiveThread(
            url, self._handlers, self._futures)

        self._send_receive_thread.daemon = True
        self._send_receive_thread.start()
Пример #4
0
    def __init__(self, url, ingest_message_func):
        self._url = url
        self._futures = future.FutureCollection()
        self._handlers = {}

        self.add_handler('default', DefaultHandler())
        self.add_handler('gossip/msg',
                         GossipMessageHandler(ingest_message_func))
        self.add_handler('gossip/ping', PingHandler(self))

        self._send_receive_thread = _ClientSendReceiveThread(
            url, self._handlers, self._futures)

        self._send_receive_thread.daemon = True
        self._send_receive_thread.start()
Пример #5
0
    def __init__(self, identity, endpoint, peer_list, dispatcher):
        LOGGER.debug("Initializing Network service")
        self._identity = identity
        self._dispatcher = dispatcher
        self._handlers = {}
        self._peered_with_us = {}
        self.inbound_queue = queue.Queue()
        self._futures = future.FutureCollection()
        self._send_receive_thread = _ServerSendReceiveThread(endpoint,
                                                             self._handlers,
                                                             self._futures)

        self._send_receive_thread.daemon = True
        self.add_handler('default', DefaultHandler())
        self.add_handler('gossip/register',
                         PeerRegisterHandler(self))
        self.add_handler('gossip/unregister',
                         PeerUnregisterHandler(self))
        self.add_handler('gossip/msg',
                         GossipMessageHandler(self))
        self.start()

        if peer_list is not None:
            for peer in peer_list:
                self._send_receive_thread.add_connection(self._identity, peer)

            LOGGER.info("Sleeping 5 seconds and then broadcasting messages "
                        "to connected peers")
            time.sleep(5)

            content = GossipMessage(content=bytes(
                str("This is a gossip payload"), 'UTF-8')).SerializeToString()

            for _ in range(1000):
                message = validator_pb2.Message(
                    message_type=b'gossip/msg',
                    correlation_id=_generate_id(),
                    content=content)

                self.broadcast_message(message)

                # If we transmit as fast as possible, we populate the
                # buffers and get faster throughput but worse avg. message
                # latency. If we sleep here or otherwise throttle input,
                # the overall duration is longer, but the per message
                # latency is low. The process is CPU bound on Vagrant VM
                # core at ~0.001-0.01 duration sleeps.
                time.sleep(0.01)
Пример #6
0
 def __init__(self):
     self._handlers = {}
     self._send_queues = {}
     self._processors = {}
     self._futures = future.FutureCollection()