Esempio n. 1
0
    def __init__(self, event_reactor, dht_network, kvp_table, fn_task_slot):
        '''
        :type event_reactor: :class:`.EventReactor
        :type dht_network: :class:`.DHTNetwork`
        :type kvp_table: :class:`.KVPTable`
        :param fn_task_slot: A slot that represents uploads.
        :type fn_task_slot: :class:`FnTaskSlot`
        '''

        EventReactorMixin.__init__(self, event_reactor)
        self._dht_network = dht_network
        self._kvp_table = kvp_table
        self._event_scheduler = EventScheduler(event_reactor)
        self._timer_id = EventID(self, 'Publish timer')
        self._schedule_id = EventID(self, 'Publish schedule')
        self._scheduled_kvpids = set()
        self._schedule_lock = threading.Lock()
        self._scan_event = threading.Event()
        self._publish_queue = BigDiskQueue()
        self._fn_task_slot = fn_task_slot

        self._event_reactor.register_handler(self._schedule_id,
            self._publish_cb)
        self._event_reactor.register_handler(self._timer_id, self._timer_cb)
        self._kvp_table.value_changed_observer.register(self._table_change_cb)

        self._event_scheduler.add_periodic(Publisher.REPUBLISH_CHECK_INTERVAL,
            self._timer_cb)

        self._scan_loop()
        self._publish_loop()
Esempio n. 2
0
    def __init__(self, event_reactor, kvp_table, node_id=None, network=None,
    download_slot=None):
        '''Init

        :Parameters:
            event_reactor : :class:`.EventReactor`
                The Event Reactor
            kvp_table : :class:`.KVPTable`
                The storage
            node_id : :class:`.KeyBytes`
                A key to be used as the node id.
        '''

        EventReactorMixin.__init__(self, event_reactor)
        self._network = network or Network(event_reactor)
        self._network.receive_callback = self._receive_callback
        self._routing_table = RoutingTable()
        self._key = node_id or KeyBytes()
        self._pool_executor = WrappedThreadPoolExecutor(
            Network.DEFAULT_POOL_SIZE / 2, event_reactor)
        self._kvp_table = kvp_table
        self._event_scheduler = EventScheduler(event_reactor)
        self._refresh_timer_id = EventID(self, 'Refresh')
        self._download_slot = download_slot or FnTaskSlot()

        self._setup_timers()
Esempio n. 3
0
 def __init__(self, event_reactor, address=('127.0.0.1', 0)):
     EventReactorMixin.__init__(self, event_reactor)
     Thread.__init__(self)
     self.name = 'network-udp-server'
     self.daemon = True
     socketserver.UDPServer.__init__(self, address, UDPRequestHandler)
     self.event_reactor.register_handler(EventReactor.STOP_ID,
         self._stop_cb)
     self._running = True
Esempio n. 4
0
    def __init__(self, event_reactor, address=('127.0.0.1', 0)):
        EventReactorMixin.__init__(self, event_reactor)
        self._server = UDPServer(event_reactor, address=address)
        # By passing in the same socket object to the client, this method
        # allows other nodes to reply to our server's port.
        self._client = UDPClient(socket_obj=self._server.socket)
        self._reply_table = ReplyTable()
        self._downloads = {}
        self._pool_executor = WrappedThreadPoolExecutor(
            Network.DEFAULT_POOL_SIZE, event_reactor)
        self._event_scheduler = EventScheduler(event_reactor)
        self._transfer_timer_id = EventID(self, 'Clean transfers')
        self._running = True

        self._register_handlers()
        self._server.start()
Esempio n. 5
0
    def __init__(self, event_reactor, dht_network, kvp_table, fn_task_slot):
        '''
        :type event_reactor: :class:`.EventReactor
        :type dht_network: :class:`.DHTNetwork`
        :type kvp_table: :class:`.KVPTable`
        :param fn_task_slot: A slot that represents uploads.
        :type fn_task_slot: :class:`FnTaskSlot`
        '''

        EventReactorMixin.__init__(self, event_reactor)
        self._dht_network = dht_network
        self._kvp_table = kvp_table
        self._event_scheduler = EventScheduler(event_reactor)
        self._timer_id = EventID(self, 'Replicate')
        self._thread_event = threading.Event()
        self._fn_task_slot = fn_task_slot

        self._event_reactor.register_handler(self._timer_id, self._timer_cb)
        self._event_scheduler.add_periodic(DHTNetwork.TIME_REPLICATE,
            self._timer_id)
        self._loop()
Esempio n. 6
0
 def __init__(self, event_reactor, config_dir, dht_network, download_slot):
     EventReactorMixin.__init__(self, event_reactor)