Skip to content

Commit 75bca51

Browse files
committed
updated to latest libraries
1 parent 551acab commit 75bca51

File tree

7 files changed

+96
-288
lines changed

7 files changed

+96
-288
lines changed

RelayServerTest.sln

+6
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,23 @@ EndProject
88
Global
99
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1010
Debug|Any CPU = Debug|Any CPU
11+
Debug|x64 = Debug|x64
1112
Debug|x86 = Debug|x86
1213
Release|Any CPU = Release|Any CPU
14+
Release|x64 = Release|x64
1315
Release|x86 = Release|x86
1416
EndGlobalSection
1517
GlobalSection(ProjectConfigurationPlatforms) = postSolution
1618
{5CBE7822-5903-4733-8DDE-67E9A5A85F0C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1719
{5CBE7822-5903-4733-8DDE-67E9A5A85F0C}.Debug|Any CPU.Build.0 = Debug|Any CPU
20+
{5CBE7822-5903-4733-8DDE-67E9A5A85F0C}.Debug|x64.ActiveCfg = Debug|x64
21+
{5CBE7822-5903-4733-8DDE-67E9A5A85F0C}.Debug|x64.Build.0 = Debug|x64
1822
{5CBE7822-5903-4733-8DDE-67E9A5A85F0C}.Debug|x86.ActiveCfg = Debug|x86
1923
{5CBE7822-5903-4733-8DDE-67E9A5A85F0C}.Debug|x86.Build.0 = Debug|x86
2024
{5CBE7822-5903-4733-8DDE-67E9A5A85F0C}.Release|Any CPU.ActiveCfg = Release|Any CPU
2125
{5CBE7822-5903-4733-8DDE-67E9A5A85F0C}.Release|Any CPU.Build.0 = Release|Any CPU
26+
{5CBE7822-5903-4733-8DDE-67E9A5A85F0C}.Release|x64.ActiveCfg = Release|x64
27+
{5CBE7822-5903-4733-8DDE-67E9A5A85F0C}.Release|x64.Build.0 = Release|x64
2228
{5CBE7822-5903-4733-8DDE-67E9A5A85F0C}.Release|x86.ActiveCfg = Release|x86
2329
{5CBE7822-5903-4733-8DDE-67E9A5A85F0C}.Release|x86.Build.0 = Release|x86
2430
EndGlobalSection

RelayServerTest/Config.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
2-
"PortRelay": 20011,
3-
"PortHttp": 20012,
2+
"ServerName": "Ophelia",
3+
"PortRelay": 20020,
4+
"PortHttp": 20021,
45
"UpdateProxy": false,
56
"ProxyUri": "http://localhost:8001/ip"
67
}

RelayServerTest/HttpSimple/Alternative/HttpNativeServer.cs

-258
This file was deleted.

RelayServerTest/HttpSimple/SimpleHttpServer.cs

+4-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using NetworkLibrary.Components.Statistics;
33
using NetworkLibrary.TCP.Base;
44
using NetworkLibrary.Utils;
5-
using Protobuff.P2P;
65
using System;
76
using System.Collections.Concurrent;
87
using System.Collections.Generic;
@@ -12,7 +11,6 @@
1211
using System.Net;
1312
using System.Text;
1413
using System.Threading.Tasks;
15-
using static RelayServer.HttpSimple.Alternative.HttpNativeServer;
1614

1715
namespace RelayServer.HttpSimple
1816
{
@@ -29,12 +27,12 @@ internal class SimpleHttpServer
2927
private ConcurrentDictionary<Guid, TcpStatistics> tcpSessionStats;
3028
private ConcurrentDictionary<IPEndPoint, UdpStatistics> udpSessionStats;
3129

32-
private SecureProtoRelayServer server;
30+
private NetworkLibrary.P2P.RelayServer server;
3331
private AsyncTcpServer httpMiniServer;
3432
private SharerdMemoryStreamPool streamPool = new SharerdMemoryStreamPool();
3533
byte[] cachedSendArray = new byte[500];
3634
private readonly string page;
37-
public SimpleHttpServer(SecureProtoRelayServer s, int porthttp)
35+
public SimpleHttpServer(NetworkLibrary.P2P.RelayServer s, int porthttp)
3836
{
3937
server = s;
4038
page = PageResources.TextVisualizePage.Replace("20012", porthttp.ToString());
@@ -84,7 +82,7 @@ PooledMemoryStream GetTextResponse(string data)
8482

8583
return stream;
8684
}
87-
private void ServerBytesReceived(in Guid guid, byte[] bytes, int offset, int count)
85+
private void ServerBytesReceived(Guid guid, byte[] bytes, int offset, int count)
8886
{
8987
try
9088
{
@@ -106,7 +104,7 @@ private void ServerBytesReceived(in Guid guid, byte[] bytes, int offset, int cou
106104

107105

108106
var stream = GetTextResponse(data);
109-
httpMiniServer.SendBytesToClient(in guid,stream.GetBuffer(),0,(int)stream.Position );
107+
httpMiniServer.SendBytesToClient(guid,stream.GetBuffer(),0,(int)stream.Position );
110108
}
111109
} catch { }
112110

RelayServerTest/PerformanceStatistics.cs

+10-4
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,31 @@ internal class PerformanceStatistics
1717
private static string lastMemoryUsage;
1818
static Stopwatch sw = new Stopwatch();
1919
static double ProcCount;
20+
private static DateTime processStartTime;
21+
2022
static PerformanceStatistics()
2123
{
2224
process = Process.GetCurrentProcess();
2325
lastProctime=process.TotalProcessorTime;
2426
lastRequestTimeCpu = 0;
2527
lastRequestTimeMemory = 0;
2628
ProcCount = Convert.ToDouble(Environment.ProcessorCount);
29+
processStartTime = process.StartTime;
2730
sw.Start();
2831

2932
}
33+
34+
3035
public static string GetCpuUsage()
3136
{
32-
3337
long elapsed = sw.ElapsedMilliseconds;
3438
long deltaTms = elapsed - lastRequestTimeCpu;
35-
if(deltaTms < 900)
39+
if (deltaTms < 900)
3640
{
3741
return lastCpuUsage;
3842
}
3943
var currentProcessorTime = process.TotalProcessorTime;
40-
double CPUUsage = (currentProcessorTime.TotalMilliseconds - lastProctime.TotalMilliseconds) / deltaTms / ProcCount;
44+
double CPUUsage = (currentProcessorTime.TotalMilliseconds - lastProctime.TotalMilliseconds) / (deltaTms * ProcCount);
4145
lastRequestTimeCpu = elapsed;
4246
lastProctime = currentProcessorTime;
4347
lastCpuUsage = (CPUUsage * 100).ToString("N3") + "%";
@@ -47,6 +51,9 @@ public static string GetCpuUsage()
4751

4852
public static string GetMemoryUsage()
4953
{
54+
const double f = 1024.0 * 1024.0;
55+
return (Environment.WorkingSet / f).ToString("N3") + "MB";
56+
5057
long elapsed = sw.ElapsedMilliseconds;
5158
long deltaTms = elapsed - lastRequestTimeMemory;
5259
if (deltaTms < 900)
@@ -55,7 +62,6 @@ public static string GetMemoryUsage()
5562
}
5663
lastRequestTimeMemory=elapsed;
5764
process.Refresh();
58-
const double f = 1024.0 * 1024.0;
5965
lastMemoryUsage = (process.WorkingSet64 / f).ToString("N3") + "MB";
6066
return lastMemoryUsage;
6167

0 commit comments

Comments
 (0)