File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2424 </Folder >
2525 <Folder Name =" /src/" >
2626 <File Path =" src/Directory.Build.props" />
27+ <Project Path =" src/RESPite.Proxy/RESPite.Proxy.csproj" />
2728 <Project Path =" src/RESPite/RESPite.csproj" />
2829 <Project Path =" src/StackExchange.Redis/StackExchange.Redis.csproj" />
2930 </Folder >
Original file line number Diff line number Diff line change 1+ using System . Net ;
2+ using Microsoft . AspNetCore . Connections ;
3+ using RESPite . Proxy ;
4+
5+ var server = new ProxyServer ( )
6+ {
7+ Password = "letmein" ,
8+ } ;
9+
10+ /*
11+ // demonstrate cluster spoofing
12+ server.ServerType = ServerType.Cluster;
13+ var ep = server.AddEmptyNode();
14+ server.Migrate("key", ep);
15+ */
16+
17+ var builder = WebApplication . CreateBuilder ( args ) ;
18+ builder . Services . AddSingleton < ProxyServer > ( server ) ;
19+ builder . WebHost . ConfigureKestrel ( options =>
20+ {
21+ // HTTP 5000 (test/debug API only)
22+ options . ListenLocalhost ( 5000 ) ;
23+
24+ // this is the core of using Kestrel to create a TCP server
25+ // TCP 6379
26+ Action < Microsoft . AspNetCore . Server . Kestrel . Core . ListenOptions > builder = builder => builder . UseConnectionHandler < ProxyHandler > ( ) ;
27+ foreach ( var ep in server . GetEndPoints ( ) )
28+ {
29+ if ( ep is IPEndPoint ip && ip . Address . Equals ( IPAddress . Loopback ) )
30+ {
31+ options . ListenLocalhost ( ip . Port , builder ) ;
32+ }
33+ else
34+ {
35+ options . Listen ( ep , builder ) ;
36+ }
37+ }
38+ } ) ;
39+
40+ var app = builder . Build ( ) ;
41+
42+ // run the server
43+ await app . RunAsync ( ) ;
Original file line number Diff line number Diff line change 1+ namespace RESPite . Proxy ;
2+
3+ public class ProxyClient
4+ {
5+ private int _db ;
6+ }
Original file line number Diff line number Diff line change 1+ using Microsoft . AspNetCore . Connections ;
2+
3+ namespace RESPite . Proxy ;
4+
5+ public sealed class ProxyHandler ( ProxyServer server ) : ConnectionHandler
6+ {
7+ public override Task OnConnectedAsync ( ConnectionContext connection )
8+ => server . RunClientAsync ( connection . Transport ) ;
9+ }
Original file line number Diff line number Diff line change 1+ using System . IO . Pipelines ;
2+ using System . Net ;
3+
4+ namespace RESPite . Proxy ;
5+
6+ public class ProxyServer
7+ {
8+ public string Password { get ; set ; } = "" ;
9+
10+ public IEnumerable < EndPoint > GetEndPoints ( )
11+ {
12+ yield return new IPEndPoint ( IPAddress . Loopback , 6379 ) ;
13+ }
14+
15+ public Task RunClientAsync ( IDuplexPipe connectionTransport )
16+ {
17+ throw new NotImplementedException ( ) ;
18+ }
19+ }
Original file line number Diff line number Diff line change 1+ <Project Sdk =" Microsoft.NET.Sdk.Web" >
2+
3+ <PropertyGroup >
4+ <OutputType >Exe</OutputType >
5+ <TargetFramework >net10.0</TargetFramework >
6+ <ImplicitUsings >enable</ImplicitUsings >
7+ <Nullable >enable</Nullable >
8+ </PropertyGroup >
9+
10+ <ItemGroup >
11+ <PackageReference Remove =" Microsoft.CodeAnalysis.PublicApiAnalyzers" />
12+ <ProjectReference Include =" ../RESPite/RESPite.csproj" />
13+ </ItemGroup >
14+
15+ </Project >
You can’t perform that action at this time.
0 commit comments