Ejemplo n.º 1
0
        public void EnqueueData(s2h.ExData[] exData)
        {
            // put all received data on the connections queue
            // Problem: the client continue to push data also if the socket if full...
            // This is not a big problem until the connection from client to web server is slower than
            // the connection from web server to remote host
            lock (m_Connections)
            {
                s2hConnection conn = null;
                foreach (s2h.ExData d in exData)
                {
                    if (d.token == null)
                    {
                        System.Diagnostics.Debug.WriteLine(
                            "*********** null Token detected in received data");
                        continue;
                    }

                    if (m_Connections.Contains(d.token))
                    {
                        conn = (s2hConnection)m_Connections[d.token];
                        conn.DataToSendQueue.Enqueue(new s2hConnectionData(d.data, 0));
                    }
                    else
                    {
                        System.Diagnostics.Debug.WriteLine(this.ToString() + ": Connection token " + d.token + " unknown");
                    }
                }
            }
        }
Ejemplo n.º 2
0
 public void AddConnection(string handle, s2hConnection conn)
 {
     lock (m_Connections)
     {
         lock (conn)
             m_Connections.Add(handle, conn);
     }
 }
Ejemplo n.º 3
0
 public bool CloseConnection(string handle)
 {
     lock (m_Connections)
     {
         //System.Diagnostics.Debug.WriteLine("Connections before:" + m_Connections.Count.ToString());
         if (m_Connections.Contains(handle))
         {
             s2hConnection conn = (s2hConnection)m_Connections[handle];
             m_Connections.Remove(handle);
             try
             {
                 conn.Close();
             }
             catch (Exception) {}
             //System.Diagnostics.Debug.WriteLine("Connections after:" + m_Connections.Count.ToString());
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 4
0
        public long Ready(string auth, string Token)
        {
            S2hState  s2hState = (S2hState)Application["s2hState"];
            s2hClient Client   = s2hState.GetClient(auth);

            if (Client == null)
            {
                return((long)s2h_errors.s2h_client_not_authenticated);
            }

            s2hConnection connection = Client.GetConnection(Token);

            if (connection == null)
            {
                return((long)s2h_errors.s2h_unknown_connection_token);
            }

            connection.bReady = true;

            return((long)s2h_errors.s2h_ok);
        }
Ejemplo n.º 5
0
        public long Conn(string auth, string host, int port, out string Token, out byte[] iplAddr, out int lPort, out byte[] iprAddr, out int rPort)
        {
            iprAddr = iplAddr = new byte[4];
            lPort   = 0;
            rPort   = port;
            Token   = "";
            S2hState  s2hState = (S2hState)Application["s2hState"];
            s2hClient Client   = s2hState.GetClient(auth);

            if (Client == null)
            {
                return((long)s2h_errors.s2h_client_not_authenticated);
            }
            s2hConnection connection = null;

            s2h_errors error = s2hState.Exchanger.CreateConnection(host, port, out connection);

            if (error != s2h_errors.s2h_ok)
            {
                return((long)error);
            }
            Client.AddConnection(connection.handle, connection);

            Token = connection.handle;
            if (connection.socket.LocalEndPoint is IPEndPoint)
            {
                IPEndPoint ip = (IPEndPoint)connection.socket.LocalEndPoint;
                iplAddr = ip.Address.GetAddressBytes();
                lPort   = ip.Port;
            }
            if (connection.socket.RemoteEndPoint is IPEndPoint)
            {
                IPEndPoint ip = (IPEndPoint)connection.socket.RemoteEndPoint;
                iprAddr = ip.Address.GetAddressBytes();
                rPort   = ip.Port;
            }
            return((long)s2h_errors.s2h_ok);
        }
Ejemplo n.º 6
0
        public s2h.s2h_errors CreateConnection(string host, int port,
                                               out s2hConnection conn)
        {
            SocksOverHttp.s2h.s2h_errors iRes;
            Socket socket = null;

            conn = new s2hConnection();
            iRes = conn.Connect(host, port, out socket);
            if (iRes != s2h.s2h_errors.s2h_ok)
            {
                try
                {
                    conn.Close();
                }
                catch (Exception) {}
                conn = null;
            }
            lock (m_Connections)
            {
                m_Connections.Add(conn.handle, conn);
            }
            return(iRes);
        }
Ejemplo n.º 7
0
        public long Close(string auth, string[] Tokens)
        {
            long      lRes     = (long)s2h_errors.s2h_ok;
            S2hState  s2hState = (S2hState)Application["s2hState"];
            s2hClient Client   = s2hState.GetClient(auth);

            if (Client == null)
            {
                return((long)s2h_errors.s2h_client_not_authenticated);
            }

            foreach (string t in Tokens)
            {
                s2hConnection connection = Client.GetConnection(t);
                if (connection == null)
                {
                    lRes = (long)s2h_errors.s2h_unknown_connection_token;
                }
                s2hState.Exchanger.CloseConnection(t);
                Client.RemoveConnection(connection.handle);
            }
            return(lRes);
        }