def addRoute(self, destination, xs): """ Add a new route. The passed XML Stream C{xs} will have an observer for all stanzas added to route its outgoing traffic. In turn, traffic for C{destination} will be passed to this stream. @param destination: Destination of the route to be added as a host name or C{None} for the default route. @type destination: C{str} or C{NoneType}. @param xs: XML Stream to register the route for. @type xs: L{EventDispatcher<utility.EventDispatcher>}. """ stanza = Presence() stanza['from'] = destination log.info("adversiting component %s" % (destination, )) self.broadcast(stanza) # advertise this component about the others stanza = Presence() stanza['to'] = destination for host in self.routes.iterkeys(): if host is not None: stanza['from'] = host xs.send(stanza) # add route and observers self.routes[destination] = xs xs.addObserver('/bind', self.bind, 100, xs = xs) xs.addObserver('/unbind', self.unbind, 100, xs = xs) xs.addObserver('/*', self.route, xs = xs)
def addRoute(self, destination, xs): """ Add a new route. The passed XML Stream C{xs} will have an observer for all stanzas added to route its outgoing traffic. In turn, traffic for C{destination} will be passed to this stream. @param destination: Destination of the route to be added as a host name or C{None} for the default route. @type destination: C{str} or C{NoneType}. @param xs: XML Stream to register the route for. @type xs: L{EventDispatcher<utility.EventDispatcher>}. """ stanza = Presence() stanza['from'] = destination log.info("adversiting component %s" % (destination, )) self.broadcast(stanza) # advertise this component about the others stanza = Presence() stanza['to'] = destination for host in self.routes.iterkeys(): if host is not None: stanza['from'] = host xs.send(stanza) # add route and observers self.routes[destination] = xs xs.addObserver('/bind', self.bind, 100, xs=xs) xs.addObserver('/unbind', self.unbind, 100, xs=xs) xs.addObserver('/*', self.route, xs=xs)
def startService(self): component.Component.startService(self) resolver.ResolverMixIn.startService(self) # register the registration provider if configured if 'registration' in self.config: from kontalk.xmppserver import register provider = self.config['registration']['provider'] try: prov_class = register.providers[provider] self.registration = prov_class(self, self.config['registration']) except: log.warn(traceback.format_exc()) if self.registration: log.info("using registration provider %s (type=%s)" % (self.registration.name, self.registration.type)) else: log.info("disabling registration") # register push notifications providers if configured if 'push' in self.config: from kontalk.xmppserver import push self.push_manager = push.PushManager(self, self.config['push']) if self.push_manager: log.info("using push notifications providers: %s" % (', '.join(self.push_manager.providers.keys()))) else: log.info("disabling push notifictions") # load local presence data d = self.presencedb.get_all() d.addCallback(self._presence_data)
def removeRoute(self, destination, xs): # remove route immediately # we assume component is disconnecting so we don't remove observers component.Router.removeRoute(self, destination, xs) # remove other bound names for host in list(self.routes.keys()): if self.routes[host] == xs: del self.routes[host] # remove log route if any self.logs.discard(xs) stanza = UnavailablePresence() stanza['from'] = destination log.info("unadvertising component %s" % (stanza['from'],)) self.broadcast(stanza)
def removeRoute(self, destination, xs): # remove route immediately # we assume component is disconnecting so we don't remove observers component.Router.removeRoute(self, destination, xs) # remove other bound names for host in list(self.routes.keys()): if self.routes[host] == xs: del self.routes[host] # remove log route if any self.logs.discard(xs) stanza = UnavailablePresence() stanza['from'] = destination log.info("unadvertising component %s" % (stanza['from'], )) self.broadcast(stanza)
def unadvertise(self, host, xs=None): stanza = UnavailablePresence() stanza['from'] = host log.info("unadvertising component %s" % (host, )) self.broadcast(stanza, xs=xs)
def unadvertise(self, host, xs=None): stanza = UnavailablePresence() stanza['from'] = host log.info("unadvertising component %s" % (host,)) self.broadcast(stanza, xs=xs)