Mercurial > libervia-pubsub
comparison sat_pubsub/tap.py @ 232:923281d4c5bc
renamed idavoll directory to sat_pubsub
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 17 May 2012 12:48:14 +0200 |
parents | idavoll/tap.py@8540825f85e0 |
children | 564ae55219e1 |
comparison
equal
deleted
inserted
replaced
231:d99047cd90f9 | 232:923281d4c5bc |
---|---|
1 # Copyright (c) 2003-2010 Ralph Meijer | |
2 # See LICENSE for details. | |
3 | |
4 from twisted.application import service | |
5 from twisted.python import usage | |
6 from twisted.words.protocols.jabber.jid import JID | |
7 | |
8 from wokkel.component import Component | |
9 from wokkel.disco import DiscoHandler | |
10 from wokkel.generic import FallbackHandler, VersionHandler | |
11 from wokkel.iwokkel import IPubSubResource | |
12 from wokkel.pubsub import PubSubService | |
13 | |
14 from idavoll import __version__ | |
15 from idavoll.backend import BackendService | |
16 | |
17 class Options(usage.Options): | |
18 optParameters = [ | |
19 ('jid', None, 'pubsub', 'JID this component will be available at'), | |
20 ('secret', None, 'secret', 'Jabber server component secret'), | |
21 ('rhost', None, '127.0.0.1', 'Jabber server host'), | |
22 ('rport', None, '5347', 'Jabber server port'), | |
23 ('backend', None, 'memory', 'Choice of storage backend'), | |
24 ('dbuser', None, None, 'Database user (pgsql backend)'), | |
25 ('dbname', None, 'pubsub', 'Database name (pgsql backend)'), | |
26 ('dbpass', None, None, 'Database password (pgsql backend)'), | |
27 ('dbhost', None, None, 'Database host (pgsql backend)'), | |
28 ('dbport', None, None, 'Database port (pgsql backend)'), | |
29 ] | |
30 | |
31 optFlags = [ | |
32 ('verbose', 'v', 'Show traffic'), | |
33 ('hide-nodes', None, 'Hide all nodes for disco') | |
34 ] | |
35 | |
36 def postOptions(self): | |
37 if self['backend'] not in ['pgsql', 'memory']: | |
38 raise usage.UsageError, "Unknown backend!" | |
39 | |
40 self['jid'] = JID(self['jid']) | |
41 | |
42 | |
43 | |
44 def makeService(config): | |
45 s = service.MultiService() | |
46 | |
47 # Create backend service with storage | |
48 | |
49 if config['backend'] == 'pgsql': | |
50 from twisted.enterprise import adbapi | |
51 from idavoll.pgsql_storage import Storage | |
52 dbpool = adbapi.ConnectionPool('psycopg2', | |
53 user=config['dbuser'], | |
54 password=config['dbpass'], | |
55 database=config['dbname'], | |
56 host=config['dbhost'], | |
57 port=config['dbport'], | |
58 cp_reconnect=True, | |
59 client_encoding='utf-8', | |
60 ) | |
61 st = Storage(dbpool) | |
62 elif config['backend'] == 'memory': | |
63 from idavoll.memory_storage import Storage | |
64 st = Storage() | |
65 | |
66 bs = BackendService(st) | |
67 bs.setName('backend') | |
68 bs.setServiceParent(s) | |
69 | |
70 # Set up XMPP server-side component with publish-subscribe capabilities | |
71 | |
72 cs = Component(config["rhost"], int(config["rport"]), | |
73 config["jid"].full(), config["secret"]) | |
74 cs.setName('component') | |
75 cs.setServiceParent(s) | |
76 | |
77 cs.factory.maxDelay = 900 | |
78 | |
79 if config["verbose"]: | |
80 cs.logTraffic = True | |
81 | |
82 FallbackHandler().setHandlerParent(cs) | |
83 VersionHandler('Idavoll', __version__).setHandlerParent(cs) | |
84 DiscoHandler().setHandlerParent(cs) | |
85 | |
86 resource = IPubSubResource(bs) | |
87 resource.hideNodes = config["hide-nodes"] | |
88 resource.serviceJID = config["jid"] | |
89 | |
90 ps = PubSubService(resource) | |
91 ps.setHandlerParent(cs) | |
92 resource.pubsubService = ps | |
93 | |
94 return s |