Exemple #1
0
        public bool Create(Models.Server.Server s, Models.Mode.Mode m)
        {
            Global.Logger.Info(String.Format("{0:x} aiodns.bin", Utils.FileHelper.Checksum("bin\\aiodns.bin")));

            Methods.aiodns_dial(NameList.TYPE_REST, "");
            Methods.aiodns_dial(NameList.TYPE_LIST, "chnsite.txt");
            Methods.aiodns_dial(NameList.TYPE_LISN, $"127.0.0.1:{Global.Config.AioDNS.ListenPort}");
            Methods.aiodns_dial(NameList.TYPE_CDNS, Global.Config.AioDNS.ChinaDNS);
            Methods.aiodns_dial(NameList.TYPE_ODNS, Global.Config.AioDNS.OtherDNS);

            return(Methods.aiodns_init());
        }
Exemple #2
0
        /// <summary>
        ///     获取延迟
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public static int Fetch(Models.Server.Server s)
        {
            /*
             * -1  : Not Test
             * -2  : DNS Exception
             * -3  : Exception
             * 999 : Timeout
             */

            try
            {
                var addr = DNS.Fetch(s.Host);
                if (addr == IPAddress.Any)
                {
                    return(-2);
                }

                if (Cache.Contains(addr))
                {
                    var rule = Cache[addr] as CacheEntry;
                    if (DateTimeOffset.Now.ToUnixTimeSeconds() - rule.Unix < 30)
                    {
                        return(rule.Time);
                    }
                    else
                    {
                        Cache.Remove(addr);
                    }
                }

                var time = 0;
                if (Global.Config.Generic.ICMPing)
                {
                    time = ICMPing(addr);
                }
                else
                {
                    return(TCPPing(addr, s.Port));
                }

                Cache.Add(addr, new CacheEntry()
                {
                    Unix = DateTimeOffset.Now.ToUnixTimeSeconds(), Time = time
                });
                return(time);
            }
            catch (Exception e)
            {
                Global.Logger.Warning(e.ToString());
                return(-3);
            }
        }
Exemple #3
0
 public bool Create(Models.Server.Server s, Models.Mode.Mode m)
 {
     throw new System.NotImplementedException();
 }
Exemple #4
0
        public bool Create(Models.Server.Server s, Models.Mode.Mode m)
        {
            switch (s.Type)
            {
            case Models.Server.ServerType.Socks:
                break;

            case Models.Server.ServerType.Shadowsocks:
                this.NodeController = new Server.ShadowsocksController();
                break;

            case Models.Server.ServerType.ShadowsocksR:
                this.NodeController = new Server.ShadowsocksRController();
                break;

            case Models.Server.ServerType.WireGuard:
                this.NodeController = new Server.WireGuardController();
                break;

            case Models.Server.ServerType.Trojan:
                this.NodeController = new Server.TrojanController();
                break;

            case Models.Server.ServerType.VMess:
                this.NodeController = new Server.VMessController();
                break;

            case Models.Server.ServerType.VLess:
                this.NodeController = new Server.VLessController();
                break;

            default:
                Global.Logger.Error($"未知的节点类型:{s.Type}");

                return(false);
            }

            {
                var status = this.NodeController?.Create(s, m);
                if (status.HasValue && !status.Value)
                {
                    return(false);
                }
            }

            switch (m.Type)
            {
            case Models.Mode.ModeType.ProcessMode:
                this.ModeController = new Mode.ProcessController();
                break;

            case Models.Mode.ModeType.ShareMode:
                this.ModeController = new Mode.ShareController();
                break;

            case Models.Mode.ModeType.TunMode:
                this.ModeController = new Mode.TunController();
                break;

            case Models.Mode.ModeType.WebMode:
                this.ModeController = new Mode.WebController();
                break;

            default:
                Global.Logger.Error($"未知的模式类型:{s.Type}");

                return(false);
            }

            {
                var status = this.ModeController?.Create(s, m);
                if (status.HasValue && !status.Value)
                {
                    return(false);
                }
            }

            return(true);
        }
Exemple #5
0
        public bool Create(Models.Server.Server s, Models.Mode.Mode m)
        {
            Global.Logger.Info(String.Format("{0:x} Redirector.bin", Utils.FileHelper.Checksum("bin\\Redirector.bin")));

            var mode = m as Models.Mode.ProcessMode.ProcessMode;

            Methods.aio_dial(NameList.AIO_FILTERLOOPBACK, mode.Loopback.ToString().ToLower());
            Methods.aio_dial(NameList.AIO_FILTERINTRANET, mode.Intranet.ToString().ToLower());
            Methods.aio_dial(NameList.AIO_FILTERTCP, mode.TCP.ToString().ToLower());
            Methods.aio_dial(NameList.AIO_FILTERUDP, mode.UDP.ToString().ToLower());
            Methods.aio_dial(NameList.AIO_FILTERDNS, mode.DNS.ToString().ToLower());

            Methods.aio_dial(NameList.AIO_ICMPING, Global.Config.ProcessMode.Icmping.ToString());

            Methods.aio_dial(NameList.AIO_DNSONLY, Global.Config.ProcessMode.DNSOnly.ToString().ToLower());
            Methods.aio_dial(NameList.AIO_DNSPROX, Global.Config.ProcessMode.DNSProx.ToString().ToLower());
            Methods.aio_dial(NameList.AIO_DNSHOST, Global.Config.ProcessMode.DNSHost);
            Methods.aio_dial(NameList.AIO_DNSPORT, Global.Config.ProcessMode.DNSPort.ToString());

            Methods.aio_dial(NameList.AIO_TGTUSER, "");
            Methods.aio_dial(NameList.AIO_TGTPASS, "");

            Methods.aio_dial(NameList.AIO_CLRNAME, "");
            Methods.aio_dial(NameList.AIO_BYPNAME, AppDomain.CurrentDomain.BaseDirectory.Replace("\\", "\\\\"));
            for (int i = 0; i < mode.BypassList.Count; i++)
            {
                if (!Methods.aio_dial(NameList.AIO_BYPNAME, mode.BypassList[i]))
                {
                    return(false);
                }
            }
            for (int i = 0; i < mode.HandleList.Count; i++)
            {
                if (!Methods.aio_dial(NameList.AIO_ADDNAME, mode.HandleList[i]))
                {
                    return(false);
                }
            }

            switch (s.Type)
            {
            case Models.Server.ServerType.Socks:
            {
                var node = s as Models.Server.Socks.Socks;
                Methods.aio_dial(NameList.AIO_TGTHOST, node.Resolve());
                Methods.aio_dial(NameList.AIO_TGTPORT, node.Port.ToString());

                if (!String.IsNullOrEmpty(node.Username))
                {
                    Methods.aio_dial(NameList.AIO_TGTUSER, node.Username);
                }

                if (!String.IsNullOrEmpty(node.Password))
                {
                    Methods.aio_dial(NameList.AIO_TGTPASS, node.Password);
                }
            }
            break;

            default:
            {
                Methods.aio_dial(NameList.AIO_TGTHOST, "127.0.0.1");
                Methods.aio_dial(NameList.AIO_TGTPORT, Global.Config.Ports.Socks.ToString());
            }
            break;
            }

            return(Methods.aio_init());
        }