Skip to content

Commit

Permalink
v3.1 使用v11核心库的IPacket数据包模型
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Sep 17, 2024
1 parent 6f35e18 commit 3025771
Show file tree
Hide file tree
Showing 14 changed files with 45 additions and 38 deletions.
2 changes: 1 addition & 1 deletion ClientTest/ClientTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="NewLife.Redis" Version="5.7.2024.801" />
<PackageReference Include="NewLife.Redis" Version="6.0.2024.829-beta1442" />
<PackageReference Include="NewLife.UnitTest" Version="1.0.2024.102-beta0146" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
Expand Down
2 changes: 1 addition & 1 deletion Samples/TestA/TestA.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NewLife.Core" Version="10.10.2024.902" />
<PackageReference Include="NewLife.Core" Version="11.0.2024.916-beta1549" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion Samples/TestB/TestB.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NewLife.Core" Version="10.10.2024.902" />
<PackageReference Include="NewLife.Core" Version="11.0.2024.916-beta1549" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions StarAgent/StarAgent.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0;net40;net45;net461;net7.0;net8.0</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0;net45;net461;net7.0;net8.0</TargetFrameworks>
<AssemblyTitle>星尘代理</AssemblyTitle>
<Description>星尘,分布式资源调度,部署于每一个节点,连接服务端,支持节点监控、远程发布。</Description>
<Company>新生命开发团队</Company>
<Copyright>©2002-2024 NewLife</Copyright>
<VersionPrefix>3.0</VersionPrefix>
<VersionPrefix>3.1</VersionPrefix>
<VersionSuffix>$([System.DateTime]::Now.ToString(`yyyy.MMdd`))</VersionSuffix>
<Version>$(VersionPrefix).$(VersionSuffix)</Version>
<FileVersion>$(Version)</FileVersion>
Expand Down
28 changes: 13 additions & 15 deletions StarGateway/Proxy/HttpReverseProxy.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using System.IO;
using NewLife;
using NewLife;
using NewLife.Http;
using NewLife.Net;
using StarGateway.Http;

namespace StarGateway.Proxy
{
Expand Down Expand Up @@ -72,19 +70,19 @@ protected override void OnReceive(ReceivedEventArgs e)

// 请求头
var request = new HttpRequest();
if (request.Read(e.Packet))
if (request.Parse(e.Packet))
{
e.Message = request;

// 解码请求头,准备修改细节
request.DecodeHeaders();
//// 解码请求头,准备修改细节
//request.DecodeHeaders();

if (OnRequest(request, e))
{
// 重新生成Http请求头
request.EncodeHeaders();
e.Packet = request.ToPacket();
}
//if (OnRequest(request, e))
//{
// // 重新生成Http请求头
// request.EncodeHeaders();
// e.Packet = request.ToPacket();
//}

//var uri = new NetUri(NetType.Http, RawHost, Session.Local.Port);
WriteDebugLog(LocalUri + "");
Expand All @@ -98,12 +96,12 @@ protected virtual Boolean OnRequest(HttpRequest request, ReceivedEventArgs e)
// 修改Host
var host = request.Headers["Host"];

LocalUri = new Uri($"http://{host}:{Session.Local.Port}{request.Uri}");
LocalUri = new Uri($"http://{host}:{Session.Local.Port}{request.RequestUri}");

host = GetHost(host);
if (host.IsNullOrEmpty()) return false;

RemoteUri = new Uri($"http://{host}:{RemoteServerUri.Port}{request.Uri}");
RemoteUri = new Uri($"http://{host}:{RemoteServerUri.Port}{request.RequestUri}");

request.Headers["Host"] = host;

Expand Down
2 changes: 1 addition & 1 deletion StarGateway/Proxy/ProxySession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ protected virtual void OnReceiveRemote(ReceivedEventArgs e)
#region 发送
/// <summary>发送数据</summary>
/// <param name="pk">缓冲区</param>
public virtual Int32 SendRemote(Packet pk)
public virtual Int32 SendRemote(IPacket pk)
{
try
{
Expand Down
8 changes: 8 additions & 0 deletions StarGateway/StarGateway.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,17 @@
<Optimize>false</Optimize>
</PropertyGroup>

<ItemGroup>
<Compile Remove="Http\HttpRequest.cs" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Stardust.Data\Stardust.Data.csproj" />
<ProjectReference Include="..\Stardust\Stardust.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="Http\" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion Stardust.Extensions/Stardust.Extensions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<Description>星尘,分布式服务框架扩展。节点管理,监控中心,配置中心,发布中心,注册中心</Description>
<Company>新生命开发团队</Company>
<Copyright>©2002-2024 NewLife</Copyright>
<VersionPrefix>3.0</VersionPrefix>
<VersionPrefix>3.1</VersionPrefix>
<VersionSuffix>$([System.DateTime]::Now.ToString(`yyyy.MMdd`))</VersionSuffix>
<Version>$(VersionPrefix).$(VersionSuffix)</Version>
<FileVersion>$(Version)</FileVersion>
Expand Down
2 changes: 1 addition & 1 deletion Stardust.Server/Stardust.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

<ItemGroup>
<PackageReference Include="NewLife.IP" Version="2.2.2024.902" />
<PackageReference Include="NewLife.Redis" Version="5.7.2024.801" />
<PackageReference Include="NewLife.Redis" Version="6.0.2024.829-beta1442" />
<PackageReference Include="NewLife.Remoting.Extensions" Version="3.0.2024.902" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion Stardust.Web/Stardust.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<ItemGroup>
<PackageReference Include="NewLife.Cube.Core" Version="6.1.2024.902" />
<PackageReference Include="NewLife.IP" Version="2.2.2024.902" />
<PackageReference Include="NewLife.Redis" Version="5.7.2024.801" />
<PackageReference Include="NewLife.Redis" Version="6.0.2024.829-beta1442" />
<PackageReference Include="NewLife.Remoting.Extensions" Version="3.0.2024.902" />
</ItemGroup>

Expand Down
9 changes: 6 additions & 3 deletions Stardust/LocalStarClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Net.NetworkInformation;
using System.Net.Sockets;
using NewLife;
using NewLife.Data;
using NewLife.Http;
using NewLife.Log;
using NewLife.Messaging;
Expand Down Expand Up @@ -470,8 +471,10 @@ public static Task ProbeAsync(String? url = null, String? version = null, String
//};
//var buf = msg.ToPacket().ToArray();

var buf = encoder.CreateRequest("Info", null).ToPacket()?.ToArray();
if (buf == null) yield break;
var pk = encoder.CreateRequest("Info", null).ToPacket();
if (pk == null) yield break;

var buf = pk.ToArray();

// 在局域网中广播消息
var udp = new UdpClient();
Expand All @@ -483,7 +486,7 @@ public static Task ProbeAsync(String? url = null, String? version = null, String
var rs = new DefaultMessage();
IPEndPoint? ep = null;
buf = udp.Receive(ref ep);
if (buf != null && rs.Read(buf))
if (buf != null && rs.Read((ArrayPacket)buf))
{
var msg = encoder.Decode(rs);
if (msg != null && msg.Data != null)
Expand Down
13 changes: 5 additions & 8 deletions Stardust/Stardust.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net40;net45;net461;netstandard2.0;netstandard2.1;netcoreapp3.1;net5.0;net6.0;net6.0-windows;net7.0;net7.0-windows;net8.0;net8.0-windows</TargetFrameworks>
<TargetFrameworks>net45;net461;netstandard2.0;netstandard2.1;netcoreapp3.1;net5.0;net6.0;net6.0-windows;net7.0;net7.0-windows;net8.0;net8.0-windows</TargetFrameworks>
<AssemblyName>Stardust</AssemblyName>
<AssemblyTitle>星尘分布式服务核心</AssemblyTitle>
<Description>星尘,分布式服务框架。节点管理,监控中心,配置中心,发布中心,注册中心</Description>
<Company>新生命开发团队</Company>
<Copyright>©2002-2024 NewLife</Copyright>
<VersionPrefix>3.0</VersionPrefix>
<VersionPrefix>3.1</VersionPrefix>
<VersionSuffix>$([System.DateTime]::Now.ToString(`yyyy.MMdd`))</VersionSuffix>
<Version>$(VersionPrefix).$(VersionSuffix)</Version>
<FileVersion>$(Version)</FileVersion>
Expand Down Expand Up @@ -112,13 +112,10 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="NewLife.Remoting" Version="3.0.2024.902" />
<PackageReference Include="NewLife.Remoting" Version="3.1.2024.914-beta0002" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)'!='net40'">
<PackageReference Include="NewLife.Core" Version="10.10.2024.902" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)'=='net40'">
<PackageReference Include="NewLife.Core" Version="10.10.2024.0801-net40" />
<ItemGroup>
<PackageReference Include="NewLife.Core" Version="11.0.2024.916-beta1549" />
</ItemGroup>

</Project>
5 changes: 3 additions & 2 deletions Test/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Net.Sockets;
using System.Threading;
using NewLife;
using NewLife.Data;
using NewLife.IO;
using NewLife.Log;
using NewLife.Messaging;
Expand Down Expand Up @@ -57,7 +58,7 @@ static async void Test1()

// Thread.Sleep(1000);
//}
await io.Put("aa.txt", "学无先后达者为师!".GetBytes());
await io.Put("aa.txt", (ArrayPacket)"学无先后达者为师!".GetBytes());
var rs = await io.Get("aa.txt");
XTrace.WriteLine(rs.Data.ToStr());

Expand Down Expand Up @@ -157,7 +158,7 @@ static void Test4()
writer.Write(0);

var msg = new DefaultMessage();
msg.Payload = ms.ToArray();
msg.Payload = (ArrayPacket)ms.ToArray();
var buf = msg.ToPacket().ToArray();
XTrace.WriteLine(buf.ToHex());

Expand Down
2 changes: 1 addition & 1 deletion Test/Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Win32.SystemEvents" Version="8.0.0" />
<PackageReference Include="NewLife.Core" Version="10.10.2024.902" />
<PackageReference Include="NewLife.Core" Version="11.0.2024.916-beta1549" />
<PackageReference Include="SSH.NET" Version="2024.1.0" />
</ItemGroup>

Expand Down

0 comments on commit 3025771

Please sign in to comment.