Beispiel #1
0
def makeService(config):
    s = service.MultiService()

    # Create backend service with storage

    if config['backend'] == 'pgsql':
        from twisted.enterprise import adbapi
        from idavoll.pgsql_storage import Storage
        from psycopg2.extras import NamedTupleConnection
        dbpool = adbapi.ConnectionPool(
            'psycopg2',
            user=config['dbuser'],
            password=config['dbpass'],
            database=config['dbname'],
            host=config['dbhost'],
            port=config['dbport'],
            cp_reconnect=True,
            client_encoding='utf-8',
            connection_factory=NamedTupleConnection,
        )
        st = Storage(dbpool)
    elif config['backend'] == 'memory':
        from idavoll.memory_storage import Storage
        st = Storage()

    bs = BackendService(st)
    bs.setName('backend')
    bs.setServiceParent(s)

    # Set up XMPP server-side component with publish-subscribe capabilities

    cs = Component(config["rhost"], int(config["rport"]), config["jid"].full(),
                   config["secret"])
    cs.setName('component')
    cs.setServiceParent(s)

    cs.factory.maxDelay = 900

    if config["verbose"]:
        cs.logTraffic = True

    FallbackHandler().setHandlerParent(cs)
    VersionHandler('Idavoll', __version__).setHandlerParent(cs)
    DiscoHandler().setHandlerParent(cs)

    resource = IPubSubResource(bs)
    resource.hideNodes = config["hide-nodes"]
    resource.serviceJID = config["jid"]

    ps = PubSubService(resource)
    ps.setHandlerParent(cs)
    resource.pubsubService = ps

    return s
Beispiel #2
0
    def __init__(self):
        config = XMPPGatewayConfig

        self.stopped = False

        self.domains = set(config.domains)
        self.muc_domains = set(
            ['%s.%s' % (config.muc_prefix, domain) for domain in self.domains])

        router = SylkRouter()
        self._server_service = ServerService(router)
        self._server_service.domains = self.domains | self.muc_domains
        self._server_service.logTraffic = False  # done manually

        self._s2s_factory = SylkS2SServerFactory(self._server_service)
        self._s2s_factory.logTraffic = False  # done manually

        # Setup internal components

        self._internal_component = SylkInternalComponent(router)
        self._internal_component.domains = self.domains
        self._internal_component.manager = self
        self._muc_component = SylkInternalComponent(router)
        self._muc_component.domains = self.muc_domains
        self._muc_component.manager = self

        # Setup protocols

        self.message_protocol = MessageProtocol()
        self.message_protocol.setHandlerParent(self._internal_component)

        self.presence_protocol = PresenceProtocol()
        self.presence_protocol.setHandlerParent(self._internal_component)

        self.disco_protocol = DiscoProtocol()
        self.disco_protocol.setHandlerParent(self._internal_component)

        self.disco_client_protocol = DiscoClientProtocol()
        self.disco_client_protocol.setHandlerParent(self._internal_component)

        self.muc_protocol = MUCServerProtocol()
        self.muc_protocol.setHandlerParent(self._muc_component)

        self.muc_presence_protocol = MUCPresenceProtocol()
        self.muc_presence_protocol.setHandlerParent(self._muc_component)

        self.disco_muc_protocol = DiscoProtocol()
        self.disco_muc_protocol.setHandlerParent(self._muc_component)

        self.version_protocol = VersionHandler('SylkServer', SYLK_VERSION)
        self.version_protocol.setHandlerParent(self._internal_component)

        self.fallback_protocol = FallbackHandler()
        self.fallback_protocol.setHandlerParent(self._internal_component)

        self.fallback_muc_protocol = FallbackHandler()
        self.fallback_muc_protocol.setHandlerParent(self._muc_component)

        self.ping_protocol = PingHandler()
        self.ping_protocol.setHandlerParent(self._internal_component)

        self.jingle_protocol = JingleProtocol()
        self.jingle_protocol.setHandlerParent(self._internal_component)

        self.jingle_coin_protocol = JingleProtocol()
        self.jingle_coin_protocol.setHandlerParent(self._muc_component)

        self._s2s_listener = None

        self.chat_session_manager = XMPPChatSessionManager()
        self.muc_session_manager = XMPPMucSessionManager()
        self.subscription_manager = XMPPSubscriptionManager()
        self.jingle_session_manager = JingleSessionManager()