source: wokkel/componentservertap.py @ 99:2c8dc93fbef4

Last change on this file since 99:2c8dc93fbef4 was 96:8e6130587088, checked in by Ralph Meijer <ralphm@…>, 11 years ago

Remove copyright dates from individual source files, only update LICENSE.

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