@@ -17,7 +17,8 @@ internal class Program
1717
1818 static void Main ( string [ ] args )
1919 {
20- MiniLogger . AllLog += ( l ) => Console . WriteLine ( l ) ;
20+ //ThreadPool.SetMinThreads(2000, 2000);
21+ MiniLogger . AllLog += Console . WriteLine ;
2122 RelayTest ( ) ;
2223
2324 Console . ReadLine ( ) ;
@@ -57,25 +58,28 @@ private static void SerializerTest()
5758 sw . Stop ( ) ;
5859 Console . WriteLine ( sw . ElapsedMilliseconds ) ;
5960 }
60- private static void RelayTest ( )
61+ static MessageEnvelope testMessage => new MessageEnvelope ( )
62+ {
63+ Header = "Test" ,
64+ Payload = new byte [ 32 ]
65+ } ;
66+ private static async void RelayTest ( )
6167 {
6268 string ip = "127.0.0.1" ;
63- MessageEnvelope testMessage = new MessageEnvelope ( )
64- {
65- Header = "Test" ,
66- // Payload = new byte[32]
67- } ;
69+
6870
6971 var cert = new X509Certificate2 ( "client.pfx" , "greenpass" ) ;
7072 var scert = new X509Certificate2 ( "server.pfx" , "greenpass" ) ;
7173
72- // var server = new SecureProtoRelayServer(20011, scert);
74+ var server = new SecureProtoRelayServer ( 20011 , scert ) ;
75+
76+ // Task.Run(async () => { while (true) { await Task.Delay(10000); server.GetTcpStatistics(out var generalStats, out _); Console.WriteLine(generalStats.ToString()); } });
77+ Thread . Sleep ( 1000 ) ;
7378 var clients = new ConcurrentBag < RelayClient > ( ) ;
74- //for (int i = 0; i < 200; i++)
7579 int numclients = 20 ;
76- Task [ ] pending = new Task [ numclients ] ;
77- // Parallel.For(0, numclients, (i) =>
78- for ( int i = 0 ; i < numclients ; i ++ )
80+ var pending = new Task [ numclients ] ;
81+ Parallel . For ( 0 , numclients , ( i ) =>
82+ // for (int i = 0; i < numclients; i++)
7983
8084 {
8185 var client = new RelayClient ( cert ) ;
@@ -84,17 +88,18 @@ private static void RelayTest()
8488 //client.OnPeerRegistered+=(id)=> client.RequestHolePunchAsync(id, 10000, false);
8589 try
8690 {
87- pending [ i ] = client . ConnectAsync ( ip , 20011 ) ;
88-
91+ pending [ i ] = client . ConnectAsync ( ip , 20011 ) ;
92+ // client.Connect(ip, 20011);
8993 clients . Add ( client ) ;
90- client . StartPingService ( ) ;
94+ client . StartPingService ( ) ;
9195 }
9296 catch { }
9397
9498 //Thread.Sleep(1000);
9599 }
96- // );
100+ ) ;
97101 Task . WaitAll ( pending ) ;
102+ Console . WriteLine ( "All Connected" ) ;
98103 Thread . Sleep ( 5000 ) ;
99104 int cc = 0 ;
100105 List < Task < bool > > pndg = new List < Task < bool > > ( ) ;
@@ -105,20 +110,21 @@ private static void RelayTest()
105110 // Console.WriteLine("--- -- - | "+client.sessionId+" count: " + client.Peers.Count);
106111 foreach ( var peer in client . Peers )
107112 {
108- if ( client . sessionId > peer . Key )
113+ if ( client . sessionId . CompareTo ( peer . Key ) > 0 )
109114 {
110115 if ( peer . Key == Guid . Empty )
111116 throw new Exception ( ) ;
112117
113118 var a = client . RequestHolePunchAsync ( peer . Key , 10000 , false ) ;
114119 pndg . Add ( a ) ;
115-
120+ //client.TestHP(peer.Key, 10000, false);
116121 // Console.WriteLine(peer.Key+" cnt=> "+ ++cc);
117122 }
118123
119124 }
120125 }
121126 Task . WaitAll ( pndg . ToArray ( ) ) ;
127+ Console . WriteLine ( "all good" ) ;
122128 int kk = 0 ;
123129 foreach ( var item in pndg )
124130 {
@@ -136,6 +142,7 @@ private static void RelayTest()
136142
137143 Task . Run ( async ( ) =>
138144 {
145+ return ;
139146 while ( true )
140147 {
141148 await Task . Delay ( 3000 ) ;
@@ -146,15 +153,20 @@ private static void RelayTest()
146153 Thread . Sleep ( 5000 ) ;
147154 Parallel . ForEach ( clients , ( client ) =>
148155 {
149- for ( int i = 0 ; i < 10 ; i ++ )
156+ var testMessage = new MessageEnvelope ( )
157+ {
158+ Header = "Test" ,
159+ // Payload = new byte[32]
160+ } ;
161+ for ( int i = 0 ; i < 1 ; i ++ )
150162 {
151163 //return;
152164 foreach ( var peer in client . Peers . Keys )
153165 {
154166 //await client.SendRequestAndWaitResponse(peer, testMessage,1000);
155167 //client.SendAsyncMessage(peer, testMessage);
156168
157- // client.SendUdpMesssage(peer, testMessage);
169+ client . SendUdpMesssage ( peer , testMessage ) ;
158170 }
159171 }
160172
@@ -172,7 +184,7 @@ void ClientMsgReceived(RelayClient client, MessageEnvelope reply)
172184
173185 void ClientUdpReceived ( RelayClient client , MessageEnvelope reply )
174186 {
175- Interlocked . Increment ( ref totMsgCl ) ;
187+ // Interlocked.Increment(ref totMsgCl);
176188 client . SendUdpMesssage ( reply . From , reply ) ;
177189
178190 }
0 commit comments