def disconnect(self, do_callback=True): self.remove_bosh_wait_timeout() if self.get_state() == DISCONNECTED: return self.fd = -1 for s in self.http_socks: s.disconnect(do_callback=False) NonBlockingTransport.disconnect(self, do_callback)
def __init__(self, raise_event, on_disconnect, idlequeue, estabilish_tls, certs, xmpp_server, domain, bosh_dict, proxy_creds): NonBlockingTransport.__init__(self, raise_event, on_disconnect, idlequeue, estabilish_tls, certs) self.bosh_sid = None if locale.getdefaultlocale()[0]: self.bosh_xml_lang = locale.getdefaultlocale()[0].split('_')[0] else: self.bosh_xml_lang = 'en' self.http_version = 'HTTP/1.1' self.http_persistent = True self.http_pipelining = bosh_dict['bosh_http_pipelining'] self.bosh_to = domain self.route_host, self.route_port = xmpp_server self.bosh_wait = bosh_dict['bosh_wait'] if not self.http_pipelining: self.bosh_hold = 1 else: self.bosh_hold = bosh_dict['bosh_hold'] self.bosh_requests = self.bosh_hold self.bosh_uri = bosh_dict['bosh_uri'] self.bosh_content = bosh_dict['bosh_content'] self.over_proxy = bosh_dict['bosh_useproxy'] if estabilish_tls: self.bosh_secure = 'true' else: self.bosh_secure = 'false' self.use_proxy_auth = bosh_dict['useauth'] self.proxy_creds = proxy_creds self.wait_cb_time = None self.http_socks = [] self.stanza_buffer = [] self.prio_bosh_stanzas = [] self.current_recv_handler = None self.current_recv_socket = None self.key_stack = None self.ack_checker = None self.after_init = False self.proxy_dict = {} if self.over_proxy and self.estabilish_tls: self.proxy_dict['type'] = 'http' # with SSL over proxy, we do HTTP CONNECT to proxy to open a channel to # BOSH Connection Manager host, port = urisplit(self.bosh_uri)[1:3] self.proxy_dict['xmpp_server'] = (host, port) self.proxy_dict['credentials'] = self.proxy_creds
def connect(self, conn_5tuple, on_connect, on_connect_failure): NonBlockingTransport.connect(self, conn_5tuple, on_connect, on_connect_failure) global FAKE_DESCRIPTOR FAKE_DESCRIPTOR = FAKE_DESCRIPTOR - 1 self.fd = FAKE_DESCRIPTOR self.stanza_buffer = [] self.prio_bosh_stanzas = [] self.key_stack = KeyStack(KEY_COUNT) self.ack_checker = AckChecker() self.after_init = True self.http_socks.append(self.get_new_http_socket()) self._tcp_connecting_started() self.http_socks[0].connect( conn_5tuple = conn_5tuple, on_connect = self._on_connect, on_connect_failure = self._on_connect_failure)
def start_disconnect(self): NonBlockingTransport.start_disconnect(self) self.renew_bosh_wait_timeout(DISCONNECT_TIMEOUT_SECONDS) self.send_BOSH( (BOSHBody(attrs={'sid': self.bosh_sid, 'type': 'terminate'}), True))
def set_timeout(self, timeout): if self.get_state() != DISCONNECTED and self.fd != -1: NonBlockingTransport.set_timeout(self, timeout) else: log.warn('set_timeout: TIMEOUT NOT SET: state is %s, fd is %s' % (self.get_state(), self.fd))
def _on_connect(self): self.peerhost = self.http_socks[0].peerhost self.ssl_lib = self.http_socks[0].ssl_lib NonBlockingTransport._on_connect(self)