示例#1
0
    static int Run()
    {
        // Locate path to certificates folder in distribution.
        string rootDir  = DllPathResolver.FindDistributionRootDir();
        string certsDir = Path.Combine(rootDir, "certs");

        // Initialize RCF.
        RCFProto.Init();

        // Create server.
        RcfProtoServer server = new RcfProtoServer();

        // Bind Protobuf service.
        SearchServiceImpl myService = new SearchServiceImpl();

        server.BindService(myService);

        // Add the endpoints that this server will support.
        List <Endpoint> endpoints = new List <Endpoint>();

        endpoints.Add(new TcpEndpoint(50001));
        endpoints.Add(new HttpEndpoint(50002));
        endpoints.Add(new HttpsEndpoint(50003));
        endpoints.Add(new Win32NamedPipeEndpoint("DemoServerPipe"));

        foreach (Endpoint endpoint in endpoints)
        {
            server.AddEndpoint(endpoint);
        }

        // By default, the server serves clients on a single thread. Here, we are
        // configuring the server to use a thread pool with up to 10 threads.
        ThreadPool threadPool = new ThreadPool(1, 10);

        threadPool.SetThreadName("RCFProto Server");
        server.SetThreadPool(threadPool);

        // Configure SSL certificate.

        // Load certificate from PFX format.
        string      certPath = Path.Combine(certsDir, "certA.p12");
        Certificate cert     = new PfxCertificate(certPath, "", "localhost");

        server.SetCertificate(cert);
        server.SetSslImplementation(SslImplementation.Schannel);

        // Start the server.
        server.Start();

        // Wait for shutdown.
        SearchServiceImpl.ShutdownEvent.WaitOne();
        System.Console.WriteLine("Shutting down server.");

        // Stop server.
        server.Stop();

        return(0);
    }
示例#2
0
    // Command line options for the automated test harness.
    static void ParseCommandLine(string[] args)
    {
        // Check for --delay option.
        int delayMs = 0;

        for (int i = 0; i < args.Length; ++i)
        {
            if (args[i] == "--delay")
            {
                delayMs = 1000;
                if (i + 1 < args.Length)
                {
                    int tempVal = Convert.ToInt32(args[i + 1]);
                    if (tempVal > 0)
                    {
                        delayMs = tempVal;
                        i++;
                    }
                }
            }
        }
        if (delayMs > 0)
        {
            System.Console.WriteLine("Delaying client: " + delayMs.ToString() + " ms.");
            System.Threading.Thread.Sleep(delayMs);
        }

        // Check for --shutdown option.
        bool shouldShutdownServer = false;

        for (int i = 0; i < args.Length; i++)
        {
            if (args[i] == "--shutdown")
            {
                shouldShutdownServer = true;
            }
        }

        if (shouldShutdownServer)
        {
            System.Console.WriteLine("Sending shutdown request to server.");
            RCFProto.Init();
            RcfProtoChannel       channel         = new RcfProtoChannel(new TcpEndpoint("127.0.0.1", 50001));
            RcfProtoController    rcfController   = new RcfProtoController();
            SearchService.Stub    searchService   = new SearchService.Stub(channel);
            ShutdownServerRequest shutdownRequest = ShutdownServerRequest.CreateBuilder().Build();
            searchService.ShutdownServer(null, shutdownRequest, null);

            // Give the server some time to shutdown.
            System.Threading.Thread.Sleep(1000);

            Environment.Exit(0);
        }
    }
示例#3
0
        public override void Configure(Container container)
        {
            ServiceStack.Text.JsConfig.IncludeNullValues = true;
            ServiceStack.Text.JsConfig.IncludeTypeInfo   = true;

            if (System.PlatformExtension.IsMono())
            {
                RCFProto.SetNativeDllPath(@"/var/mono-www/bin/libRCFProto_NET_impl.so");
            }
            else
            {
                RCFProto.SetNativeDllPath(@"C:/Users/Brenden/Documents/visual studio 2013/Projects/SwgEMU-API/SWGEmu-API/bin/RCFProto_NET_impl.dll");
            }
            RCFProto.Init();

            container.Register <RcfProtoChannel>(AccquireChannel).ReusedWithin(ReuseScope.Request);

            container.RegisterAutoWiredAs <InventoryItemTransformModel, IInventoryItemTransformModel>();
            container.RegisterAutoWiredAs <StructureTransformModel, IStructureTransformModel>();

            container.Register <swgemurpcserver.rpc.SWGEmuAccountService.Stub>(c => swgemurpcserver.rpc.SWGEmuAccountService.CreateStub(c.Resolve <DeltaVSoft.RCFProto.RcfProtoChannel>())).ReusedWithin(ReuseScope.Request);
            container.Register <swgemurpcserver.rpc.SWGEmuCharacterDetailsService.Stub>(c => swgemurpcserver.rpc.SWGEmuCharacterDetailsService.Stub.CreateStub(c.Resolve <DeltaVSoft.RCFProto.RcfProtoChannel>())).ReusedWithin(ReuseScope.Request);
            container.Register <swgemurpcserver.rpc.SWGEmuStructureItemDetailsService.Stub>(c => swgemurpcserver.rpc.SWGEmuStructureItemDetailsService.CreateStub(c.Resolve <RcfProtoChannel>())).ReusedWithin(ReuseScope.Request);
            container.RegisterAutoWiredAs <Model.AccountModel, Model.IAccountModel>().ReusedWithin(ReuseScope.Request);
            container.RegisterAutoWiredAs <Model.CharacterModel, Model.ICharacterModel>().ReusedWithin(ReuseScope.Request);
            container.RegisterAutoWiredAs <Model.StructureModel, IStructureModel>().ReusedWithin(ReuseScope.Request);

            container.Register <Model.IStringDetailsModel>(c =>
            {
                string path = SWGEmuAPI.Properties.Settings.Default.DetailsFilePath;
                System.IO.DirectoryInfo pathInfo = new System.IO.DirectoryInfo(path);

                //throw new Exception(ServiceStack.Text.JsonSerializer.SerializeToString<List<string>>(realpaths));
                if (!pathInfo.Exists)
                {
                    //throw new System.IO.DirectoryNotFoundException("Direcotry for string details not found: " + path);
                }

                return(new Model.StringDetailsModel(new FileSystemVirtualDirectory(VirtualPathProvider, null, pathInfo)));
            }).ReusedWithin(ReuseScope.Hierarchy);


            SetConfig(new EndpointHostConfig
            {
                DebugMode = true //Show StackTraces for easier debugging (default auto inferred by Debug/Release builds)
            });

            //enable cors requests and enable the options method.
            Plugins.Add(new CorsFeature(allowedHeaders: "Content-Type, Authorization, Accept"));

            var emitGlobalHeadersHandler = new CustomActionHandler((httpReq, httpRes) => httpRes.EndRequest());

            this.Config.RawHttpHandlers.Add(httpReq =>
                                            httpReq.HttpMethod == HttpMethods.Options
                    ? emitGlobalHeadersHandler
                    : null);

            //cahcing
            container.Register <IRedisClientsManager>(c => new PooledRedisClientManager("localhost:6379"));
            container.Register <ICacheClient>(c => (ICacheClient)c.Resolve <IRedisClientsManager>().GetCacheClient()).ReusedWithin(Funq.ReuseScope.None);
            container.Register <IRedisClient>(c => c.Resolve <IRedisClientsManager>().GetClient()).ReusedWithin(Funq.ReuseScope.Request);

            Plugins.Add(new ServiceStack.ServiceInterface.Admin.RequestLogsFeature());
            Plugins.Add(new RazorFormat());
            Plugins.Add(new SessionFeature());
            Plugins.Add(new ValidationFeature());


            //OAuth2 classes
            container.Register <IDbConnectionFactory>(c => new OrmLiteConnectionFactory(Properties.Settings.Default.ConnectionString, ServiceStack.OrmLite.MySql.MySqlDialectProvider.Instance));
            container.RegisterAutoWiredAs <OAuth2.Server.Model.ClientModel, OAuth2.Server.Model.IClientModel>();
            container.RegisterAutoWiredAs <OAuth2.Server.Model.ResourceOwnerModel, OAuth2.Server.Model.IResourceOwnerModel>();
            container.RegisterAutoWiredAs <OAuth2.Server.Model.TokenDBModel, OAuth2.Server.Model.IDBTokenModel>();
            container.RegisterAutoWiredAs <OAuth2.Server.Model.TokenCacheModel, OAuth2.Server.Model.ICacheTokenModel>();
            container.RegisterAutoWiredAs <OAuth2.Server.Model.CacheDBTokenModel, OAuth2.Server.Model.ITokenModel>();
            container.RegisterAutoWiredAs <OAuth2.Server.Model.ApprovalModel, OAuth2.Server.Model.IApprovalModel>();
            container.RegisterAutoWiredAs <OAuth2.Server.Model.ScopeModel, OAuth2.Server.Model.IScopeModel>();
            container.RegisterAutoWiredAs <OAuth2.Server.Model.AuthorizationCodeModel, OAuth2.Server.Model.IAuthorizationCodeModel>();
            container.RegisterAutoWired <OAuth2.Server.Model.ClientGrantModel>();
            container.RegisterAutoWired <OAuth2.Server.Model.CodeGrantModel>();
            container.RegisterAutoWired <OAuth2.Server.Model.PasswordGrantModel>();
            container.RegisterAutoWired <OAuth2.Server.Model.RefreshTokenGrantModel>();
            container.RegisterAutoWired <OAuth2.Server.Model.TokenGrantModel>();

            //add filter to inject client details from basic auth
            RequestFilters.Add(AddClientDetails);
        }
示例#4
0
    static int Run(string[] args)
    {
        ParseCommandLine(args);

        // Locate path to certificates folder in distribution.
        string rootDir  = DllPathResolver.FindDistributionRootDir();
        string certsDir = Path.Combine(rootDir, "certs");

        // Initialize RCFProto.
        RCFProto.Init();

        // Build a search request.
        SearchRequest request = SearchRequest.CreateBuilder()
                                .SetQuery("something to search for")
                                .SetResultPerPage(10)
                                .SetPageNumber(0)
                                .Build();

        // Call the server on each of its supported endpoints.
        List <Endpoint> endpoints = new List <Endpoint>();

        endpoints.Add(new TcpEndpoint(50001));
        endpoints.Add(new HttpEndpoint(50002));
        endpoints.Add(new HttpsEndpoint(50003));
        endpoints.Add(new Win32NamedPipeEndpoint("DemoServerPipe"));

        foreach (Endpoint endpoint in endpoints)
        {
            // Create channel.
            RcfProtoChannel    channel       = new RcfProtoChannel(endpoint);
            RcfProtoController rcfController = new RcfProtoController();
            SearchService.Stub searchService = new SearchService.Stub(channel);

            // Set certificate validation callback, for SSL.
            channel.SetCertificateValidationCallback(OnValidateCertificate);

            {
                // Synchronous remote call.
                searchService.Search(null, request, null);
                SearchResponse response = (SearchResponse)channel.GetResponse();
            }

            {
                // Asynchronous remote call.
                channel.SetAsynchronousRpcMode(true);

                Action <SearchResponse> done = delegate(SearchResponse response)
                {
                    OnRpcDone(searchService, rcfController, request, response);
                };
                searchService.Search(rcfController, request, done);

                while (gCallCompleted == false)
                {
                    System.Threading.Thread.Sleep(500);
                }
            }
        }

        {
            // Create TCP channel.
            RcfProtoChannel    channel       = new RcfProtoChannel(endpoints[0]);
            RcfProtoController rcfController = new RcfProtoController();
            SearchService.Stub searchService = new SearchService.Stub(channel);

            // Enable compression (requires zlib to be installed).
            //channel.SetEnableCompression(true);

            // Custom connection timeout (10s).
            channel.SetConnectTimeoutMs(10 * 1000);

            // Custom remote call timeout (60s).
            channel.SetRemoteCallTimeoutMs(60 * 1000);

            // Enable NTLM authentication and encryption.
            channel.SetTransportProtocol(TransportProtocol.Ntlm);

            // The channel will pick up the credentials of the user running the
            // program. Alternatively, we can set the credentials explicitly:

            //channel.setUsername("MyDomain\\MyUsername");
            //channel.setPassword("MyPassword");

            searchService.Search(null, request, null);
            SearchResponse response = (SearchResponse)channel.GetResponse();

            // Enable SSL, with custom certificate validation callback.
            channel.SetTransportProtocol(TransportProtocol.Ssl);
            channel.SetCertificateValidationCallback(OnValidateCertificate);

            searchService.Search(null, request, null);
            response = (SearchResponse)channel.GetResponse();

            // Enable SSL, with validation against Windows certificate root store. Requires Schannel.
            string certPath = Path.Combine(certsDir, "caCertA.p12");

            // Open CA certificate.
            PfxCertificate caCert = new PfxCertificate(certPath, "", "RCF CA A");

            // Add it to the root store of the local machine.
            caCert.AddToStore(Win32CertificateLocation.LocalMachine, Win32CertificateStore.Root);

            channel.SetEnableSchannelCertificateValidation("localhost");
            channel.SetSslImplementation(SslImplementation.Schannel);

            // Disconnect so SSL handshake takes place again.
            channel.Disconnect();

            searchService.Search(null, request, null);
            response = (SearchResponse)channel.GetResponse();
        }

        return(0);
    }