public InternetChecker(InternetCheckerOptions?options = null, TcpIpSystem?tcpIp = null)
    {
        this.Options = options?._CloneIfClonable() ?? new InternetCheckerOptions();
        this.TcpIp   = tcpIp ?? LocalNet;

        this.StartMainLoop(MainLoopAsync);
    }
Exemple #2
0
    public SpeedTestServer(TcpIpSystem system, params int[] ports)
    {
        this.System      = system;
        this.ServerPorts = ports;

        InitSendData();

        StartMainLoop(ServerMainLoop);
    }
Exemple #3
0
    public async Task ResolveDestHostnameIfNecessaryAsync(TcpIpSystem system, CancellationToken cancel = default)
    {
        if (this.NeedToSolveDestHostname == false)
        {
            return;
        }

        IPAddress ip = await system.GetIpAsync(this.DestHostname !, this.AddressFamily, this.DnsTimeout, cancel);

        this.DestIp = ip;
        this.NeedToSolveDestHostname = false;
    }
Exemple #4
0
 public GetMyIpClient(TcpIpSystem?tcpIp = null, bool useNativeLibrary = false)
 {
     try
     {
         this.TcpIp = tcpIp ?? LocalNet;
         this.Web   = new WebApi(new WebApiOptions(new WebApiSettings {
             SslAcceptAnyCerts = true, UseProxy = false, Timeout = CoresConfig.GetMyIpClientSettings.Timeout
         }, this.TcpIp, useNativeLibrary));
     }
     catch
     {
         this._DisposeSafe();
         throw;
     }
 }
Exemple #5
0
 public SpeedTestClient(TcpIpSystem system, IPAddress ip, int port, int numConnection, int timespan, SpeedTestModeFlag mode, CancellationToken cancel = default)
 {
     this.System        = system;
     this.ServerIP      = ip;
     this.ServerPort    = port;
     this.Cancel        = cancel;
     this.NumConnection = Math.Max(numConnection, 1);
     this.TimeSpan      = Math.Max(timespan, 1000);
     this.Mode          = mode;
     if (Mode == SpeedTestModeFlag.Both)
     {
         this.NumConnection = Math.Max(NumConnection, 2);
     }
     this.ClientStartEvent = new AsyncManualResetEvent();
     InitSendData();
 }
Exemple #6
0
        public AcmeClientOptions(string directoryUrl = DefaultEntryPointUrl, TcpIpSystem?tcpIp = null)
        {
            DirectoryUrl = directoryUrl;
            this.TcpIp   = tcpIp ?? LocalNet;

            DirectoryWebContentsCache = new PersistentLocalCache <AcmeEntryPoints>($"acme/directory_{PathParser.Windows.MakeSafeFileName(this.DirectoryUrl)}",
                                                                                   CoresConfig.AcmeClientSettings.AcmeDirectoryCacheLifeTime,
                                                                                   true,
                                                                                   async(cancel) =>
            {
                using (WebApi api = new WebApi(new WebApiOptions(new WebApiSettings()
                {
                    SslAcceptAnyCerts = true, Timeout = CoresConfig.AcmeClientSettings.ShortTimeout
                })))
                {
                    WebRet ret = await api.SimpleQueryAsync(WebMethods.GET, this.DirectoryUrl, cancel);

                    return(ret.Deserialize <AcmeEntryPoints>(true)._NullCheck());
                }
            });
        }
    public IPv4V6DualStackSpeculativeConnector(TcpConnectParam basicParam, TcpIpSystem system) : base(basicParam)
    {
        if (basicParam.DestHostname._IsEmpty())
        {
            // IP address is specified
            AddAttempt(new Attempt(system, basicParam, 0));
            return;
        }

        // Hostname is specified
        var hostInfo = system.GetHostInfo(true);

        if (hostInfo.IsIPv4Supported)
        {
            AddAttempt(new Attempt(system, new TcpConnectParam(basicParam.DestHostname, basicParam.DestPort, AddressFamily.InterNetwork,
                                                               connectTimeout: basicParam.ConnectTimeout, dnsTimeout: basicParam.DnsTimeout), 0));
        }

        if (hostInfo.IsIPv6Supported)
        {
            AddAttempt(new Attempt(system, new TcpConnectParam(basicParam.DestHostname, basicParam.DestPort, AddressFamily.InterNetworkV6,
                                                               connectTimeout: basicParam.ConnectTimeout, dnsTimeout: basicParam.DnsTimeout), 0));
        }
    }
Exemple #8
0
    static public async Task <List <SpeedTestClient.Result> > RunSpeedTestWithMultiTryAsync(TcpIpSystem system, IPAddress ip, int port, int numConnection, int timespan, SpeedTestModeFlag mode, int numTry, int interval, CancellationToken cancel = default)
    {
        List <SpeedTestClient.Result> ret = new List <Result>();

        numTry = Math.Max(numTry, 1);

        for (int i = 0; i < numTry; i++)
        {
            if (cancel.IsCancellationRequested)
            {
                return(new List <Result>());
            }

            SpeedTestClient tc = new SpeedTestClient(system, ip, port, numConnection, timespan, mode, cancel);

            var result = await tc.RunClientAsync();

            if (result != null)
            {
                ret.Add(result);
            }

            await cancel._WaitUntilCanceledAsync(Util.GenRandInterval(interval));
        }

        return(ret);
    }
Exemple #9
0
 public LogServerOptionsBase(TcpIpSystem tcpIp, PalSslServerAuthenticationOptions sslAuthOptions, string?rateLimiterConfigName = null, params IPEndPoint[] endPoints)
     : base(tcpIp, sslAuthOptions, rateLimiterConfigName, endPoints.Any() ? endPoints : IPUtil.GenerateListeningEndPointsList(false, Consts.Ports.LogServerDefaultServicePort))
 {
 }