Skip to content

Commit 2e42364

Browse files
committed
added proxy update routine
1 parent 26e8525 commit 2e42364

File tree

1 file changed

+55
-10
lines changed

1 file changed

+55
-10
lines changed

RelayServerTest/Program.cs

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,89 @@
11
using NetworkLibrary.Components;
2+
using NetworkLibrary.Components.Statistics;
23
using ProtoBuf;
34
using Protobuff;
45
using Protobuff.P2P;
6+
using System;
57
using System.Security.Cryptography.X509Certificates;
8+
using System.Text.Json;
69

710
namespace RrlayServerTest
811
{
912
//KFtyEu7h6E
10-
internal class Program
13+
public class Adress
1114
{
12-
[ProtoContract]
13-
public class PeerList
14-
{
15-
[ProtoMember(1)]
16-
public Guid asd;
15+
public string ip { get; set; }
16+
public string country { get; set; }
17+
public string cc { get; set; }
18+
}
1719

20+
public class UpdateAdress
21+
{
22+
public string Ip { get; set; }
1823

19-
}
24+
public string Id { get; set; }
25+
}
26+
27+
internal class Program
28+
29+
{
30+
private static readonly string uri = @"http://localhost:8001/";
31+
static ManualResetEvent m = new ManualResetEvent(false);
32+
2033
static void Main(string[] args)
2134
{
2235

2336
var scert = new X509Certificate2("server.pfx", "greenpass");
2437
var server = new SecureProtoRelayServer(20011, 1000, scert);
38+
Task.Run(async () => {
39+
while (true)
40+
{
41+
try
42+
{
43+
HttpClient cl = new HttpClient();
44+
45+
var uri_ = @"https://api.myip.com";
46+
var result = await cl.GetAsync(uri_);
47+
var str = await result.Content.ReadAsStringAsync();
48+
49+
var IPinfo = JsonSerializer.Deserialize<Adress>(str);
50+
var update = new UpdateAdress()
51+
{
52+
Ip = IPinfo.ip,
53+
Id = "IPass"
54+
};
55+
56+
var updateMsg = JsonSerializer.Serialize(update);
57+
await cl.PostAsync(uri, new StringContent(updateMsg));
58+
await Task.Delay(60000);
59+
}
60+
catch (Exception ex) { }
61+
62+
63+
}
64+
65+
66+
67+
});
2568
Task.Run(async () =>
2669
{
2770
while (true)
2871
{
2972
await Task.Delay(1000);
3073
server.GetTcpStatistics(out SessionStats generalStats, out var a);
3174
server.GetUdpStatistics(out UdpStatistics generalStatsU, out _);
32-
(int left,int right )=Console.GetCursorPosition();
75+
(int left, int right) = Console.GetCursorPosition();
3376
Console.Clear();
34-
Console.WriteLine("Session Count: "+a.Count);
77+
Console.WriteLine("Session Count: " + a.Count);
3578
Console.WriteLine(generalStats.ToString());
3679
Console.WriteLine(generalStatsU.ToString());
37-
if(left != 0 && right != 0)
80+
if (left != 0 && right != 0)
3881
Console.SetCursorPosition(left, right);
3982
}
4083

4184
});
85+
86+
m.WaitOne();
4287
while (Console.ReadLine() != "e")
4388
{
4489

0 commit comments

Comments
 (0)