Esempio n. 1
0
 def _CH_discover(self, command):
     notification_center = NotificationCenter()
     settings = SIPSimpleSettings()
     if self._discover_timer is not None and self._discover_timer.active():
         self._discover_timer.cancel()
     self._discover_timer = None
     supported_transports = set(transport for transport in settings.sip.transport_list if transport!='tls' or self.account.tls.certificate is not None)
     discoverable_transports = set('tcp' if transport=='tls' else transport for transport in supported_transports)
     old_files = []
     for file in (f for f in self._files[:] if isinstance(f, (BonjourDiscoveryFile, BonjourResolutionFile)) and f.transport not in discoverable_transports):
         old_files.append(file)
         self._files.remove(file)
     self._select_proc.kill(RestartSelect)
     for file in old_files:
         file.close()
     for service_description in [service for service, record in self._neighbours.iteritems() if record.uri.transport not in supported_transports]:
         record = self._neighbours.pop(service_description)
         notification_center.post_notification('BonjourAccountDidRemoveNeighbour', sender=self.account, data=NotificationData(neighbour=service_description, record=record))
     discovered_transports = set(file.transport for file in self._files if isinstance(file, BonjourDiscoveryFile))
     missing_transports = discoverable_transports - discovered_transports
     added_transports = set()
     for transport in missing_transports:
         notification_center.post_notification('BonjourAccountWillInitiateDiscovery', sender=self.account, data=NotificationData(transport=transport))
         try:
             file = _bonjour.DNSServiceBrowse(regtype="_sipuri._%s" % transport, callBack=self._browse_cb)
         except _bonjour.BonjourError, e:
             notification_center.post_notification('BonjourAccountDiscoveryDidFail', sender=self.account, data=NotificationData(reason=str(e), transport=transport))
         else:
             self._files.append(BonjourDiscoveryFile(file, transport))
             added_transports.add(transport)
Esempio n. 2
0
 def _CH_discover(self, command):
     notification_center = NotificationCenter()
     settings = SIPSimpleSettings()
     if self._discover_timer is not None and self._discover_timer.active():
         self._discover_timer.cancel()
     self._discover_timer = None
     account = BonjourAccount()
     supported_transports = set(transport for transport in settings.sip.transport_list if transport!='tls' or account.tls.certificate is not None)
     discoverable_transports = set('tcp' if transport=='tls' else transport for transport in supported_transports)
     old_files = []
     for file in (f for f in self._files[:] if isinstance(f, (BonjourDiscoveryFile, BonjourResolutionFile)) and f.transport not in discoverable_transports):
         old_files.append(file)
         self._files.remove(file)
     self._select_proc.kill(RestartSelect)
     for file in old_files:
         file.close()
     for service_description in [service for service, description in self._servers.items() if description.uri.transport not in supported_transports]:
         del self._servers[service_description]
         notification_center.post_notification('BonjourConferenceServicesDidRemoveServer', sender=self, data=NotificationData(server=service_description))
     discovered_transports = set(file.transport for file in self._files if isinstance(file, BonjourDiscoveryFile))
     missing_transports = discoverable_transports - discovered_transports
     added_transports = set()
     for transport in missing_transports:
         notification_center.post_notification('BonjourConferenceServicesWillInitiateDiscovery', sender=self, data=NotificationData(transport=transport))
         try:
             file = _bonjour.DNSServiceBrowse(regtype="_sipfocus._%s" % transport, callBack=self._browse_cb)
         except _bonjour.BonjourError as e:
             notification_center.post_notification('BonjourConferenceServicesDiscoveryDidFail', sender=self, data=NotificationData(reason=str(e), transport=transport))
         else:
             self._files.append(BonjourDiscoveryFile(file, transport))
             added_transports.add(transport)
     if added_transports:
         self._select_proc.kill(RestartSelect)
     if added_transports != missing_transports:
         self._discover_timer = reactor.callLater(1, self._command_channel.send, Command('discover', command.event))
     else:
         command.signal()