コード例 #1
0
ファイル: s2hDataExchanger.cs プロジェクト: aloux00/s2h
        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");
                    }
                }
            }
        }
コード例 #2
0
 public void AddConnection(string handle, s2hConnection conn)
 {
     lock (m_Connections)
     {
         lock (conn)
             m_Connections.Add(handle, conn);
     }
 }
コード例 #3
0
ファイル: s2hDataExchanger.cs プロジェクト: aloux00/s2h
 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);
 }
コード例 #4
0
ファイル: s2h.asmx.cs プロジェクト: aloux00/s2h
        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);
        }
コード例 #5
0
ファイル: s2h.asmx.cs プロジェクト: aloux00/s2h
        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);
        }
コード例 #6
0
ファイル: s2hDataExchanger.cs プロジェクト: aloux00/s2h
        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);
        }
コード例 #7
0
ファイル: s2h.asmx.cs プロジェクト: aloux00/s2h
        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);
        }