예제 #1
0
파일: Global.asax.cs 프로젝트: aloux00/s2h
        protected void Application_End(Object sender, EventArgs e)
        {
            S2hState s2hState = (S2hState)Application["s2hState"];

            Application.Remove("s2hState");
            s2hState.RemoveAllClients();
            System.Diagnostics.Debug.WriteLine("Application_End: Midori's HTTP tunnel stopped...");
        }
예제 #2
0
파일: Global.asax.cs 프로젝트: aloux00/s2h
 protected void Application_Start(Object sender, EventArgs e)
 {
     m_config   = new ApplicationStorage(System.IO.Path.Combine(this.Server.MapPath(""), m_ConfigFileName));
     m_s2hState = new S2hState();
     Application.Add("s2hState", m_s2hState);
     Application.Add("s2hConfig", m_config);
     Application.Add("s2hUsersPath", System.IO.Path.Combine(this.Server.MapPath(""), m_UsersFileName));
     System.Diagnostics.Debug.WriteLine("Application_Start: Midori's HTTP tunnel started...");
 }
예제 #3
0
파일: s2h.asmx.cs 프로젝트: aloux00/s2h
        public long CloseAll(string auth)
        {
            S2hState  s2hState = (S2hState)Application["s2hState"];
            s2hClient Client   = s2hState.GetClient(auth);

            if (Client == null)
            {
                return((long)s2h_errors.s2h_client_not_authenticated);
            }
            Client = null;
            s2hState.RemoveClient(auth);
            return((long)s2h_errors.s2h_ok);
        }
예제 #4
0
파일: s2h.asmx.cs 프로젝트: aloux00/s2h
        public long Recv(string a, int Seq, int WaitTimeout, out ExData[] d)
        {
            System.Diagnostics.Debug.WriteLine(this.ToString() + ": requested seq=" + Seq.ToString());
            d = null;
            int       tmpWaitTimeout = WaitTimeout;
            S2hState  s2hState       = (S2hState)Application["s2hState"];
            s2hClient Client         = s2hState.GetClient(a);

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

            lock (Client)
            {
                // the client wants the last packet; last communication failed?
                if (Seq == Client.LastRecvSequenceId)
                {
                    d = Client.LastRecvData;
                    return((long)s2h_errors.s2h_ok);                     // sending last recieved data
                }
            }

            // try to recieve data on all active connections
            while (true)
            {
                s2hState.Exchanger.DeQueueData(out d);

                if ((d == null || d.Length == 0) && tmpWaitTimeout > 0)
                {
                    System.Threading.Thread.Sleep(tmpWaitTimeout < 100?tmpWaitTimeout:100);
                    tmpWaitTimeout -= 100;
                }
                else
                {
                    break;
                }
            }


            // remember the last sent packet
            lock (Client)
            {
                // NOTE: store current value, also if the packet is null
                Client.LastRecvData       = d;
                Client.LastRecvSequenceId = Seq;
            }
            return((long)s2h_errors.s2h_ok);
        }
예제 #5
0
파일: s2h.asmx.cs 프로젝트: aloux00/s2h
        public long Auth(string usr, string pwd, out string auth)
        {
            S2hState  s2hState = (S2hState)Application["s2hState"];
            s2hClient Client   = new s2hClient();

            auth = null;

            UserManager.user_info user = m_userManager.GetUser(usr);
            if (user == null || pwd != user.pass)
            {
                return((long)s2h_errors.s2h_invalid_credentials);
            }

            auth = Client.AuthToken = s2hState.GetNewAuthToken();
            Client.ClientAddress = IPAddress.Parse(this.Context.Request.UserHostAddress);
            s2hState.PutClient(auth, Client);

            return((long)s2h_errors.s2h_ok);
        }
예제 #6
0
파일: s2h.asmx.cs 프로젝트: aloux00/s2h
        public long Send(string a, ExData[] d, int Seq)
        {
            System.Diagnostics.Debug.WriteLine(this.ToString() + ": sent seq=" + Seq.ToString());
            S2hState  s2hState = (S2hState)Application["s2hState"];
            s2hClient Client   = s2hState.GetClient(a);

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

            if (Seq == Client.LastSendSequenceId)
            {
                return((long)s2h_errors.s2h_ok);                 // already processed data
            }
            // just send recv data to the data exchanger
            s2hState.Exchanger.EnqueueData(d);

            return((long)s2h_errors.s2h_ok);
        }
예제 #7
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);
        }
예제 #8
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);
        }
예제 #9
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);
        }
예제 #10
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            TableRow  r;
            TableCell c;

            System.Net.IPEndPoint rep;
            S2hState         s2hState = (S2hState)Application["s2hState"];
            HybridDictionary conns    = s2hState.Exchanger.Connections;
            HybridDictionary clients  = s2hState.Clients;

            r           = new TableRow();
            c           = new TableCell();
            c.Text      = "Connetion ID";
            c.BackColor = System.Drawing.Color.Gray;
            r.Cells.Add(c);
            c           = new TableCell();
            c.Text      = "Remote End Point";
            c.BackColor = System.Drawing.Color.Gray;
            r.Cells.Add(c);

            Table1.Rows.Add(r);

            lock (conns)
            {
                foreach (s2hConnection conn in conns.Values)
                {
                    lock (conn)
                    {
                        r      = new TableRow();
                        c      = new TableCell();
                        c.Text = conn.handle;
                        r.Cells.Add(c);
                        c = new TableCell();
                        if (conn.Connected)
                        {
                            rep    = ((System.Net.IPEndPoint)conn.socket.RemoteEndPoint);
                            c.Text = rep.Address.ToString()
                                     + ":" + rep.Port.ToString();
                        }
                        else
                        {
                            c.Text = "Disconnected...";
                        }
                        r.Cells.Add(c);
                        Table1.Rows.Add(r);
                    }
                }
            }

            r           = new TableRow();
            c           = new TableCell();
            c.Text      = "Client ID";
            c.BackColor = System.Drawing.Color.Gray;
            r.Cells.Add(c);
            c           = new TableCell();
            c.Text      = "Client Address";
            c.BackColor = System.Drawing.Color.Gray;
            r.Cells.Add(c);
            Table2.Rows.Add(r);
            lock (clients)
            {
                foreach (s2hClient client in clients.Values)
                {
                    lock (client)
                    {
                        r      = new TableRow();
                        c      = new TableCell();
                        c.Text = client.AuthToken;
                        r.Cells.Add(c);
                        c      = new TableCell();
                        c.Text = client.ClientAddress.ToString();
                        r.Cells.Add(c);
                        Table2.Rows.Add(r);
                    }
                }
            }
        }