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)
    def startService(self):
        service.Service.startService(self)
        if self.broker:
            # daemon mode - print init message
            log.debug("fileserver init")
            self.storage = self.broker.storage
            self.db = self.broker.db
            self.keyring = self.broker.keyring
        else:
            # standalone - print version
            self.print_version()
            # create storage and database connection on our own
            self.storage = storage.__dict__[self.config['broker']['storage'][0]](*self.config['broker']['storage'][1:])
            self.db = database.connect_config(self.config)
            self.storage.set_datasource(self.db)
            self.keyring = keyring.Keyring(database.servers(self.db), str(self.config['server']['fingerprint']))

        credFactory = utils.AuthKontalkTokenFactory(str(self.config['server']['fingerprint']), self.keyring)

        # setup upload endpoint
        portal = Portal(FileUploadRealm(self), [utils.AuthKontalkToken()])
        resource = HTTPAuthSessionWrapper(portal, [credFactory])
        self.putChild('upload', resource)

        # setup download endpoint
        portal = Portal(FileDownloadRealm(self), [utils.AuthKontalkToken()])
        resource = HTTPAuthSessionWrapper(portal, [credFactory])
        self.putChild('download', resource)

        # setup serverlist endpoint
        self.putChild('serverlist', ServerlistDownload(self))

        # create http service
        factory = server.Site(self)
        fs_service = internet.TCPServer(port=self.config['server']['fileserver.bind'][1],
            factory=factory, interface=self.config['server']['fileserver.bind'][0])
        fs_service.setServiceParent(self.parent)

        # old attachments entries purger
        self._loop(self.config['fileserver']['attachments_purger.delay'], self._purge_attachments, True)
Exemple #3
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)
 def __init__(self, fileserver):
     resource.Resource.__init__(self)
     self.servers = database.servers(fileserver.db)
     self.config = fileserver.config