Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port HA Proxy support from Netty #338

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions DotNetty.sln
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotNetty.Codecs.ProtocolBuf
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotNetty.Codecs.Redis", "src\DotNetty.Codecs.Redis\DotNetty.Codecs.Redis.csproj", "{1F442118-A665-4891-B056-FE9E54C5B049}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotNetty.Codecs.HaProxy", "src\DotNetty.Codecs.HaProxy\DotNetty.Codecs.HaProxy.csproj", "{23C52DC6-F4E7-457F-B36E-CEEBFA95D24D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotNetty.Buffers.Tests", "test\DotNetty.Buffers.Tests\DotNetty.Buffers.Tests.csproj", "{572E1914-489F-402D-944F-71EE0632E5D8}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotNetty.Tests.Common", "test\DotNetty.Tests.Common\DotNetty.Tests.Common.csproj", "{DA54DBAF-CCDA-4AD1-9FF9-EB6F890D1091}"
Expand All @@ -51,6 +53,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotNetty.Codecs.Protobuf.Te
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotNetty.Codecs.ProtocolBuffers.Tests", "test\DotNetty.Codecs.ProtocolBuffers.Tests\DotNetty.Codecs.ProtocolBuffers.Tests.csproj", "{A7FC497E-790A-4980-B57C-32AF4AD4AB9D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotNetty.Codecs.HaProxy.Tests", "test\DotNetty.Codecs.HaProxy.Tests\DotNetty.Codecs.HaProxy.Tests.csproj", "{34DBC7D4-A9AE-4BD6-96CD-DD7CDD4B5D5D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotNetty.Codecs.Redis.Tests", "test\DotNetty.Codecs.Redis.Tests\DotNetty.Codecs.Redis.Tests.csproj", "{08C19033-23B2-47D7-8332-86273AE287BC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotNetty.Codecs.Tests", "test\DotNetty.Codecs.Tests\DotNetty.Codecs.Tests.csproj", "{CE97D2EC-3EA9-4FEC-B304-F57646DB54FD}"
Expand Down Expand Up @@ -169,6 +173,10 @@ Global
{3AF8A62F-F5CE-4C2D-B356-8B9FDFA51668}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3AF8A62F-F5CE-4C2D-B356-8B9FDFA51668}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3AF8A62F-F5CE-4C2D-B356-8B9FDFA51668}.Release|Any CPU.Build.0 = Release|Any CPU
{34DBC7D4-A9AE-4BD6-96CD-DD7CDD4B5D5D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{34DBC7D4-A9AE-4BD6-96CD-DD7CDD4B5D5D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{34DBC7D4-A9AE-4BD6-96CD-DD7CDD4B5D5D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{34DBC7D4-A9AE-4BD6-96CD-DD7CDD4B5D5D}.Release|Any CPU.Build.0 = Release|Any CPU
{A7FC497E-790A-4980-B57C-32AF4AD4AB9D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A7FC497E-790A-4980-B57C-32AF4AD4AB9D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A7FC497E-790A-4980-B57C-32AF4AD4AB9D}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -285,6 +293,10 @@ Global
{3326DB6E-023E-483F-9A1C-5905D3091B57}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3326DB6E-023E-483F-9A1C-5905D3091B57}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3326DB6E-023E-483F-9A1C-5905D3091B57}.Release|Any CPU.Build.0 = Release|Any CPU
{23C52DC6-F4E7-457F-B36E-CEEBFA95D24D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{23C52DC6-F4E7-457F-B36E-CEEBFA95D24D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{23C52DC6-F4E7-457F-B36E-CEEBFA95D24D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{23C52DC6-F4E7-457F-B36E-CEEBFA95D24D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -299,11 +311,13 @@ Global
{D284C2BF-E06E-481B-B301-503A9D477B0E} = {126EA539-4B28-4B07-8B5D-D1D7F794D189}
{75A1BCC1-A7F3-4893-99C5-3235F87DB00E} = {126EA539-4B28-4B07-8B5D-D1D7F794D189}
{1F442118-A665-4891-B056-FE9E54C5B049} = {126EA539-4B28-4B07-8B5D-D1D7F794D189}
{23C52DC6-F4E7-457F-B36E-CEEBFA95D24D} = {126EA539-4B28-4B07-8B5D-D1D7F794D189}
{572E1914-489F-402D-944F-71EE0632E5D8} = {541093F6-616E-43D9-B671-FCD1F9C0A181}
{DA54DBAF-CCDA-4AD1-9FF9-EB6F890D1091} = {541093F6-616E-43D9-B671-FCD1F9C0A181}
{72C92F76-F804-4300-BFF1-459420D9EF0B} = {541093F6-616E-43D9-B671-FCD1F9C0A181}
{E31A5D46-71B7-4B7E-A9F8-3F011822F28A} = {541093F6-616E-43D9-B671-FCD1F9C0A181}
{3AF8A62F-F5CE-4C2D-B356-8B9FDFA51668} = {541093F6-616E-43D9-B671-FCD1F9C0A181}
{34DBC7D4-A9AE-4BD6-96CD-DD7CDD4B5D5D} = {541093F6-616E-43D9-B671-FCD1F9C0A181}
{A7FC497E-790A-4980-B57C-32AF4AD4AB9D} = {541093F6-616E-43D9-B671-FCD1F9C0A181}
{08C19033-23B2-47D7-8332-86273AE287BC} = {541093F6-616E-43D9-B671-FCD1F9C0A181}
{CE97D2EC-3EA9-4FEC-B304-F57646DB54FD} = {541093F6-616E-43D9-B671-FCD1F9C0A181}
Expand Down
42 changes: 42 additions & 0 deletions src/DotNetty.Codecs.HaProxy/DotNetty.Codecs.HaProxy.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?><Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup Label="NuGet">
<TargetFrameworks>netstandard1.3;net45</TargetFrameworks>
<IsPackable>true</IsPackable>
<PackageId>DotNetty.Codecs.HaProxy</PackageId>
<Description>HAProxy codec for DotNetty</Description>
<Copyright>Copyright © Microsoft Corporation</Copyright>
<AssemblyTitle>DotNetty: HAProxy codec</AssemblyTitle>
<NeutralLanguage>en-US</NeutralLanguage>
<VersionPrefix>0.4.7</VersionPrefix>
<Authors>Microsoft Azure</Authors>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyName>DotNetty.Codecs.HaProxy</AssemblyName>
<AssemblyOriginatorKeyFile>../../DotNetty.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
<PackageTags>socket;tcp;protocol;netty;dotnetty;network;HAProxy</PackageTags>
<PackageProjectUrl>https://github.com/Azure/DotNetty/</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/Azure/DotNetty/blob/master/LICENSE.txt</PackageLicenseUrl>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/Azure/DotNetty/</RepositoryUrl>
<NetStandardImplicitPackageVersion Condition=" '$(TargetFramework)' == 'netstandard1.3' ">1.6.1</NetStandardImplicitPackageVersion>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\shared\SharedAssemblyInfo.cs" Link="Properties\SharedAssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DotNetty.Common\DotNetty.Common.csproj" />
<ProjectReference Include="..\DotNetty.Buffers\DotNetty.Buffers.csproj" />
<ProjectReference Include="..\DotNetty.Codecs\DotNetty.Codecs.csproj" />
<ProjectReference Include="..\DotNetty.Transport\DotNetty.Transport.csproj" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
<PackageReference Include="System.Diagnostics.Contracts" Version="4.3.0" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
</Project>
73 changes: 73 additions & 0 deletions src/DotNetty.Codecs.HaProxy/HAProxyCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace DotNetty.Codecs.HaProxy
{
using System;
using System.Collections.Generic;

/**
* The command of an HAProxy proxy protocol header
*/
public sealed class HAProxyCommand
{
/**
* The LOCAL command represents a connection that was established on purpose by the proxy
* without being relayed.
*/
public static readonly HAProxyCommand LOCAL = new HAProxyCommand(HAProxyConstants.COMMAND_LOCAL_BYTE);
/**
* The PROXY command represents a connection that was established on behalf of another node,
* and reflects the original connection endpoints.
*/
public static readonly HAProxyCommand PROXY = new HAProxyCommand(HAProxyConstants.COMMAND_PROXY_BYTE);

public static IEnumerable<HAProxyCommand> Values
{
get
{
yield return LOCAL;
yield return PROXY;
}
}

/**
* Returns the {@link HAProxyCommand} represented by the lowest 4 bits of the specified byte.
*
* @param verCmdByte protocol version and command byte
*/
public static HAProxyCommand ValueOf(byte verCmdByte)
{
int cmd = verCmdByte & COMMAND_MASK;
switch ((byte)cmd)
{
case HAProxyConstants.COMMAND_PROXY_BYTE:
return PROXY;
case HAProxyConstants.COMMAND_LOCAL_BYTE:
return LOCAL;
default:
throw new ArgumentOutOfRangeException(nameof(verCmdByte), "unknown command: " + cmd);
}
}

/**
* The command is specified in the lowest 4 bits of the protocol version and command byte
*/
const byte COMMAND_MASK = 0x0f;

readonly byte byteValue;

HAProxyCommand(byte byteValue)
{
this.byteValue = byteValue;
}

/**
* Returns the byte value of this command.
*/
public byte ByteValue()
{
return this.byteValue;
}
}
}
49 changes: 49 additions & 0 deletions src/DotNetty.Codecs.HaProxy/HAProxyConstants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace DotNetty.Codecs.HaProxy
{
sealed class HAProxyConstants
{

/**
* Command byte constants
*/
internal const byte COMMAND_LOCAL_BYTE = 0x00;
internal const byte COMMAND_PROXY_BYTE = 0x01;

/**
* Version byte constants
*/
internal const byte VERSION_ONE_BYTE = 0x10;
internal const byte VERSION_TWO_BYTE = 0x20;

/**
* Transport protocol byte constants
*/
internal const byte TRANSPORT_UNSPEC_BYTE = 0x00;
internal const byte TRANSPORT_STREAM_BYTE = 0x01;
internal const byte TRANSPORT_DGRAM_BYTE = 0x02;

/**
* Address family byte constants
*/
internal const byte AF_UNSPEC_BYTE = 0x00;
internal const byte AF_IPV4_BYTE = 0x10;
internal const byte AF_IPV6_BYTE = 0x20;
internal const byte AF_UNIX_BYTE = 0x30;

/**
* Transport protocol and address family byte constants
*/
internal const byte TPAF_UNKNOWN_BYTE = 0x00;
internal const byte TPAF_TCP4_BYTE = 0x11;
internal const byte TPAF_TCP6_BYTE = 0x21;
internal const byte TPAF_UDP4_BYTE = 0x12;
internal const byte TPAF_UDP6_BYTE = 0x22;
internal const byte TPAF_UNIX_STREAM_BYTE = 0x31;
internal const byte TPAF_UNIX_DGRAM_BYTE = 0x32;

private HAProxyConstants() { }
}
}
Loading