Beispiel #1
0
        /// <summary>
        /// Synchronously reads a packet from a Rendezvous proxy connection
        /// </summary>
        private RendezvousProxyPacket ReadProxyPacket()
        {
            int bytesreceived = 0;

            byte[] header = new byte[12];
            while (bytesreceived < header.Length)
            {
                bytesreceived += socket.Read(header, bytesreceived, header.Length - bytesreceived);
            }
            Logging.DumpFLAP(header, "Rendezvous proxy read packet header");

            RendezvousProxyPacket retval = new RendezvousProxyPacket();

            using (ByteStream bstream = new ByteStream(header))
            {
                retval.Data = new byte[bstream.ReadUshort() - 10];
                bstream.AdvanceToPosition(4);
                retval.Command = (RendezvousProxyCommand)bstream.ReadUshort();
            }

            bytesreceived = 0;
            while (bytesreceived < retval.Data.Length)
            {
                bytesreceived +=
                    socket.Read(retval.Data, bytesreceived, retval.Data.Length - bytesreceived);
            }
            Logging.DumpFLAP(retval.Data, "Rendezvous proxy read packet data");
            return(retval);
        }
Beispiel #2
0
        /// <summary>
        /// Synchronously reads a packet from a Rendezvous proxy connection
        /// </summary>
        RendezvousProxyPacket ReadProxyPacket(RendezvousData rd)
        {
            Socket sock          = rd.DirectConnection.Transfer;
            int    bytesreceived = 0;

            byte[] header = new byte[12];
            while (bytesreceived < header.Length)
            {
                bytesreceived += sock.Receive(header, bytesreceived, header.Length - bytesreceived, SocketFlags.None);
            }
            Logging.DumpFLAP(header, "Rendezvous proxy read packet header");

            int index = 4;
            RendezvousProxyPacket retval = new RendezvousProxyPacket();

            retval.Command = (RendezvousProxyCommand)Marshal.ByteArrayToUshort(header, ref index);

            index         = 0;
            retval.Data   = new byte[Marshal.ByteArrayToUshort(header, ref index) - 10];
            bytesreceived = 0;
            while (bytesreceived < retval.Data.Length)
            {
                bytesreceived += sock.Receive(retval.Data, bytesreceived, retval.Data.Length - bytesreceived, SocketFlags.None);
            }
            Logging.DumpFLAP(retval.Data, "Rendezvous proxy read packet data");
            return(retval);
        }
Beispiel #3
0
 private void SendThroughStage2AolProxyConnectFinished()
 {
     try
     {
         ProxyInitializeReceive();
         RendezvousProxyPacket rpp = ReadProxyPacket();
         if (rpp.Command == RendezvousProxyCommand.Ready)
         {
             OnDirectConnectReady();
         }
     }
     catch (Exception)
     {
         OnDirectConnectFailed("Proxy refused connection");
     }
 }
Beispiel #4
0
 /// <summary>
 /// Sends a Rendezvous INITRECV and begins sending the file through the proxy connection
 /// </summary>
 internal void StartSendThroughStage2Proxy(RendezvousData rd)
 {
     try
     {
         ProxyInitializeReceive(rd);
         RendezvousProxyPacket rpp = ReadProxyPacket(rd);
         if (rpp.Command == RendezvousProxyCommand.Ready)
         {
             BeginSendFile(rd);
         }
     }
     catch (Exception)
     {
         rd.DirectConnection.CancelTransfer("Proxy refused connection");
     }
 }
Beispiel #5
0
 /// <summary>
 /// Completes the final connection to the proxy server
 /// </summary>
 private void InitAolProxyReceiveConnectFinished()
 {
     try
     {
         ProxyInitializeReceive();
         RendezvousProxyPacket rpp = ReadProxyPacket();
         if (rpp.Command == RendezvousProxyCommand.Error)
         {
             throw new Exception("Proxy server refused connection");
         }
         OnDirectConnectReady();
     }
     catch (Exception ex)
     {
         OnDirectConnectFailed(ex.Message);
     }
 }
Beispiel #6
0
        /// <summary>
        /// Completes the initial connection to the AOL proxy server
        /// </summary>
        /// <remarks>This method is used to complete the proxy server transaction for both
        /// Stage 1 sending and Stage 2 receiver-redirect proxy scenarios</remarks>
        private void InitAolProxyConnectFinished()
        {
            try
            {
                ProxyInitializeSend();
                RendezvousProxyPacket rpp = ReadProxyPacket();
                if (rpp.Command == RendezvousProxyCommand.Acknowledge)
                {
                    using (ByteStream bstream = new ByteStream(rpp.Data))
                    {
                        Port       = bstream.ReadUshort();
                        aolProxyIP = (new IPAddress(bstream.ReadByteArray(4))).ToString();
                    }

                    // Send the "send file" request on SNAC(04,06):02
                    parent.Messages.RequestDirectConnectionInvite(this);

                    // Wait for the proxy to send its 12 byte READY sequence
                    lock (socket)
                    {
                        socket.BeginRead(new byte[12], 0, 12, new AsyncCallback(ProxyReceivedReady), null);
                        //socket.BeginReceive(new byte[12], 0, 12, SocketFlags.None, new AsyncCallback(ProxyReceivedReady), null);
                    }
                }
                else
                {
                    ushort error = (ushort)((rpp.Data[0] << 8) | rpp.Data[1]);
                    if (error == 0x0004)
                    {
                        throw new Exception("Recipient not logged in");
                    }
                    else if (error == 0x000D)
                    {
                        throw new Exception("Client sent bad request");
                    }
                    throw new Exception("AOL proxy sent unknown error");
                }
            }
            catch (Exception ex)
            {
                if (DirectConnectionFailed != null)
                {
                    DirectConnectionFailed(ex.Message);
                }
            }
        }
Beispiel #7
0
        /// <summary>
        /// Completes the initial connection to the proxy server
        /// </summary>
        /// <remarks>This method is used to complete the proxy server transaction for both
        /// Stage 1 sending and Stage 2 receiver-redirect proxy scenarios</remarks>
        private void InitProxyConnectFinished(IAsyncResult res)
        {
            RendezvousData    rd  = res.AsyncState as RendezvousData;
            DirectConnectInfo fti = rd.DirectConnection;

            try
            {
                fti.Transfer.EndConnect(res);

                ProxyInitializeSend(rd);
                RendezvousProxyPacket rpp = ReadProxyPacket(rd);
                if (rpp.Command == RendezvousProxyCommand.Acknowledge)
                {
                    rd.Port = Marshal.ByteArrayToUshort(rpp.Data, 0);
                    byte[] ipaddr = new byte[4];
                    Marshal.CopyArray(rpp.Data, ipaddr, 2);
                    rd.ProxyIP = (new IPAddress(ipaddr)).ToString();

                    // Send the "send file" request on SNAC(04,06):02
                    // SNAC04.SendDirectConnectionRequest(_parent, rd);

                    // Wait for the proxy to send its 12 byte READY sequence
                    rd.DirectConnection.Transfer.BeginReceive(new byte[12], 0, 12,
                                                              SocketFlags.None, new AsyncCallback(ProxyReceivedReady), rd);
                }
                else
                {
                    int    index = 0;
                    ushort error = Marshal.ByteArrayToUshort(rpp.Data, ref index);
                    if (error == 0x0004)
                    {
                        throw new Exception("Recipient not logged in");
                    }
                    else if (error == 0x000D)
                    {
                        throw new Exception("Client sent bad request");
                    }
                    throw new Exception("AOL proxy sent unknown error");
                }
            }
            catch (Exception ex)
            {
                fti.CancelTransfer(ex.Message);
            }
        }
Beispiel #8
0
        /// <summary>
        /// Completes the final connection to the proxy server
        /// </summary>
        private void InitProxyReceiveConnectFinished(IAsyncResult res)
        {
            RendezvousData rd = res.AsyncState as RendezvousData;

            try
            {
                rd.DirectConnection.Transfer.EndConnect(res);

                ProxyInitializeReceive(rd);
                RendezvousProxyPacket rpp = ReadProxyPacket(rd);
                if (rpp.Command == RendezvousProxyCommand.Error)
                {
                    throw new Exception("Proxy server refused connection");
                }
                BeginReceiveFile(rd);
            }
            catch (Exception ex)
            {
                rd.DirectConnection.CancelTransfer(ex.Message);
            }
        }
Beispiel #9
0
        /// <summary>
        /// Synchronously reads a packet from a Rendezvous proxy connection
        /// </summary>
        RendezvousProxyPacket ReadProxyPacket(RendezvousData rd)
        {
            Socket sock = rd.DirectConnection.Transfer;
              int bytesreceived = 0;

              byte[] header = new byte[12];
              while (bytesreceived < header.Length)
              {
            bytesreceived += sock.Receive(header, bytesreceived, header.Length - bytesreceived, SocketFlags.None);
              }
              Logging.DumpFLAP(header, "Rendezvous proxy read packet header");

              int index = 4;
              RendezvousProxyPacket retval = new RendezvousProxyPacket();
              retval.Command = (RendezvousProxyCommand)Marshal.ByteArrayToUshort(header, ref index);

              index = 0;
              retval.Data = new byte[Marshal.ByteArrayToUshort(header, ref index) - 10];
              bytesreceived = 0;
              while (bytesreceived < retval.Data.Length)
              {
            bytesreceived += sock.Receive(retval.Data, bytesreceived, retval.Data.Length - bytesreceived, SocketFlags.None);
              }
              Logging.DumpFLAP(retval.Data, "Rendezvous proxy read packet data");
              return retval;
        }
Beispiel #10
0
        /// <summary>
        /// Synchronously reads a packet from a Rendezvous proxy connection
        /// </summary>
        private RendezvousProxyPacket ReadProxyPacket()
        {
            int bytesreceived = 0;

            byte[] header = new byte[12];
            while (bytesreceived < header.Length)
            {
                bytesreceived += socket.Read(header, bytesreceived, header.Length - bytesreceived);
            }
            Logging.DumpFLAP(header, "Rendezvous proxy read packet header");

            RendezvousProxyPacket retval = new RendezvousProxyPacket();
            using (ByteStream bstream = new ByteStream(header))
            {
                retval.Data = new byte[bstream.ReadUshort() - 10];
                bstream.AdvanceToPosition(4);
                retval.Command = (RendezvousProxyCommand)bstream.ReadUshort();
            }

            bytesreceived = 0;
            while (bytesreceived < retval.Data.Length)
            {
                bytesreceived +=
                    socket.Read(retval.Data, bytesreceived, retval.Data.Length - bytesreceived);
            }
            Logging.DumpFLAP(retval.Data, "Rendezvous proxy read packet data");
            return retval;
        }