Skip to content

Commit

Permalink
update to v1.3.6.7
Browse files Browse the repository at this point in the history
  • Loading branch information
beetlex-io committed Apr 14, 2020
1 parent 3f01857 commit 84d242f
Show file tree
Hide file tree
Showing 13 changed files with 266 additions and 60 deletions.
27 changes: 18 additions & 9 deletions Bumblebee/Bumblebee.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,36 @@

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<Version>1.3.5.2</Version>
<Version>1.3.6.7</Version>
<Authors>henryfan</Authors>
<Company>ikende.com</Company>
<Copyright>Copyright © beetlex.io 2019-2020 email:henryfan@msn.com</Copyright>
<Description>.net core webapi and websocket gateway service component</Description>
<PackageIconUrl>https://raw.githubusercontent.com/IKende/Bumblebee/master/Bumblebee/Bumblebee.png</PackageIconUrl>
<PackageLicenseUrl>https://github.com/IKende/Bumblebee/blob/master/LICENSE</PackageLicenseUrl>
<Company>beetlex.io</Company>
<Copyright>Copyright © 2019-2020 beetlex.io</Copyright>
<Description>.net core http and websocket gateway service component</Description>
<PackageIconUrl></PackageIconUrl>
<PackageLicenseUrl></PackageLicenseUrl>
<PackageProjectUrl>https://github.com/IKende/Bumblebee</PackageProjectUrl>
<PackageId>BeetleX.Bumblebee</PackageId>
<AssemblyVersion>1.3.5.2</AssemblyVersion>
<AssemblyVersion>1.3.6.7</AssemblyVersion>
<SignAssembly>false</SignAssembly>
<AssemblyOriginatorKeyFile>Bumblebbe.pfx</AssemblyOriginatorKeyFile>
<FileVersion>1.3.5.2</FileVersion>
<FileVersion>1.3.6.7</FileVersion>
<PackageReleaseNotes>.net core http and websocket gateway service component</PackageReleaseNotes>
<PackageIcon>beetlex200.png</PackageIcon>
</PropertyGroup>

<ItemGroup>
<Compile Remove="Controller.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="BeetleX.FastHttpApi" Version="1.7.9.8" />
<None Include="..\..\..\..\beetlex200.png">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>

<ItemGroup>
<PackageReference Include="BeetleX.FastHttpApi" Version="1.8.2.2" />
</ItemGroup>

</Project>
35 changes: 24 additions & 11 deletions Bumblebee/Gateway.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class Gateway : IDisposable

public const int URL_FILTER_ERROR = 593;

public const int IP_LIMITS_ERROR = 594;
public const int IP_LIMITS_ERROR = 509;

public const int URL_LIMITS_ERROR = 595;

Expand All @@ -58,7 +58,7 @@ public class Gateway : IDisposable

public int BufferSize { get; set; } = 1024 * 4;

public int PoolMaxSize { get; set; } = 1024 * 50;
public int PoolMaxSize { get; set; } = 1024 * 500;

static Gateway()
{
Expand All @@ -76,14 +76,15 @@ public Gateway()
Statistics.Server = "Gateway";
AgentMaxSocketError = 3;
MaxStatsUrls = 20000;
AgentMaxConnection = 200;
AgentMaxConnection = 500;
AgentRequestQueueSize = 500;
ThreadQueues = (Environment.ProcessorCount / 2);
if (ThreadQueues == 0)
ThreadQueues = 1;
GatewayQueueSize = Environment.ProcessorCount * 100;
InstanceID = Guid.NewGuid().ToString("N");
GATEWAY_VERSION = $"beetlex.io[{typeof(BeetleX.BXException).Assembly.GetName().Version}/{HttpServer.GetType().Assembly.GetName().Version}/{GetType().Assembly.GetName().Version}]";
GATEWAY_VERSION = $"beetlex.io";
TimeoutFactory = new TimeoutFactory(this);

}

Expand Down Expand Up @@ -170,6 +171,8 @@ private void OnVerifyTimer(Object state)

public Servers.ServerCenter Agents { get; private set; }

internal Servers.TimeoutFactory TimeoutFactory { get; private set; }

public Statistics Statistics { get; private set; } = new Statistics();

public Servers.ServerAgent SetServer(string host, string category, string remark, int maxConnections = 200)
Expand Down Expand Up @@ -359,19 +362,19 @@ internal void OnResponseError(EventResponseErrorArgs e)
);
Pluginer.Requested(se);
}
RequestIncrementCompleted(e.Request, e.ErrorCode, 1, null);
this.Pluginer.ResponseError(e);
if (e.Result != null)
{
e.Response.Result(e.Result);
}
RequestIncrementCompleted(e.Request, e.ErrorCode, 1, null);
}

internal void OnRequestCompleted(Servers.RequestAgent success)
{
try
{
ServerHttpRequested.Invoke(this, success);
ServerHttpRequested?.Invoke(this, success);
}
catch (Exception e_)
{
Expand All @@ -381,6 +384,7 @@ internal void OnRequestCompleted(Servers.RequestAgent success)
$"Gateway {success.Request.ID} {success.Request.RemoteIPAddress} {success.Request.Method} {success.Request.Url} error {e_.Message}@{e_.StackTrace}");
}
}
HttpServer.IncrementResponsed(success.Request, null, success.Time, success.Code, success.Message);
RequestIncrementCompleted(success.Request, success.Code, success.Time, success.Server);
if (Pluginer.RequestedEnabled)
Pluginer.Requested(success.GetEventRequestCompletedArgs());
Expand All @@ -405,7 +409,6 @@ internal void OnResponding(RequestAgent request, ArraySegment<byte> data, bool c

public void RequestIncrementCompleted(HttpRequest request, int code, long time, Servers.ServerAgent server = null)
{
HttpServer.IncrementResponsed(request, null, time, code, null);
if (StatisticsEnabled)
{
Statistics.Add(code, time);
Expand Down Expand Up @@ -487,11 +490,21 @@ public void Open()

private void OutputLogo()
{
AssemblyCopyrightAttribute productAttr = typeof(BeetleX.BXException).Assembly.GetCustomAttribute<AssemblyCopyrightAttribute>();
AssemblyCopyrightAttribute productAttr = typeof(Gateway).Assembly.GetCustomAttribute<AssemblyCopyrightAttribute>();
var logo = "\r\n";
logo += "*******************************************************************************\r\n";
logo += " BeetleX http and websocket gateway framework \r\n";
logo += " -----------------------------------------------------------------------------\r\n";
logo +=
@" ____ _ _ __ __
| _ \ | | | | \ \ / /
| |_) | ___ ___ | |_ | | ___ \ V /
| _ < / _ \ / _ \ | __| | | / _ \ > <
| |_) | | __/ | __/ | |_ | | | __/ / . \
|____/ \___| \___| \__| |_| \___| /_/ \_\
http and websocket gateway framework
";
logo += " -----------------------------------------------------------------------------\r\n";
logo += $" {productAttr.Copyright}\r\n";
logo += $" ServerGC [{GCSettings.IsServerGC}]\r\n";
logo += $" BeetleX Version [{typeof(BeetleX.BXException).Assembly.GetName().Version}]\r\n";
Expand All @@ -502,7 +515,7 @@ private void OutputLogo()
{
logo += $" {item}\r\n";
}
logo += "*******************************************************************************\r\n";
logo += " -----------------------------------------------------------------------------\r\n";

HttpServer.Log(LogType.Info, logo);

Expand Down
52 changes: 46 additions & 6 deletions Bumblebee/GatewayConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ public class GatewayConfig

public GatewayConfig()
{
GatewayQueueSize = Environment.ProcessorCount * 500;
GatewayQueueSize = Environment.ProcessorCount * 100;
InstanceID = Guid.NewGuid().ToString("N");
}

public int AgentMaxConnection { get; set; } = 300;

public int AgentRequestQueueSize { get; set; } = 2000;
public int AgentRequestQueueSize { get; set; } = 500;

public int GatewayQueueSize { get; set; }

Expand Down Expand Up @@ -57,8 +57,9 @@ public void From(Gateway gateway)
Uri = server.Uri.ToString(),
Remark = server.Remark,
Category = server.Category,
Command = server.Command,
Properties = server.GetProperties()
});
}); ;
}
this.OutputServerAddress = gateway.OutputServerAddress;
this.AgentMaxConnection = gateway.AgentMaxConnection;
Expand Down Expand Up @@ -107,6 +108,7 @@ public void To(Gateway gateway)
foreach (var server in Servers)
{
var agent = gateway.SetServer(server.Uri, server.Category, server.Remark, server.MaxConnections);
agent.Command = server.Command;
agent.SetProperties(server.Properties);
}
foreach (var s in gateway.Agents.Servers)
Expand Down Expand Up @@ -140,6 +142,8 @@ public class ServerInfo

public string Remark { get; set; }

public string Command { get; set; }

public Tuple<string, string>[] Properties { get; set; }
}

Expand All @@ -158,6 +162,20 @@ public class UrlConfig

public int MaxRps { get; set; }

public long TimeOut { get; set; }

public string AccessControlAllowOrigin { get; set; }

public string AccessControlAllowMethods { get; set; } = "*";

public string AccessControlAllowHeaders { get; set; }

public int AccessControlMaxAge { get; set; }

public bool AccessControlAllowCredentials { get; set; }

public string Vary { get; set; } = "Origin";

public class RouteServer
{
public string Url { get; set; }
Expand All @@ -175,6 +193,13 @@ public void From(Routes.UrlRoute urlRoute)
Remark = urlRoute.Remark;
HashPattern = urlRoute.HashPattern;
MaxRps = urlRoute.MaxRps;
TimeOut = urlRoute.TimeOut;
AccessControlAllowHeaders = urlRoute.AccessControlAllowHeaders;
AccessControlAllowMethods = urlRoute.AccessControlAllowMethods;
AccessControlAllowOrigin = urlRoute.AccessControlAllowOrigin;
AccessControlMaxAge = urlRoute.AccessControlMaxAge;
Vary = urlRoute.Vary;
AccessControlAllowCredentials = urlRoute.AccessControlAllowCredentials;
this.PluginConfig = new PluginConfig(urlRoute.Pluginer);
foreach (var server in urlRoute.Servers)
{
Expand All @@ -185,13 +210,28 @@ public void From(Routes.UrlRoute urlRoute)
public void To(Gateway gateway)
{
gateway.RemoveRoute(Url);

var result = gateway.SetRoute(Url, Remark, HashPattern);
Routes.UrlRoute result;
if (Url == "*")
{
result = gateway.Routes.Default;
}
else
{
result = gateway.SetRoute(Url, Remark, HashPattern);
}
result.MaxRps = MaxRps;
result.TimeOut = TimeOut;
result.Vary = Vary;
result.AccessControlMaxAge = AccessControlMaxAge;
result.AccessControlAllowOrigin = AccessControlAllowOrigin;
result.AccessControlAllowMethods = AccessControlAllowMethods;
result.AccessControlAllowHeaders = AccessControlAllowHeaders;
result.AccessControlAllowCredentials = this.AccessControlAllowCredentials;
this.PluginConfig.To(result.Pluginer);
foreach (var server in Servers)
{
var r = result.AddServer(server.Url, server.Weight, server.MaxRps, server.Standby);

r.TimeOut = TimeOut;
r.MaxRps = this.MaxRps;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Bumblebee/Plugins/IRespondingHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ namespace Bumblebee.Plugins
{
public interface IRespondingHandler:IPlugin
{
void Exeucte(EventRespondingArgs e);
void Execute(EventRespondingArgs e);
}
}
2 changes: 1 addition & 1 deletion Bumblebee/Plugins/Pluginer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ public void Responding(EventRespondingArgs e)
for (int i = 0; i < items.Length; i++)
{
if (Gateway.PluginCenter.PluginIsEnabled(items[i]))
items[i].Exeucte(e);
items[i].Execute(e);
}
}
}
Expand Down
20 changes: 20 additions & 0 deletions Bumblebee/Routes/UrlRoute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,26 @@ public void BuildHashPattern(string hashPattern = null)

public string UrlPattern { get; set; }

public long TimeOut { get; set; }

#region access-control

public string AccessControlAllowOrigin { get; set; }

public string AccessControlAllowMethods { get; set; }

public string AccessControlAllowHeaders { get; set; }

public int AccessControlMaxAge { get; set; }

public string Vary { get; set; } = "Origin";

public bool AccessControlAllowCredentials { get; set; }

#endregion



#region rps limit

public int MaxRps { get; set; } = 0;
Expand Down
18 changes: 16 additions & 2 deletions Bumblebee/Routes/UrlRouteAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void ExecuteWS(HttpRequest request, BeetleX.FastHttpApi.WebSockets.DataFr
request.Server.Log(LogType.Info, $"Gateway websocket {request.RemoteIPAddress} {request.Method} {request.Url} request {UrlRoute.Url}'s route server unavailable");
}

UrlRoute.Gateway.RequestIncrementCompleted(request, Gateway.URL_NODE_SERVER_UNAVAILABLE, 1,null);
UrlRoute.Gateway.RequestIncrementCompleted(request, Gateway.URL_NODE_SERVER_UNAVAILABLE, 1, null);
var frame = request.Server.CreateDataFrame(new { Code = Gateway.WEBSOCKET_INNER_ERROR, Error = $"Gateway websocket {UrlRoute.Url}'s route server unavailable" });
frame.Send(request.Session);
}
Expand Down Expand Up @@ -74,7 +74,21 @@ public void Execute(HttpRequest request, HttpResponse response)
{
request.Server.Log(LogType.Debug, $"Gateway {request.RemoteIPAddress} {request.Method} {request.Url} request {UrlRoute.Url}'s get urlroute agent!");
}

if (string.Compare(request.Method, "OPTIONS", true) == 0)
{
if (!string.IsNullOrEmpty(UrlRoute.AccessControlAllowOrigin))
{
OptionsAttribute oa = new OptionsAttribute();
oa.AllowCredentials = UrlRoute.AccessControlAllowCredentials;
oa.AllowHeaders = UrlRoute.AccessControlAllowHeaders;
oa.AllowMaxAge = UrlRoute.AccessControlMaxAge > 0 ? UrlRoute.AccessControlMaxAge.ToString() : null;
oa.AllowMethods = UrlRoute.AccessControlAllowMethods;
oa.AllowOrigin = UrlRoute.AccessControlAllowOrigin;
oa.Vary = UrlRoute.Vary;
response.Result(oa);
return;
}
}
if (!UrlRoute.ValidateRPS())
{
string error = $"Unable to reach [{UrlRoute.Url} route {request.Url}] in HTTP request, exceeding maximum number of rps limit";
Expand Down
Loading

1 comment on commit 84d242f

@snltty
Copy link

@snltty snltty commented on 84d242f Apr 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这次更新力度好大啊

Please sign in to comment.