public override void Given()
        {
            string internalHostAdvertiseAs = "127.0.1.1";
            string externalHostAdvertiseAs = "127.0.1.2";
            var    internalIPToAdvertise   = IPAddress.Parse(internalHostAdvertiseAs);
            var    externalIPToAdvertise   = IPAddress.Parse(externalHostAdvertiseAs);
            var    intTcpEndpoint          = new IPEndPoint(internalIPToAdvertise, 1111);
            var    intSecTcpEndpoint       = new IPEndPoint(internalIPToAdvertise, 1112);
            var    extTcpEndpoint          = new IPEndPoint(externalIPToAdvertise, 1113);
            var    extSecTcpEndpoint       = new IPEndPoint(externalIPToAdvertise, 1114);
            var    httpEndpoint            = new IPEndPoint(externalIPToAdvertise, 1116);

            _advertiseInfo = new Data.GossipAdvertiseInfo(intTcpEndpoint.ToDnsEndPoint(),
                                                          intSecTcpEndpoint.ToDnsEndPoint(), extTcpEndpoint.ToDnsEndPoint(),
                                                          extSecTcpEndpoint.ToDnsEndPoint(), httpEndpoint.ToDnsEndPoint(),
                                                          internalHostAdvertiseAs, externalHostAdvertiseAs, httpEndpoint.Port);

            _builder
            .WithServerCertificate(ssl_connections.GetServerCertificate())
            .WithInternalTcpOn(intTcpEndpoint)
            .WithInternalSecureTcpOn(intSecTcpEndpoint)
            .WithExternalTcpOn(extTcpEndpoint)
            .WithExternalSecureTcpOn(extSecTcpEndpoint)
            .WithHttpOn(httpEndpoint)
            .AdvertiseInternalHostAs(internalHostAdvertiseAs)
            .AdvertiseExternalHostAs(externalHostAdvertiseAs)
            .AdvertiseInternalTCPPortAs(intTcpEndpoint.Port)
            .AdvertiseExternalTCPPortAs(extTcpEndpoint.Port)
            .AdvertiseInternalSecureTCPPortAs(intSecTcpEndpoint.Port)
            .AdvertiseExternalSecureTCPPortAs(extSecTcpEndpoint.Port)
            .AdvertiseHttpPortAs(httpEndpoint.Port);
        }
        public void should_have_default_endpoints()
        {
            var internalTcp  = new IPEndPoint(IPAddress.Loopback, 1112);
            var externalTcp  = new IPEndPoint(IPAddress.Loopback, 1113);
            var httpEndPoint = new IPEndPoint(IPAddress.Loopback, 2113);

            Assert.AreEqual(internalTcp, _settings.NodeInfo.InternalTcp);
            Assert.AreEqual(externalTcp, _settings.NodeInfo.ExternalTcp);
            Assert.AreEqual(httpEndPoint, _settings.NodeInfo.HttpEndPoint);

            Assert.AreEqual(internalTcp.ToDnsEndPoint(), _settings.GossipAdvertiseInfo.InternalTcp);
            Assert.AreEqual(externalTcp.ToDnsEndPoint(), _settings.GossipAdvertiseInfo.ExternalTcp);
            Assert.AreEqual(httpEndPoint.ToDnsEndPoint(), _settings.GossipAdvertiseInfo.HttpEndPoint);
        }
示例#3
0
        public MiniClusterNode(
            string pathname, int debugIndex, IPEndPoint internalTcp, IPEndPoint internalTcpSec,
            IPEndPoint externalTcp, IPEndPoint externalTcpSec, IPEndPoint httpEndPoint, EndPoint[] gossipSeeds,
            ISubsystem[] subsystems = null, int?chunkSize = null, int?cachedChunkSize = null,
            bool enableTrustedAuth  = false, bool skipInitializeStandardUsersCheck = true, int memTableSize = 1000,
            bool inMemDb            = true, bool disableFlushToDisk = false, bool readOnlyReplica = false)
        {
            if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport",
                                     true);    //TODO JPB Remove this sadness when dotnet core supports kestrel + http2 on macOS
            }

            RunningTime.Start();
            RunCount += 1;

            DebugIndex = debugIndex;

            _dbPath = Path.Combine(
                pathname,
                string.Format(
                    "mini-cluster-node-db-{0}-{1}-{2}", externalTcp.Port, externalTcpSec.Port, httpEndPoint.Port));

            Directory.CreateDirectory(_dbPath);
            FileStreamExtensions.ConfigureFlush(disableFlushToDisk);
            Db =
                new TFChunkDb(
                    CreateDbConfig(chunkSize ?? ChunkSize, _dbPath, cachedChunkSize ?? CachedChunkSize, inMemDb));

            InternalTcpEndPoint    = internalTcp;
            InternalTcpSecEndPoint = internalTcpSec;

            ExternalTcpEndPoint    = externalTcp;
            ExternalTcpSecEndPoint = externalTcpSec;
            HttpEndPoint           = httpEndPoint;

            var useHttps                = EnableHttps();
            var certificate             = useHttps ? ssl_connections.GetServerCertificate() : null;
            var trustedRootCertificates =
                useHttps ? new X509Certificate2Collection(ssl_connections.GetRootCertificate()) : null;

            var singleVNodeSettings = new ClusterVNodeSettings(
                Guid.NewGuid(), debugIndex, () => new ClusterNodeOptions(),
                InternalTcpEndPoint, InternalTcpSecEndPoint, ExternalTcpEndPoint,
                ExternalTcpSecEndPoint, HttpEndPoint,
                new Data.GossipAdvertiseInfo(
                    InternalTcpEndPoint.ToDnsEndPoint(),
                    InternalTcpSecEndPoint.ToDnsEndPoint(),
                    ExternalTcpEndPoint.ToDnsEndPoint(), ExternalTcpSecEndPoint.ToDnsEndPoint(), HttpEndPoint.ToDnsEndPoint(),
                    null, null, 0, null, 0, 0), enableTrustedAuth,
                certificate, trustedRootCertificates, Opts.CertificateReservedNodeCommonNameDefault, 1, false,
                "", gossipSeeds, TFConsts.MinFlushDelayMs, 3, 2, 2, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(10),
                TimeSpan.FromSeconds(10), false, false, TimeSpan.FromHours(1), StatsStorage.None, 0,
                new AuthenticationProviderFactory(components =>
                                                  new InternalAuthenticationProviderFactory(components)),
                new AuthorizationProviderFactory(components =>
                                                 new LegacyAuthorizationProviderFactory(components.MainQueue)),
                disableScavengeMerging: true, scavengeHistoryMaxAge: 30,
                adminOnPublic: true,
                statsOnPublic: true, gossipOnPublic: true, gossipInterval: TimeSpan.FromSeconds(2),
                gossipAllowedTimeDifference: TimeSpan.FromSeconds(1), gossipTimeout: TimeSpan.FromSeconds(3),
                extTcpHeartbeatTimeout: TimeSpan.FromSeconds(2), extTcpHeartbeatInterval: TimeSpan.FromSeconds(2),
                intTcpHeartbeatTimeout: TimeSpan.FromSeconds(2), intTcpHeartbeatInterval: TimeSpan.FromSeconds(2),
                deadMemberRemovalPeriod: TimeSpan.FromSeconds(1800),
                verifyDbHash: false, maxMemtableEntryCount: memTableSize,
                hashCollisionReadLimit: Opts.HashCollisionReadLimitDefault,
                startStandardProjections: false, disableHTTPCaching: false, logHttpRequests: false,
                connectionPendingSendBytesThreshold: Opts.ConnectionPendingSendBytesThresholdDefault,
                connectionQueueSizeThreshold: Opts.ConnectionQueueSizeThresholdDefault,
                readOnlyReplica: readOnlyReplica,
                ptableMaxReaderCount: Constants.PTableMaxReaderCountDefault,
                enableExternalTCP: true,
                disableHttps: !useHttps,
                enableAtomPubOverHTTP: true);

            _isReadOnlyReplica = readOnlyReplica;

            Log.Information(
                "\n{0,-25} {1} ({2}/{3}, {4})\n" + "{5,-25} {6} ({7})\n" + "{8,-25} {9} ({10}-bit)\n"
                + "{11,-25} {12}\n" + "{13,-25} {14}\n" + "{15,-25} {16}\n" + "{17,-25} {18}\n" + "{19,-25} {20}\n\n",
                "ES VERSION:", VersionInfo.Version, VersionInfo.Branch, VersionInfo.Hashtag, VersionInfo.Timestamp,
                "OS:", OS.OsFlavor, Environment.OSVersion, "RUNTIME:", OS.GetRuntimeVersion(),
                Marshal.SizeOf(typeof(IntPtr)) * 8, "GC:",
                GC.MaxGeneration == 0
                                        ? "NON-GENERATION (PROBABLY BOEHM)"
                                        : string.Format("{0} GENERATIONS", GC.MaxGeneration + 1), "DBPATH:", _dbPath, "ExTCP ENDPOINT:",
                ExternalTcpEndPoint, "ExTCP SECURE ENDPOINT:", ExternalTcpSecEndPoint, "ExHTTP ENDPOINT:",
                HttpEndPoint);

            Node = new ClusterVNode(Db, singleVNodeSettings,
                                    infoControllerBuilder: new InfoControllerBuilder()
                                    , subsystems: subsystems,
                                    gossipSeedSource: new KnownEndpointGossipSeedSource(gossipSeeds));
            Node.HttpService.SetupController(new TestController(Node.MainQueue));

            _host = new WebHostBuilder()
                    .UseKestrel(o => {
                o.Listen(HttpEndPoint, options => {
                    if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
                    {
                        options.Protocols = HttpProtocols.Http2;
                    }
                    else
                    {
                        options.UseHttps(new HttpsConnectionAdapterOptions {
                            ServerCertificate           = certificate,
                            ClientCertificateMode       = ClientCertificateMode.AllowCertificate,
                            ClientCertificateValidation = (certificate, chain, sslPolicyErrors) => {
                                var(isValid, error) =
                                    ClusterVNode.ValidateClientCertificateWithTrustedRootCerts(certificate, chain, sslPolicyErrors, () => trustedRootCertificates);
                                if (!isValid && error != null)
                                {
                                    Log.Error("Client certificate validation error: {e}", error);
                                }
                                return(isValid);
                            }
                        });
                    }
                });
            })
                    .UseStartup(Node.Startup)
                    .Build();

            _kestrelTestServer = new TestServer(new WebHostBuilder()
                                                .UseKestrel()
                                                .UseStartup(Node.Startup));
        }
示例#4
0
        public void Start()
        {
            try
            {
                UdpServer = new UdpClient(30000);
            }
            catch (Exception ex)
            {
                throw new Exception("UdpServer初始化失败,原因:" + ex.Message);
            }
            SendLoginBeatSend();
            IPEndPoint tbip = null;

            if (IsLoad)
            {
                try
                {
                    UdpServer.Client.ReceiveTimeout = 5 * 1000;
                    byte[]       dataLogin = UdpServer.Receive(ref tbip);
                    LoginBeatRec BeatRec   = ProcessJsonLogin(dataLogin.ToASCIIString());
                    if (BeatRec != null && BeatRec.las != null && BeatRec.las.login_success)
                    {
                    }
                    else
                    {
                        throw new Exception("服务器拒绝登陆,登陆失败");
                    }
                }
                catch { throw new Exception("服务器无响应登陆失败,Time=" + UdpServer.Client.ReceiveTimeout + "MS"); }
            }
            UdpServer.Client.ReceiveTimeout = 5 * 60 * 1000;
            IsRuning = true;
            Task.Run(() =>
            {
                while (IsRuning)
                {
                    try
                    {
                        IPEndPoint ip = null;
                        byte[] data   = UdpServer.Receive(ref ip);
                        if (!IsLoad)
                        {
                            Ep = ip.ToDnsEndPoint();
                        }
                        if (data.Length > 0)
                        {
                            if (data[2] == 'a' && data[3] == 's')
                            {
                                LoginBeatRec nas = ProcessJsonLogin(data.ToASCIIString());
                                if (nas?.las != null && nas.las.login_success)
                                {
                                    BeatRcvTime = DateTime.Now;
                                }
                            }
                            else
                            {
                                ProcessLoraPackage(data);
                            }
                        }
                    }
                    catch (Exception ex) { log.Error(ex); }
                }
            });
        }