forked from planetarium/libplanet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
216 additions
and
123 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
sdk/node/Libplanet.Node.Executable/EntryPoints/DefaultEntryPoint.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using Libplanet.Node.DependencyInjection; | ||
using Libplanet.Node.Options.Schema; | ||
using Microsoft.AspNetCore.Server.Kestrel.Core; | ||
|
||
namespace Libplanet.Node.API.EntryPoints; | ||
|
||
[Singleton<IApplicationEntryPoint>] | ||
[Singleton<IApplicationBuilderEntryPoint>] | ||
internal sealed class DefaultEntryPoint | ||
: IApplicationEntryPoint, IApplicationBuilderEntryPoint | ||
{ | ||
private const string HandlerMessage = """ | ||
Communication with gRPC endpoints must be made through a gRPC client. To learn how to | ||
create a client, visit: https://go.microsoft.com/fwlink/?linkid=2086909 | ||
"""; | ||
|
||
public void Run(WebApplicationBuilder builder) | ||
{ | ||
builder.Logging.AddConsole(); | ||
|
||
if (builder.Environment.IsDevelopment()) | ||
{ | ||
builder.WebHost.ConfigureKestrel(options => | ||
{ | ||
// Setup a HTTP/2 endpoint without TLS. | ||
options.ListenLocalhost(5259, o => o.Protocols = | ||
HttpProtocols.Http1AndHttp2); | ||
}); | ||
} | ||
} | ||
|
||
public async Task RunAsync(WebApplication app, CancellationToken cancellationToken) | ||
{ | ||
var serviceProvider = app.Services; | ||
var schema = await OptionsSchemaBuilder.GetSchemaAsync(cancellationToken); | ||
app.MapGet("/", () => HandlerMessage); | ||
app.MapGet("/schema", () => schema); | ||
} | ||
} |
23 changes: 14 additions & 9 deletions
23
sdk/node/Libplanet.Node.Executable/EntryPoints/GrpcServiceEntryPoint.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
global using Libplanet.Node.API; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using Libplanet.Node.DependencyInjection; | ||
using Libplanet.Node.Extensions; | ||
using Libplanet.Node.Options; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace Libplanet.Node.API; | ||
|
||
public sealed class NodeApplication : IAsyncDisposable | ||
{ | ||
private readonly WebApplicationBuilder _builder; | ||
private WebApplication? _app; | ||
|
||
public NodeApplication(string[] args) | ||
{ | ||
SynchronizationContext.SetSynchronizationContext(new()); | ||
var builder = WebApplication.CreateBuilder(args); | ||
var nodeBuilder = builder.Services.AddLibplanetNode(builder.Configuration); | ||
var serviceProvider = builder.Services.BuildServiceProvider(); | ||
var serviceEntryPoints | ||
= serviceProvider.GetRequiredService<IEnumerable<IApplicationBuilderEntryPoint>>(); | ||
var nodeOptions = serviceProvider.GetRequiredService<IOptions<NodeOptions>>(); | ||
var seedOptionsMonitor = serviceProvider.GetRequiredService<IOptionsMonitor<SeedOptions>>(); | ||
|
||
foreach (var serviceEntryPoint in serviceEntryPoints) | ||
{ | ||
serviceEntryPoint.Run(builder); | ||
} | ||
|
||
if (nodeOptions.Value.IsEnabled) | ||
{ | ||
nodeBuilder.WithNode(); | ||
} | ||
|
||
if (seedOptionsMonitor.Get(SeedOptions.BlocksyncSeed).IsEnabled) | ||
{ | ||
nodeBuilder.WithBlocksyncSeed(); | ||
} | ||
|
||
if (seedOptionsMonitor.Get(SeedOptions.ConsensusSeed).IsEnabled) | ||
{ | ||
nodeBuilder.WithConsensusSeed(); | ||
} | ||
|
||
_builder = builder; | ||
} | ||
|
||
public async ValueTask DisposeAsync() | ||
{ | ||
if (_app is not null) | ||
{ | ||
await _app.DisposeAsync(); | ||
_app = null; | ||
} | ||
} | ||
|
||
public async Task RunAsync() | ||
{ | ||
_app = _builder.Build(); | ||
await _app.RunEntryPointAsync(default); | ||
await _app.RunAsync(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,2 @@ | ||
using Libplanet.Node.DependencyInjection; | ||
using Libplanet.Node.Extensions; | ||
using Libplanet.Node.Options.Schema; | ||
using Microsoft.AspNetCore.Server.Kestrel.Core; | ||
|
||
SynchronizationContext.SetSynchronizationContext(new()); | ||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
builder.Logging.AddConsole(); | ||
|
||
if (builder.Environment.IsDevelopment()) | ||
{ | ||
builder.WebHost.ConfigureKestrel(options => | ||
{ | ||
// Setup a HTTP/2 endpoint without TLS. | ||
options.ListenLocalhost(5259, o => o.Protocols = | ||
HttpProtocols.Http1AndHttp2); | ||
}); | ||
} | ||
|
||
// Additional configuration is required to successfully run gRPC on macOS. | ||
// For instructions on how to configure Kestrel and gRPC clients on macOS, | ||
// visit https://go.microsoft.com/fwlink/?linkid=2099682 | ||
|
||
// Add services to the container. | ||
|
||
|
||
// builder.Services.AddGrpc(); | ||
// builder.Services.AddGrpcReflection(); | ||
var libplanetBuilder = builder.Services.AddLibplanetNode(builder.Configuration) | ||
.WithFlexible(builder.Environment); | ||
|
||
var app = builder.Build(); | ||
var handlerMessage = """ | ||
Communication with gRPC endpoints must be made through a gRPC client. To learn how to | ||
create a client, visit: https://go.microsoft.com/fwlink/?linkid=2086909 | ||
"""; | ||
var schema = await OptionsSchemaBuilder.GetSchemaAsync(default); | ||
var applicationEntryPoints | ||
= app.Services.GetRequiredService<IEnumerable<IApplicationEntryPoint>>(); | ||
|
||
foreach (var entryPoint in applicationEntryPoints) | ||
{ | ||
entryPoint.Build(app, app.Environment, libplanetBuilder.Scopes); | ||
} | ||
|
||
// Configure the HTTP request pipeline. | ||
// app.MapGrpcServiceFromDomain(libplanetBuilder.Scopes); | ||
app.MapGet("/", () => handlerMessage); | ||
app.MapGet("/schema", () => schema); | ||
|
||
// if (builder.Environment.IsDevelopment()) | ||
// { | ||
// app.MapGrpcReflectionService().AllowAnonymous(); | ||
// } | ||
|
||
await using var app = new NodeApplication(args); | ||
await app.RunAsync(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
41 changes: 41 additions & 0 deletions
41
sdk/node/Libplanet.Node.Swagger/EntryPoints/SwaggerEntryPoint.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using Libplanet.Node.DependencyInjection; | ||
using Libplanet.Node.Swagger.Options; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace Libplanet.Node.Swagger.EntryPoints; | ||
|
||
[Singleton<IApplicationBuilderEntryPoint>] | ||
[Singleton<IApplicationEntryPoint>] | ||
internal sealed class SwaggerEntryPoint( | ||
IOptions<SwaggerOptions> options, IWebHostEnvironment environment) | ||
: IApplicationBuilderEntryPoint, IApplicationEntryPoint | ||
{ | ||
private readonly SwaggerOptions _options = options.Value; | ||
|
||
public Task RunAsync(WebApplication app, CancellationToken cancellationToken) | ||
{ | ||
if (environment.IsDevelopment()) | ||
{ | ||
app.UseSwagger(); | ||
app.UseSwaggerUI(); | ||
} | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
public void Run(WebApplicationBuilder builder) | ||
{ | ||
if (_options.IsEnabled) | ||
{ | ||
builder.Services.AddEndpointsApiExplorer(); | ||
builder.Services.AddSwaggerGen(); | ||
|
||
builder.Services.AddAuthorization(); | ||
builder.Services.AddAuthentication("Bearer").AddJwtBearer(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
sdk/node/Libplanet.Node/DependencyInjection/IApplicationBuilderEntryPoint.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using Microsoft.AspNetCore.Builder; | ||
|
||
namespace Libplanet.Node.DependencyInjection; | ||
|
||
public interface IApplicationBuilderEntryPoint | ||
{ | ||
void Run(WebApplicationBuilder builder); | ||
} |
5 changes: 2 additions & 3 deletions
5
sdk/node/Libplanet.Node/DependencyInjection/IApplicationEntryPoint.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.Routing; | ||
using Microsoft.AspNetCore.Builder; | ||
|
||
namespace Libplanet.Node.DependencyInjection; | ||
|
||
public interface IApplicationEntryPoint | ||
{ | ||
void Build(IEndpointRouteBuilder app, IWebHostEnvironment environment, string[] scopes); | ||
Task RunAsync(WebApplication app, CancellationToken cancellationToken); | ||
} |
Oops, something went wrong.