def added(self, rname, rhost, raddr, rport, rtxt, ahost): """ This is a callback for the BonjourServiceDiscovery. This is called when a new service is found. """ peerid = Peerid(str(rname)) proxy = ServiceProxy(peerid, str(rhost), str(raddr), int(rport), str(ahost)) reactor.callInThread(self.dispatchAdded, proxy, rtxt)
def removed(self, rname): """ This is a callback for the BonjourServiceDiscovery. This is called when a service is removed from the environment. """ peerid = Peerid(str(rname)) if peerid in self.proxys: proxy = self.proxys[peerid] proxy.alive = False reactor.callInThread(self.dispatchRemoved, proxy) del self.proxys[peerid]
def dispatchAnswer(self, root, msg): """ This method is intended to dispatch the answer for a query. """ if logger.isEnabledFor(logging.DEBUG): logger.debug("Query Answer") qid = Peerid(root.attrib['id']) if qid in self.deferred_answers[msg.peerid]: answer = self.deferred_answers[msg.peerid].pop(qid) answer.callback(root.getchildren()) else: if logger.isEnabledFor(logging.WARNING): logger.warning('UnRequested or TimedOut Answer : qid.%08.x' % qid)
def getConnectedPeers(self, cname): """ This method returns a list of connected peerid of the given connector name """ conn = self.connectors[cname] with self.supervisor: if logger.isEnabledFor(logging.DEBUG): logger.debug("Thread blocking function called") element = threads.blockingCallFromThread( reactor, self.control.query, REQUEST_CONTROL_QUERY % (conn.xml_type, cname), self.peerid)[0] el = element.find('peers') res = [Peerid(e.text) for e in el.findall('peer')] return res
def __set_peerid__(self, val): self.__peerid__ = Peerid(val)
def __set_peers__(self, value): if value in [None, '', 'None']: value = [] elif isinstance(value, dict): value = [Peerid(p['id']) for p in value['peer']] self.__peers__ = value
self.addr = addr def __get_tcp__(self): return self.__tcp__ def __set_tcp__(self, val): self.__tcp__ = None if val in [None, 'None'] else int(val) tcp = property(__get_tcp__, __set_tcp__) def __set_peerid__(self, val): self.__peerid__ = Peerid(val) def __get_peerid__(self): return self.__peerid__ peerid = property(__get_peerid__, __set_peerid__) peerId = peerid def __set_udp__(self, val): self.__udp__ = None if val in [None, 'None'] else int(val) def __get_udp__(self): return self.__udp__ udp = property(__get_udp__, __set_udp__) __unbound_control__ = ControlConnector() __unbound_control__.peerid = Peerid()