示例#1
0
        public static void Start(IPEndPoint[] localAddresses)
        {
            if (!IsRunning)
            {
                if (localAddresses != null)
                {
                    if (Conf.Status == Conf.ProxyStatus.SMART ||
                        Conf.EnableEagleTunnel)
                    {
                        EagleTunnelHandler.StartResolvInside();
                    }

                    servers               = new Socket[localAddresses.Length];
                    reqGotNumbers         = new ConCurrentCounter(100);
                    Server.localAddresses = localAddresses;
                    IsRunning             = true;

                    if (threadLimitCheck == null)
                    {
                        threadLimitCheck = new Thread(LimitSpeed);
                        threadLimitCheck.IsBackground = true;
                        threadLimitCheck.Start();
                    }

                    for (int i = 1; i < localAddresses.Length; ++i)
                    {
                        ListenAsync(i);
                    }
                    Listen(0);
                }
            }
        }
示例#2
0
        public static Tunnel Handle(byte[] firstMsg, Socket socket2Client)
        {
            Tunnel result = null;

            if (firstMsg != null && socket2Client != null)
            {
                Tunnel      tunnel       = null;
                string      firstMsg_Str = Encoding.UTF8.GetString(firstMsg);
                RequestType reqType      = GetType(firstMsg);
                switch (reqType)
                {
                case RequestType.Eagle_Tunnel:
                    if (Conf.EnableEagleTunnel)
                    {
                        tunnel = EagleTunnelHandler.Handle(
                            firstMsg_Str, socket2Client);
                    }
                    break;

                case RequestType.HTTP_Proxy:
                    if (Conf.EnableHTTP)
                    {
                        tunnel = HTTPHandler.Handle(
                            firstMsg_Str, socket2Client);
                    }
                    break;

                case RequestType.SOCKS5:
                    if (Conf.EnableSOCKS)
                    {
                        tunnel = SocksHandler.Handle(
                            firstMsg, socket2Client);
                    }
                    break;
                }
                if (tunnel != null)
                {
                    result = tunnel;
                }
                else
                {
                    if (socket2Client.Connected)
                    {
                        try {
                            socket2Client.Shutdown(SocketShutdown.Both);
                            Thread.Sleep(100);
                            socket2Client.Close();
                        } catch {; }
                    }
                }
            }
            return(result);
        }
        public static bool Handle(Tunnel tunnel)
        {
            bool result = false;

            if (tunnel == null)
            {
                result = false;
            }
            else
            {
                ByteBuffer firstMsg = new ByteBuffer();
                int        read     = tunnel.ReadL(firstMsg);
                if (read > 0)
                {
                    string      firstMsg_Str = firstMsg.ToString();
                    RequestType reqType      = GetType(firstMsg);
                    switch (reqType)
                    {
                    case RequestType.Eagle_Tunnel:
                        if (Conf.EnableEagleTunnel)
                        {
                            result = EagleTunnelHandler.Handle(
                                firstMsg_Str, tunnel);
                        }
                        break;

                    case RequestType.HTTP_Proxy:
                        if (Conf.EnableHTTP)
                        {
                            result = HTTPHandler.Handle(
                                firstMsg_Str, tunnel);
                        }
                        break;

                    case RequestType.SOCKS5:
                        if (Conf.EnableSOCKS)
                        {
                            result = SocksHandler.Handle(
                                firstMsg, tunnel);
                        }
                        break;
                    }
                }
            }
            return(result);
        }
示例#4
0
 public static void Close()
 {
     if (IsRunning)
     {
         IsRunning = false;
         Thread.Sleep(1000);
         // stop listening
         lock (servers)
         {
             foreach (Socket item in servers)
             {
                 if (item != null)
                 {
                     try
                     {
                         item.Close();
                     }
                     catch {; }
                 }
             }
         }
         EagleTunnelHandler.StopResolvInside();
     }
 }