def handle_proxy_connect(self): log.info('handle_proxy_connect called') self.conn.set_terminator(0) #activate streamhost = self.streamhost sh_jid = streamhost.jid targ_jid = self.jid b = ByteStreams(None, self.sid) b.activate = targ_jid i = Iq(to_jid=sh_jid, stanza_type='set') b.as_xml(i.get_node()) self.j.send_cb(i, success=self.handle_proxy_activate, error=self.handle_proxy_failure2, timeout=self.proxy_activate_timeout)
def connect_stream(self): try: #protection against None stream self.hash = self.j.s5bserver.conn_id(self.sid, self.j.stream.me, self.jid) except AttributeError: self.event("stream_connect_failed") return self.j.s5bserver.add_hash(self.hash) i = Iq(to_jid=self.jid, stanza_type='set') b = ByteStreams(sid=self.sid) if pref('jabber.use_direct_ft'): if not pref('jabber.use_faulty_localhost_ips'): [ b.add_host(self.j.stream.me, h[0], h[1]) for h in self.j.s5bserver.hosts ] else: [ b.add_host(self.j.stream.me, h[0].replace("192", "129"), h[1]) for h in self.j.s5bserver.hosts ] if pref('jabber.use_proxy_ft'): b.hosts.extend( set(h for hosts in self.j.known_s5b_proxies.values() for h in hosts)) if pref('jabber.use_jabber_org_proxy', True): b.add_host("proxy.jabber.org", "208.245.212.98", 7777) b.as_xml(i.get_node()) self.j.send_cb(i, success=self.handle_ready, error=self.handle_error, timeout=self.timed_out)
def on_succ(self, num_tries_taken, sock): host_used = self.hosts_bytestreams.hosts[num_tries_taken-1].jid self.my_sock = sock i2 = Iq(to_jid=self.from_, stanza_type="result", stanza_id = self.respond_id) b = ByteStreams() b.host_used = JID(host_used) b.as_xml(i2.get_node()) self.my_sock.found_terminator = self.close self.my_sock.collect_incoming_data = self.collect_incoming_data self.my_sock.set_terminator(self.si_ft.file.size) self.my_sock.bind_event("socket_closed", self.closed) self.my_sock.bind_event("socket_error", self.stream_error) self.j.send(i2) self.log.info("S5BFileXferHandler connect succeeded to %s", host_used) self.event("stream_connected")
def handleSI(self, stanza): ''' someone wants to open a stream with us ''' print 'handleSI called' b = ByteStreams(stanza.get_query()) sid = b.sid try: s5b = self.d.pop(sid) except KeyError: return False else: s5b.accept_stream(b, stanza.get_from(), stanza.get_to(), stanza.get_id()) return True
def handle_ready(self, stanza): log.info(stanza.serialize()) try: b = ByteStreams(stanza.get_query()) used_jid = b.host_used except: #cleanup self.kill_socket_hash() self.event("stream_connect_failed") return #debug: if not pref('jabber.use_proxy_ft'): assert used_jid == self.j.stream.me if not pref('jabber.use_direct_ft'): assert used_jid != self.j.stream.me # assert used_jid != self.j.stream.me if used_jid == self.j.stream.me: self.conn = self.j.s5bserver.retrieve_hash(self.hash) if self.conn not in (False, None): self.socket_connected() self.event("stream_connected") else: self.event("stream_connect_failed") #cleanup? else: #cleanup socket server self.kill_socket_hash() hosts = set(h for hosts in self.j.known_s5b_proxies.values() for h in hosts) if not (used_jid in [h.jid for h in hosts]): self.event("stream_connect_failed") return streamhost = [h for h in hosts if h.jid == used_jid] if len(streamhost) != 1: self.event("stream_connect_failed") return self.streamhost = streamhost = streamhost[0] #start proxy here: #same as s5bsocket self.conn = S5B_proxyConnect((streamhost.host, streamhost.port), self.hash, streamhost) self.conn.bind_event("connected", self.handle_proxy_connect) self.conn.bind_event("connection_failed", self.socket_failed) self.conn.get_connect() log.info('handle_ready done')
def connect_stream(self): try: #protection against None stream self.hash = self.j.s5bserver.conn_id(self.sid, self.j.stream.me, self.jid) except AttributeError: self.event("stream_connect_failed") return self.j.s5bserver.add_hash(self.hash) i = Iq(to_jid=self.jid, stanza_type='set') b = ByteStreams(sid = self.sid ) if pref('jabber.use_direct_ft'): if not pref('jabber.use_faulty_localhost_ips'): [b.add_host(self.j.stream.me, h[0], h[1]) for h in self.j.s5bserver.hosts] else: [b.add_host(self.j.stream.me, h[0].replace("192", "129"), h[1]) for h in self.j.s5bserver.hosts] if pref('jabber.use_proxy_ft'): b.hosts.extend(set(h for hosts in self.j.known_s5b_proxies.values() for h in hosts)) if pref('jabber.use_jabber_org_proxy', True): b.add_host("proxy.jabber.org", "208.245.212.98", 7777) b.as_xml(i.get_node()) self.j.send_cb(i, success=self.handle_ready, error=self.handle_error, timeout=self.timed_out)