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)); } } } } }