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
def get_client_uri(self): return URI(use_tls=self.use_tls)
def get_server_uri(self): return URI(port=0, use_tls=self.use_tls, credentials=self.server_credentials)
# Copyright (C) 2008-2009 AG Projects. See LICENSE for details. # import sys from eventlib import proc from msrplib.connect import AcceptorDirect from msrplib.protocol import URI from msrplib.trafficlog import Logger from msrplib.session import GreenMSRPSession from twisted.internet import reactor # let eventlib know we want twisted-based hub local_uri = URI(session_id='server', use_tls=False) remote_uri = URI(session_id='client', use_tls=False) connector = AcceptorDirect(logger=Logger()) connector.prepare(local_uri) transport = connector.complete([remote_uri]) session = GreenMSRPSession(transport) session.send_message('hello', 'text/plain') print 'received: %s' % session.receive_chunk().data session.shutdown()