Skip to content

Commit

Permalink
add server option EnableProxyProtocol
Browse files Browse the repository at this point in the history
  • Loading branch information
kerryjiang committed Aug 10, 2024
1 parent 2b191a2 commit 4a924e6
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 12 deletions.
6 changes: 0 additions & 6 deletions src/SuperSocket.ProtoBase/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,5 @@ public static int Write(this IBufferWriter<byte> writer, ReadOnlySpan<char> text

return totalBytes;
}

public static IPipelineFilterFactory<TPackageInfo> UseProxyProtocol<TPackageInfo>(this IPipelineFilterFactory<TPackageInfo> pipelineFilterFactory)
where TPackageInfo : class
{
return new ProxyProtocolPipelineFilterFactory<TPackageInfo>(pipelineFilterFactory);
}
}
}
5 changes: 2 additions & 3 deletions src/SuperSocket.ProtoBase/PackagePartsPipelineFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace SuperSocket.ProtoBase
{
public abstract class PackagePartsPipelineFilter<TPackageInfo> : IPipelineFilter<TPackageInfo>
where TPackageInfo : class
{
private IPackagePartReader<TPackageInfo> _currentPartReader;

Expand Down Expand Up @@ -40,7 +39,7 @@ public virtual TPackageInfo Filter(SequenceReader<byte> reader)
}

if (needMoreData || reader.Remaining <= 0)
return null;
return default;
}
}

Expand All @@ -51,7 +50,7 @@ protected virtual void OnPartReaderSwitched(IPackagePartReader<TPackageInfo> cur

public virtual void Reset()
{
CurrentPackage = null;
CurrentPackage = default;
_currentPartReader = null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
namespace SuperSocket.ProtoBase.ProxyProtocol
{
public class ProxyProtocolPipelineFilter<TPackageInfo> : PackagePartsPipelineFilter<TPackageInfo>
where TPackageInfo : class
{
private readonly IPipelineFilter<TPackageInfo> _applicationPipelineFilter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
namespace SuperSocket.ProtoBase.ProxyProtocol
{
public class ProxyProtocolPipelineFilterFactory<TPackageInfo> : IPipelineFilterFactory<TPackageInfo>
where TPackageInfo : class
{
private readonly IPipelineFilterFactory<TPackageInfo> _pipelineFilterFactory;

Expand Down
2 changes: 2 additions & 0 deletions src/SuperSocket.Server.Abstractions/ServerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ public class ServerOptions : ConnectionOptions
/// In seconds.
/// </summary>
public int PackageHandlingTimeOut { get; set; } = 30;

public bool EnableProxyProtocol { get; set; }
}
}
8 changes: 7 additions & 1 deletion src/SuperSocket.Server/SuperSocketService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using SuperSocket.Server.Abstractions.Session;
using SuperSocket.Server.Abstractions.Middleware;
using SuperSocket.Server.Connection;
using SuperSocket.ProtoBase.ProxyProtocol;

namespace SuperSocket.Server
{
Expand Down Expand Up @@ -113,7 +114,12 @@ public SuperSocketService(IServiceProvider serviceProvider, IOptions<ServerOptio

protected virtual IPipelineFilterFactory<TReceivePackageInfo> GetPipelineFilterFactory()
{
return _serviceProvider.GetRequiredService<IPipelineFilterFactory<TReceivePackageInfo>>();
var filterFactory = _serviceProvider.GetRequiredService<IPipelineFilterFactory<TReceivePackageInfo>>();

if (Options.EnableProxyProtocol)
filterFactory = new ProxyProtocolPipelineFilterFactory<TReceivePackageInfo>(filterFactory);

return filterFactory;
}

private bool AddConnectionListener(ListenOptions listenOptions, ServerOptions serverOptions)
Expand Down

0 comments on commit 4a924e6

Please sign in to comment.