Exemple #1
0
    def startService(self):
        service.Service.startService(self)
        self.print_version()
        log.debug("broker init")

        self.storage = storage.__dict__[self.config['broker']['storage'][0]](
            *self.config['broker']['storage'][1:])
        self.usercache = usercache.__dict__[
            self.config['broker']['usercache'][0]](
                *self.config['broker']['usercache'][1:])

        # estabilish a connection to the database
        self.db = database.connect_config(self.config)
        # datasource it will not be used if not needed
        self.storage.set_datasource(self.db)
        self.usercache.set_datasource(self.db)

        # setup keyring
        sdb = database.servers(self.db)
        self.keyring = keyring.Keyring(sdb, self.fingerprint)

        # create push notifications manager
        if self.config['server']['push_notifications']:
            log.debug("enabling push notifications support")
            from push_notifications import PushNotifications
            self.push_manager = PushNotifications(self.config, self.db)

        # create listening service for clients
        factory = InternalServerFactory(C2SServerProtocol, C2SChannel, self,
                                        self.config)
        c2s_service = internet.TCPServer(
            port=self.config['server']['c2s.bind'][1],
            factory=factory,
            interface=self.config['server']['c2s.bind'][0])
        c2s_service.setServiceParent(self.parent)

        # create listening service for servers (messages only)
        factory = InternalServerFactory(S2SMessageServerProtocol,
                                        S2SMessageChannel, self, self.config)
        s2s_service = internet.TCPServer(
            port=self.config['server']['s2s.bind'][1],
            factory=factory,
            interface=self.config['server']['s2s.bind'][0])
        s2s_service.setServiceParent(self.parent)

        # create listening service for servers (notifications and requests)
        protocol = S2SRequestServerProtocol(self.config)
        self.network = S2SRequestChannel(protocol, self)
        s2s_service = internet.UDPServer(
            port=self.config['server']['s2s.bind'][1],
            protocol=protocol,
            interface=self.config['server']['s2s.bind'][0])
        s2s_service.setServiceParent(self.parent)

        if self.push_manager:
            self._push_init()

        # old usercache entries purger
        self._loop(self.config['broker']['usercache_purger.delay'],
                   self._purge_usercache)
        # expired/unknown messages purger
        self._loop(self.config['broker']['message_purger.delay'],
                   self._purge_messages, True)
        # old validations entries purger
        self._loop(self.config['broker']['validations.expire'],
                   self._purge_validations, True)