source: wokkel/componentservertap.py @ 241:8b70aa92733d

Last change on this file since 241:8b70aa92733d was 209:1f9f603586ad, checked in by Ralph Meijer <ralphm@…>, 6 years ago

imported patch py3-imports.patch

  • Property exe set to *
File size: 2.3 KB
Line 
1# Copyright (c) Ralph Meijer.
2# See LICENSE for details.
3
4"""
5XMPP Component Service.
6
7This provides an XMPP server that accepts External Components connections
8and accepts and initiates server-to-server connections for the specified
9domain(s).
10"""
11
12from __future__ import division, absolute_import
13
14from twisted.application import service, strports
15from twisted.python import usage
16from twisted.words.protocols.jabber import component
17from wokkel import server
18
19class Options(usage.Options):
20
21    optParameters = [
22            ('component-port', None, 'tcp:5347:interface=127.0.0.1',
23                'Port components connect to'),
24            ('component-secret', None, 'secret',
25                'Secret components use to connect'),
26            ('server-port', None, 'tcp:5269',
27                'Port other servers connect to'),
28            ('server-secret', None, None,
29                'Shared secret for dialback verification'),
30    ]
31
32    optFlags = [
33            ('verbose', 'v', 'Log traffic'),
34    ]
35
36    def __init__(self):
37        usage.Options.__init__(self)
38        self['domains'] = set()
39
40
41    def opt_domain(self, domain):
42        """
43        Domain to accept server connections for. Repeat for more domains.
44        """
45        self['domains'].add(domain)
46
47
48    def postOptions(self):
49        if not self['domains']:
50            raise usage.UsageError('Need at least one domain')
51
52
53
54def makeService(config):
55    s = service.MultiService()
56
57    router = component.Router()
58
59    # Set up the XMPP server service
60
61    serverService = server.ServerService(router, secret=config['server-secret'])
62    serverService.domains = config['domains']
63    serverService.logTraffic = config['verbose']
64
65    # Hook up XMPP server-to-server service
66    s2sFactory = server.XMPPS2SServerFactory(serverService)
67    s2sFactory.logTraffic = config['verbose']
68    s2sService = strports.service(config['server-port'], s2sFactory)
69    s2sService.setServiceParent(s)
70
71    # Hook up XMPP external server-side component service
72    cFactory = component.XMPPComponentServerFactory(router,
73                                                    config['component-secret'])
74
75    cFactory.logTraffic = config['verbose']
76    cServer = strports.service(config['component-port'], cFactory)
77    cServer.setServiceParent(s)
78
79    return s
Note: See TracBrowser for help on using the repository browser.