| Trees | Indices | Help |
|
|---|
|
|
1 """
2 Contains classes for transmitting and receiving python objects over the network.
3
4 Copyright: John Stowers, 2006
5 License: GPLv2
6 """
7 import logging
8 log = logging.getLogger("modules.Network")
9
10 import Peers
11 import XMLRPCUtils
12
13 import conduit
14 import conduit.dataproviders.DataProvider as DataProvider
15
16 from gettext import gettext as _
17
18 SERVER_PORT = 3400
19
21 """
22 Controlls all network related communication aspects. This involves
23 1) Advertising dataprovider presence on local network using avahi
24 2) Discovering remote conduit capabilities (i.e. what dataproviders it has advertised)
25 3) Data transmission to/from remote conduit instances
26 """
28 DataProvider.DataProviderFactory.__init__(self)
29
30 self.shared = {}
31 self.DP_PORT = 3401
32
33 # Initiate Avahi stuff & announce our presence
34 try:
35 log.debug("Starting AvahiAdvertiser server")
36 self.advertiser = Peers.AvahiAdvertiser("_conduit.tcp", SERVER_PORT)
37 self.advertiser.announce()
38
39 #Start the server which anounces other shared servers
40 self.peerAnnouncer = XMLRPCUtils.StoppableXMLRPCServer('',SERVER_PORT)
41 self.peerAnnouncer.register_function(self.list_shared_dataproviders)
42 self.peerAnnouncer.start()
43
44 #FIXME: Only show the endpoint if the server was started.
45 #self.emit_added(
46 # klass=NetworkEndpoint,
47 # initargs=(),
48 # category=conduit.dataproviders.CATEGORY_MISC
49 # )
50 except Exception, e:
51 self.peerAnnouncer = None
52 log.warn("Error starting AvahiAdvertiser server: %s" % e)
53
54 #watch the modulemanager for added conduits and syncsets
55 if conduit.GLOBALS.moduleManager != None:
56 conduit.GLOBALS.moduleManager.connect('syncset-added', self._syncset_added)
57 else:
58 log.warn("Could not start AvahiAdvertiser server, moduleManager not created yet")
59
61 syncset.connect("conduit-added", self._conduit_added)
62 syncset.connect("conduit-removed", self._conduit_removed)
63
65 cond.connect("dataprovider-added", self._dataprovider_added)
66 cond.connect("dataprovider-removed", self._dataprovider_removed)
67
71
92
94 sharedDpw,networkEndpoint = self._get_shared_dps(cond)
95 if sharedDpw != None:
96 if sharedDpw.get_UID() not in self.shared and sharedDpw.module != None:
97 #Update the network enpoint to have the same input and output
98 #types as the shared DP.
99 networkEndpoint.module.input_type = sharedDpw.module.get_input_type()
100 networkEndpoint.module.output_type = sharedDpw.module.get_output_type()
101 cond._parameters_changed()
102 self.share_dataprovider(sharedDpw)
103
105 if dpw.get_UID() in self.shared:
106 self.unshare_dataprovider(dpw)
107 cond._parameters_changed()
108
114
116 #stop all the xmlrpc servers
117 for server in self.shared.values():
118 server.stop()
119
120 if self.peerAnnouncer != None:
121 self.peerAnnouncer.stop()
122
132
141
143 """
144 Simple class used for detecting when a user connects
145 another dataprovider to this one, symbolising a network sync
146 """
147 _name_ = _("Network")
148 _description_ = _("Enable synchronization via network")
149 _category_ = conduit.dataproviders.CATEGORY_MISC
150