Beispiel #1
0
 def get_acceptor(self):
     if self.server_relay is not None:
         return RelayConnection(self.server_relay,
                                'passive',
                                logger=self.client_logger)
     else:
         return DirectAcceptor(logger=self.server_logger)
Beispiel #2
0
 def get_connector(self):
     if self.client_relay is not None:
         return RelayConnection(self.client_relay,
                                'active',
                                logger=self.client_logger)
     else:
         return DirectConnector(logger=self.client_logger)
 def initialize(self, session, direction):
     self.greenlet = api.getcurrent()
     notification_center = NotificationCenter()
     notification_center.add_observer(self, sender=self)
     try:
         self.session = session
         self.transport = self.session.account.msrp.transport
         outgoing = direction == 'outgoing'
         logger = NotificationProxyLogger()
         if self.session.account is BonjourAccount():
             if outgoing:
                 self.msrp_connector = DirectConnector(logger=logger)
                 self.local_role = 'active'
             else:
                 if self.transport == 'tls' and None in (
                         self.session.account.tls_credentials.cert,
                         self.session.account.tls_credentials.key):
                     raise MSRPStreamError(
                         "Cannot accept MSRP connection without a TLS certificate"
                     )
                 self.msrp_connector = DirectAcceptor(logger=logger)
                 self.local_role = 'passive'
         else:
             if self.session.account.msrp.connection_model == 'relay':
                 if not outgoing and self.remote_role in ('actpass',
                                                          'passive'):
                     # 'passive' not allowed by the RFC but play nice for interoperability. -Saul
                     self.msrp_connector = DirectConnector(
                         logger=logger, use_sessmatch=True)
                     self.local_role = 'active'
                 elif outgoing and not self.session.account.nat_traversal.use_msrp_relay_for_outbound:
                     self.msrp_connector = DirectConnector(
                         logger=logger, use_sessmatch=True)
                     self.local_role = 'active'
                 else:
                     if self.session.account.nat_traversal.msrp_relay is None:
                         relay_host = relay_port = None
                     else:
                         if self.transport != self.session.account.nat_traversal.msrp_relay.transport:
                             raise MSRPStreamError(
                                 "MSRP relay transport conflicts with MSRP transport setting"
                             )
                         relay_host = self.session.account.nat_traversal.msrp_relay.host
                         relay_port = self.session.account.nat_traversal.msrp_relay.port
                     relay = MSRPRelaySettings(
                         domain=self.session.account.uri.host.decode(),
                         username=self.session.account.uri.user.decode(),
                         password=self.session.account.credentials.password.
                         decode(),
                         host=relay_host,
                         port=relay_port,
                         use_tls=self.transport == 'tls')
                     self.msrp_connector = RelayConnection(
                         relay,
                         'passive',
                         logger=logger,
                         use_sessmatch=True)
                     self.local_role = 'actpass' if outgoing else 'passive'
             else:
                 if not outgoing and self.remote_role in ('actpass',
                                                          'passive'):
                     # 'passive' not allowed by the RFC but play nice for interoperability. -Saul
                     self.msrp_connector = DirectConnector(
                         logger=logger, use_sessmatch=True)
                     self.local_role = 'active'
                 else:
                     if not outgoing and self.transport == 'tls' and None in (
                             self.session.account.tls_credentials.cert,
                             self.session.account.tls_credentials.key):
                         raise MSRPStreamError(
                             "Cannot accept MSRP connection without a TLS certificate"
                         )
                     self.msrp_connector = DirectAcceptor(
                         logger=logger, use_sessmatch=True)
                     self.local_role = 'actpass' if outgoing else 'passive'
         full_local_path = self.msrp_connector.prepare(local_uri=URI(
             host=host.default_ip,
             port=0,
             use_tls=self.transport == 'tls',
             credentials=self.session.account.tls_credentials))
         self.local_media = self._create_local_media(full_local_path)
     except (CertificateError, CertificateAuthorityError,
             CertificateExpiredError, CertificateSecurityError,
             CertificateRevokedError) as e:
         reason = "%s for %s" % (e.error, e.certificate.subject.CN.lower())
         notification_center.post_notification(
             'MediaStreamDidNotInitialize',
             sender=self,
             data=NotificationData(reason=reason))
     except Exception as e:
         notification_center.post_notification(
             'MediaStreamDidNotInitialize',
             sender=self,
             data=NotificationData(reason=str(e)))
     else:
         notification_center.post_notification('MediaStreamDidInitialize',
                                               sender=self)
     finally:
         self._initialize_done = True
         self.greenlet = None