private void SendStreamHosts() { /* * Recv: * <iq xmlns="jabber:client" from="[email protected]/Psi" to="[email protected]/SharpIM" * type="set" id="aab6a"> <query xmlns="http://jabber.org/protocol/bytestreams" sid="s5b_405645b6f2b7c681" * mode="tcp"> <streamhost port="8010" jid="[email protected]/Psi" host="192.168.74.142" /> * <streamhost port="7777" jid="proxy.ag-software.de" host="82.165.34.23"> * <proxy xmlns="http://affinix.com/jabber/stream" /> * </streamhost> * <fast xmlns="http://affinix.com/jabber/stream" /> </query> </iq> */ ByteStreamIq bsIq = new ByteStreamIq(); bsIq.To = m_To; bsIq.Type = IqType.set; bsIq.Query.Sid = m_Sid; string hostname = System.Net.Dns.GetHostName(); System.Net.IPHostEntry iphe = System.Net.Dns.Resolve(hostname); for (int i = 0; i < iphe.AddressList.Length; i++) { Console.WriteLine("IP address: {0}", iphe.AddressList[i].ToString()); //bsIq.Query.AddStreamHost(m_XmppCon.MyJID, iphe.AddressList[i].ToString(), 1000); } bsIq.Query.AddStreamHost(new Jid(PROXY), PROXY, 7777); _p2pSocks5Socket = new JEP65Socket(); _p2pSocks5Socket.Initiator = m_XmppCon.MyJID; _p2pSocks5Socket.Target = m_To; _p2pSocks5Socket.SID = m_Sid; _p2pSocks5Socket.OnConnect += new ObjectHandler(_socket_OnConnect); _p2pSocks5Socket.OnDisconnect += new ObjectHandler(_socket_OnDisconnect); _p2pSocks5Socket.Listen(1000); m_XmppCon.IqGrabber.SendIq(bsIq, new IqCB(SendStreamHostsResult), null); }
private void HandleStreamHost(ByteStream bs, IQ iq) //private void HandleStreamHost(object obj) { //IQ iq = obj as IQ; //ByteStream bs = iq.Query as agsXMPP.protocol.extensions.bytestreams.ByteStream;; //ByteStream bs = iq.Query as ByteStream; if (bs != null) { _proxySocks5Socket = new JEP65Socket(); _proxySocks5Socket.OnConnect += new ObjectHandler(m_s5Sock_OnConnect); _proxySocks5Socket.OnReceive += new agsXMPP.net.BaseSocket.OnSocketDataHandler(m_s5Sock_OnReceive); _proxySocks5Socket.OnDisconnect += new ObjectHandler(m_s5Sock_OnDisconnect); StreamHost[] streamhosts = bs.GetStreamHosts(); //Scroll through the possible sock5 servers and try to connect //foreach (StreamHost sh in streamhosts) //this is done back to front in order to make sure that the proxy JID is chosen first //this is necessary as at this stage the application only knows how to connect to a //socks 5 proxy. foreach (StreamHost sHost in streamhosts) { if (sHost.Host != null) { _proxySocks5Socket.Address = sHost.Host; _proxySocks5Socket.Port = sHost.Port; _proxySocks5Socket.Target = m_XmppCon.MyJID; _proxySocks5Socket.Initiator = m_From; _proxySocks5Socket.SID = m_Sid; _proxySocks5Socket.ConnectTimeout = 5000; _proxySocks5Socket.SyncConnect(); if (_proxySocks5Socket.Connected) { SendStreamHostUsedResponse(sHost, iq); break; } } } } }
private void SendStreamHostsResult(object sender, IQ iq, object data) { // <iq xmlns="jabber:client" type="result" to="[email protected]/Psi" id="aab6a"> // <query xmlns="http://jabber.org/protocol/bytestreams"> // <streamhost-used jid="[email protected]/Psi" /> // </query> // </iq> if (iq.Type == IqType.result) { ByteStream bs = iq.Query as ByteStream; if (bs != null) { Jid sh = bs.StreamHostUsed.Jid; if (sh != null & sh.Equals(m_XmppCon.MyJID, new agsXMPP.Collections.FullJidComparer())) { // direct connection SendFile(null); } if (sh != null & sh.Equals(new Jid(PROXY), new agsXMPP.Collections.FullJidComparer())) { _p2pSocks5Socket = new JEP65Socket(); _p2pSocks5Socket.Address = PROXY; _p2pSocks5Socket.Port = 7777; _p2pSocks5Socket.Target = m_To; _p2pSocks5Socket.Initiator = m_XmppCon.MyJID; _p2pSocks5Socket.SID = m_Sid; _p2pSocks5Socket.ConnectTimeout = 5000; _p2pSocks5Socket.SyncConnect(); if (_p2pSocks5Socket.Connected) { ActivateBytestream(new Jid(PROXY)); } } } } }