Beispiel #1
0
        /// <nodoc/>
        internal void Start(int port, ServerServiceDefinition serverService)
        {
            var interceptor = new ServerInterceptor(m_loggingContext, m_invocationId);

            ServerCredentials serverCreds = null;

            if (GrpcSettings.EncryptionEnabled)
            {
                string certSubjectName = EngineEnvironmentSettings.CBBuildUserCertificateName;
                if (GrpcEncryptionUtil.TryGetPublicAndPrivateKeys(certSubjectName, out string publicCertificate, out string privateKey, out var _) &&
                    publicCertificate != null &&
                    privateKey != null)
                {
                    serverCreds = new SslServerCredentials(
                        new List <KeyCertificatePair> {
                        new KeyCertificatePair(publicCertificate, privateKey)
                    },
                        null,
                        SslClientCertificateRequestType.DontRequest);

                    Logger.Log.GrpcAuthTrace(m_loggingContext, $"Server-side SSL credentials is enabled.");
                }
                else
                {
                    Logger.Log.GrpcAuthWarningTrace(m_loggingContext, $"Could not extract public certificate and private key from '{certSubjectName}'. Server will be started without ssl.");
                }
            }
        /// <nodoc/>
        public void Start(int port)
        {
            var interceptor = new ServerInterceptor(m_loggingContext, m_buildId);

            m_server = new Server(ClientConnectionManager.ServerChannelOptions)
            {
                Services = { Master.BindService(this).Intercept(interceptor) },
                Ports    = { new ServerPort(IPAddress.Any.ToString(), port, ServerCredentials.Insecure) },
            };
            m_server.Start();
        }
 private TestInterceptor GetInterceptor(ServerInterceptor interceptor) {
     TestInterceptor result;
     switch (interceptor) {
         case ServerInterceptor.InterceptorA:
             result = m_interceptorInit.A;
             break;
         case ServerInterceptor.InterceptorB:
             result = m_interceptorInit.B;
             break;
         case ServerInterceptor.InterceptorC:
             result = m_interceptorInit.C;
             break;
         default:
             throw new BAD_PARAM(3000, CompletionStatus.Completed_Yes);
     }
     return result;
 }
Beispiel #4
0
        public TestServer(ServerMetrics metrics = null)
        {
            _metricsServer = new MetricServer(MetricsHostname, MetricsPort);
            _metricsServer.Start();
            _interceptor =
                new ServerInterceptor(enableLatencyMetrics: true, metrics);

            _server = new Server()
            {
                Services =
                {
                    TestService.BindService(new TestServiceImp()).Intercept(_interceptor)
                },
                Ports = { new ServerPort(GrpcHostname, GrpcPort, ServerCredentials.Insecure) }
            };

            _server.Start();
        }
Beispiel #5
0
        public TestServer()
        {
            _interceptor =
                new ServerInterceptor(MetricsHostname, MetricsPort)
            {
                EnableLatencyMetrics = true
            };

            _server = new Server()
            {
                Services =
                {
                    TestService.BindService(new TestServiceImp()).Intercept(_interceptor)
                },
                Ports = { new ServerPort(GrpcHostname, GrpcPort, ServerCredentials.Insecure) }
            };

            _server.Start();
        }
        public void SetThrowException(ServerInterceptor interceptor, ServerInterceptionPoint point)
        {
            TestInterceptor toModify = GetInterceptor(interceptor);

            switch (point)
            {
            case ServerInterceptionPoint.ReceiveSvcContext:
                toModify.SetExceptionOnInPathSvcContext(new BAD_PARAM(2000, CompletionStatus.Completed_No));
                break;

            case ServerInterceptionPoint.ReceiveRequest:
                toModify.SetExceptionOnInPathRequest(new BAD_PARAM(2000, CompletionStatus.Completed_No));
                break;

            case ServerInterceptionPoint.SendResponse:
                toModify.SetExceptionOnOutPath(new BAD_PARAM(2000, CompletionStatus.Completed_Yes));
                break;
            }
        }
        private TestInterceptor GetInterceptor(ServerInterceptor interceptor)
        {
            TestInterceptor result;

            switch (interceptor)
            {
            case ServerInterceptor.InterceptorA:
                result = m_interceptorInit.A;
                break;

            case ServerInterceptor.InterceptorB:
                result = m_interceptorInit.B;
                break;

            case ServerInterceptor.InterceptorC:
                result = m_interceptorInit.C;
                break;

            default:
                throw new BAD_PARAM(3000, CompletionStatus.Completed_Yes);
            }
            return(result);
        }
Beispiel #8
0
 /// <summary>
 /// 注入服务端中间件
 /// </summary>
 /// <param name="interceptor"></param>
 /// <returns></returns>
 public ServerBuilder UseInterceptor(ServerInterceptor interceptor)
 {
     _interceptors.Add(interceptor);
     return(this);
 }
 public OutPathResult GetOutPathResult(ServerInterceptor interceptor)
 {
     return(GetInterceptor(interceptor).OutPathResult);
 }
 public bool IsReceiveRequestCalled(ServerInterceptor interceptor)
 {
     return(GetInterceptor(interceptor).InvokedOnInPathReceive);
 }
 public bool IsReceiveSvcContextCalled(ServerInterceptor interceptor)
 {
     return(GetInterceptor(interceptor).InvokedOnInPathReceiveSvcContext);
 }
 public void SetThrowException(ServerInterceptor interceptor, ServerInterceptionPoint point) {
     TestInterceptor toModify = GetInterceptor(interceptor);
     switch (point) {
         case ServerInterceptionPoint.ReceiveSvcContext:
             toModify.SetExceptionOnInPathSvcContext(new BAD_PARAM(2000, CompletionStatus.Completed_No));
             break;
         case ServerInterceptionPoint.ReceiveRequest:
             toModify.SetExceptionOnInPathRequest(new BAD_PARAM(2000, CompletionStatus.Completed_No));
             break;
         case ServerInterceptionPoint.SendResponse:
             toModify.SetExceptionOnOutPath(new BAD_PARAM(2000, CompletionStatus.Completed_Yes));
             break;
     }
 }
 public OutPathResult GetOutPathResult(ServerInterceptor interceptor) {
     return GetInterceptor(interceptor).OutPathResult;
 }
 public bool IsReceiveRequestCalled(ServerInterceptor interceptor) {
     return GetInterceptor(interceptor).InvokedOnInPathReceive;
 }
 public bool IsReceiveSvcContextCalled(ServerInterceptor interceptor) {
     return GetInterceptor(interceptor).InvokedOnInPathReceiveSvcContext;
 }