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

Master 2.2 #2

Merged
merged 16 commits into from
Jan 24, 2019
Merged
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
4 changes: 3 additions & 1 deletion Statement-of-Income-and-Expense.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
## 汇总

截止到 2018 年 12 月 28 日:
+ 共获得捐赠 `38` 笔计 `8250.4` 元人民币
+ 共获得捐赠 `40` 笔计 `8380.4` 元人民币
+ 暂无支出项

## 明细
Expand Down Expand Up @@ -51,3 +51,5 @@
| 36 | 忠全 | 2018-01-02 | 200 | 忠全个人捐赠 | 学习一下 |获赠 |
| 37 | 思恒 | 2018-01-03 | 10 | 思恒个人捐赠 | 这家伙很懒 |获赠 |
| 38 | 松波 | 2018-01-04 | 100 | 松波个人捐赠 | 出精品 |获赠 |
| 39 | 先鸿 | 2019-01-05 | 30 | 先鸿个人捐赠 | 加油 |获赠 |
| 40 | 杨坚 | 2019-01-08 | 100 | 杨坚个人捐赠 | 加油,希望surging能形成自己的社区 |获赠 |
7 changes: 4 additions & 3 deletions src/Surging.ApiGateway/Surging.ApiGateway.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp2.2</TargetFramework>
<MvcRazorCompileOnPublish>true</MvcRazorCompileOnPublish>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
<UserSecretsId>aspnet-Surging.ApiGateway-147A234E-A922-4E6A-89B8-DCC64AEA96EE</UserSecretsId>
<ServerGarbageCollection>false</ServerGarbageCollection>
<ServerGarbageCollection>false</ServerGarbageCollection>
<TieredCompilation>true</TieredCompilation>
<Version>1.0.0.0</Version>
<Authors>fanly</Authors>
<Product>surging Micro Service Framework</Product>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp2.2</TargetFramework>
<Version>1.0.0.0</Version>
<Authors>fanly</Authors>
<Product>surging Micro Service Framework</Product>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Surging.Core.CPlatform.Support;
using System;
using System.Collections.Generic;
using System.Net;

Expand All @@ -16,6 +17,8 @@ public partial class SurgingServerOptions: ServiceCommand

public double WatchInterval { get; set; } = 20d;

public int DisconnTimeInterval { get; set; } = 60;

public bool Libuv { get; set; } = false;

public int SoBacklog { get; set; } = 8192;
Expand All @@ -29,6 +32,8 @@ public partial class SurgingServerOptions: ServiceCommand
public CommunicationProtocol Protocol { get; set; }
public string RootPath { get; set; }

public string WebRootPath { get; set; } = AppContext.BaseDirectory;

public int Port { get; set; }

public ProtocolPortOptions Ports { get; set; } = new ProtocolPortOptions();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp2.2</TargetFramework>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<PackageId>surging</PackageId>
<Authors>fanly</Authors>
Expand Down
5 changes: 2 additions & 3 deletions src/Surging.Core/Surging.Core.CPlatform/Utilities/NetUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ public static bool IsAnyHost(String host)
private static bool IsValidAddress(string address)
{
return (address != null
&& !ANYHOST.Equals(address)
&& !LOCALHOST.Equals(address)
&& !ANYHOST.Equals(address)
&& address.IsMatch(IP_PATTERN));
}

Expand Down Expand Up @@ -75,7 +74,7 @@ public static string GetAnyHostAddress()
public static string GetHostAddress(string hostAddress)
{
var result = hostAddress;
if(IsValidAddress(hostAddress) || IsAnyHost(hostAddress))
if((!IsValidAddress(hostAddress) && !IsLocalHost(hostAddress)) || IsAnyHost(hostAddress))
{
result = GetAnyHostAddress();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp2.2</TargetFramework>
<Version>1.0.0.0</Version>
<Authors>fanly</Authors>
<Product>surging Micro Service Framework</Product>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public DynamicItem(object value)
var valueType = value.GetType();
var code = Type.GetTypeCode(valueType);

if (code != TypeCode.Object)
if (code != TypeCode.Object && valueType.BaseType!=typeof(Enum))
TypeName = valueType.FullName;
else
TypeName = valueType.AssemblyQualifiedName;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp2.2</TargetFramework>
<Version>1.0.0.0</Version>
<Authors>fanly</Authors>
<Product>surging Micro Service Framework</Product>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp2.2</TargetFramework>
<Description>surging is a distributed micro service framework that provides high-performance RPC remote service calls, using Zookeeper, Consul as the registration center for surging services, integrating hash, random, polling as a load balancing algorithm, RPC integration using the netty framework, Using asynchronous transmission. Use json.net, protobuf, messagepack for serialization Codec</Description>
<Version>1.0.0.0</Version>
<Authors>fanly</Authors>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp2.2</TargetFramework>
<Authors>fanly</Authors>
<Version>1.0.0.0</Version>
<Product>surging Micro Service Framework</Product>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp2.2</TargetFramework>
<Version>1.0.0.0</Version>
<Product>surging Micro Service Framework</Product>
<Company />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp2.2</TargetFramework>
<Version>1.0.0.0</Version>
<Authors>fanly</Authors>
<Company>fanly</Company>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp2.2</TargetFramework>
<Description>surging is a distributed micro service framework that provides high-performance RPC remote service calls, using Zookeeper, Consul as the registration center for surging services, integrating hash, random, polling as a load balancing algorithm, RPC integration using the netty framework, Using asynchronous transmission. Use json.net, protobuf, messagepack for serialization Codec</Description>
<Version>1.0.0.0</Version>
<Authors>fanly</Authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Surging.Core.CPlatform.Engines;
using Surging.Core.CPlatform.Serialization;
using Surging.Core.KestrelHttpServer.Internal;
using Surging.Core.Swagger.Builder;
Expand All @@ -19,25 +20,27 @@ public class KestrelHttpMessageListener : HttpMessageListener, IDisposable
private IWebHost _host;
private readonly ISerializer<string> _serializer;
private readonly IServiceSchemaProvider _serviceSchemaProvider;
private readonly IServiceEngineLifetime _lifetime;


public KestrelHttpMessageListener(ILogger<KestrelHttpMessageListener> logger,
ISerializer<string> serializer,
IServiceSchemaProvider serviceSchemaProvider) :base(logger, serializer)
IServiceSchemaProvider serviceSchemaProvider, IServiceEngineLifetime lifetime) :base(logger, serializer)
{
_logger = logger;
_serializer = serializer;
_serviceSchemaProvider = serviceSchemaProvider;
_lifetime = lifetime;
}

public async Task StartAsync(EndPoint endPoint)
{
var ipEndPoint = endPoint as IPEndPoint;
try
{
_host = new WebHostBuilder()
var hostBuilder = new WebHostBuilder()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseKestrel(options=> {
.UseKestrel(options => {
options.Listen(ipEndPoint);

})
Expand All @@ -46,10 +49,16 @@ public async Task StartAsync(EndPoint endPoint)
logger.AddConfiguration(
CPlatform.AppConfig.GetSection("Logging"));
})
.Configure(AppResolve)
.Build();
.Configure(AppResolve);

await _host.RunAsync();
if (Directory.Exists(CPlatform.AppConfig.ServerOptions.WebRootPath))
hostBuilder = hostBuilder.UseWebRoot(CPlatform.AppConfig.ServerOptions.WebRootPath);
_host= hostBuilder.Build();
_lifetime.ServiceEngineStarted.Register(async () =>
{
await _host.RunAsync();
});

}
catch
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Surging.Core.CPlatform;
using Surging.Core.CPlatform.Engines;
using Surging.Core.CPlatform.Module;
using Surging.Core.CPlatform.Runtime.Server;
using Surging.Core.CPlatform.Runtime.Server.Implementation;
Expand Down Expand Up @@ -52,7 +53,8 @@ private static void RegisterDefaultProtocol(ContainerBuilderWrapper builder)
return new KestrelHttpMessageListener(
provider.Resolve<ILogger<KestrelHttpMessageListener>>(),
provider.Resolve<ISerializer<string>>(),
provider.Resolve<IServiceSchemaProvider>()
provider.Resolve<IServiceSchemaProvider>(),
provider.Resolve<IServiceEngineLifetime>()
);
}).SingleInstance();
builder.Register(provider =>
Expand All @@ -75,7 +77,8 @@ private static void RegisterHttpProtocol(ContainerBuilderWrapper builder)
return new KestrelHttpMessageListener(
provider.Resolve<ILogger<KestrelHttpMessageListener>>(),
provider.Resolve<ISerializer<string>>(),
provider.Resolve<IServiceSchemaProvider>()
provider.Resolve<IServiceSchemaProvider>(),
provider.Resolve<IServiceEngineLifetime>()
);
}).SingleInstance();
builder.Register(provider =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp2.2</TargetFramework>
<Version>1.0.0.0</Version>
<Authors>fanly</Authors>
<Company>fanly</Company>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp2.2</TargetFramework>
<Version>1.0.0.0</Version>
<Authors>fanly</Authors>
<Company></Company>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp2.2</TargetFramework>
<PackageReleaseNotes>1. fix bug</PackageReleaseNotes>
<Version>1.0.0.0</Version>
<Authors>fanly</Authors>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp2.2</TargetFramework>
<Version>1.0.0.0</Version>
<Authors>fanly</Authors>
<Company>fanly</Company>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public async Task Login(IChannelHandlerContext context, ConnectPacket packet)
&& await mqttBehavior.Authorized(packet.Username, packet.Password))
{
var mqttChannel = _channelService.GetMqttChannel(deviceId);
if (mqttChannel == null || mqttChannel.SessionStatus == SessionStatus.CLOSE)
if (mqttChannel == null || !mqttChannel.IsOnine())
{
byte[] bytes = null;
if (packet.WillMessage != null)
Expand Down Expand Up @@ -108,6 +108,7 @@ public async Task PingReq(IChannelHandlerContext context, PingReqPacket packet)
{
if (_logger.IsEnabled(LogLevel.Information))
_logger.LogInformation("收到来自:【" + context.Channel.RemoteAddress.ToString() + "】心跳");
await _channelService.PingReq(context.Channel);
await PingResp(context, PingRespPacket.Instance);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using DotNetty.Common.Utilities;
using DotNetty.Transport.Channels;
using Surging.Core.CPlatform;
using Surging.Core.Protocol.Mqtt.Internal.Enums;
using Surging.Core.Protocol.Mqtt.Internal.Messages;
using System;
Expand All @@ -18,6 +19,9 @@ public class MqttChannel
public SubscribeStatus SubscribeStatus { get; set; }
public List<string> Topics { get; set; }
public SessionStatus SessionStatus { get; set; }

public DateTime PingReqTime { get; set; } = DateTime.Now;

public bool CleanSession { get; set; }
public ConcurrentDictionary<int, SendMqttMessage> Messages { get; set; }

Expand Down Expand Up @@ -57,6 +61,11 @@ public async Task Close()
await Channel.CloseAsync();
}

public bool IsOnine()
{
return (DateTime.Now - PingReqTime).TotalSeconds <= AppConfig.ServerOptions.DisconnTimeInterval && SessionStatus== SessionStatus.OPEN;
}

public bool IsActive()
{
return Channel != null && Channel.Active;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,8 @@ public async ValueTask<string> GetDeviceId(IChannel channel)
{
string deviceId = null;
if (channel != null)
{
AttributeKey<string> deviceIdAttrKey = AttributeKey<string>.ValueOf("deviceId");
deviceId = channel.GetAttribute<string>(deviceIdAttrKey).Get();
{
deviceId = channel.GetAttribute<string>(DeviceIdAttrKey).Get();
}
return await new ValueTask<string>(deviceId);
}
Expand Down Expand Up @@ -172,6 +171,8 @@ await _mqttRemoteInvokeService.InvokeAsync(new MqttRemoteInvokeContext

public abstract Task Pubrec(MqttChannel channel, int messageId);

public abstract ValueTask PingReq(IChannel channel);

public abstract Task Pubrel(IChannel channel, int messageId);

public abstract Task SendWillMsg(MqttWillMessage willMeaasge);
Expand All @@ -181,15 +182,15 @@ await _mqttRemoteInvokeService.InvokeAsync(new MqttRemoteInvokeContext

public abstract Task Publish(string deviceId, MqttWillMessage willMessage);

public ValueTask<SessionStatus?> GetDeviceStatus(string deviceId)
public ValueTask<bool> GetDeviceIsOnine(string deviceId)
{
SessionStatus? result = null;
bool result = false;
if (!string.IsNullOrEmpty(deviceId))
{
MqttChannels.TryGetValue(deviceId, out MqttChannel mqttChannel);
result = mqttChannel?.SessionStatus;
result = mqttChannel==null?false: mqttChannel.IsOnine();
}
return new ValueTask<SessionStatus?>(result);
return new ValueTask<bool>(result);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ public interface IChannelService
Task Suscribe(String deviceId, params string[] topics);
Task Login(IChannel channel, string deviceId, ConnectMessage mqttConnectMessage);
Task Publish(IChannel channel, PublishPacket mqttPublishMessage);
ValueTask PingReq(IChannel channel);
Task Publish(string deviceId, MqttWillMessage willMessage);
Task Close(string deviceId, bool isDisconnect);
ValueTask<SessionStatus?> GetDeviceStatus(string deviceId);
ValueTask<bool> GetDeviceIsOnine(string deviceId);
Task SendWillMsg(MqttWillMessage willMeaasge);
ValueTask<string> GetDeviceId(IChannel channel);
Task UnSubscribe(string deviceId, params string[] topics);
Expand Down
Loading